예제 #1
0
    public void UpdateTimeline()
    {
        TurnOrder.Clear();
        //add every character once and sort them
        foreach (GameObject character in player1.GetComponent <Player>().Characters)
        {
            LivingPlaceable   placeable    = character.GetComponent <LivingPlaceable>();
            StackAndPlaceable newCharacter = new StackAndPlaceable(placeable, placeable.SpeedStack, false);
            TurnOrder.Add(newCharacter);
        }
        foreach (GameObject character in player2.GetComponent <Player>().Characters)
        {
            LivingPlaceable   placeable    = character.GetComponent <LivingPlaceable>();
            StackAndPlaceable newCharacter = new StackAndPlaceable(placeable, placeable.SpeedStack, false);
            TurnOrder.Add(newCharacter);
        }
        TurnOrder.Sort((x, y) => x.SpeedStack == y.SpeedStack ? 1 : (int)((x.SpeedStack - y.SpeedStack) / (Mathf.Abs(x.SpeedStack - y.SpeedStack))));

        //Check for every Character if it has to play more than once in the "Grand Turn"

        int numberOfTurns = 1;

        for (int i = 0; i < turnOrder.Count - 1; i++)
        {
            StackAndPlaceable check = turnOrder[i];
            if (!check.SeenBefore)
            {
                for (int j = i + 1; j < turnOrder.Count - 1; j++)
                {
                    float compare = check.SpeedStack + ((numberOfTurns * (j - i)) / check.Character.Speed);
                    if (turnOrder[j].SpeedStack > compare)
                    {
                        turnOrder.Insert(j, new StackAndPlaceable(check.Character, check.SpeedStack + numberOfTurns * (j - i) / check.Character.Speed, true));
                        j++;
                    }
                }
            }
            check.SeenBefore = true;
        }
    }
예제 #2
0
 /// <summary>
 /// Adds the given actor to the turn order.
 /// </summary>
 public void Add(ITurnBased actor)
 {
     turnOrder.Add(actor);
 }