Exemplo n.º 1
0
        /// <summary>
        /// Gets a List of ids from the current and next turns.
        /// </summary>
        /// <returns></returns>
        public IReadOnlyList <int>[] GetRoundOrderIds()
        {
            var displayCharacters = new List <int> [2];

            displayCharacters[0] = new List <int>(CurrentRoundOrder.Select(chara => chara.Id));
            displayCharacters[1] = new List <int>(NextRoundOrder.Select(chara => chara.Id));
            return(displayCharacters);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Makes a character wait until the end of the round to act.
 /// </summary>
 /// <param name="character">The character that is waiting.</param>
 internal void BeginWait(Character character)
 {
     CurrentRoundOrder.Add(character);
     if (!_anyWaitingCharacters)
     {
         _anyWaitingCharacters   = true;
         _waitingCharactersIndex = CurrentRoundOrder.Count() - 1;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Potentially changes the round order of a round if a character has it's speed changed.
        /// </summary>
        /// <param name="characterId">The Id of the character whose speed changed.</param>
        /// <param name="RoundOrder">The round order list to change the order of.</param>
        /// <param name="speedChange">The amount that the character's speed is changed by.</param>
        private void ChangeRoundOrder(int characterId, List <Character> RoundOrder, int speedChange)
        {
            int startIndex = CurrentRoundOrder.FindIndex(chr => chr.Id == characterId);

            if (speedChange > 0)
            {
                bool foundMaxDisplacement = false;
                // Can never surpass current turn character
                while (startIndex > 1 && !foundMaxDisplacement)
                {
                    if (RoundOrder[startIndex - 1].CurrentStats.Speed < RoundOrder[startIndex].CurrentStats.Speed)
                    {
                        Character temp = RoundOrder[startIndex - 1];
                        RoundOrder[startIndex - 1] = RoundOrder[startIndex];
                        RoundOrder[startIndex]     = temp;
                        startIndex--;
                    }
                    else
                    {
                        foundMaxDisplacement = true;
                    }
                }
            }
            else if (speedChange < 0)
            {
                // If there are any waiting characters, can't be slower than them
                int maxIndex = (_anyWaitingCharacters) ? _waitingCharactersIndex - 1 : RoundOrder.Count() - 1;

                // Character is already the last to act in the round, can't be slower than anyone else
                if (startIndex >= maxIndex)
                {
                    return;
                }

                bool foundMaxDisplacement = false;
                while (startIndex < maxIndex && !foundMaxDisplacement)
                {
                    if (RoundOrder[startIndex + 1].CurrentStats.Speed > RoundOrder[startIndex].CurrentStats.Speed)
                    {
                        Character temp = RoundOrder[startIndex + 1];
                        RoundOrder[startIndex + 1] = RoundOrder[startIndex];
                        RoundOrder[startIndex]     = temp;
                        startIndex++;
                    }
                    else
                    {
                        foundMaxDisplacement = true;
                    }
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Called whenever a character's turn has ended. Removes that character from the current round order.
 /// </summary>
 internal void EndTurn()
 {
     // If this is the last turn of the round, start the next round and prepare the round after
     if (CurrentRoundOrder.Count == 1)
     {
         CurrentRoundOrder       = new List <Character>(NextRoundOrder);
         NextRoundOrder          = DetermineTurnOrder();
         _anyWaitingCharacters   = false;
         _waitingCharactersIndex = -1;
     }
     // Remove the current turn from the round order list
     else
     {
         var indecesToCull = new List <int>();
         int maxIndex      = CurrentRoundOrder.Count - 1;
         if (_waitingCharactersIndex > 0 && _anyWaitingCharacters)
         {
             _waitingCharactersIndex--;
         }
         Character charToMove = null;
         for (int i = maxIndex; i >= 0; i--)
         {
             var temp = charToMove;
             charToMove           = CurrentRoundOrder[i];
             CurrentRoundOrder[i] = temp;
             if (CurrentRoundOrder[i] == null || CurrentRoundOrder[i].CurrentHealth <= 0)
             {
                 indecesToCull.Add(i);
             }
         }
         foreach (var index in indecesToCull)
         {
             CurrentRoundOrder.RemoveAt(index);
         }
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Called whenever a character has died. Removes that character from the current and next rounds.
 /// </summary>
 /// <param name="args"></param>
 internal void CharactersDied(CharactersDiedEventArgs args)
 {
     CurrentRoundOrder.RemoveAll(character => args.DyingCharacters.Contains(character));
     NextRoundOrder.RemoveAll(character => args.DyingCharacters.Contains(character));
 }