Ejemplo n.º 1
0
    /*==================================================================
    *  ACTION
    * ================================================================*/

    public void ShowAction(int index)
    {
        if (!SelectAction(index))
        {
            return;
        }

        mapManager.Mark(selectedUnit.unit.position, Marking.Orange);

        Marking mark = 0;

        if (action.type == ActionType.Attack)
        {
            mark = Marking.Red;
        }
        else if (action.type == ActionType.Buff)
        {
            mark = Marking.Purple;
        }

        mapManager.RemoveMarkings();
        foreach (TargetTile targetTile in targets)
        {
            Marking m = mark;
            if (targetTile.type == TargetType.NotValid)
            {
                m = Marking.Orange;
            }
            mapManager.Mark(targetTile.point, m);
        }
    }
Ejemplo n.º 2
0
    public IEnumerator NewRound(CombatMap map, bool firstRound = false)
    {
        Debug.Log(unit.position + " start");
        isActive = true;

        spriteRenderer.material.color = Color.yellow;
        map.RemoveMarkings();

        if (!firstRound)
        {
            if (unit.hasActionLeft)
            {
                Action            action  = unit.actions[0];
                List <TargetTile> targets = action?.GetTargets(map, false);
                if (targets != null && action.CanUse() && action.GetTargets(map, false).Count > 0)
                {
                    map.Mark(unit.position, Marking.Orange);
                    map.Mark(targets[0].point, Marking.Red);
                    yield return(new WaitForSeconds(.25f));

                    map.unitManager.PerformAction(this, action, targets[0].point);
                    yield return(new WaitForSeconds(.75f));

                    map.RemoveMarkings();
                }
                else if (unit.energy < unit.maxEnergy)
                {
                    Effect(Attribute.Energy, 1);
                    yield return(new WaitForSeconds(.5f));
                }
            }
        }
        spriteRenderer.material.color = Color.white;
        bool triggered = unit.NewRound(map, firstRound);

        if (triggered)
        {
            yield return(new WaitForSeconds(.5f));
        }
        Debug.Log(unit.position + " done");
        isActive = false;
    }
Ejemplo n.º 3
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();
            }
        }
    }