예제 #1
0
    // Selected unit has completed it's turn
    public void EndTurn(bool skip = false)
    {
        // Hide inspectors and markings
        combatUI.HideUnitInspector(true);
        combatUI.HideHint();
        mapManager.RemoveMarkings();

        if (state == CombatState.end)
        {
            return;
        }

        // Wait for animations to complete
        if (state != CombatState.endTurn)
        {
            state         = CombatState.endTurn;
            playerControl = false;
            return;
        }

        // Consume crystal and end unit's turn
        if (!skip)
        {
            combatUI.UseCrystal(faction == Faction.Player);
            if (faction == Faction.Player)
            {
                armyCrystalsLeft--;
            }
            else
            {
                monsterCrystalLeft--;
            }
            unitManager.EndTurn();
        }

        // Save
        if (faction == Faction.Monster)
        {
            GameData.instance.data.combat = ToString();
            SaveManager.Save(GameData.instance);
        }

        // Next armys turn
        int other         = unitManager.ActiveUnits(faction);
        int otherCrystals = faction == Faction.Player ? armyCrystalsLeft : monsterCrystalLeft;

        faction = faction == Faction.Player ? Faction.Monster : Faction.Player;

        int current         = unitManager.ActiveUnits(faction);
        int currentCrystals = faction == Faction.Player ? armyCrystalsLeft : monsterCrystalLeft;

        // No active units left or out of crystals
        if (current == 0 || currentCrystals == 0)
        {
            // Neither army has any active units left or out of crystals
            if (other == 0 || otherCrystals == 0)
            {
                StartCoroutine(NewRound());
            }

            // Give turn to other army
            else
            {
                EndTurn(true);
            }
        }
        // Perform turn
        else
        {
            // Player turn
            if (faction == Faction.Player)
            {
                combatUI.SetHint("Select unit");
                state         = CombatState.ready;
                playerControl = true;
                StartTurn(Faction.Player);
            }

            // Enemy turn
            else
            {
                state         = CombatState.ai;
                playerControl = false;
                ai.PerformTurn();
            }
        }
    }