Entities/Player: Properly restore PvP-enabled state on login

(cherry picked from commit 671052575a36624b06379ee5e13a7fea26870194)
This commit is contained in:
Treeston
2021-12-14 23:31:56 +01:00
committed by Shauren
parent 3ad5bc1e15
commit a5d8807af8
3 changed files with 29 additions and 14 deletions
+26 -12
View File
@@ -18357,11 +18357,10 @@ bool Player::LoadFromDB(ObjectGuid guid, CharacterDatabaseQueryHolder* holder)
// set value, including drunk invisibility detection
// calculate sobering. after 15 minutes logged out, the player will be sober again
uint8 newDrunkValue = 0;
if (time_diff < uint32(GetDrunkValue()) * 9)
newDrunkValue = GetDrunkValue() - time_diff / 9;
SetDrunkValue(newDrunkValue);
SetDrunkValue(GetDrunkValue() - time_diff / 9);
else
SetDrunkValue(0);
m_createTime = fields.createTime;
m_createMode = fields.createMode;
@@ -18602,6 +18601,8 @@ bool Player::LoadFromDB(ObjectGuid guid, CharacterDatabaseQueryHolder* holder)
}
}
InitPvP();
// RaF stuff.
if (GetSession()->IsARecruiter() || (GetSession()->GetRecruiterId() != 0))
AddDynamicFlag(UNIT_DYNFLAG_REFER_A_FRIEND);
@@ -21875,13 +21876,14 @@ void Player::ResetContestedPvP()
void Player::UpdatePvPFlag(time_t currTime)
{
if (!IsPvP())
return;
if (pvpInfo.EndTimer && pvpInfo.EndTimer <= currTime)
{
pvpInfo.EndTimer = 0;
RemovePlayerFlag(PLAYER_FLAGS_PVP_TIMER);
}
if (!pvpInfo.EndTimer || currTime < (pvpInfo.EndTimer + 300) || pvpInfo.IsHostile)
return;
UpdatePvP(false);
if (IsPvP() && !pvpInfo.IsHostile && !HasPlayerFlag(PlayerFlags(PLAYER_FLAGS_IN_PVP | PLAYER_FLAGS_PVP_TIMER)))
UpdatePvP(false);
}
void Player::UpdateDuelFlag(time_t currTime)
@@ -23553,6 +23555,18 @@ void Player::UpdateHomebindTime(uint32 time)
}
}
void Player::InitPvP()
{
if (HasPlayerFlag(PLAYER_FLAGS_IN_PVP))
UpdatePvP(true, true);
else if (HasPlayerFlag(PLAYER_FLAGS_PVP_TIMER))
{
UpdatePvP(true, true);
if (!pvpInfo.IsHostile)
pvpInfo.EndTimer = GameTime::GetGameTime() + 300;
}
}
void Player::UpdatePvPState(bool onlyFFA)
{
/// @todo should we always synchronize UNIT_FIELD_BYTES_2, 1 of controller and controlled?
@@ -23585,7 +23599,7 @@ void Player::UpdatePvPState(bool onlyFFA)
else // in friendly area
{
if (IsPvP() && !HasPlayerFlag(PLAYER_FLAGS_IN_PVP) && !pvpInfo.EndTimer)
pvpInfo.EndTimer = GameTime::GetGameTime(); // start toggle-off
pvpInfo.EndTimer = GameTime::GetGameTime() + 300; // start toggle-off
}
}
@@ -23605,7 +23619,7 @@ void Player::UpdatePvP(bool state, bool _override)
}
else
{
pvpInfo.EndTimer = GameTime::GetGameTime();
pvpInfo.EndTimer = GameTime::GetGameTime() + 300;
SetPvP(state);
}
}
+1
View File
@@ -1891,6 +1891,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
void SetMultiActionBars(uint8 mask) { SetUpdateFieldValue(m_values.ModifyValue(&Player::m_activePlayerData).ModifyValue(&UF::ActivePlayerData::MultiActionBars), mask); }
PvPInfo pvpInfo;
void InitPvP();
void UpdatePvPState(bool onlyFFA = false);
void SetPvP(bool state) override;
void UpdatePvP(bool state, bool override = false);
+2 -2
View File
@@ -318,7 +318,7 @@ void WorldSession::HandleTogglePvP(WorldPackets::Misc::TogglePvP& /*packet*/)
GetPlayer()->RemovePlayerFlag(PLAYER_FLAGS_IN_PVP);
GetPlayer()->AddPlayerFlag(PLAYER_FLAGS_PVP_TIMER);
if (!GetPlayer()->pvpInfo.IsHostile && GetPlayer()->IsPvP())
GetPlayer()->pvpInfo.EndTimer = GameTime::GetGameTime(); // start toggle-off
GetPlayer()->pvpInfo.EndTimer = GameTime::GetGameTime() + 300; // start toggle-off
}
else
{
@@ -336,7 +336,7 @@ void WorldSession::HandleSetPvP(WorldPackets::Misc::SetPvP& packet)
GetPlayer()->RemovePlayerFlag(PLAYER_FLAGS_IN_PVP);
GetPlayer()->AddPlayerFlag(PLAYER_FLAGS_PVP_TIMER);
if (!GetPlayer()->pvpInfo.IsHostile && GetPlayer()->IsPvP())
GetPlayer()->pvpInfo.EndTimer = GameTime::GetGameTime(); // start toggle-off
GetPlayer()->pvpInfo.EndTimer = GameTime::GetGameTime() + 300; // start toggle-off
}
else
{