Esempio n. 1
0
        internal static int AddDamage(HPInstance hpi, Unit hero, string notes)
        {
            Id++;
            var id = Id;

            var aiHero = ZLib.GetUnits().FirstOrDefault(x => x.Instance.NetworkId == hero.Instance.NetworkId);

            if (aiHero != null && !ZLib.DamageCollection.ContainsKey(id))
            {
                aiHero.Attacker = hpi.Attacker;

                if (aiHero.Instance.IsValid)
                {
                    switch (hpi.EventType)
                    {
                    case EventType.Spell:
                        aiHero.AbilityDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.Spell);
                        break;

                    case EventType.Buff:
                        aiHero.BuffDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.Buff);

                        if (notes == "aura.Evade")
                        {
                            aiHero.Events.Add(EventType.Ultimate);
                        }

                        break;

                    case EventType.Troy:
                        aiHero.TroyDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.Troy);

                        if (notes != "debug.Test")
                        {
                            aiHero.Events.AddRange(hpi.GameData.EventTypes);
                        }

                        break;

                    case EventType.Item:
                        aiHero.ItemDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.Spell);
                        break;

                    case EventType.TurretAttack:
                        aiHero.TowerDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.TurretAttack);
                        break;

                    case EventType.MinionAttack:
                        aiHero.MinionDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.MinionAttack);
                        break;

                    case EventType.AutoAttack:
                        aiHero.AbilityDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.AutoAttack);
                        break;

                    case EventType.Stealth:
                        aiHero.Events.Add(EventType.Stealth);
                        break;

                    case EventType.Initiator:
                        aiHero.AbilityDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.Initiator);
                        break;

                    case EventType.Danger:
                        aiHero.AbilityDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.Danger);
                        break;

                    case EventType.CrowdControl:
                        aiHero.AbilityDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.CrowdControl);
                        break;

                    case EventType.Ultimate:
                        aiHero.AbilityDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.Ultimate);
                        break;

                    case EventType.ForceExhaust:
                        aiHero.AbilityDamage += hpi.PredictedDmg;
                        aiHero.Events.Add(EventType.ForceExhaust);
                        break;
                    }

                    if (hpi.EventType == EventType.Stealth)
                    {
                        hpi.PredictedDmg = 0;
                    }

                    var damageEventArgs = new PredictDamageEventArgs {
                        HpInstance = hpi
                    };
                    ZLib.TriggerOnPredictDamage(hero, damageEventArgs);

                    if (damageEventArgs.NoProcess)
                    {
                        Helpers.ResetIncomeDamage(aiHero);
                        ZLib.DamageCollection.Add(id, null);
                        return(id);
                    }

                    hpi.Id = id;
                    ZLib.DamageCollection.Add(id, hpi);
                }
            }

            return(id);
        }
Esempio n. 2
0
        internal static void EmulateDamage(Obj_AI_Base sender, Unit hero, Gamedata data, EventType dmgType, string notes = null,
                                           float dmgEntry = 0f, int expiry = 500)
        {
            var hpred = new HPInstance();

            hpred.EventType = dmgType;
            hpred.Target    = hero.Instance;
            hpred.GameData  = data;
            hpred.Name      = string.Empty;

            if (sender != null)
            {
                hpred.Attacker = sender;
            }

            if (!string.IsNullOrEmpty(data?.SpellName))
            {
                hpred.Name = data.SpellName;
            }

            if (dmgEntry < 1f && sender != null)
            {
                switch (dmgType)
                {
                case EventType.AutoAttack:
                    hpred.PredictedDmg = (float)Math.Max(sender.GetAutoAttackDamage(hero.Instance), 0);
                    break;

                case EventType.MinionAttack:
                case EventType.TurretAttack:
                    hpred.PredictedDmg =
                        (float)
                        Math.Max(sender.CalculateDamage(hero.Instance, DamageType.Physical,
                                                        sender.BaseAttackDamage + sender.FlatPhysicalDamageMod), 0);
                    break;

                default:
                    var aiHero = sender as Obj_AI_Hero;
                    if (aiHero != null)
                    {
                        if (!string.IsNullOrEmpty(data?.SpellName))
                        {
                            hpred.PredictedDmg = (float)Math.Max(aiHero.GetSpellDamage(hero.Instance, data.Slot), 0);
                        }
                    }

                    break;
                }
            }

            else
            {
                var idmg = dmgEntry;
                hpred.PredictedDmg = (float)Math.Round(idmg);
            }

            if (hpred.PredictedDmg > 0)
            {
                var idmg = hpred.PredictedDmg * ZLib.Menu["weightdmg"].As <MenuSlider>().Value / 100;
                hpred.PredictedDmg = (float)Math.Round(idmg);
            }

            else
            {
                var idmg = (hero.Instance.Health / hero.Instance.MaxHealth) * 5;
                hpred.PredictedDmg = (float)Math.Round(idmg);
            }

            if (dmgType != EventType.Buff && dmgType != EventType.Troy)
            {
                // check duplicates (missiles and process spell)
                if (ZLib.DamageCollection.Select(entry => entry.Value).Any(o => data != null && o.Name == data.SpellName))
                {
                    return;
                }
            }

            var dmg             = AddDamage(hpred, hero, notes);
            var extendedEndtime = ZLib.Menu["lagtolerance"].As <MenuSlider>().Value * 10;

            DelayAction.Queue(expiry + extendedEndtime, () => RemoveDamage(dmg, notes));
        }