Ensage.Common.UnitDatabase.GetAttackRate C# (CSharp) Метод

GetAttackRate() публичный статический Метод

Gets the attack rate.
public static GetAttackRate ( Hero unit ) : double
unit Hero /// The unit. ///
Результат double
        public static double GetAttackRate(Hero unit)
        {
            try
            {
                var attackSpeed = GetAttackSpeed(unit);
                double attackBaseTime;
                if (!AttackRateDictionary.TryGetValue(unit.Handle, out attackBaseTime))
                {
                    attackBaseTime =
                        Game.FindKeyValues(unit.StoredName() + "/AttackRate", KeyValueSource.Hero).FloatValue;
                    AttackRateDictionary.Add(unit.Handle, attackBaseTime);
                }

                Ability spell = null;
                if (
                    !unit.HasModifiers(
                        new[]
                            {
                                "modifier_alchemist_chemical_rage", "modifier_terrorblade_metamorphosis", 
                                "modifier_lone_druid_true_form", "modifier_troll_warlord_berserkers_rage"
                            }, 
                        false))
                {
                    return attackBaseTime / (1 + (attackSpeed - 100) / 100);
                }

                switch (unit.ClassID)
                {
                    case ClassID.CDOTA_Unit_Hero_Alchemist:
                        spell = unit.Spellbook.Spells.First(x => x.StoredName() == "alchemist_chemical_rage");
                        break;
                    case ClassID.CDOTA_Unit_Hero_Terrorblade:
                        spell = unit.Spellbook.Spells.First(x => x.StoredName() == "terrorblade_metamorphosis");
                        break;
                    case ClassID.CDOTA_Unit_Hero_LoneDruid:
                        spell = unit.Spellbook.Spells.First(x => x.StoredName() == "lone_druid_true_form");
                        break;
                    case ClassID.CDOTA_Unit_Hero_TrollWarlord:
                        spell = unit.Spellbook.Spells.First(x => x.StoredName() == "troll_warlord_berserkers_rage");
                        break;
                }

                if (spell == null)
                {
                    return attackBaseTime / (1 + (attackSpeed - 100) / 100);
                }

                attackBaseTime = spell.GetAbilityData("base_attack_time");

                return attackBaseTime / (1 + (attackSpeed - 100) / 100);
            }
            catch (KeyValuesNotFoundException)
            {
                if (!Utils.SleepCheck("Ensage.Common.DemoModeWarning"))
                {
                    return 0;
                }

                Utils.Sleep(10000, "Ensage.Common.DemoModeWarning");
                Console.WriteLine(@"[[Please do not use demo mode for testing assemblies]]");
                return 0;
            }
        }

Same methods

UnitDatabase::GetAttackRate ( Unit unit ) : double

Usage Example

Пример #1
0
        /// <summary>
        ///     Checks if attack is currently on cooldown
        /// </summary>
        /// <param name="target"></param>
        /// <param name="bonusWindupMs"></param>
        /// <returns></returns>
        public static bool AttackOnCooldown(Entity target = null, float bonusWindupMs = 0)
        {
            if (me == null)
            {
                return(false);
            }
            var turnTime = 0d;

            if (target != null)
            {
                turnTime = me.GetTurnTime(target);
            }
            //Console.WriteLine(turnTime*1000);
            return((LastAttackStart + UnitDatabase.GetAttackRate(me) * 1000 - Game.Ping - turnTime * 1000 - 75
                    + bonusWindupMs) > tick);
        }