Example #1
0
        /// Evaluates the next action or in case of a
        /// player waits for the user to choose one
        /// and executes it. Shifts the turn list
        /// afterwards to the left
        public void nextTurn()
        {
            if (NextAction != null)
            {
                TurnList.First.Value.AP -= NextAction.APCost;
                NextAction.execute();
            }

            // shift turn list
            if (oldTurns > 0)
            {
                --oldTurns;
            }
            else
            {
                TurnList.AddLast(TurnList.First.Value);
            }
            TurnList.RemoveFirst();
        }
Example #2
0
        /// Adds passed creatures to the battle. Creatures
        /// may occour multiple times in the turn list if
        /// their agility is exceptional high relative
        /// to the other participants
        public void addToBattle(List <Creature> participants)
        {
            if (Participants != null)
            {
                participants = participants
                               .Where(c => !Participants.Contains(c))
                               .ToList();
            }

            participants.ForEach(c => {
                c.IsFighting   = true;
                c.DeathEvent  += onDeath;
                c.DamageEvent += onDamage;
                if (c is Npc)
                {
                    (c as Npc).Pathfinder.Path.Clear();
                }
                if (!c.ContainingMap.BattleMap.Participants.Contains(c))
                {
                    c.ContainingMap.BattleMap.Participants.Add(c);
                }
            });

            if (Participants != null)
            {
                Participants.AddRange(participants);
                oldTurns = TurnList.Count;
            }
            else
            {
                Participants = participants;
                TurnList     = new LinkedList <Creature>();
                oldTurns     = 0;
            }

            int i, n = 1, m = Participants.Count;

            int[] weights = new int[m];

            Participants = Participants
                           .OrderByDescending(c => c.Stats.AGI)
                           .ToList();

            for (i = 0; i < m; ++i)
            {
                weights[i] =
                    n * Participants[i].Stats.AGI
                    / Participants[m - 1].Stats.AGI;
            }

            while (m > 0)
            {
                for (i = 0; i < m; ++i)
                {
                    if (weights[i] > 0)
                    {
                        TurnList.AddLast(Participants[i]);
                        --weights[i];
                    }
                    else
                    {
                        --m;
                    }
                }
            }
        }