Beispiel #1
0
        public int GetChargeRecoveryTime(uint chargeCategoryId)
        {
            SpellCategoryRecord chargeCategoryEntry = CliDB.SpellCategoryStorage.LookupByKey(chargeCategoryId);

            if (chargeCategoryEntry == null)
            {
                return(0);
            }

            int recoveryTime = chargeCategoryEntry.ChargeRecoveryTime;

            recoveryTime += _owner.GetTotalAuraModifierByMiscValue(AuraType.ChargeRecoveryMod, (int)chargeCategoryId);

            float recoveryTimeF = recoveryTime;

            recoveryTimeF *= _owner.GetTotalAuraMultiplierByMiscValue(AuraType.ChargeRecoveryMultiplier, (int)chargeCategoryId);

            if (_owner.HasAuraType(AuraType.ChargeRecoveryAffectedByHaste))
            {
                recoveryTimeF *= _owner.GetFloatValue(UnitFields.ModCastHaste);
            }

            if (_owner.HasAuraType(AuraType.ChargeRecoveryAffectedByHasteRegen))
            {
                recoveryTimeF *= _owner.GetFloatValue(UnitFields.ModHasteRegen);
            }

            return((int)Math.Floor(recoveryTimeF));
        }
Beispiel #2
0
        public int GetMaxCharges(uint chargeCategoryId)
        {
            SpellCategoryRecord chargeCategoryEntry = CliDB.SpellCategoryStorage.LookupByKey(chargeCategoryId);

            if (chargeCategoryEntry == null)
            {
                return(0);
            }

            uint charges = chargeCategoryEntry.MaxCharges;

            charges += (uint)_owner.GetTotalAuraModifierByMiscValue(AuraType.ModMaxCharges, (int)chargeCategoryId);
            return((int)charges);
        }
Beispiel #3
0
        public void StartCooldown(SpellInfo spellInfo, uint itemId, Spell spell = null, bool onHold = false)
        {
            // init cooldown values
            uint categoryId       = 0;
            int  cooldown         = -1;
            int  categoryCooldown = -1;

            GetCooldownDurations(spellInfo, itemId, ref cooldown, ref categoryId, ref categoryCooldown);

            DateTime curTime = DateTime.Now;
            DateTime catrecTime;
            DateTime recTime;
            bool     needsCooldownPacket = false;

            // overwrite time for selected category
            if (onHold)
            {
                // use +MONTH as infinite cooldown marker
                catrecTime = categoryCooldown > 0 ? (curTime + PlayerConst.InfinityCooldownDelay) : curTime;
                recTime    = cooldown > 0 ? (curTime + PlayerConst.InfinityCooldownDelay) : catrecTime;
            }
            else
            {
                // shoot spells used equipped item cooldown values already assigned in GetAttackTime(RANGED_ATTACK)
                // prevent 0 cooldowns set by another way
                if (cooldown <= 0 && categoryCooldown <= 0 && (categoryId == 76 || (spellInfo.IsAutoRepeatRangedSpell() && spellInfo.Id != 75)))
                {
                    cooldown = (int)_owner.GetUInt32Value(UnitFields.RangedAttackTime);
                }

                // Now we have cooldown data (if found any), time to apply mods
                Player modOwner = _owner.GetSpellModOwner();
                if (modOwner)
                {
                    if (cooldown > 0)
                    {
                        modOwner.ApplySpellMod(spellInfo.Id, SpellModOp.Cooldown, ref cooldown, spell);
                    }

                    if (categoryCooldown > 0 && !spellInfo.HasAttribute(SpellAttr6.IgnoreCategoryCooldownMods))
                    {
                        modOwner.ApplySpellMod(spellInfo.Id, SpellModOp.Cooldown, ref categoryCooldown, spell);
                    }
                }

                if (_owner.HasAuraTypeWithAffectMask(AuraType.ModSpellCooldownByHaste, spellInfo))
                {
                    cooldown         = (int)(cooldown * _owner.GetFloatValue(UnitFields.ModCastHaste));
                    categoryCooldown = (int)(categoryCooldown * _owner.GetFloatValue(UnitFields.ModCastHaste));
                }

                if (_owner.HasAuraTypeWithAffectMask(AuraType.ModCooldownByHasteRegen, spellInfo))
                {
                    cooldown         = (int)(cooldown * _owner.GetFloatValue(UnitFields.ModHasteRegen));
                    categoryCooldown = (int)(categoryCooldown * _owner.GetFloatValue(UnitFields.ModHasteRegen));
                }

                int cooldownMod = _owner.GetTotalAuraModifier(AuraType.ModCooldown);
                if (cooldownMod != 0)
                {
                    // Apply SPELL_AURA_MOD_COOLDOWN only to own spells
                    Player playerOwner = GetPlayerOwner();
                    if (!playerOwner || playerOwner.HasSpell(spellInfo.Id))
                    {
                        needsCooldownPacket = true;
                        cooldown           += cooldownMod * Time.InMilliseconds; // SPELL_AURA_MOD_COOLDOWN does not affect category cooldows, verified with shaman shocks
                    }
                }

                // Apply SPELL_AURA_MOD_SPELL_CATEGORY_COOLDOWN modifiers
                // Note: This aura applies its modifiers to all cooldowns of spells with set category, not to category cooldown only
                if (categoryId != 0)
                {
                    int categoryModifier = _owner.GetTotalAuraModifierByMiscValue(AuraType.ModSpellCategoryCooldown, (int)categoryId);
                    if (categoryModifier != 0)
                    {
                        if (cooldown > 0)
                        {
                            cooldown += categoryModifier;
                        }

                        if (categoryCooldown > 0)
                        {
                            categoryCooldown += categoryModifier;
                        }
                    }

                    SpellCategoryRecord categoryEntry = CliDB.SpellCategoryStorage.LookupByKey(categoryId);
                    if (categoryEntry.Flags.HasAnyFlag(SpellCategoryFlags.CooldownExpiresAtDailyReset))
                    {
                        categoryCooldown = (int)(Time.UnixTimeToDateTime(Global.WorldMgr.GetNextDailyQuestsResetTime()) - DateTime.Now).TotalMilliseconds;
                    }
                }

                // replace negative cooldowns by 0
                if (cooldown < 0)
                {
                    cooldown = 0;
                }

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

                // no cooldown after applying spell mods
                if (cooldown == 0 && categoryCooldown == 0)
                {
                    return;
                }

                catrecTime = categoryCooldown != 0 ? curTime + TimeSpan.FromMilliseconds(categoryCooldown) : curTime;
                recTime    = cooldown != 0 ? curTime + TimeSpan.FromMilliseconds(cooldown) : catrecTime;
            }

            // self spell cooldown
            if (recTime != curTime)
            {
                AddCooldown(spellInfo.Id, itemId, recTime, categoryId, catrecTime, onHold);

                if (needsCooldownPacket)
                {
                    Player playerOwner = GetPlayerOwner();
                    if (playerOwner)
                    {
                        SpellCooldownPkt spellCooldown = new SpellCooldownPkt();
                        spellCooldown.Caster = _owner.GetGUID();
                        spellCooldown.Flags  = SpellCooldownFlags.None;
                        spellCooldown.SpellCooldowns.Add(new SpellCooldownStruct(spellInfo.Id, (uint)cooldown));
                        playerOwner.SendPacket(spellCooldown);
                    }
                }
            }
        }