Core/Misc: Split the calculating of the corpse reclaim delay and sending of SMSG_CORPSE_RECLAIM_DELAY in two different methods.

This commit is contained in:
Discover- committed 2014-01-19 13:50:30 +01:00
1 parent 55bde59a92
commit e1f1e0cef5
3 files changed
+48 -39

No files matched your search

+38 -30
View File
@@ -5127,7 +5127,10 @@ void Player::BuildPlayerRepop()
// BG - remove insignia related
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
SendCorpseReclaimDelay();
int32 corpseReclaimDelay = CalculateCorpseReclaimDelay();
if (corpseReclaimDelay >= 0)
SendCorpseReclaimDelay(corpseReclaimDelay);
// to prevent cheating
corpse->ResetGhostTime();
@@ -5235,7 +5238,11 @@ void Player::KillPlayer()
m_deathTimer = 6 * MINUTE * IN_MILLISECONDS;
UpdateCorpseReclaimDelay(); // dependent at use SetDeathPvP() call before kill
SendCorpseReclaimDelay();
int32 corpseReclaimDelay = CalculateCorpseReclaimDelay();
if (corpseReclaimDelay >= 0)
SendCorpseReclaimDelay(corpseReclaimDelay);
// don't create corpse at this moment, player might be falling
@@ -23844,7 +23851,7 @@ uint32 Player::GetCorpseReclaimDelay(bool pvp) const
time_t now = time(NULL);
// 0..2 full period
// should be ceil(x)-1 but not floor(x)
uint64 count = (now < m_deathExpireTime - 1) ? (m_deathExpireTime - 1 - now)/DEATH_EXPIRE_STEP : 0;
uint64 count = (now < m_deathExpireTime - 1) ? (m_deathExpireTime - 1 - now) / DEATH_EXPIRE_STEP : 0;
return copseReclaimDelay[count];
}
@@ -23857,65 +23864,66 @@ void Player::UpdateCorpseReclaimDelay()
return;
time_t now = time(NULL);
if (now < m_deathExpireTime)
{
// full and partly periods 1..3
uint64 count = (m_deathExpireTime - now)/DEATH_EXPIRE_STEP +1;
uint64 count = (m_deathExpireTime - now) / DEATH_EXPIRE_STEP + 1;
if (count < MAX_DEATH_COUNT)
m_deathExpireTime = now+(count+1)*DEATH_EXPIRE_STEP;
m_deathExpireTime = now+(count + 1) * DEATH_EXPIRE_STEP;
else
m_deathExpireTime = now+MAX_DEATH_COUNT*DEATH_EXPIRE_STEP;
m_deathExpireTime = now + MAX_DEATH_COUNT*DEATH_EXPIRE_STEP;
}
else
m_deathExpireTime = now+DEATH_EXPIRE_STEP;
m_deathExpireTime = now + DEATH_EXPIRE_STEP;
}
void Player::SendCorpseReclaimDelay(bool load)
int32 Player::CalculateCorpseReclaimDelay(bool load)
{
Corpse* corpse = GetCorpse();
if (load && !corpse)
return;
return -1;
bool pvp;
if (corpse)
pvp = (corpse->GetType() == CORPSE_RESURRECTABLE_PVP);
else
pvp = (m_ExtraFlags & PLAYER_EXTRA_PVP_DEATH);
bool pvp = corpse ? corpse->GetType() == CORPSE_RESURRECTABLE_PVP : m_ExtraFlags & PLAYER_EXTRA_PVP_DEATH;
uint32 delay;
time_t delay;
if (load)
{
if (corpse->GetGhostTime() > m_deathExpireTime)
return;
return -1;
uint64 count = 0;
uint64 count;
if ((pvp && sWorld->getBoolConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVP)) ||
(!pvp && sWorld->getBoolConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE)))
{
count = (m_deathExpireTime-corpse->GetGhostTime())/DEATH_EXPIRE_STEP;
count = (m_deathExpireTime - corpse->GetGhostTime()) / DEATH_EXPIRE_STEP;
if (count >= MAX_DEATH_COUNT)
count = MAX_DEATH_COUNT-1;
count = MAX_DEATH_COUNT - 1;
}
else
count=0;
time_t expected_time = corpse->GetGhostTime()+copseReclaimDelay[count];
time_t expected_time = corpse->GetGhostTime() + copseReclaimDelay[count];
time_t now = time(NULL);
if (now >= expected_time)
return;
delay = expected_time-now;
if (now >= expected_time)
return -1;
delay = expected_time - now;
}
else
delay = GetCorpseReclaimDelay(pvp);
if (!delay)
return;
return delay * IN_MILLISECONDS;
}
//! corpse reclaim delay 30 * 1000ms or longer at often deaths
void Player::SendCorpseReclaimDelay(uint32 delay)
{
WorldPacket data(SMSG_CORPSE_RECLAIM_DELAY, 4);
data << uint32(delay*IN_MILLISECONDS);
data << uint32(delay);
GetSession()->SendPacket(&data);
}
+2 -1
View File
@@ -1936,7 +1936,8 @@ class Player : public Unit, public GridObject<Player>
uint32 GetDeathTimer() const { return m_deathTimer; }
uint32 GetCorpseReclaimDelay(bool pvp) const;
void UpdateCorpseReclaimDelay();
void SendCorpseReclaimDelay(bool load = false);
int32 CalculateCorpseReclaimDelay(bool load = false);
void SendCorpseReclaimDelay(uint32 delay);
uint32 GetShieldBlockValue() const; // overwrite Unit version (virtual)
bool CanParry() const { return m_canParry; }
+8 -8
View File
@@ -734,34 +734,34 @@ void WorldSession::HandleReclaimCorpseOpcode(WorldPacket& recvData)
uint64 guid;
recvData >> guid;
if (GetPlayer()->IsAlive())
if (_player->IsAlive())
return;
// do not allow corpse reclaim in arena
if (GetPlayer()->InArena())
if (_player->InArena())
return;
// body not released yet
if (!GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
if (!_player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
return;
Corpse* corpse = GetPlayer()->GetCorpse();
Corpse* corpse = _player->GetCorpse();
if (!corpse)
return;
// prevent resurrect before 30-sec delay after body release not finished
if (time_t(corpse->GetGhostTime() + GetPlayer()->GetCorpseReclaimDelay(corpse->GetType() == CORPSE_RESURRECTABLE_PVP)) > time_t(time(NULL)))
if (time_t(corpse->GetGhostTime() + _player->GetCorpseReclaimDelay(corpse->GetType() == CORPSE_RESURRECTABLE_PVP)) > time_t(time(NULL)))
return;
if (!corpse->IsWithinDistInMap(GetPlayer(), CORPSE_RECLAIM_RADIUS, true))
if (!corpse->IsWithinDistInMap(_player, CORPSE_RECLAIM_RADIUS, true))
return;
// resurrect
GetPlayer()->ResurrectPlayer(GetPlayer()->InBattleground() ? 1.0f : 0.5f);
_player->ResurrectPlayer(_player->InBattleground() ? 1.0f : 0.5f);
// spawn bones
GetPlayer()->SpawnCorpseBones();
_player->SpawnCorpseBones();
}
void WorldSession::HandleResurrectResponseOpcode(WorldPacket& recvData)