Ejemplo n.º 1
0
        public void SpawnEnemies()
        {
            while (enemyUnitsParent.transform.childCount < loadedLevel.EnemiesOnField && enemyQueue.childCount > 0)
            {
                Transform enemy = enemyQueue.GetChild(0);
                enemy.SetParent(enemyUnitsParent.transform);
                UnitLogic logic = enemy.GetComponent <UnitLogic>();
                enemyUnitsParent.NewChilder(logic);
                if (logic.unitObject.FirstLinePriority && logic.position.y == 0)
                {
                    EnemyControll.enemyControll.PositionReload(logic);
                }
                else if (logic.unitObject.IsRangeUnit && logic.position.y > 0)
                {
                    EnemyControll.enemyControll.PositionReload(logic);
                }

                enemy.gameObject.SetActive(true);
            }
            if (enemyUnitsParent.transform.childCount == 0 && enemyQueue.childCount == 0)
            {
                winPanel.SetActive(true);
            }
            EnemyControll.enemyControll.NeedRefreshPos = true;
        }
Ejemplo n.º 2
0
        public void ShowUnitEffects(UnitLogic unit)
        {
            for (int i = 0; i < emEffects.childCount; i++)
            {
                Destroy(emEffects.GetChild(i).gameObject);
            }

            foreach (Effect effect in unit.unitlogic.unitEffects)
            {
                if (effect.Duration == 0)
                {
                    continue;
                }
                GameObject obj = Instantiate <GameObject>(effectPrefab, emEffects);
                if (effect.effectStacking != EffectStacking.Stack)
                {
                    obj.GetComponentInChildren <Text>().text = effect.Duration.ToString();
                }
                else
                {
                    obj.GetComponentInChildren <Text>().text = effect.stacks.ToString();
                }

                obj.GetComponent <Image>().sprite = (effect.VisualEffect == null || effect.VisualEffect.Img == null) ? effect.spell.uImage.img : effect.VisualEffect.Img;
            }
        }
Ejemplo n.º 3
0
        public void Summon(UnitObject unitObject)
        {
            UnitLogic unit = SpawnPerson(unitObject);

            unit.gameObject.SetActive(true);
            enemyUnitsParent.NewChilder(unit);
            unit.unitlogic.unitImage.GetComponent <ImageMove>().Setup();
        }
Ejemplo n.º 4
0
        private UnitLogic SpawnPerson(UnitObject unitObject)
        {
            UnitLogic enemy = Instantiate <UnitLogic>(enemyPrefab, enemyQueue);

            enemy.unitObject = unitObject;
            enemy.transform.GetChild(0).position = new Vector3(Screen.width + enemy.GetComponent <RectTransform>().sizeDelta.x * 2, enemy.transform.position.y, 0);
            enemy.gameObject.SetActive(false);
            enemy.ReloadNameTag();
            enemy.InitLogic();

            return(enemy);
        }
Ejemplo n.º 5
0
        public void UnitInfoShow(UnitLogic unit)
        {
            enemyInfo.SetActive(true);

            unitInfo         = unit;
            enemyHp.maxValue = unit.unitObject.unitProperty.Hp;
            enemyHp.value    = unit.unitlogic.Hp;
            enemyHp.GetComponentInChildren <Text>().text = System.Math.Round(unit.unitlogic.Hp, 1) + "/" + unit.unitObject.unitProperty.Hp;
            enemyAvatar.sprite = unit.unitObject.ico.img;
            enemyAvatar.GetComponent <RectTransform>().localScale = (unit.unitObject.ico.size == Vector2.zero) ? Vector2.one : unit.unitObject.ico.size;
            enemyAvatar.GetComponent <RectTransform>().pivot      = (unit.unitObject.ico.pos == Vector2.zero) ? Vector2.one / 2 : unit.unitObject.ico.pos;
            nameTag.text = unit.UnitName;
            ShowUnitEffects(unit);
        }
Ejemplo n.º 6
0
        public bool CanAttack(Unit unit)
        {
            if (transform == null)
            {
                return(false);
            }
            UnitLogic lg = transform.GetComponent <UnitLogic>();

            if (lg != null)
            {
                if (lg.unitlogic.UnitAction >= 0)
                {
                    if (lg.position.y > 0 || unitObject.IsRangeUnit || !HasBlocked(unit))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
        public void NewChilder(UnitLogic unitLogic)
        {
            for (int y = units.GetLength(1) - 1; y >= 0; y--)
            {
                for (int x = 0; x < units.GetLength(0); x++)
                {
                    if (units[x, y] == null)
                    {
                        vc = new Vector2Int(x, y);

                        if (y > 0 && unitLogic.unitObject.IsRangeUnit && BattleControll.battleControll.EnemyLines > 1)
                        {
                            continue;
                        }
                        if (y == 0 && !unitLogic.unitObject.IsRangeUnit && BattleControll.battleControll.EnemyLines > 1)
                        {
                            continue;
                        }

                        if (unitLogic != null)
                        {
                            units[x, y] = unitLogic;
                            units[x, y].SetPosition(new Vector2Int(x, y), GetPosition(x, y));
                            if (y == 0)
                            {
                                unitLogic.transform.SetAsFirstSibling();
                            }
                            else
                            {
                                unitLogic.transform.SetAsLastSibling();
                            }
                            return;
                        }
                    }
                }
            }
            units[vc.x, vc.y] = unitLogic;
            units[vc.x, vc.y].SetPosition(new Vector2Int(vc.x, vc.y), GetPosition(vc.x, vc.y));
            EnemyControll.enemyControll.NeedRefreshPos = true;
        }
Ejemplo n.º 8
0
        private IEnumerator enumerator(UnitLogic unit, UnitLogic swapUnit, Vector2Int myPos, Vector2Int newPos)
        {
            yield return(new WaitForEndOfFrame());

            if (myPos.y == 0)
            {
                swapUnit.transform.SetAsFirstSibling();
            }
            else
            {
                swapUnit.transform.SetAsLastSibling();
            }

            if (newPos.y == 0)
            {
                unit.transform.SetAsFirstSibling();
            }
            else
            {
                unit.transform.SetAsLastSibling();
            }
        }
Ejemplo n.º 9
0
        public void GoToFirstLine()
        {
            if (BattleControll.battleControll.EnemyLines <= 1)
            {
                return;
            }
            UnitLogic[,] units = BattleControll.battleControll.enemyUnitsParent.units;

            int y = units.GetLength(1) - 1;

            for (int x = 0; x < units.GetLength(0); x++)
            {
                if (units[x, y] == null)
                {
                    UnitLogic logic = null;
                    for (int q = 0; q < units.GetLength(0); q++)
                    {
                        if (!units[q, 0].unitObject.IsRangeUnit)
                        {
                            if (logic == null || units[q, 0].unitlogic.Hp > logic.unitlogic.Hp || units[q, 0].unitlogic.Hp == logic.unitlogic.Hp && Mathf.Abs(x - q) < Math.Abs(x - logic.position.x))
                            {
                                logic = units[q, 0];
                            }
                        }
                    }
                    if (logic != null)
                    {
                        Vector3 pos = BattleControll.battleControll.enemyUnitsParent.GetPosition(x, y);

                        logic.SetPosition(new Vector2Int(x, y), pos);

                        BattleControll.battleControll.enemyUnitsParent.units[logic.position.x, logic.position.y] = null;
                        BattleControll.battleControll.enemyUnitsParent.units[x, y] = logic;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void TakeImpact(Impact impact, Logic unitLogic, string property = "Hp")
        {
            if (transform == null || Hp <= 0)
            {
                return;
            }
            Helper.lstDamagedEnemy = this;
            float damage = 0;

            bool[] Avoided = new bool[Resources.Load <Transform>(GameManager.DamageIndicator[unitLogic.attackType != null ? unitLogic.attackType.damageIndicator : 0]).GetComponentsInChildren <Text>().Length];

            if (property != null && property.Length > 0)
            {
                if (property == "Hp")
                {
                    for (int i = 0; i < Avoided.Length; i++)
                    {
                        if (impact.value > 0)
                        {
                            if (Randomize.Random(MissChanse(unitLogic)))
                            {
                                Avoided[i] = true;
                            }
                        }

                        if (!Avoided[i])
                        {
                            if (!impact.isProcent)
                            {
                                damage = impact.value;
                            }
                            else
                            {
                                damage = (float)Math.Round(Hp / 100 * impact.value, 1);
                            }

                            damage /= Avoided.Length;
                            damage -= unitProperty.DamageResist;
                            if (unitProperty.Armor != 0)
                            {
                                BattleConstants.CalculateArmor(ref damage, unitProperty.Armor);
                            }
                            UnitProperty enemyProperty = unitLogic.unitProperty;

                            if (Randomize.Random(enemyProperty.AttackCritChanse))
                            {
                                damage += damage / 100 * enemyProperty.CriticalDamage;
                            }

                            if (Randomize.Random(unitProperty.BlockChanse))
                            {
                                if (!Randomize.Random(unitProperty.AbsoluteBlockChanse))
                                {
                                    damage -= unitProperty.BlockDamage;
                                }
                                else
                                {
                                    damage = 0;
                                }
                            }

                            if (Randomize.Random(unitProperty.ParryChanse))
                            {
                                damage /= 2;
                                if (!unitLogic.unitObject.IsRangeUnit)
                                {
                                    unitLogic.TakeImpact(new Impact {
                                        value = damage / 1.5f
                                    }, this, "Hp");
                                }
                            }

                            if (damage < 0)
                            {
                                damage = 0;
                            }

                            Hp -= damage;
                            Helper.lstOffender.Stats.AddDamage(damage);

                            if (Hp > this.unitObject.unitProperty.Hp)
                            {
                                Hp = this.unitObject.unitProperty.Hp;
                            }
                        }
                    }
                }
                else
                {
                    ChangeValue(impact, property);
                    Debug.Log(unitProperty.Armor);
                }
            }
            UnitObject unitObject = unitLogic.unitObject;
            UnitLogic  MyLogic    = transform.GetComponent <UnitLogic>();

            if (property == "Hp")
            {
                DestroyObject des       = unitImage.GetComponentInChildren <DestroyObject>();
                Transform     indicator = (des != null) ? des.transform : null;

                Transform loadedIndicator = Resources.Load <Transform>(damage >= 0 ? (GameManager.DamageIndicator[unitLogic.attackType != null ? unitLogic.attackType.damageIndicator : 0]) : GameManager.HealIndicator);
                if (des != null && des.name.StartsWith(loadedIndicator.name) && des.lifeTime > 0.2f)
                {
                    indicator.GetComponent <Animation>().Stop();
                    indicator.GetComponent <Animation>().Play(des.stop.name);
                }
                else
                {
                    indicator = null;
                    des       = null;
                }

                for (int avd = 0; avd < Avoided.Length; avd++)
                {
                    if (damage != 0 || damage == 0 && Avoided[avd])
                    {
                        if (!Avoided[avd])
                        {
                            if (!transform.GetComponent <HeroLogic>())
                            {
                                BattleLog.battleLog.addLog("<color=red>" + MyLogic.UnitName + "</color>"
                                                           + " теряет " +
                                                           "<color=red>" + damage.ToString() + "</color>" +
                                                           " от " + "<color=green>" + (unitObject.UnitName) + "</color>");
                            }
                            else
                            {
                                BattleLog.battleLog.addLog("<color=green>" + this.unitObject.UnitName + "</color>" + " теряет " +
                                                           "<color=red>" + damage.ToString() + "</color>");
                            }
                            if (Hp <= 0)
                            {
                                BattleLog.battleLog.addLog("<color=red>" + ((MyLogic.UnitName != null) ? MyLogic.UnitName : this.unitObject.UnitName) + "</color>"
                                                           + " умерает от  " + "<color=green>" + (unitObject.UnitName) + "</color>");
                                Death(this);
                            }
                        }

                        if (indicator == null)
                        {
                            indicator = UnityEngine.Object.Instantiate <Transform>(loadedIndicator, unitImage);
                        }
                        if ((unitImage.localScale.x < 0))
                        {
                            indicator.GetChild(0).localScale = new Vector3(-1, 1, 1);
                        }

                        indicator.transform.localPosition = Vector3.zero;
                        Text[] txt = indicator.GetComponentsInChildren <Text>();
                        float  val = (txt[avd].text == "Miss") ? 0 : float.Parse(txt[avd].text);
                        if (Avoided.Length == 1)
                        {
                            if (Avoided[0])
                            {
                                UnityEngine.Object.Instantiate <Transform>(Resources.Load <Transform>(GameManager.MissIndicator), indicator.transform);
                            }
                            txt[0].text = (val + Math.Abs(damage)).ToString();
                        }
                        else
                        {
                            if (Avoided[avd])
                            {
                                txt[avd].text = "Miss";
                            }
                            else
                            {
                                if (damage < 2)
                                {
                                    txt[avd].text = Math.Round(val + damage, 1).ToString();
                                }
                                else
                                {
                                    txt[avd].text = (Math.Round((avd != txt.Length - 1) ? val + Mathf.Floor(damage) : val + (damage * Avoided.Length - Mathf.Floor(damage) * (Avoided.Length - 1)), 1).ToString());
                                }
                            }
                        }
                    }
                }
            }

            if (Hp <= this.unitObject.unitProperty.Hp / 3)
            {
                EnemyControll.enemyControll.NeedRefreshPos = true;
            }

            if (unitEvents.OnGetDamage != null)
            {
                unitEvents.OnGetDamage.Invoke();
            }
        }
Ejemplo n.º 11
0
        public void TakeImpact(Impact impact, Spell spell, Effect[] effects = null, string property = "Hp", bool zeroDuration = false, bool InstantAction = false)
        {
            if (transform == null)
            {
                return;
            }
            Helper.lstDamagedEnemy = this;
            float damage = 0;

            if (property != null && property.Length > 0)
            {
                if (property == "Hp")
                {
                    if (!impact.isProcent)
                    {
                        damage = impact.value;
                    }
                    else
                    {
                        damage = (float)Math.Round(Hp / 100 * impact.value, 1);
                    }

                    if (unitProperty.MagicResist != 0)
                    {
                        BattleConstants.CalculateArmor(ref damage, unitProperty.MagicResist);
                    }

                    if (spell.unitEvents.MyUnit != null)
                    {
                        UnitProperty enemyProperty = spell.unitEvents.MyUnit.unitlogic.unitProperty;

                        if (Randomize.Random(enemyProperty.MagicCritChanse) && spell.splashType <= (Spell.SplashType) 9)
                        {
                            damage += damage / 100 * enemyProperty.CriticalDamage;
                        }

                        if (Randomize.Random(unitProperty.ParryChanse))
                        {
                            damage /= 2;
                        }
                    }

                    Hp -= damage;

                    if (Hp > unitObject.unitProperty.Hp)
                    {
                        Hp = unitObject.unitProperty.Hp;
                    }
                }
                else
                {
                    ChangeValue(impact, property);
                    Debug.Log(unitProperty.Armor);
                }
            }
            UnitLogic MyLogic = transform.GetComponent <UnitLogic>();

            if (property == "Hp")
            {
                DestroyObject des       = unitImage.GetComponentInChildren <DestroyObject>();
                Transform     indicator = (des != null) ? des.transform : null;

                Transform loadedIndicator = Resources.Load <Transform>(damage >= 0 ? (GameManager.DamageIndicator[0]) : GameManager.HealIndicator);
                if (des != null && des.name.StartsWith(loadedIndicator.name) && des.lifeTime > 0.2f)
                {
                    indicator.GetComponent <Animation>().Stop();
                    indicator.GetComponent <Animation>().Play(des.stop.name);
                }
                else
                {
                    indicator = null;
                    des       = null;
                }

                if (damage != 0)
                {
                    if (!transform.GetComponent <HeroLogic>())
                    {
                        BattleLog.battleLog.addLog("<color=red>" + MyLogic.UnitName + "</color>"
                                                   + " теряет " +
                                                   "<color=red>" + damage.ToString() + "</color>" +
                                                   " от " + "<color=green>" + (spell.SpellName) + "</color>");
                    }
                    else
                    {
                        BattleLog.battleLog.addLog("<color=green>" + unitObject.UnitName + "</color>" + " теряет " +
                                                   "<color=red>" + damage.ToString() + "</color>");
                    }
                    if (Hp <= 0)
                    {
                        BattleLog.battleLog.addLog("<color=red>" + ((MyLogic.UnitName != null) ? MyLogic.UnitName : unitObject.UnitName) + "</color>"
                                                   + " умерает от  " + "<color=green>" + (spell.SpellName) + "</color>");
                        Death(this);
                    }

                    if (indicator == null)
                    {
                        indicator = UnityEngine.Object.Instantiate <Transform>(loadedIndicator, unitImage);
                    }

                    if ((unitImage.localScale.x < 0))
                    {
                        indicator.GetChild(0).localScale = new Vector3(-1, 1, 1);
                    }

                    indicator.transform.localPosition = Vector3.zero;
                    Text  txt = indicator.GetComponentInChildren <Text>();
                    float val = (txt.text == "Miss") ? 0 : float.Parse(txt.text);
                    txt.text = (val + Math.Abs(damage)).ToString();
                }
            }

            if (Hp <= unitObject.unitProperty.Hp / 3)
            {
                EnemyControll.enemyControll.NeedRefreshPos = true;
            }

            if (spell != null && effects != null)
            {
                if (spell.spellClass != classType.none)
                {
                    SpecClassSpellPassive.spec.UseSpell(spell, myUnit, spell.unitEvents.MyUnit);
                }
            }

            if (unitEvents.OnGetDamage != null)
            {
                unitEvents.OnGetDamage.Invoke();
            }

            bool PutEvents = true;

            if (effects != null)
            {
                foreach (Effect effect in effects)
                {
                    if (effect == null)
                    {
                        continue;
                    }
                    //effect.effectStacking == EffectStacking.none
                    bool   stop = false;
                    Effect eff  = (Effect)effect.Clone();
                    eff.spell = spell;
                    eff.EffectFunction();

                    for (int i = 0; i < unitEffects.Count; i++)
                    {
                        if (unitEffects[i].Name == eff.Name)
                        {
                            PutEvents = false;
                            switch (effect.effectStacking)
                            {
                            case EffectStacking.Refresh:
                                if (!zeroDuration)
                                {
                                    unitEffects[i].Duration = eff.Duration;
                                }
                                stop = true;
                                break;

                            case EffectStacking.Prolong:
                                if (!zeroDuration)
                                {
                                    unitEffects[i].Duration += eff.Duration;
                                }
                                stop = true;
                                break;

                            case EffectStacking.Stack:
                                if (unitEffects[i].stacks < eff.MaxImpact)
                                {
                                    ChangeValue(eff.ImpactValue, eff.spellType);
                                    unitEffects[i].stacks++;
                                    unitEffects[i].ImpactValue.value += eff.ImpactValue.value;
                                }
                                unitEffects[i].Duration = Math.Max(unitEffects[i].Duration, eff.Duration);
                                stop = true;
                                break;

                            case EffectStacking.ImpactMult:
                                if (unitEffects[i].Duration == eff.Duration)
                                {
                                    unitEffects[i].ImpactValue.value += eff.ImpactValue.value;
                                    unitEffects[i].stacks++;
                                    stop = true;
                                }
                                break;
                            }

                            if (stop)
                            {
                                if (unitEffects[i].refreshFunction)
                                {
                                    unitEffects[i].EffectFunction();
                                }
                                break;
                            }
                        }
                        else
                        {
                        }
                    }
                    if (zeroDuration)
                    {
                        eff.Duration = 0;
                    }

                    if (!stop)
                    {
                        ChangeValue(eff.ImpactValue, eff.spellType);
                        unitEffects.Add(eff);
                    }
                    if (InstantAction)
                    {
                        eff.Duration++; eff.Execute((Unit)MyLogic);
                    }

                    if (myUnit.unitlogic == BattleControll.heroLogic.unitlogic)
                    {
                        BattleControll.battleControll.HeroEffectsRefresh();
                    }
                }
            }

            if (PutEvents && spell.unitEvents.AfterDead != null && spell.unitEvents.AfterDead.GetPersistentEventCount() > 0 && !UnderLink(spell))
            {
                spell.linkedUnits.Add(this);
                unitEvents.AfterDead.AddListener(() => { if (UnderSpell(spell))
                                                         {
                                                             spell.unitEvents.AfterDead.Invoke();
                                                         }
                                                 });
            }
        }
Ejemplo n.º 12
0
        public bool HasBlocked(Unit unit = null)
        {
            if (unit != null && unit.unitObject.IsRangeUnit)
            {
                return(false);
            }
            UnitLogic unitLogic = transform.GetComponent <UnitLogic>();

            if (unitLogic != null && BattleControll.battleControll.EnemyLines > 1 && unitLogic.position.y == BattleControll.battleControll.EnemyLines - 1)
            {
                if (unitLogic.position.x > 0)
                {
                    if (BattleControll.battleControll.ConstainsPositionUnit(unitLogic.position.x - 1) == null)
                    {
                        return(false);
                    }
                }
                if (unitLogic.position.x < BattleControll.loadedLevel.EnemyRows - 1)
                {
                    if (BattleControll.battleControll.ConstainsPositionUnit(unitLogic.position.x + 1) == null)
                    {
                        return(false);
                    }
                }

                UnitLogic lg = BattleControll.battleControll.ConstainsPositionUnit(unitLogic.position.x);
                if (lg != unitLogic && lg != null)
                {
                    return(true);
                }
            }
            else if (unit != null && BattleControll.battleControll.EnemyLines > 1)
            {
                UnitLogic un = (transform.GetComponent <UnitLogic>()) ? transform.GetComponent <UnitLogic>() : unit.unitlogic.transform.GetComponent <UnitLogic>();
                HeroLogic hr = (transform.GetComponent <HeroLogic>()) ? transform.GetComponent <HeroLogic>() : unit.unitlogic.transform.GetComponent <HeroLogic>();
                //   if (un.position.y == BattleControll.battleControll.EnemyLines - 1) return false;
                if (un != null && hr != null)
                {
                    if (Math.Abs(hr.unitlogic.position - un.unitlogic.position) < .6f)
                    {
                        if (BattleControll.battleControll.ConstainsPositionUnit(un.position.x) == null)
                        {
                            return(false);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    if (hr.unitlogic.position > un.unitlogic.position)
                    {
                        for (int i = un.position.x + 1; i < Mathf.FloorToInt(hr.unitlogic.position) + 1; i++)
                        {
                            if (BattleControll.battleControll.ConstainsPositionUnit(i) != null)
                            {
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        for (int i = un.position.x - 1; i > Mathf.CeilToInt(hr.unitlogic.position) - 1; i--)
                        {
                            if (BattleControll.battleControll.ConstainsPositionUnit(i) != null)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 13
0
        public void JustHitStrategy()
        {
            Transform enemies = BattleControll.battleControll.enemyUnitsParent.transform;

            for (int i = 0; i < regions.Count; i++)
            {
                if (!regions[i].NextTurnRepose(1))
                {
                    regions.RemoveAt(i);
                }
            }
            for (int i = 0; i < enemies.childCount; i++)
            {
                UnitLogic enamy = enemies.GetChild(i).GetComponent <UnitLogic>();
                enamy.NextTurnRepose(Effect.actionCall.OnStartTurn);
                if (NeedRefreshPos)
                {
                    PositionReload(enamy);
                }

                if (enamy.unitlogic.totem != null)
                {
                    enamy.unitlogic.totem.Execute(Effect.actionCall.OnStartTurn);
                }
            }

            BattleControll.heroLogic.LinkedSpells();
            for (int i = 0; i < enemies.childCount; i++)
            {
                UnitLogic enamy = enemies.GetChild(i).GetComponent <UnitLogic>();
                int       act   = enamy.unitlogic.UnitAction;

                if (enamy.unitlogic.attackType != null)
                {
                    SpellPart sp = enamy.unitlogic.attackType.AvailableSpell;
                    if (sp.Available(enamy.unitlogic.attackType))
                    {
                        try
                        {
                            switch (sp.spell.spellTarget)
                            {
                            case Spell.SpellTarget.Enemy & Spell.SpellTarget.Alies:
                                sp.spell.Execute(null, BattleControll.heroLogic);
                                break;

                            case  Spell.SpellTarget.Enemy:
                                sp.spell.Execute(null, BattleControll.heroLogic);
                                break;

                            case Spell.SpellTarget.Alies:

                                break;

                            default:
                                sp.spell.Execute(null, null, true);
                                break;
                            }
                        }
                        catch
                        {
                            Debug.Log("eerr");
                        }
                        finally
                        {
                            enamy.unitlogic.UnitAction -= sp.spell.EnergyCost;
                            act -= sp.spell.EnergyCost;
                        }
                    }
                }

                if (enamy.spells.Length > 0)
                {
                    for (int sp = 0; sp < enamy.spells.Length; sp++)
                    {
                        SpellInBattle spell = enamy.spells[sp];
                        if (spell.spellImage.passiveSettings.IsPassiveSkill)
                        {
                            continue;
                        }
                        if (spell.Reloading())
                        {
                            if (spell.spellImage.spellTarget == Spell.SpellTarget.Enemy)
                            {
                                spell.Realizeto(enamy, BattleControll.heroLogic);
                                enamy.unitlogic.UnitAction--;
                                act -= spell.spellImage.EnergyCost;
                            }
                        }
                    }
                }

                if (enamy.unitlogic.CanAttack(BattleControll.heroLogic))
                {
                    for (int q = 0; q < act; q++)
                    {
                        if (enamy.unitlogic.UnitAction > 0)
                        {
                            enamy.unitlogic.AttackUnit(BattleControll.heroLogic, 1);
                        }
                    }
                    BattleLogic.battleLogic.addAction(null, null, -1, 0.5f);
                }
            }

            for (int i = 0; i < regions.Count; i++)
            {
                if (!regions[i].NextTurnRepose(0))
                {
                    regions.RemoveAt(i);
                }
            }

            for (int i = 0; i < enemies.childCount; i++)
            {
                UnitLogic enamy = enemies.GetChild(i).GetComponent <UnitLogic>();
                enamy.EffectsTick(Effect.actionCall.OnEndTurn);
                if (enamy.unitlogic.totem != null)
                {
                    enamy.unitlogic.totem.Execute(Effect.actionCall.OnEndTurn);
                }
            }
            NeedRefreshPos = false;
            BattleLogic.battleLogic.addAction(() =>
            {
                BattleControll.battleControll.SpawnEnemies();
                GoToFirstLine();
                TurnController.turnController.NextTurn();
                RealizeLogicToNextTurn();
            }, null);
        }
Ejemplo n.º 14
0
        public void PositionReload(UnitLogic unit)
        {
            int        Lines    = BattleControll.loadedLevel.EnemiesOnField / BattleControll.loadedLevel.EnemyRows;
            Vector2Int myPos    = unit.position;
            UnitLogic  swapUnit = null;
            Transform  enemies  = BattleControll.battleControll.enemyUnitsParent.transform;

            for (int i = 0; i < enemies.childCount; i++)
            {
                UnitLogic enamy = enemies.GetChild(i).GetComponent <UnitLogic>();
                if (enamy == unit)
                {
                    continue;
                }
                if (unit.unitObject.FirstLinePriority)
                {
                    if (enamy.position.y > myPos.y)
                    {
                        if (swapUnit == null)
                        {
                            swapUnit = enamy;
                        }
                        else
                        {
                            if (enamy.unitlogic.Hp < swapUnit.unitlogic.Hp)
                            {
                                swapUnit = enamy;
                            }
                        }
                    }
                }
                else if (unit.unitObject.IsRangeUnit && unit.position.y != 0)
                {
                    if (enamy.position.y == 0 && !enamy.unitObject.IsRangeUnit)
                    {
                        if (swapUnit == null)
                        {
                            swapUnit = enamy;
                        }
                        else
                        {
                            if (enamy.unitlogic.Hp > swapUnit.unitlogic.Hp)
                            {
                                swapUnit = enamy;
                            }
                        }
                    }
                }
                else
                {
                    // if (unit.position.y > 0 && enamy.position.y > 0)
                    if (unit.unitlogic.Hp <= unit.unitObject.unitProperty.Hp / 3 && !enamy.unitObject.IsRangeUnit && unit.position.y > 0)
                    {
                        if (swapUnit == null)
                        {
                            if (enamy.unitlogic.Hp > unit.unitlogic.Hp && Math.Abs(BattleControll.heroLogic.GetRealPos() - enamy.position.x) > Math.Abs(BattleControll.heroLogic.GetRealPos() - unit.position.x) || enamy.position.y == 0 && enamy.unitlogic.Hp > unit.unitlogic.Hp)
                            {
                                swapUnit = enamy;
                            }
                        }
                        else if (enamy.position.y == 0 && enamy.unitlogic.Hp > unit.unitlogic.Hp)
                        {
                            if (swapUnit.position.y > 0 || enamy.unitlogic.Hp > swapUnit.unitlogic.Hp)
                            {
                                swapUnit = enamy;
                            }
                        }
                        else if (enamy.unitlogic.Hp > unit.unitlogic.Hp && Math.Abs(BattleControll.heroLogic.GetRealPos() - enamy.position.x) > Math.Abs(BattleControll.heroLogic.GetRealPos() - swapUnit.position.x))
                        {
                            if (swapUnit.position.y != 0 || enamy.unitlogic.Hp > swapUnit.unitlogic.Hp * 2)
                            {
                                swapUnit = enamy;
                            }
                        }
                    }
                }
            }

            if (swapUnit != null && swapUnit != unit)
            {
                Vector2Int newPos = swapUnit.position;
                Vector3    pos1   = BattleControll.battleControll.enemyUnitsParent.GetPosition(newPos.x, newPos.y);
                Vector3    pos2   = BattleControll.battleControll.enemyUnitsParent.GetPosition(myPos.x, myPos.y);

                swapUnit.SetPosition(myPos, pos2);
                unit.SetPosition(newPos, pos1);

                BattleControll.battleControll.enemyUnitsParent.units[myPos.x, myPos.y]   = swapUnit;
                BattleControll.battleControll.enemyUnitsParent.units[newPos.x, newPos.y] = unit;

                //   unit.unitlogic.UnitAction = 0;

                StartCoroutine(enumerator(unit, swapUnit, myPos, newPos));
            }
        }