Esempio n. 1
0
    void OnNextTurn()
    {
        for (int i = 0; i < activeUnitAbilityEffectList.Count; i++)
        {
            UnitAbility uAB = activeUnitAbilityEffectList[i];
            uAB.countTillNextTurn -= 1;
            if (uAB.countTillNextTurn == 0)
            {
                if (GameControlTB.GetTurnMode() == _TurnMode.FactionAllUnitPerTurn)
                {
                    uAB.countTillNextTurn = UnitControl.activeFactionCount;
                }
                else
                {
                    uAB.countTillNextTurn = UnitControl.GetAllUnitCount();
                }

                bool flag = CalulateEffect(uAB);

                //false means no more effect active for the ability, remove the ability
                if (!flag)
                {
                    activeUnitAbilityEffectList.RemoveAt(i);
                    i -= 1;

                    //if not more ability, stop listening to any event
                    if (activeUnitAbilityEffectList.Count == 0)
                    {
                        UnsubscribeEvent();
                    }
                }
            }
        }

        //apply the effect, this is placed here so it only runs when there are active effect
        countTillNextTurn -= 1;
        if (countTillNextTurn == 0)
        {
            //apply the effect on unit
            if (unit != null)
            {
                if (HPGainModifier > 0)
                {
                    unit.ApplyHeal(HPGainModifier);
                }
                else if (HPGainModifier < 0)
                {
                    unit.ApplyDamage(HPGainModifier);
                }
                if (APGainModifier != 0)
                {
                    unit.GainAP(APGainModifier);
                }
            }

            if (GameControlTB.GetTurnMode() == _TurnMode.FactionAllUnitPerTurn)
            {
                countTillNextTurn = UnitControl.activeFactionCount;
            }
            else
            {
                countTillNextTurn = UnitControl.GetAllUnitCount();
            }
        }
    }