private void BuildPatrolState(State inTargetState, NpcController inNpcController, NpcDataHolder inNpcData, State inIdleState, State inAttackState, State inDieState) { // -------------------------------------------------------------------------------- // 1- Setup Actions // -------------------------------------------------------------------------------- var patrolAction = new PatrolAction(inNpcController, inNpcData.patrolRange, inNpcData.patrolDuration); // -------------------------------------------------------------------------------- // 2- Setup decisions // -------------------------------------------------------------------------------- var attackDecision = new AttackDecision(inNpcController); var idleDecision = new IdleDecision(patrolAction); var dieDecision = new DieDecision(inNpcController.gameView as IDestructible); // -------------------------------------------------------------------------------- // 3- Setup Transitions // -------------------------------------------------------------------------------- var transitionToAttack = new Transition() { hasFalseState = false, decision = attackDecision, trueState = inAttackState }; var transitionToIdle = new Transition() { hasFalseState = false, decision = idleDecision, trueState = inIdleState }; var transitionToDie = new Transition() { hasFalseState = false, decision = dieDecision, trueState = inDieState }; // -------------------------------------------------------------------------------- // 4- Define State // -------------------------------------------------------------------------------- inTargetState.Define( Color.cyan, new Action[] { patrolAction }, new [] { transitionToDie, transitionToAttack, transitionToIdle } ); }
private void BuildAttackState(State inTargetState, NpcController inNpcController, NpcDataHolder inNpcData, State inPatrolState, State inDieState) { // -------------------------------------------------------------------------------- // 1- Setup Actions // -------------------------------------------------------------------------------- var attackAction = new AttackAction(inNpcController, inNpcData.profile.fireRate); // -------------------------------------------------------------------------------- // 2- Setup decisions // -------------------------------------------------------------------------------- var attackToPatrolDecision = new AttackToPatrolDecision(inNpcController); var dieDecision = new DieDecision(inNpcController.gameView as IDestructible); // -------------------------------------------------------------------------------- // 3- Setup Transitions // -------------------------------------------------------------------------------- var transitionToPatrol = new Transition() { hasFalseState = false, decision = attackToPatrolDecision, trueState = inPatrolState }; var transitionToDie = new Transition() { hasFalseState = false, decision = dieDecision, trueState = inDieState }; // -------------------------------------------------------------------------------- // 4- Define State // -------------------------------------------------------------------------------- inTargetState.Define( Color.red, new Action[] { attackAction }, new [] { transitionToDie, transitionToPatrol } ); }