Skip to content

Commit

Permalink
Player: Refactor corpse reclaim delay code to fix crash
Browse files Browse the repository at this point in the history
Closes #477
  • Loading branch information
Karth-Xyver authored and killerwife committed Oct 29, 2023
1 parent 5247c28 commit 030f137
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/game/Entities/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,22 @@ SpellAuraHolder const* Player::GetMirrorTimerBuff(MirrorTimer::Type timer) const
}
}

uint32 Player::getCorpseReclaimDelayHelper(time_t deathExpirationTime, time_t time, bool pvp) const
{
uint32 count;
if ((pvp && sWorld.getConfig(CONFIG_BOOL_DEATH_CORPSE_RECLAIM_DELAY_PVP)) ||
(!pvp && sWorld.getConfig(CONFIG_BOOL_DEATH_CORPSE_RECLAIM_DELAY_PVE)))
{
count = uint32(deathExpirationTime - time) / DEATH_EXPIRE_STEP;
if (count >= MAX_DEATH_COUNT)
count = MAX_DEATH_COUNT - 1;
}
else
count = 0;

return corpseReclaimDelay[count];
}

bool Player::IsMirrorTimerActive(MirrorTimer::Type timer) const
{
return m_mirrorTimers[timer].IsActive();
Expand Down Expand Up @@ -22358,16 +22374,11 @@ void Player::UpdateZoneDependentPets()

uint32 Player::GetCorpseReclaimDelay(bool pvp) const
{
if ((pvp && !sWorld.getConfig(CONFIG_BOOL_DEATH_CORPSE_RECLAIM_DELAY_PVP)) ||
(!pvp && !sWorld.getConfig(CONFIG_BOOL_DEATH_CORPSE_RECLAIM_DELAY_PVE)))
{
return corpseReclaimDelay[0];
}

time_t now = time(nullptr);
if (now > m_deathExpireTime)
now = m_deathExpireTime;
// 0..2 full period
uint32 count = (now < m_deathExpireTime) ? uint32((m_deathExpireTime - now) / DEATH_EXPIRE_STEP) : 0;
return corpseReclaimDelay[count];
return getCorpseReclaimDelayHelper(m_deathExpireTime, now, pvp);
}

void Player::UpdateCorpseReclaimDelay()
Expand Down Expand Up @@ -22405,19 +22416,7 @@ void Player::SendCorpseReclaimDelay(bool load) const
return;

bool pvp = corpse->GetType() == CORPSE_RESURRECTABLE_PVP;

uint32 count;
if ((pvp && sWorld.getConfig(CONFIG_BOOL_DEATH_CORPSE_RECLAIM_DELAY_PVP)) ||
(!pvp && sWorld.getConfig(CONFIG_BOOL_DEATH_CORPSE_RECLAIM_DELAY_PVE)))
{
count = uint32(m_deathExpireTime - corpse->GetGhostTime()) / DEATH_EXPIRE_STEP;
if (count >= MAX_DEATH_COUNT)
count = MAX_DEATH_COUNT - 1;
}
else
count = 0;

time_t expected_time = corpse->GetGhostTime() + corpseReclaimDelay[count];
time_t expected_time = corpse->GetGhostTime() + getCorpseReclaimDelayHelper(m_deathExpireTime, corpse->GetGhostTime(), pvp);

time_t now = time(nullptr);
if (now >= expected_time)
Expand Down
2 changes: 2 additions & 0 deletions src/game/Entities/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,8 @@ class Player : public Unit
inline uint32 GetMirrorTimerMaxDuration(MirrorTimer::Type timer) const;
inline SpellAuraHolder const* GetMirrorTimerBuff(MirrorTimer::Type timer) const;

uint32 getCorpseReclaimDelayHelper(time_t deathExpirationTime, time_t time, bool pvp) const;

/*********************************************************/
/*** HONOR SYSTEM ***/
/*********************************************************/
Expand Down

0 comments on commit 030f137

Please sign in to comment.