refactor(Core/Cache): move the GlobalPlayerCache to its own class (#9166)

This commit is contained in:
Skjalf
2021-11-18 12:53:36 -03:00
committed by GitHub
parent 00dc369cb6
commit 731d256420
47 changed files with 898 additions and 595 deletions

View File

@@ -29,6 +29,7 @@
#include "CellImpl.h"
#include "Channel.h"
#include "ChannelMgr.h"
#include "CharacterCache.h"
#include "CharacterDatabaseCleaner.h"
#include "Chat.h"
#include "Config.h"
@@ -2785,8 +2786,6 @@ void Player::SendNewMail()
void Player::AddNewMailDeliverTime(time_t deliver_time)
{
sWorld->UpdateGlobalPlayerMails(GetGUID().GetCounter(), GetMailSize(), false);
if (deliver_time <= time(nullptr)) // ready now
{
++unReadMails;
@@ -3876,10 +3875,10 @@ void Player::DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool up
// if we want to finally delete the character or the character does not meet the level requirement,
// we set it to mode CHAR_DELETE_REMOVE
if (deleteFinally || Player::GetLevelFromStorage(lowGuid) < charDelete_minLvl)
if (deleteFinally || sCharacterCache->GetCharacterLevelByGuid(playerGuid) < charDelete_minLvl)
charDelete_method = CHAR_DELETE_REMOVE;
if (uint32 guildId = GetGuildIdFromStorage(lowGuid))
if (uint32 guildId = sCharacterCache->GetCharacterGuildIdByGuid(playerGuid))
if (Guild* guild = sGuildMgr->GetGuildById(guildId))
guild->DeleteMember(playerGuid, false, false, true);
@@ -3892,7 +3891,7 @@ void Player::DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool up
sTicketMgr->CloseTicket(ticket->GetId(), playerGuid);
// remove from group
if (uint32 groupId = GetGroupIdFromStorage(lowGuid))
if (uint32 groupId = sCharacterCache->GetCharacterGuildIdByGuid(playerGuid))
if (Group* group = sGroupMgr->GetGroupByGUID(groupId))
RemoveFromGroup(group, playerGuid);
@@ -3984,7 +3983,7 @@ void Player::DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool up
stmt->setUInt32(0, mail_id);
trans->Append(stmt);
uint32 pl_account = sObjectMgr->GetPlayerAccountIdByGUID(lowGuid);
uint32 pl_account = sCharacterCache->GetCharacterAccountIdByGuid(ObjectGuid(HighGuid::Player, lowGuid));
draft.AddMoney(money).SendReturnToSender(pl_account, lowGuid, sender, trans);
} while (resultMail->NextRow());
@@ -6086,33 +6085,6 @@ void Player::ModifyArenaPoints(int32 value, CharacterDatabaseTransaction trans)
}
}
uint32 Player::GetGuildIdFromStorage(ObjectGuid::LowType guid)
{
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
return playerData->guildId;
return 0;
}
uint32 Player::GetGroupIdFromStorage(ObjectGuid::LowType guid)
{
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
return playerData->groupId;
return 0;
}
uint32 Player::GetArenaTeamIdFromStorage(ObjectGuid::LowType guid, uint8 slot)
{
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
{
auto itr = playerData->arenaTeamId.find(slot);
if (itr != playerData->arenaTeamId.end())
{
return itr->second;
}
}
return 0;
}
uint32 Player::GetArenaTeamIdFromDB(ObjectGuid guid, uint8 type)
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ARENA_TEAM_ID_BY_PLAYER_GUID);
@@ -6178,15 +6150,6 @@ uint32 Player::GetZoneIdFromDB(ObjectGuid guid)
return zone;
}
uint32 Player::GetLevelFromStorage(ObjectGuid::LowType guid)
{
// xinef: Get data from global storage
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
return playerData->level;
return 0;
}
//If players are too far away from the duel flag... they lose the duel
void Player::CheckDuelDistance(time_t currTime)
{

View File

@@ -20,6 +20,7 @@
#include "ArenaTeam.h"
#include "Battleground.h"
#include "CharacterCache.h"
#include "DatabaseEnvFwd.h"
#include "DBCStores.h"
#include "GroupReference.h"
@@ -1500,7 +1501,6 @@ public:
static uint32 GetUInt32ValueFromArray(Tokenizer const& data, uint16 index);
static float GetFloatValueFromArray(Tokenizer const& data, uint16 index);
static uint32 GetZoneIdFromDB(ObjectGuid guid);
static uint32 GetLevelFromStorage(ObjectGuid::LowType guid);
static bool LoadPositionFromDB(uint32& mapid, float& x, float& y, float& z, float& o, bool& in_flight, ObjectGuid::LowType guid);
static bool IsValidGender(uint8 Gender) { return Gender <= GENDER_FEMALE; }
@@ -1832,16 +1832,13 @@ public:
{
SetUInt32Value(PLAYER_GUILDID, GuildId);
// xinef: update global storage
sWorld->UpdateGlobalPlayerGuild(GetGUID().GetCounter(), GuildId);
sCharacterCache->UpdateCharacterGuildId(GetGUID(), GetGuildId());
}
void SetRank(uint8 rankId) { SetUInt32Value(PLAYER_GUILDRANK, rankId); }
[[nodiscard]] uint8 GetRank() const { return uint8(GetUInt32Value(PLAYER_GUILDRANK)); }
void SetGuildIdInvited(uint32 GuildId) { m_GuildIdInvited = GuildId; }
[[nodiscard]] uint32 GetGuildId() const { return GetUInt32Value(PLAYER_GUILDID); }
[[nodiscard]] Guild* GetGuild() const;
static uint32 GetGuildIdFromStorage(ObjectGuid::LowType guid);
static uint32 GetGroupIdFromStorage(ObjectGuid::LowType guid);
static uint32 GetArenaTeamIdFromStorage(ObjectGuid::LowType guid, uint8 slot);
uint32 GetGuildIdInvited() { return m_GuildIdInvited; }
static void RemovePetitionsAndSigns(ObjectGuid guid, uint32 type);

View File

@@ -4830,7 +4830,7 @@ void Player::_LoadArenaTeamInfo()
memset((void*)&m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1], 0, sizeof(uint32) * MAX_ARENA_SLOT * ARENA_TEAM_END);
for (auto const& itr : ArenaTeam::ArenaSlotByType)
if (uint32 arenaTeamId = Player::GetArenaTeamIdFromStorage(GetGUID().GetCounter(), itr.second))
if (uint32 arenaTeamId = sCharacterCache->GetCharacterArenaTeamIdByGuid(GetGUID(), itr.second))
{
ArenaTeam* arenaTeam = sArenaTeamMgr->GetArenaTeamById(arenaTeamId);
if (!arenaTeam)
@@ -6564,12 +6564,16 @@ void Player::_LoadSpells(PreparedQueryResult result)
void Player::_LoadGroup()
{
if (uint32 groupId = GetGroupIdFromStorage(GetGUID().GetCounter()))
if (Group* group = sGroupMgr->GetGroupByGUID(groupId))
if (ObjectGuid groupId = sCharacterCache->GetCharacterGroupGuidByGuid(GetGUID()))
{
if (Group* group = sGroupMgr->GetGroupByGUID(groupId.GetCounter()))
{
if (group->GetMemberGroup(GetGUID()) <= MAX_RAID_SUBGROUPS)
{
if (group->IsLeader(GetGUID()))
{
SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GROUP_LEADER);
}
uint8 subgroup = group->GetMemberGroup(GetGUID());
SetGroup(group, subgroup);
@@ -6578,6 +6582,8 @@ void Player::_LoadGroup()
SetDungeonDifficulty(group->GetDungeonDifficulty());
SetRaidDifficulty(group->GetRaidDifficulty());
}
}
}
if (!GetGroup() || !GetGroup()->IsLeader(GetGUID()))
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GROUP_LEADER);