protected override void DoAction(AgentAction action) { if (action == null) { return; } if (CurState.HandleSameAction(action) == true) { return; } FsmState preState = CurState; if (action is AgentActionGoTo) { CurState = GetState((int)FsmStateType.GOTO_POS); } else if (action is AgentActionCombatMove) { CurState = GetState((int)FsmStateType.COMBAT_MOVE); } else if (action is AgentActionAttackMelee) { CurState = GetState((int)FsmStateType.ATTACK_MELEE); } else if (action is AgentActionInjury) { CurState = GetState((int)FsmStateType.INJURY); } else if (action is AgentActionDeath) { CurState = GetState((int)FsmStateType.DEATH); } else if (action is AgentActionKnockdown) { CurState = GetState((int)FsmStateType.KNOCKDOWN); } else if (action is AgentActionBlock) { CurState = GetState((int)FsmStateType.BLOCK); } preState.Exit(); CurState.Enter(action); }
protected override void DoAction(AgentAction action) { FsmState preState = CurState; // ------------------------------ 无要执行的action ------------------------------ if (action == null) { //if (_blackBoard.curAction != null && _blackBoard.curAction.Type == AgentAction.ActionType.MOVE) if ((_blackBoard.curAction as AgentActionMove) != null) { CurState = GetState((int)FsmStateType.IDLE); // 转入idle状态 preState.Exit(); CurState.Enter(action); } return; } // ------------------------------ 有要执行的action ------------------------------ // 执行同样行为 /*if (_blackBoard.curAction != null && _blackBoard.curAction.Type == action.Type) * { * CurState.HandleSameAction(action); * return; * }*/ if (CurState.HandleSameAction(action)) { return; } //if (action.Type == AgentAction.ActionType.DEATH) if (action as AgentActionDeath != null) { CurState = GetState((int)FsmStateType.DEATH); } //else if (action.Type == AgentAction.ActionType.INJURY && _blackBoard.curAction.Type != AgentAction.ActionType.DEATH) else if (action as AgentActionInjury != null && _blackBoard.curAction as AgentActionDeath == null) { CurState = GetState((int)FsmStateType.INJURY); } else if (_blackBoard.curAction == null) // 当前是idle状态 { switch (action.Type) { case AgentActionType.MOVE: CurState = GetState((int)FsmStateType.MOVE); break; case AgentActionType.ROLL: CurState = GetState((int)FsmStateType.ROLL); break; case AgentActionType.ATTACK_MELEE: CurState = GetState((int)FsmStateType.ATTACK_MELEE); break; default: return; } } //else if (_blackBoard.curAction.Type == AgentAction.ActionType.MOVE) else if (_blackBoard.curAction as AgentActionMove != null) // 当前是move状态 { switch (action.Type) { case AgentActionType.ROLL: CurState = GetState((int)FsmStateType.ROLL); break; case AgentActionType.ATTACK_MELEE: CurState = GetState((int)FsmStateType.ATTACK_MELEE); break; default: return; } } else if (_blackBoard.curAction.Type == AgentActionType.ATTACK_MELEE) // 当前是attack状态 { switch (action.Type) { case AgentActionType.ROLL: CurState = GetState((int)FsmStateType.ROLL); break; default: return; } } else { return; } preState.Exit(); CurState.Enter(action); /*FsmState preState = CurState; * if (action == null && _blackBoard.curAction != null && _blackBoard.curAction.Type == AgentAction.ActionType.MOVE) * { * CurState = GetState((int)FsmStateType.IDLE); * return; * } * else if (action == null) * { * return; * } * else if (_blackBoard.curAction != null && _blackBoard.curAction.Type == action.Type) * { * CurState.HandleSameAction(action); * return; * } * else if (action.Type == AgentAction.ActionType.DEATH) * { * CurState = GetState((int)FsmStateType.DEATH); * } * else if (action.Type == AgentAction.ActionType.INJURY && _blackBoard.curAction.Type != AgentAction.ActionType.DEATH) * { * CurState = GetState((int)FsmStateType.INJURY); * } * else if (CurState == DefState) // 当前是idle状态 * { * switch (action.Type) * { * case AgentAction.ActionType.MOVE: * CurState = GetState((int)FsmStateType.MOVE); * break; * case AgentAction.ActionType.ROLL: * CurState = GetState((int)FsmStateType.ROLL); * break; * case AgentAction.ActionType.ATTACK_MELEE: * CurState = GetState((int)FsmStateType.ATTACK_MELEE); * break; * default: * return; * } * } * else * { * return; * } * * preState.Exit(); * CurState.Enter(action);*/ }