示例#1
0
    public PlayerOwnedObject GetNextUnitInTurnQueue(TurningUnitInfo turningUnit, out int turnIndex)
    {
        var aliveUnits = TurningPlayer.Entity.OwnedObjects
                         .Where(obj => HealthComponent.IsAliveOrHasNoHealthComponent(obj.gameObject));

        return(turningUnit.GetNextObjectInQueue(aliveUnits, out turnIndex));
    }
示例#2
0
    public void TransferControlToNextPlayer()
    {
        if (PauseHealthChangesDuringTurn)
        {
            HealthComponent.PauseChangesForAll();
        }

        if (TurningPlayer.Entity != null)
        {
            TurningPlayer.Entity.ReleaseUserControl();
        }

        Player firstPickedPlayer = null;
        Player currentPlayer;
        bool   firstRound = true;

        do
        {
            currentPlayer = TurningPlayer.Entity = GetNextPlayerInTurnQueue(out TurningPlayer.TurnIndex);

            if (currentPlayer == null)
            {
                return;
            }

            if (firstPickedPlayer == null)
            {
                firstPickedPlayer = currentPlayer;
            }
            else
            {
                firstRound = false;
            }

            TurningUnitInfo turningUnit;

            if (!turningUnitsByPlayer.TryGetValue(currentPlayer, out turningUnit))
            {
                turningUnit = new TurningUnitInfo();
                turningUnitsByPlayer [currentPlayer] = turningUnit;
            }

            var currentUnit = turningUnit.Entity = GetNextUnitInTurnQueue(turningUnit, out turningUnit.TurnIndex);

            if (currentUnit != null)
            {
                InputReceiverSwitch.SetReceiveInput(currentUnit.gameObject, true);
                currentUnit.BroadcastMessage(OnPrepareToStartTurnMessagName, SendMessageOptions.DontRequireReceiver);

                return;
            }
        } while (firstRound || currentPlayer != firstPickedPlayer);

        // If this line was reached then there were no "turnable" units.
    }