/// <summary>
        /// A method for executing a set of actions while the FSM
        /// is in the state.
        /// </summary>
        /// <param name="intelligentCharacter">The AI controller character.</param>
        public void Execute(IIntelligentCharacter intelligentCharacter)
        {
            if (intelligentCharacter == null)
            {
                throw new System.ArgumentException(nameof(intelligentCharacter) + " reference not found.");
            }

            // For right now, this method should only be executed one
            // time. All it needs to do is wait a pre-defined period of
            // time before switching to StateDeciding.
            if (!_executeEntered)
            {
                _executeEntered = true;

                IntelligentCharacter theIntelligentCharacter = (IntelligentCharacter)intelligentCharacter;

                Task strategizing = new Task(simulateStrategizing());

                // Delegate for receiving notifications when the task finished.
                strategizing.Finished += delegate(bool manual)
                {
                    if (manual)
                    {
                        Console.WriteLine("Task was stopped manually.");
                    }
                    else
                    {
                        // Done strategizing. Time to decide what techniques to use.
                        // Change FSM state to the one for deciding what techniques to use.
                        theIntelligentCharacter.MindOfTheFighter.ChangeState(new StateDeciding());
                    }
                };
            }
        }
コード例 #2
0
        /// <summary>
        /// A method for executing a set of actions while the FSM
        /// is in the state.
        /// </summary>
        /// /// <param name="intelligentCharacter">The AI controller character.</param>
        public void Execute(IIntelligentCharacter intelligentCharacter)
        {
            if (intelligentCharacter == null)
            {
                throw new System.ArgumentException("IntelligentCharacter reference not found.");
            }

            // For right now, this method should only be executed one
            // time. All it needs to do is wait a pre-defined period of
            // time before switching to StatePerforming.
            if (!_executeEntered)
            {
                _executeEntered = true;

                IntelligentCharacter theIntelligentCharacter = (IntelligentCharacter)intelligentCharacter;

                Task strategizing = new Task(simulateDeciding());

                // Delegate for receiving notifications when the task finished.
                strategizing.Finished += delegate(bool manual)
                {
                    if (manual)
                    {
                        Console.WriteLine("Task was stopped manually.");
                    }
                    else
                    {
                        // Set the input and the character for the Utility-Based system
                        // and call the method for picking actions for the character to
                        // perform.
                        TacticalMind.Input    = (TacticalMindInput)((FightersMind)_fightersMind).TacticalInput;
                        TacticalMind.Opponent = intelligentCharacter;
                        TacticalMind.PickActions();

                        // Done deciding. Time to perform techniques.
                        // Change FSM state to the one for performing techniques.
                        theIntelligentCharacter.MindOfTheFighter.ChangeState(new StatePerforming(_sceneContext.Container.Resolve <FightManagerBase>(),
                                                                                                 _sceneContext.Container.Resolve <FightStatusManager>(),
                                                                                                 _sceneContext.Container.Resolve <ITechniqueActionPicker>(),
                                                                                                 _sceneContext.Container.ResolveId <ITechniquePerformer>("MainCharacterReceiveHitPerformer")));
                    }
                };
            }
        }
コード例 #3
0
        /// <summary>
        /// A method for executing a set of actions while the FSM
        /// is in the state.
        /// </summary>
        /// <param name="intelligentCharacter">The AI controller character.</param>
        public void Execute(IIntelligentCharacter intelligentCharacter)
        {
            if (intelligentCharacter == null)
            {
                throw new System.ArgumentException("IntelligentCharacter reference not found.");
            }

            IntelligentCharacter theIntelligentCharacter = (IntelligentCharacter)intelligentCharacter;

            if (theIntelligentCharacter.Fighter == null)
            {
                throw new System.ArgumentException("Fighter reference not found.");
            }

            Fighter fighter = (Fighter)theIntelligentCharacter.Fighter;

            if (!fighter.ObservingOpponent)
            {
                // Change FSM state to the one for strategizing.
                theIntelligentCharacter.MindOfTheFighter.ChangeState(new StateStrategizing());
            }
        }
        /// <summary>
        /// A method for executing a set of actions while the FSM
        /// is in the state.
        /// </summary>
        /// <param name="intelligentCharacter">The AI controller character.</param>
        public void Execute(IIntelligentCharacter intelligentCharacter)
        {
            if (intelligentCharacter == null)
            {
                throw new System.ArgumentException(nameof(intelligentCharacter) + " reference not found.");
            }

            // Make sure the method gets called only once.
            if (!_executeEntered)
            {
                _executeEntered = true;

                AnimationManager animationManager = GameObject.Find("ScriptConnector").GetComponent <AnimationManager> ();

                if (animationManager != null)
                {
                    // Set the fighting bounce animation and the active fighter
                    // properties for the opponent.
                    animationManager.FightingBounceAnimation = FIGHTING_BOUNCE_ANIMATION_NAME;
                    IList <FightingAction> fightingActions = _fightManager.FightingActions;

                    Task attacking = new Task(animationManager.PerformFightingActions());

                    // Delegate for receiving notifications when the task finished.
                    attacking.Finished += delegate(bool manual)
                    {
                        if (manual)
                        {
                            Console.WriteLine("Task was stopped manually.");
                        }
                        else
                        {
                            Task turnSwitchDelayTask = new Task(turnSwitchDelay());

                            // Delegate for receiving notifications when the task finished.
                            turnSwitchDelayTask.Finished += delegate(bool manualStop)
                            {
                                if (manual)
                                {
                                    Console.WriteLine("Task was stopped manually.");
                                }
                                else
                                {
                                    // Update the status of the fight. It includes the damage
                                    // incured to various body parts on each of the opponents
                                    // bodies, the mental and physical conditions of of both
                                    // fighters, and so on.
                                    _fightStatusManager.UpdateStatus();
                                    IntelligentCharacter theIntelligentCharacter = (IntelligentCharacter)intelligentCharacter;

                                    if (theIntelligentCharacter.Fighter == null)
                                    {
                                        throw new System.ArgumentException(nameof(theIntelligentCharacter.Fighter) + " reference not found.");
                                    }

                                    Fighter fighter = (Fighter)theIntelligentCharacter.Fighter;
                                    fighter.ObservingOpponent = true;

                                    _fightManager.SetNextTurn();

                                    // Change FSM state to the one for observing the opponent.
                                    theIntelligentCharacter.MindOfTheFighter.ChangeState(new StateObserving());

                                    IList <TechniqueAction> receiveHitActions = _techniqueActionPicker.PickActions(fightingActions);
                                    _techniquePerformer.PerformTechniques(receiveHitActions);
                                }
                            }; // End Finished
                        }      // End else
                    };
                }              // End if
            }
        }