Skip to content

Commit 2add4aa

Browse files
committed
Fix pet cooldowns not being saved and sent properly.
1 parent 4ee66d9 commit 2add4aa

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

src/game/Objects/Pet.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ void Pet::_LoadSpellCooldowns()
15251525
{
15261526
if (!m_pTmpCache)
15271527
return;
1528-
1528+
15291529
std::vector<WorldPackets::Spell::SpellCooldownEntry> cooldownEntries;
15301530
auto curTime = sWorld.GetCurrentClockTime();
15311531
for (const auto& it : m_pTmpCache->spellCooldowns)
@@ -1566,7 +1566,14 @@ void Pet::_LoadSpellCooldowns()
15661566
auto packet = std::make_unique<WorldPackets::Spell::SpellCooldown>();
15671567
packet->casterGuid = GetObjectGuid();
15681568
packet->cooldownEntries = std::move(cooldownEntries);
1569-
owner->GetSession()->SendPacket(std::move(packet));
1569+
1570+
// cooldown packet is ignored if create object is not received yet
1571+
owner->m_Events.AddLambdaEventAtOffset([owner, pkt = std::move(packet)]()
1572+
{
1573+
WorldPacket packet(pkt->GetOpcode());
1574+
pkt->AppendBodyTo(packet);
1575+
owner->GetSession()->SendPacket(&packet);
1576+
}, 1);
15701577
}
15711578
}
15721579

@@ -1581,16 +1588,20 @@ void Pet::_SaveSpellCooldowns()
15811588
SqlStatement stmt = CharacterDatabase.CreateStatement(delSpellCD, "DELETE FROM `pet_spell_cooldown` WHERE `guid` = ?");
15821589
stmt.PExecute(m_charmInfo->GetPetNumber());
15831590

1584-
TimePoint currTime = sWorld.GetCurrentClockTime();
1585-
15861591
for (auto& cdItr : m_cooldownMap)
15871592
{
15881593
auto& cdData = cdItr.second;
15891594
if (!cdData->IsPermanent())
15901595
{
1591-
TimePoint sTime = currTime;
1592-
cdData->GetSpellCDExpireTime(sTime);
1593-
TimePoint spellExpireTime = std::chrono::time_point_cast<std::chrono::milliseconds>(sTime);
1596+
TimePoint spellExpireTime;
1597+
cdData->GetSpellCDExpireTime(spellExpireTime);
1598+
1599+
if (spellExpireTime.time_since_epoch().count() == 0)
1600+
{
1601+
cdData->GetCatCDExpireTime(spellExpireTime);
1602+
if (spellExpireTime.time_since_epoch().count() == 0)
1603+
continue;
1604+
}
15941605

15951606
if (m_pTmpCache)
15961607
{

0 commit comments

Comments
 (0)