diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/database/Database/Implementation/CharacterDatabase.cpp | 8 | ||||
-rw-r--r-- | src/server/game/DataStores/DBCStores.cpp | 11 | ||||
-rw-r--r-- | src/server/game/DataStores/DBCStores.h | 1 | ||||
-rw-r--r-- | src/server/game/DataStores/DBCStructure.h | 3 | ||||
-rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Spells/Auras/SpellAuras.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Spells/Spell.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Spells/SpellHistory.cpp | 174 | ||||
-rw-r--r-- | src/server/game/Spells/SpellHistory.h | 30 | ||||
-rw-r--r-- | src/server/scripts/Spells/spell_dk.cpp | 2 |
10 files changed, 125 insertions, 110 deletions
diff --git a/src/server/database/Database/Implementation/CharacterDatabase.cpp b/src/server/database/Database/Implementation/CharacterDatabase.cpp index 2de1dc0645b..940bee4e3a2 100644 --- a/src/server/database/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/database/Database/Implementation/CharacterDatabase.cpp @@ -115,7 +115,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PrepareStatement(CHAR_SEL_MAIL_COUNT, "SELECT COUNT(*) FROM mail WHERE receiver = ?", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_CHARACTER_SOCIALLIST, "SELECT friend, flags, note FROM character_social JOIN characters ON characters.guid = character_social.friend WHERE character_social.guid = ? AND deleteinfos_name IS NULL LIMIT 255", CONNECTION_ASYNC); PrepareStatement(CHAR_SEL_CHARACTER_HOMEBIND, "SELECT mapId, zoneId, posX, posY, posZ FROM character_homebind WHERE guid = ?", CONNECTION_ASYNC); - PrepareStatement(CHAR_SEL_CHARACTER_SPELLCOOLDOWNS, "SELECT spell, item, time FROM character_spell_cooldown WHERE guid = ? AND time > UNIX_TIMESTAMP()", CONNECTION_ASYNC); + PrepareStatement(CHAR_SEL_CHARACTER_SPELLCOOLDOWNS, "SELECT spell, item, time, categoryId, categoryEnd FROM character_spell_cooldown WHERE guid = ? AND time > UNIX_TIMESTAMP()", CONNECTION_ASYNC); PrepareStatement(CHAR_SEL_CHARACTER_SPELL_CHARGES, "SELECT categoryId, rechargeStart, rechargeEnd FROM character_spell_charges WHERE guid = ? AND rechargeEnd > UNIX_TIMESTAMP() ORDER BY rechargeEnd", CONNECTION_ASYNC); PrepareStatement(CHAR_SEL_CHARACTER_DECLINEDNAMES, "SELECT genitive, dative, accusative, instrumental, prepositional FROM character_declinedname WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_SEL_GUILD_MEMBER, "SELECT guildid, rank FROM guild_member WHERE guid = ?", CONNECTION_BOTH); @@ -530,7 +530,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PrepareStatement(CHAR_UPD_CHAR_TITLES_FACTION_CHANGE, "UPDATE characters SET knownTitles = ? WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_RES_CHAR_TITLES_FACTION_CHANGE, "UPDATE characters SET chosenTitle = 0 WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_CHAR_SPELL_COOLDOWNS, "DELETE FROM character_spell_cooldown WHERE guid = ?", CONNECTION_ASYNC); - PrepareStatement(CHAR_INS_CHAR_SPELL_COOLDOWN, "INSERT INTO character_spell_cooldown (guid, spell, item, time) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC); + PrepareStatement(CHAR_INS_CHAR_SPELL_COOLDOWN, "INSERT INTO character_spell_cooldown (guid, spell, item, time, categoryId, categoryEnd) VALUES (?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_CHAR_SPELL_CHARGES, "DELETE FROM character_spell_charges WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_INS_CHAR_SPELL_CHARGES, "INSERT INTO character_spell_charges (guid, categoryId, rechargeStart, rechargeEnd) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_CHARACTER, "DELETE FROM characters WHERE guid = ?", CONNECTION_ASYNC); @@ -631,13 +631,13 @@ void CharacterDatabaseConnection::DoPrepareStatements() PrepareStatement(CHAR_SEL_PET_AURA, "SELECT casterGuid, spell, effectMask, recalculateMask, stackCount, maxDuration, remainTime, remainCharges FROM pet_aura WHERE guid = ?", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_PET_AURA_EFFECT, "SELECT casterGuid, spell, effectMask, effectIndex, amount, baseAmount FROM pet_aura_effect WHERE guid = ?", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_PET_SPELL, "SELECT spell, active FROM pet_spell WHERE guid = ?", CONNECTION_SYNCH); - PrepareStatement(CHAR_SEL_PET_SPELL_COOLDOWN, "SELECT spell, time FROM pet_spell_cooldown WHERE guid = ? AND time > UNIX_TIMESTAMP()", CONNECTION_SYNCH); + PrepareStatement(CHAR_SEL_PET_SPELL_COOLDOWN, "SELECT spell, time, categoryId, categoryEnd FROM pet_spell_cooldown WHERE guid = ? AND time > UNIX_TIMESTAMP()", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_PET_DECLINED_NAME, "SELECT genitive, dative, accusative, instrumental, prepositional FROM character_pet_declinedname WHERE owner = ? AND id = ?", CONNECTION_SYNCH); PrepareStatement(CHAR_DEL_PET_AURAS, "DELETE FROM pet_aura WHERE guid = ?", CONNECTION_BOTH); PrepareStatement(CHAR_DEL_PET_AURA_EFFECTS, "DELETE FROM pet_aura_effect WHERE guid = ?", CONNECTION_BOTH); PrepareStatement(CHAR_DEL_PET_SPELLS, "DELETE FROM pet_spell WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_PET_SPELL_COOLDOWNS, "DELETE FROM pet_spell_cooldown WHERE guid = ?", CONNECTION_BOTH); - PrepareStatement(CHAR_INS_PET_SPELL_COOLDOWN, "INSERT INTO pet_spell_cooldown (guid, spell, time) VALUES (?, ?, ?)", CONNECTION_BOTH); + PrepareStatement(CHAR_INS_PET_SPELL_COOLDOWN, "INSERT INTO pet_spell_cooldown (guid, spell, time, categoryId, categoryEnd) VALUES (?, ?, ?, ?, ?)", CONNECTION_BOTH); PrepareStatement(CHAR_SEL_PET_SPELL_CHARGES, "SELECT categoryId, rechargeStart, rechargeEnd FROM pet_spell_charges WHERE guid = ? AND rechargeEnd > UNIX_TIMESTAMP() ORDER BY rechargeEnd", CONNECTION_SYNCH); PrepareStatement(CHAR_DEL_PET_SPELL_CHARGES, "DELETE FROM pet_spell_charges WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_INS_PET_SPELL_CHARGES, "INSERT INTO pet_spell_charges (guid, categoryId, rechargeStart, rechargeEnd) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC); diff --git a/src/server/game/DataStores/DBCStores.cpp b/src/server/game/DataStores/DBCStores.cpp index 15174cc7f7a..8402c3989b3 100644 --- a/src/server/game/DataStores/DBCStores.cpp +++ b/src/server/game/DataStores/DBCStores.cpp @@ -130,7 +130,6 @@ DBCStorage<SkillRaceClassInfoEntry> sSkillRaceClassInfoStore(SkillRaceCl SkillRaceClassInfoMap SkillRaceClassInfoBySkill; DBCStorage<SpellAuraOptionsEntry> sSpellAuraOptionsStore(SpellAuraOptionsfmt); DBCStorage<SpellCategoriesEntry> sSpellCategoriesStore(SpellCategoriesfmt); -SpellCategoryStore sSpellsByCategoryStore; DBCStorage<SpellCategoryEntry> sSpellCategoryStore(SpellCategoryfmt); DBCStorage<SpellCooldownsEntry> sSpellCooldownsStore(SpellCooldownsfmt); DBCStorage<SpellEffectEntry> sSpellEffectStore(SpellEffectfmt); @@ -447,16 +446,6 @@ void LoadDBCStores(const std::string& dataPath, uint32 defaultLocale) if (sSkillLineStore.LookupEntry(entry->SkillID)) SkillRaceClassInfoBySkill.emplace(entry->SkillID, entry); - for (uint32 i = 1; i < sSpellStore.GetNumRows(); ++i) - { - SpellEntry const* spell = sSpellStore.LookupEntry(i); - if (!spell) - continue; - - if (SpellCategoriesEntry const* category = sSpellCategoriesStore.LookupEntry(spell->CategoriesID)) - sSpellsByCategoryStore[category->Category].insert(i); - } - for (uint32 j = 0; j < sSpellEffectScalingStore.GetNumRows(); j++) { SpellEffectScalingEntry const* spellEffectScaling = sSpellEffectScalingStore.LookupEntry(j); diff --git a/src/server/game/DataStores/DBCStores.h b/src/server/game/DataStores/DBCStores.h index bb4151979f4..c8e03ee95e7 100644 --- a/src/server/game/DataStores/DBCStores.h +++ b/src/server/game/DataStores/DBCStores.h @@ -185,7 +185,6 @@ extern DBCStorage<SkillLineEntry> sSkillLineStore; extern DBCStorage<SkillRaceClassInfoEntry> sSkillRaceClassInfoStore; extern DBCStorage<SpellAuraOptionsEntry> sSpellAuraOptionsStore; extern DBCStorage<SpellCategoriesEntry> sSpellCategoriesStore; -extern SpellCategoryStore sSpellsByCategoryStore; extern DBCStorage<SpellCategoryEntry> sSpellCategoryStore; extern DBCStorage<SpellCooldownsEntry> sSpellCooldownsStore; extern DBCStorage<SpellEffectEntry> sSpellEffectStore; diff --git a/src/server/game/DataStores/DBCStructure.h b/src/server/game/DataStores/DBCStructure.h index 6d192b247fb..dc53a316ee7 100644 --- a/src/server/game/DataStores/DBCStructure.h +++ b/src/server/game/DataStores/DBCStructure.h @@ -1093,9 +1093,6 @@ struct SpellCategoriesEntry uint32 ChargeCategory; // 9 }; -typedef std::set<uint32> SpellCategorySet; -typedef std::map<uint32, SpellCategorySet > SpellCategoryStore; - struct SpellCategoryEntry { uint32 ID; // 0 diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 901bd81ecba..b00b18f2f4f 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -22779,7 +22779,7 @@ void Player::ApplyEquipCooldown(Item* pItem) continue; // Don't replace longer cooldowns by equip cooldown if we have any. - if (GetSpellHistory()->GetRemainingCooldown(effectData->SpellID) > 30 * IN_MILLISECONDS) + if (GetSpellHistory()->GetRemainingCooldown(sSpellMgr->AssertSpellInfo(effectData->SpellID)) > 30 * IN_MILLISECONDS) continue; GetSpellHistory()->AddCooldown(effectData->SpellID, pItem->GetEntry(), std::chrono::seconds(30)); diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp index 8098c8db3d5..1cad126e116 100644 --- a/src/server/game/Spells/Auras/SpellAuras.cpp +++ b/src/server/game/Spells/Auras/SpellAuras.cpp @@ -1485,7 +1485,7 @@ void Aura::HandleAuraSpecificMods(AuraApplication const* aurApp, Unit* caster, b { // This additional check is needed to add a minimal delay before cooldown in in effect // to allow all bubbles broken by a single damage source proc mana return - if (caster->GetSpellHistory()->GetRemainingCooldown(aura->GetId()) <= 11) + if (caster->GetSpellHistory()->GetRemainingCooldown(aura->GetSpellInfo()) <= 11) break; } else // and add if needed diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 632392ada32..80d90bfa543 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -4698,7 +4698,7 @@ SpellCastResult Spell::CheckCast(bool strict) return SPELL_FAILED_NOT_READY; } - if (!m_caster->GetSpellHistory()->IsReady(m_spellInfo)) + if (!m_caster->GetSpellHistory()->IsReady(m_spellInfo, m_castItemEntry)) { if (m_triggeredByAuraSpell) return SPELL_FAILED_DONT_REPORT; diff --git a/src/server/game/Spells/SpellHistory.cpp b/src/server/game/Spells/SpellHistory.cpp index 13aa7b39b03..3b86e3d594b 100644 --- a/src/server/game/Spells/SpellHistory.cpp +++ b/src/server/game/Spells/SpellHistory.cpp @@ -42,6 +42,8 @@ struct SpellHistory::PersistenceHelper<Player> cooldownEntry->CooldownEnd = Clock::from_time_t(time_t(fields[2].GetUInt32())); cooldownEntry->ItemId = fields[1].GetUInt32(); + cooldownEntry->CategoryId = fields[3].GetUInt32(); + cooldownEntry->CategoryEnd = Clock::from_time_t(time_t(fields[4].GetUInt32())); return true; } @@ -61,6 +63,8 @@ struct SpellHistory::PersistenceHelper<Player> stmt->setUInt32(index++, cooldown.first); stmt->setUInt32(index++, cooldown.second.ItemId); stmt->setUInt32(index++, uint32(Clock::to_time_t(cooldown.second.CooldownEnd))); + stmt->setUInt32(index++, cooldown.second.CategoryId); + stmt->setUInt32(index++, uint32(Clock::to_time_t(cooldown.second.CategoryEnd))); } static void WriteCharge(PreparedStatement* stmt, uint8& index, uint32 chargeCategory, ChargeEntry const& charge) @@ -89,6 +93,8 @@ struct SpellHistory::PersistenceHelper<Pet> cooldownEntry->CooldownEnd = Clock::from_time_t(time_t(fields[1].GetUInt32())); cooldownEntry->ItemId = 0; + cooldownEntry->CategoryId = fields[2].GetUInt32(); + cooldownEntry->CategoryEnd = Clock::from_time_t(time_t(fields[3].GetUInt32())); return true; } @@ -107,6 +113,8 @@ struct SpellHistory::PersistenceHelper<Pet> { stmt->setUInt32(index++, cooldown.first); stmt->setUInt32(index++, uint32(Clock::to_time_t(cooldown.second.CooldownEnd))); + stmt->setUInt32(index++, cooldown.second.CategoryId); + stmt->setUInt32(index++, uint32(Clock::to_time_t(cooldown.second.CategoryEnd))); } static void WriteCharge(PreparedStatement* stmt, uint8& index, uint32 chargeCategory, ChargeEntry const& charge) @@ -129,7 +137,11 @@ void SpellHistory::LoadFromDB(PreparedQueryResult cooldownsResult, PreparedQuery uint32 spellId; CooldownEntry cooldown; if (StatementInfo::ReadCooldown(cooldownsResult->Fetch(), &spellId, &cooldown)) + { _spellCooldowns[spellId] = cooldown; + if (cooldown.CategoryId) + _categoryCooldowns[cooldown.CategoryId] = &_spellCooldowns[spellId]; + } } while (cooldownsResult->NextRow()); } @@ -191,10 +203,18 @@ void SpellHistory::Update() { SQLTransaction t; Clock::time_point now = Clock::now(); + for (auto itr = _categoryCooldowns.begin(); itr != _categoryCooldowns.end();) + { + if (itr->second->CategoryEnd < now) + itr = _categoryCooldowns.erase(itr); + else + ++itr; + } + for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();) { if (itr->second.CooldownEnd < now) - itr = _spellCooldowns.erase(itr); + itr = EraseCooldown(itr); else ++itr; } @@ -212,7 +232,7 @@ void SpellHistory::HandleCooldowns(SpellInfo const* spellInfo, Item const* item, HandleCooldowns(spellInfo, item ? item->GetEntry() : 0, spell); } -void SpellHistory::HandleCooldowns(SpellInfo const* spellInfo, uint32 ItemID, Spell* spell /*= nullptr*/) +void SpellHistory::HandleCooldowns(SpellInfo const* spellInfo, uint32 itemID, Spell* spell /*= nullptr*/) { if (ConsumeCharge(spellInfo->ChargeCategoryEntry)) return; @@ -220,11 +240,11 @@ void SpellHistory::HandleCooldowns(SpellInfo const* spellInfo, uint32 ItemID, Sp if (Player* player = _owner->ToPlayer()) { // potions start cooldown until exiting combat - if (ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(ItemID)) + if (ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemID)) { if (itemTemplate->IsPotion() || spellInfo->IsCooldownStartedOnEvent()) { - player->SetLastPotionId(ItemID); + player->SetLastPotionId(itemID); return; } } @@ -233,16 +253,16 @@ void SpellHistory::HandleCooldowns(SpellInfo const* spellInfo, uint32 ItemID, Sp if (spellInfo->IsCooldownStartedOnEvent() || spellInfo->IsPassive() || (spell && spell->IsIgnoringCooldowns())) return; - StartCooldown(spellInfo, ItemID, spell); + StartCooldown(spellInfo, itemID, spell); } -bool SpellHistory::IsReady(SpellInfo const* spellInfo) const +bool SpellHistory::IsReady(SpellInfo const* spellInfo, uint32 itemId /*= 0*/) const { if (spellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE) if (IsSchoolLocked(spellInfo->GetSchoolMask())) return false; - if (HasCooldown(spellInfo->Id)) + if (HasCooldown(spellInfo->Id, itemId)) return false; if (!HasCharge(spellInfo->ChargeCategoryEntry)) @@ -265,11 +285,9 @@ void SpellHistory::WritePacket(WorldPackets::Spells::SendSpellHistory* sendSpell Clock::time_point now = Clock::now(); for (auto const& p : _spellCooldowns) { - SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(p.first); WorldPackets::Spells::SpellHistoryEntry historyEntry; historyEntry.SpellID = p.first; historyEntry.ItemID = p.second.ItemId; - historyEntry.Category = spellInfo->GetCategory(); if (p.second.OnHold) historyEntry.OnHold = true; @@ -279,10 +297,13 @@ void SpellHistory::WritePacket(WorldPackets::Spells::SendSpellHistory* sendSpell if (cooldownDuration.count() <= 0) continue; - if (spellInfo->GetCategory()) - historyEntry.CategoryRecoveryTime = uint32(cooldownDuration.count()); - else - historyEntry.RecoveryTime = uint32(cooldownDuration.count()); + historyEntry.RecoveryTime = uint32(cooldownDuration.count()); + std::chrono::milliseconds categoryDuration = std::chrono::duration_cast<std::chrono::milliseconds>(p.second.CategoryEnd - now); + if (categoryDuration.count() > 0) + { + historyEntry.Category = p.second.CategoryId; + historyEntry.CategoryRecoveryTime = uint32(categoryDuration.count()); + } } sendSpellHistory->Entries.push_back(historyEntry); @@ -324,7 +345,7 @@ void SpellHistory::WritePacket(WorldPackets::Pet::PetSpells* petSpells) SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(p.first); WorldPackets::Pet::PetSpellCooldown petSpellCooldown; petSpellCooldown.SpellID = p.first; - petSpellCooldown.Category = spellInfo->GetCategory(); + petSpellCooldown.Category = p.second.CategoryId; if (!p.second.OnHold) { @@ -332,10 +353,10 @@ void SpellHistory::WritePacket(WorldPackets::Pet::PetSpells* petSpells) if (cooldownDuration.count() <= 0) continue; - if (spellInfo->GetCategory()) - petSpellCooldown.CategoryDuration = uint32(cooldownDuration.count()); - else - petSpellCooldown.Duration = uint32(cooldownDuration.count()); + petSpellCooldown.Duration = uint32(cooldownDuration.count()); + std::chrono::milliseconds categoryDuration = std::chrono::duration_cast<std::chrono::milliseconds>(p.second.CategoryEnd - now); + if (categoryDuration.count() > 0) + petSpellCooldown.CategoryDuration = uint32(categoryDuration.count()); } petSpells->Cooldowns.push_back(historyEntry); @@ -471,7 +492,7 @@ void SpellHistory::StartCooldown(SpellInfo const* spellInfo, uint32 itemId, Spel // self spell cooldown if (recTime != curTime) { - AddCooldown(spellInfo->Id, itemId, recTime, onHold); + AddCooldown(spellInfo->Id, itemId, recTime, categoryId, catrecTime, onHold); if (needsCooldownPacket) { @@ -485,22 +506,6 @@ void SpellHistory::StartCooldown(SpellInfo const* spellInfo, uint32 itemId, Spel } } } - - // category spells - if (categoryId && catrecTime != curTime) - { - SpellCategoryStore::const_iterator i_scstore = sSpellsByCategoryStore.find(categoryId); - if (i_scstore != sSpellsByCategoryStore.end()) - { - for (SpellCategorySet::const_iterator i_scset = i_scstore->second.begin(); i_scset != i_scstore->second.end(); ++i_scset) - { - if (*i_scset == spellInfo->Id) // skip main spell, already handled above - continue; - - AddCooldown(*i_scset, itemId, catrecTime, onHold); - } - } - } } void SpellHistory::SendCooldownEvent(SpellInfo const* spellInfo, uint32 itemId /*= 0*/, Spell* spell /*= nullptr*/, bool startCooldown /*= true*/) @@ -509,43 +514,22 @@ void SpellHistory::SendCooldownEvent(SpellInfo const* spellInfo, uint32 itemId / if (startCooldown) StartCooldown(spellInfo, itemId, spell); + // Send activate cooldown timer (possible 0) at client side if (Player* player = GetPlayerOwner()) - { - // Send activate cooldown timer (possible 0) at client side player->SendDirectMessage(WorldPackets::Spells::CooldownEvent(player != _owner, spellInfo->Id).Write()); - - uint32 category = spellInfo->GetCategory(); - if (category && spellInfo->CategoryRecoveryTime) - { - SpellCategoryStore::const_iterator ct = sSpellsByCategoryStore.find(category); - if (ct != sSpellsByCategoryStore.end()) - { - for (auto const& cooldownPair : _spellCooldowns) - { - uint32 categorySpell = cooldownPair.first; - if (!ct->second.count(categorySpell)) - continue; - - if (categorySpell == spellInfo->Id) // skip main spell, already handled above - continue; - - SpellInfo const* spellInfo2 = sSpellMgr->AssertSpellInfo(categorySpell); - if (!spellInfo2->IsCooldownStartedOnEvent()) - continue; - - player->SendDirectMessage(WorldPackets::Spells::CooldownEvent(player != _owner, categorySpell).Write()); - } - } - } - } } -void SpellHistory::AddCooldown(uint32 spellId, uint32 itemId, Clock::time_point cooldownEnd, bool onHold /*= false*/) +void SpellHistory::AddCooldown(uint32 spellId, uint32 itemId, Clock::time_point cooldownEnd, uint32 categoryId, Clock::time_point categoryEnd, bool onHold /*= false*/) { CooldownEntry& cooldownEntry = _spellCooldowns[spellId]; cooldownEntry.CooldownEnd = cooldownEnd; cooldownEntry.ItemId = itemId; + cooldownEntry.CategoryId = categoryId; + cooldownEntry.CategoryEnd = categoryEnd; cooldownEntry.OnHold = onHold; + + if (categoryId) + _categoryCooldowns[categoryId] = &cooldownEntry; } void SpellHistory::ModifyCooldown(uint32 spellId, int32 cooldownModMs) @@ -559,7 +543,7 @@ void SpellHistory::ModifyCooldown(uint32 spellId, int32 cooldownModMs) if (itr->second.CooldownEnd + offset > now) itr->second.CooldownEnd += offset; else - _spellCooldowns.erase(itr); + EraseCooldown(itr); if (Player* playerOwner = GetPlayerOwner()) { @@ -594,7 +578,7 @@ void SpellHistory::ResetCooldown(CooldownStorageType::iterator& itr, bool update } } - itr = _spellCooldowns.erase(itr); + itr = EraseCooldown(itr); } void SpellHistory::ResetAllCooldowns() @@ -609,31 +593,69 @@ void SpellHistory::ResetAllCooldowns() SendClearCooldowns(cooldowns); } + _categoryCooldowns.clear(); _spellCooldowns.clear(); } -bool SpellHistory::HasCooldown(uint32 spellId) const +bool SpellHistory::HasCooldown(SpellInfo const* spellInfo, uint32 itemId /*= 0*/) const { - return _spellCooldowns.count(spellId) != 0; + if (_spellCooldowns.count(spellInfo->Id) != 0) + return true; + + uint32 category = 0; + if (ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId)) + { + for (ItemEffectEntry const* itemEffect : itemTemplate->Effects) + { + if (itemEffect->SpellID == spellInfo->Id) + { + category = itemEffect->Category; + break; + } + } + } + + if (!category) + category = spellInfo->GetCategory(); + + if (!category) + return false; + + return _categoryCooldowns.count(category) != 0; } -uint32 SpellHistory::GetRemainingCooldown(uint32 spellId) const +bool SpellHistory::HasCooldown(uint32 spellId, uint32 itemId /*= 0*/) const { - auto itr = _spellCooldowns.find(spellId); - if (itr == _spellCooldowns.end()) - return 0; + return HasCooldown(sSpellMgr->AssertSpellInfo(spellId), itemId); +} + +uint32 SpellHistory::GetRemainingCooldown(SpellInfo const* spellInfo) const +{ + Clock::time_point end; + auto itr = _spellCooldowns.find(spellInfo->Id); + if (itr != _spellCooldowns.end()) + end = itr->second.CooldownEnd; + else + { + auto catItr = _categoryCooldowns.find(spellInfo->GetCategory()); + if (catItr == _categoryCooldowns.end()) + return 0; + + end = catItr->second->CategoryEnd; + } Clock::time_point now = Clock::now(); - if (itr->second.CooldownEnd < now) + if (end < now) return 0; - Clock::duration remaining = itr->second.CooldownEnd - now; + Clock::duration remaining = end - now; return uint32(std::chrono::duration_cast<std::chrono::milliseconds>(remaining).count()); } void SpellHistory::LockSpellSchool(SpellSchoolMask schoolMask, uint32 lockoutTime) { - Clock::time_point lockoutEnd = Clock::now() + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(lockoutTime)); + Clock::time_point now = Clock::now(); + Clock::time_point lockoutEnd = now + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(lockoutTime)); for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i) if (SpellSchoolMask(1 << i) & schoolMask) _schoolLockouts[i] = lockoutEnd; @@ -671,10 +693,10 @@ void SpellHistory::LockSpellSchool(SpellSchoolMask schoolMask, uint32 lockoutTim if (spellInfo->PreventionType != SPELL_PREVENTION_TYPE_SILENCE) continue; - if ((schoolMask & spellInfo->GetSchoolMask()) && GetRemainingCooldown(spellId) < lockoutTime) + if ((schoolMask & spellInfo->GetSchoolMask()) && GetRemainingCooldown(spellInfo) < lockoutTime) { spellCooldown.SpellCooldowns.emplace_back(spellId, lockoutTime); - AddCooldown(spellId, 0, lockoutEnd); + AddCooldown(spellId, 0, lockoutEnd, 0, now); } } diff --git a/src/server/game/Spells/SpellHistory.h b/src/server/game/Spells/SpellHistory.h index 9f269dfee73..0a504668997 100644 --- a/src/server/game/Spells/SpellHistory.h +++ b/src/server/game/Spells/SpellHistory.h @@ -46,12 +46,11 @@ public: struct CooldownEntry { - CooldownEntry() : ItemId(0), OnHold(false) { } - CooldownEntry(Clock::time_point endTime, uint32 itemId) : CooldownEnd(endTime), ItemId(itemId), OnHold(false) { } - Clock::time_point CooldownEnd; - uint32 ItemId; - bool OnHold; + uint32 ItemId = 0; + uint32 CategoryId = 0; + Clock::time_point CategoryEnd; + bool OnHold = false; }; struct ChargeEntry @@ -65,6 +64,7 @@ public: }; typedef std::unordered_map<uint32 /*spellId*/, CooldownEntry> CooldownStorageType; + typedef std::unordered_map<uint32 /*categoryId*/, CooldownEntry*> CategoryCooldownStorageType; typedef std::unordered_map<uint32 /*categoryId*/, std::deque<ChargeEntry>> ChargeStorageType; typedef std::unordered_map<uint32 /*categoryId*/, Clock::time_point> GlobalCooldownStorageType; @@ -79,8 +79,8 @@ public: void Update(); void HandleCooldowns(SpellInfo const* spellInfo, Item const* item, Spell* spell = nullptr); - void HandleCooldowns(SpellInfo const* spellInfo, uint32 ItemID, Spell* spell = nullptr); - bool IsReady(SpellInfo const* spellInfo) const; + void HandleCooldowns(SpellInfo const* spellInfo, uint32 itemID, Spell* spell = nullptr); + bool IsReady(SpellInfo const* spellInfo, uint32 itemId = 0) const; template<class PacketType> void WritePacket(PacketType* packet) const; @@ -93,10 +93,11 @@ public: template<class Type, class Period> void AddCooldown(uint32 spellId, uint32 itemId, std::chrono::duration<Type, Period> cooldownDuration) { - AddCooldown(spellId, itemId, Clock::now() + std::chrono::duration_cast<Clock::duration>(cooldownDuration)); + Clock::time_point now = Clock::now(); + AddCooldown(spellId, itemId, now + std::chrono::duration_cast<Clock::duration>(cooldownDuration), 0, now); } - void AddCooldown(uint32 spellId, uint32 itemId, Clock::time_point cooldownEnd, bool onHold = false); + void AddCooldown(uint32 spellId, uint32 itemId, Clock::time_point cooldownEnd, uint32 categoryId, Clock::time_point categoryEnd, bool onHold = false); void ModifyCooldown(uint32 spellId, int32 cooldownModMs); void ResetCooldown(uint32 spellId, bool update = false); void ResetCooldown(CooldownStorageType::iterator& itr, bool update = false); @@ -121,8 +122,9 @@ public: } void ResetAllCooldowns(); - bool HasCooldown(uint32 spellId) const; - uint32 GetRemainingCooldown(uint32 spellId) const; + bool HasCooldown(SpellInfo const* spellInfo, uint32 itemId = 0) const; + bool HasCooldown(uint32 spellId, uint32 itemId = 0) const; + uint32 GetRemainingCooldown(SpellInfo const* spellInfo) const; // School lockouts void LockSpellSchool(SpellSchoolMask schoolMask, uint32 lockoutTime); @@ -145,9 +147,15 @@ public: private: Player* GetPlayerOwner() const; void SendClearCooldowns(std::vector<int32> const& cooldowns) const; + CooldownStorageType::iterator EraseCooldown(CooldownStorageType::iterator itr) + { + _categoryCooldowns.erase(itr->second.CategoryId); + return _spellCooldowns.erase(itr); + } Unit* _owner; CooldownStorageType _spellCooldowns; + CategoryCooldownStorageType _categoryCooldowns; Clock::time_point _schoolLockouts[MAX_SPELL_SCHOOL]; ChargeStorageType _categoryCharges; GlobalCooldownStorageType _globalCooldowns; diff --git a/src/server/scripts/Spells/spell_dk.cpp b/src/server/scripts/Spells/spell_dk.cpp index 98c6781e866..c1aecf6ed4d 100644 --- a/src/server/scripts/Spells/spell_dk.cpp +++ b/src/server/scripts/Spells/spell_dk.cpp @@ -149,7 +149,7 @@ class spell_dk_anti_magic_shell : public SpellScriptLoader { // Cannot reduce cooldown by more than 50% int32 val = std::min(glyph->GetAmount(), int32(absorbedAmount) * 100 / maxHealth); - player->GetSpellHistory()->ModifyCooldown(GetId(), -int32(player->GetSpellHistory()->GetRemainingCooldown(GetId()) * val / 100)); + player->GetSpellHistory()->ModifyCooldown(GetId(), -int32(player->GetSpellHistory()->GetRemainingCooldown(GetSpellInfo()) * val / 100)); } } |