Few small optimizations here and there

This commit is contained in:
Aokromes committed 2017-02-01 16:51:21 +01:00
1 parent 0f9c7106ce
commit 8bb777ef5c
35 files changed
+366 -373

No files matched your search

+60 -74
View File
@@ -62,6 +62,7 @@
#include "OutdoorPvP.h"
#include "OutdoorPvPMgr.h"
#include "Pet.h"
#include "QueryCallback.h"
#include "QuestDef.h"
#include "ReputationMgr.h"
#include "GitRevision.h"
@@ -4142,7 +4143,7 @@ void Player::DestroyForPlayer(Player* target, bool onDeath) const
{
Unit::DestroyForPlayer(target, onDeath);
for (uint8 i = 0; i < INVENTORY_SLOT_BAG_END; ++i)
for (uint8 i = 0; i < EQUIPMENT_SLOT_END; ++i)
{
if (m_items[i] == nullptr)
continue;
@@ -4271,22 +4272,26 @@ void Player::DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRe
// Convert guid to low GUID for CharacterNameData, but also other methods on success
ObjectGuid::LowType guid = playerguid.GetCounter();
uint32 charDelete_method = sWorld->getIntConfig(CONFIG_CHARDELETE_METHOD);
CharacterInfo const* characterInfo = sWorld->GetCharacterInfo(playerguid);
std::string name;
if (characterInfo)
name = characterInfo->Name;
if (deleteFinally)
charDelete_method = CHAR_DELETE_REMOVE;
else if (CharacterInfo const* nameData = sWorld->GetCharacterInfo(playerguid)) // To avoid a query, we select loaded data. If it doesn't exist, return.
else if (characterInfo) // To avoid a query, we select loaded data. If it doesn't exist, return.
{
// Define the required variables
uint32 charDelete_minLvl = sWorld->getIntConfig(nameData->Class != CLASS_DEATH_KNIGHT ? CONFIG_CHARDELETE_MIN_LEVEL : CONFIG_CHARDELETE_HEROIC_MIN_LEVEL);
uint32 charDelete_minLvl = sWorld->getIntConfig(characterInfo->Class != CLASS_DEATH_KNIGHT ? CONFIG_CHARDELETE_MIN_LEVEL : CONFIG_CHARDELETE_HEROIC_MIN_LEVEL);
// if we want to finalize the character removal or the character does not meet the level requirement of either heroic or non-heroic settings,
// we set it to mode CHAR_DELETE_REMOVE
if (nameData->Level < charDelete_minLvl)
if (characterInfo->Level < charDelete_minLvl)
charDelete_method = CHAR_DELETE_REMOVE;
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
if (ObjectGuid::LowType guildId = GetGuildIdFromDB(playerguid))
if (ObjectGuid::LowType guildId = Player::GetGuildIdFromCharacterInfo(playerguid))
if (Guild* guild = sGuildMgr->GetGuildById(guildId))
guild->DeleteMember(trans, playerguid, false, false, true);
@@ -4627,7 +4632,7 @@ void Player::DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRe
if (updateRealmChars)
sWorld->UpdateRealmCharCount(accountId);
sWorld->DeleteCharacterInfo(playerguid);
sWorld->DeleteCharacterInfo(playerguid, name);
}
/**
@@ -7296,24 +7301,13 @@ void Player::SetInGuild(uint32 guildId)
SetUInt16Value(OBJECT_FIELD_TYPE, 1, guildId != 0);
}
uint32 Player::GetGuildIdFromDB(ObjectGuid guid)
ObjectGuid::LowType Player::GetGuildIdFromCharacterInfo(ObjectGuid guid)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUILD_MEMBER);
stmt->setUInt32(0, guid.GetCounter());
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
return result->Fetch()[0].GetUInt32();
CharacterInfo const* characterInfo = sWorld->GetCharacterInfo(guid);
if (!characterInfo)
return 0;
}
uint8 Player::GetRankFromDB(ObjectGuid guid)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUILD_MEMBER);
stmt->setUInt32(0, guid.GetCounter());
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
return result->Fetch()[1].GetUInt8();
return 0;
return characterInfo->GuildId;
}
void Player::SetArenaTeamInfoField(uint8 slot, ArenaTeamInfoType type, uint32 value)
@@ -7332,18 +7326,13 @@ void Player::SetInArenaTeam(uint32 ArenaTeamId, uint8 slot, uint8 type)
SetArenaTeamInfoField(slot, ARENA_TEAM_TYPE, type);
}
uint32 Player::GetArenaTeamIdFromDB(ObjectGuid guid, uint8 type)
uint32 Player::GetArenaTeamIdFromCharacterInfo(ObjectGuid guid, uint8 type)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ARENA_TEAM_ID_BY_PLAYER_GUID);
stmt->setUInt32(0, guid.GetCounter());
stmt->setUInt8(1, type);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
CharacterInfo const* characterInfo = sWorld->GetCharacterInfo(guid);
if (!characterInfo)
return 0;
uint32 id = (*result)[0].GetUInt32();
return id;
return characterInfo->ArenaTeamId[type];
}
uint32 Player::GetZoneIdFromDB(ObjectGuid guid)
@@ -7392,19 +7381,13 @@ uint32 Player::GetZoneIdFromDB(ObjectGuid guid)
return zone;
}
uint32 Player::GetLevelFromDB(ObjectGuid guid)
uint32 Player::GetLevelFromCharacterInfo(ObjectGuid guid)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_LEVEL);
stmt->setUInt32(0, guid.GetCounter());
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
CharacterInfo const* characterInfo = sWorld->GetCharacterInfo(guid);
if (!characterInfo)
return 0;
Field* fields = result->Fetch();
uint8 level = fields[0].GetUInt8();
return level;
return characterInfo->Level;
}
void Player::UpdateArea(uint32 newArea)
@@ -15822,17 +15805,17 @@ bool Player::SatisfyQuestWeek(Quest const* qInfo, bool /*msg*/)
return m_weeklyquests.find(qInfo->GetQuestId()) == m_weeklyquests.end();
}
bool Player::SatisfyQuestSeasonal(Quest const* qInfo, bool /*msg*/)
bool Player::SatisfyQuestSeasonal(Quest const* qInfo, bool /*msg*/) const
{
if (!qInfo->IsSeasonal() || m_seasonalquests.empty())
return true;
uint16 eventId = sGameEventMgr->GetEventIdForQuest(qInfo);
if (m_seasonalquests.find(eventId) == m_seasonalquests.end() || m_seasonalquests[eventId].empty())
auto itr = m_seasonalquests.find(qInfo->GetEventIdForQuest());
if (itr == m_seasonalquests.end() || itr->second.empty())
return true;
// if not found in cooldown list
return m_seasonalquests[eventId].find(qInfo->GetQuestId()) == m_seasonalquests[eventId].end();
return itr->second.find(qInfo->GetQuestId()) == itr->second.end();
}
bool Player::SatisfyQuestMonth(Quest const* qInfo, bool /*msg*/)
@@ -15918,15 +15901,7 @@ bool Player::GetQuestRewardStatus(uint32 quest_id) const
if (qInfo)
{
if (qInfo->IsSeasonal() && !qInfo->IsRepeatable())
{
uint16 eventId = sGameEventMgr->GetEventIdForQuest(qInfo);
auto seasonalQuestItr = m_seasonalquests.find(eventId);
if (seasonalQuestItr != m_seasonalquests.end())
return seasonalQuestItr->second.find(quest_id) != seasonalQuestItr->second.end();
return false;
}
return !SatisfyQuestSeasonal(qInfo, false);
// for repeatable quests: rewarded field is set after first reward only to prevent getting XP more than once
if (!qInfo->IsRepeatable())
@@ -15948,14 +15923,9 @@ QuestStatus Player::GetQuestStatus(uint32 quest_id) const
if (Quest const* qInfo = sObjectMgr->GetQuestTemplate(quest_id))
{
if (qInfo->IsSeasonal() && !qInfo->IsRepeatable())
{
uint16 eventId = sGameEventMgr->GetEventIdForQuest(qInfo);
auto seasonalQuestItr = m_seasonalquests.find(eventId);
if (seasonalQuestItr == m_seasonalquests.end() || seasonalQuestItr->second.find(quest_id) == seasonalQuestItr->second.end())
return QUEST_STATUS_NONE;
}
return SatisfyQuestSeasonal(qInfo, false) ? QUEST_STATUS_NONE : QUEST_STATUS_REWARDED;
if (!qInfo->IsRepeatable() && m_RewardedQuests.find(quest_id) != m_RewardedQuests.end())
if (!qInfo->IsRepeatable() && IsQuestRewarded(quest_id))
return QUEST_STATUS_REWARDED;
}
}
@@ -21480,17 +21450,13 @@ void Player::RemovePetitionsAndSigns(ObjectGuid guid, uint32 type)
void Player::LeaveAllArenaTeams(ObjectGuid guid)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PLAYER_ARENA_TEAMS);
stmt->setUInt32(0, guid.GetCounter());
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
CharacterInfo const* characterInfo = sWorld->GetCharacterInfo(guid);
if (!characterInfo)
return;
do
for (uint8 i = 0; i < MAX_ARENA_SLOT; ++i)
{
Field* fields = result->Fetch();
uint32 arenaTeamId = fields[0].GetUInt32();
uint32 arenaTeamId = characterInfo->ArenaTeamId[i];
if (arenaTeamId != 0)
{
ArenaTeam* arenaTeam = sArenaTeamMgr->GetArenaTeamById(arenaTeamId);
@@ -21498,7 +21464,6 @@ void Player::LeaveAllArenaTeams(ObjectGuid guid)
arenaTeam->DelMember(guid, true);
}
}
while (result->NextRow());
}
void Player::SetRestBonus(float rest_bonus_new)
@@ -23695,7 +23660,7 @@ void Player::SetSeasonalQuestStatus(uint32 quest_id)
if (!quest)
return;
m_seasonalquests[sGameEventMgr->GetEventIdForQuest(quest)].insert(quest_id);
m_seasonalquests[quest->GetEventIdForQuest()].insert(quest_id);
m_SeasonalQuestChanged = true;
}
@@ -26693,15 +26658,22 @@ void Player::ActivateSpec(uint8 spec)
SetUsedTalentCount(spentTalents);
InitTalentForLevel();
// load them asynchronously
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_ACTIONS_SPEC);
stmt->setUInt32(0, GetGUID().GetCounter());
stmt->setUInt8(1, GetActiveSpec());
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
_LoadActions(result);
}
SendActionButtons(1);
WorldSession* mySess = GetSession();
mySess->GetQueryProcessor().AddQuery(CharacterDatabase.AsyncQuery(stmt)
.WithPreparedCallback([mySess](PreparedQueryResult result)
{
// safe callback, we can't pass this pointer directly
// in case player logs out before db response (player would be deleted in that case)
if (Player* thisPlayer = mySess->GetPlayer())
thisPlayer->LoadActions(result);
}));
}
Powers pw = getPowerType();
if (pw != POWER_MANA)
@@ -26720,6 +26692,14 @@ void Player::ActivateSpec(uint8 spec)
ResetTalents(true);
}
void Player::LoadActions(PreparedQueryResult result)
{
if (result)
_LoadActions(result);
SendActionButtons(1);
}
void Player::ResetTimeSync()
{
m_timeSyncTimer = 0;
@@ -27299,6 +27279,12 @@ std::string Player::GetCoordsMapAreaAndZoneString() const
return str.str();
}
void Player::SetInGuild(uint32 guildId)
{
SetUInt32Value(PLAYER_GUILDID, guildId);
sWorld->UpdateCharacterGuildId(GetGUID(), guildId);
}
Guild* Player::GetGuild()
{
uint32 guildId = GetGuildId();