WhiteEngine-专注图形渲染与游戏引擎技术的网站

新浪微薄腾讯微薄

最新碎语:暂无碎语

您的位置:WhiteEngine-专注图形渲染与游戏引擎技术的网站 >引擎相关> 复合状态机

复合状态机

//限制类状态
public enum OBJ_STATE
{
BASE = 0, //基本状态
MOVING = 2, //移动状态
FASTMOVE = 4, //快速移动状态
CHENGMO = 8, //沉默
BINGDONG = 16, //冰冻
XUANYUN = 32, //眩晕
WUDI = 64, //无敌
MIANYI = 128, //免疫
KANGCHAOFENG = 256, //抗嘲讽
JIAOXIE = 512, //缴械
YINGSHENG = 1024, //隐身
CHAOFENG = 2048, //嘲讽
DINGSHENG = 4096, //定身
HUNSHUI = 8192, //昏睡

}


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Common;

namespace Manager
{

	public class CStateControler {

		private int currState = 0;
		public int CurrState
		{
			get{return currState;}
		}

		private CObjectCharacter character;

		public CStateControler(CObjectCharacter c)
		{
			character = c;
		}

		private void ReSetCStateControler()
		{
			currState = 0;
		}

		public void InitCStateControler()
		{
			ReSetCStateControler ();
		}

		public void RecoverCStateControler()
		{
			ReSetCStateControler ();
		}

		public bool CheckHaveState(CommonEnum.OBJ_STATE state)
		{
			if(currState & state == state)
			{
				return true;
			}
			return false;
		}

		public void AddState(CommonEnum.OBJ_STATE state)
		{
			if(!CheckHaveState(state))
			{
				currState = currState | state;
			}
		}

		public void RemoveState(CommonEnum.OBJ_STATE state)
		{
			if(CheckHaveState(state))
			{
				currState = currState ^ state;
			}
		}

		//用于重置状态到某个状态使用,比如重生恢复默认状态,或某个状态
		public void SetState(CommonEnum.OBJ_STATE state)
		{
			currState = state;
		}

		public bool CanMove()
		{
			bool ret = true;
			ret += !CheckHaveState (CommonEnum.OBJ_STATE.FASTMOVE);
			ret += !CheckHaveState (CommonEnum.OBJ_STATE.BINGDONG);
			ret += !CheckHaveState (CommonEnum.OBJ_STATE.XUANYUN);
			ret += !CheckHaveState (CommonEnum.OBJ_STATE.DINGSHENG);
			ret += !CheckHaveState (CommonEnum.OBJ_STATE.HUNSHUI);
			return ret;
		}

		public void CanUseSkill()
		{
			bool ret = true;
			ret += !CheckHaveState (CommonEnum.OBJ_STATE.FASTMOVE);
			ret += !CheckHaveState (CommonEnum.OBJ_STATE.CHENGMO);
			ret += !CheckHaveState (CommonEnum.OBJ_STATE.BINGDONG);
			ret += !CheckHaveState (CommonEnum.OBJ_STATE.XUANYUN);
			ret += !CheckHaveState (CommonEnum.OBJ_STATE.JIAOXIE);
			ret += !CheckHaveState (CommonEnum.OBJ_STATE.HUNSHUI);
			return ret;
		}
	}
}

---

转载请注明本文标题和链接:《复合状态机

分享到:

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交