示例#1
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();
            }
        }
示例#2
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();
                                                         }
                                                 });
            }
        }