/// <summary>
        /// Choose which defensive action to perform.
        /// </summary>
        /// <returns>The chosen action, or null if no action is desired.</returns>
        private CombatAction ChooseDefensiveAction()
        {
            List <CombatantMonster> monsters = CombatEngine.Monsters;

            // be sure that there is a valid combat in progress
            if ((monsters == null) || (monsters.Count <= 0))
            {
                return(null);
            }

            // find the monster with the least health
            CombatantMonster target = null;
            int leastHealthAmount   = Int32.MaxValue;

            foreach (CombatantMonster targetMonster in monsters)
            {
                // skip dead or dying targets
                if (targetMonster.IsDeadOrDying)
                {
                    continue;
                }
                // if the monster is damaged and it has the least health points,
                // then it becomes the new target
                StatisticsValue maxStatistics =
                    targetMonster.Monster.CharacterClass.GetStatisticsForLevel(
                        targetMonster.Monster.CharacterLevel);
                int targetMonsterHealthPoints = targetMonster.Statistics.HealthPoints;
                if ((targetMonsterHealthPoints < maxStatistics.HealthPoints) &&
                    (targetMonsterHealthPoints < leastHealthAmount))
                {
                    target            = targetMonster;
                    leastHealthAmount = targetMonsterHealthPoints;
                }
            }

            // if there is no target, then don't do anything
            if (target == null)
            {
                return(null);
            }

            // the action lists are sorted by descending potential,
            // so find the first eligible action
            foreach (CombatAction action in defensiveActions)
            {
                // check the restrictions on the action
                if (action.IsCharacterValidUser)
                {
                    action.Target = target;
                    return(action);
                }
            }

            // no eligible actions found
            return(null);
        }
示例#2
0
        /// <summary>
        /// Construct a new ArtificialIntelligence object to control a given combatant.
        /// </summary>
        public ArtificialIntelligence(CombatantMonster monster)
        {
            // check the parameter
            if (monster == null)
            {
                throw new ArgumentNullException("monster");
            }

            // assign the parameter
            this.monster = monster;

            // generate all actions available
            GenerateAllActions();
        }
        /// <summary>
        /// Construct a new ArtificialIntelligence object to control a given combatant.
        /// </summary>
        public ArtificialIntelligence(CombatantMonster monster)
        {
            // check the parameter
            if (monster == null)
            {
                throw new ArgumentNullException("monster");
            }

            // assign the parameter
            this.monster = monster;

            // generate all actions available
            GenerateAllActions();
        }
示例#4
0
        /// <summary>
        /// Start the given player's combat turn.
        /// </summary>
        private void BeginMonsterTurn(CombatantMonster monster)
        {
            // if it's null, find a random living monster who has yet to take their turn
            if (monster == null)
            {
                // don't bother if all monsters have finished
                if (IsMonstersTurnComplete)
                {
                    return;
                }
                // pick random living monsters who haven't taken their turn
                do
                {
                    monster = monsters[Session.Random.Next(monsters.Count)];
                }
                while (monster.IsTurnTaken || monster.IsDeadOrDying);
            }

            // set the highlight sprite
            highlightedCombatant = monster;
            primaryTargetedCombatant = null;
            secondaryTargetedCombatants.Clear();

            // choose the action immediate
            monster.CombatAction = monster.ArtificialIntelligence.ChooseAction();
        }