Skip to content

Commit

Permalink
Player: Implement ModifyCooldownTo and fix ModifyCooldown
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Jan 12, 2024
1 parent 6a33d90 commit 799553c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/game/Entities/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25074,7 +25074,7 @@ void Player::ModifyCooldown(uint32 spellId, int32 cooldownModMs)
{
auto& cdData = cdItr->second;
TimePoint expireTime;
if (!cdData->GetSpellCDExpireTime(expireTime) && cdData->GetSpellId() == spellId)
if (cdData->GetSpellCDExpireTime(expireTime) && cdData->GetSpellId() == spellId)
{
if (GetMap()->GetCurrentClockTime() > expireTime + std::chrono::milliseconds(cooldownModMs))
{
Expand All @@ -25093,6 +25093,35 @@ void Player::ModifyCooldown(uint32 spellId, int32 cooldownModMs)
SendDirectMessage(modifyCooldown);
}

void Player::ModifyCooldownTo(uint32 spellId, std::chrono::milliseconds remainingCooldown)
{
TimePoint now = GetMap()->GetCurrentClockTime();
auto cdItr = m_cooldownMap.begin();
std::chrono::milliseconds cdChange;
bool found = false;
for (; cdItr != m_cooldownMap.end(); ++cdItr)
{
auto& cdData = cdItr->second;
TimePoint expireTime;
if (!cdData->GetSpellCDExpireTime(expireTime) && cdData->GetSpellId() == spellId)
{
auto newCdExpiry = now + remainingCooldown;
cdChange = newCdExpiry - expireTime;
cdData->SetSpellCDExpireTime(newCdExpiry);
found = true;
}
}

if (!found)
return;

WorldPacket modifyCooldown(SMSG_MODIFY_COOLDOWN, 4 + 8 + 4);
modifyCooldown << uint32(spellId);
modifyCooldown << uint64(GetObjectGuid());
modifyCooldown << int32(cdChange.count());
SendDirectMessage(modifyCooldown);
}

void Player::RemoveSpellLockout(SpellSchoolMask spellSchoolMask, std::set<uint32>* spellAlreadySent /*= nullptr*/)
{
for (auto ownerSpellItr : GetSpellMap())
Expand Down
1 change: 1 addition & 0 deletions src/game/Entities/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,7 @@ class Player : public Unit
virtual void RemoveAllCooldowns(bool sendOnly = false);
virtual void LockOutSpells(SpellSchoolMask schoolMask, uint32 duration) override;
void ModifyCooldown(uint32 spellId, int32 cooldownModMs);
void ModifyCooldownTo(uint32 spellId, std::chrono::milliseconds remainingCooldown);
void RemoveSpellLockout(SpellSchoolMask spellSchoolMask, std::set<uint32>* spellAlreadySent = nullptr);
void SendClearCooldown(uint32 spell_id, Unit* target) const;
void RemoveArenaSpellCooldowns();
Expand Down

0 comments on commit 799553c

Please sign in to comment.