some optimization + adding level to CharacterNameData

This commit is contained in:
tibbi
2012-10-08 17:21:09 +01:00
parent d49c2a5e4d
commit 5896da6689
7 changed files with 43 additions and 38 deletions

View File

@@ -7591,7 +7591,7 @@ SpellScriptsBounds ObjectMgr::GetSpellScriptsBounds(uint32 spell_id)
}
// this allows calculating base reputations to offline players, just by race and class
int32 ObjectMgr::GetBaseReputation(FactionEntry const* factionEntry, uint8 race, uint32 playerClass)
int32 ObjectMgr::GetBaseReputation(FactionEntry const* factionEntry, uint8 race, uint8 playerClass)
{
if (!factionEntry)
return 0;
@@ -7599,13 +7599,12 @@ int32 ObjectMgr::GetBaseReputation(FactionEntry const* factionEntry, uint8 race,
uint32 raceMask = (1 << (race - 1));
uint32 classMask = (1 << (playerClass-1));
for (int i=0; i < 4; i++)
for (int i = 0; i < 4; i++)
{
if ((factionEntry->BaseRepRaceMask[i] & raceMask ||
(factionEntry->BaseRepRaceMask[i] == 0 &&
factionEntry->BaseRepClassMask[i] != 0)) &&
(factionEntry->BaseRepClassMask[i] & classMask ||
factionEntry->BaseRepClassMask[i] == 0))
if ((!factionEntry->BaseRepClassMask[i] ||
factionEntry->BaseRepClassMask[i] & classMask) &&
(!factionEntry->BaseRepRaceMask[i] ||
factionEntry->BaseRepRaceMask[i] & raceMask))
return factionEntry->BaseRepValue[i];
}

View File

@@ -749,7 +749,7 @@ class ObjectMgr
return NULL;
}
int32 GetBaseReputation(FactionEntry const* factionEntry, uint8 race, uint32 playerClass);
int32 GetBaseReputation(FactionEntry const* factionEntry, uint8 race, uint8 playerClass);
RepSpilloverTemplate const* GetRepSpilloverTemplate(uint32 factionId) const
{

View File

@@ -660,7 +660,7 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
std::string IP_str = GetRemoteAddress();
sLog->outInfo(LOG_FILTER_CHARACTER, "Account: %d (IP: %s) Create Character:[%s] (GUID: %u)", GetAccountId(), IP_str.c_str(), createInfo->Name.c_str(), newChar.GetGUIDLow());
sScriptMgr->OnPlayerCreate(&newChar);
sWorld->AddCharacterNameData(newChar.GetGUIDLow(), std::string(newChar.GetName()), newChar.getGender(), newChar.getRace(), newChar.getClass());
sWorld->AddCharacterNameData(newChar.GetGUIDLow(), std::string(newChar.GetName()), newChar.getGender(), newChar.getRace(), newChar.getClass(), newChar.getLevel());
newChar.CleanupsBeforeDelete();
delete createInfo;
@@ -1626,22 +1626,14 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
uint32 lowGuid = GUID_LOPART(guid);
// get the players old (at this moment current) race
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_RACE);
stmt->setUInt32(0, guid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
{
WorldPacket data(SMSG_CHAR_FACTION_CHANGE, 1);
data << uint8(CHAR_CREATE_ERROR);
SendPacket(&data);
return;
}
Field* fields = result->Fetch();
uint8 oldRace = fields[0].GetUInt8();
CharacterNameData const* nameData = sWorld->GetCharacterNameData(lowGuid);
uint8 oldRace = nameData->m_race;
uint8 playerClass = nameData->m_class;
uint8 level = nameData->m_level;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_CLASS_LVL_AT_LOGIN);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_CLASS_LVL_AT_LOGIN);
stmt->setUInt32(0, lowGuid);
result = CharacterDatabase.Query(stmt);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
{
@@ -1651,9 +1643,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
return;
}
fields = result->Fetch();
uint32 playerClass = uint32(fields[0].GetUInt8());
uint32 level = uint32(fields[1].GetUInt8());
Field* fields = result->Fetch();
uint32 at_loginFlags = fields[2].GetUInt16();
uint32 used_loginFlag = ((recv_data.GetOpcode() == CMSG_CHAR_RACE_CHANGE) ? AT_LOGIN_CHANGE_RACE : AT_LOGIN_CHANGE_FACTION);
char const* knownTitlesStr = fields[3].GetCString();
@@ -2015,10 +2005,12 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
{
uint32 reputation_alliance = it->first;
uint32 reputation_horde = it->second;
uint32 newReputation = (team == TEAM_ALLIANCE) ? reputation_alliance : reputation_horde;
uint32 oldReputation = (team == TEAM_ALLIANCE) ? reputation_horde : reputation_alliance;
// select old standing set in db
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_REP_BY_FACTION);
stmt->setUInt32(0, team == TEAM_ALLIANCE ? reputation_horde : reputation_alliance);
stmt->setUInt32(0, oldReputation);
stmt->setUInt32(1, lowGuid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
@@ -2032,27 +2024,27 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
Field* fields = result->Fetch();
int32 oldDBRep = fields[0].GetInt32();
FactionEntry const* factionEntry = sFactionStore.LookupEntry(team == TEAM_ALLIANCE ? reputation_horde : reputation_alliance);
FactionEntry const* factionEntry = sFactionStore.LookupEntry(oldReputation);
// old base reputation
int32 oldBaseRep = sObjectMgr->GetBaseReputation(factionEntry, oldRace, playerClass);
// new base reputation
int32 newBaseRep = sObjectMgr->GetBaseReputation(sFactionStore.LookupEntry(team == TEAM_ALLIANCE ? reputation_alliance : reputation_horde), race, playerClass);
int32 newBaseRep = sObjectMgr->GetBaseReputation(sFactionStore.LookupEntry(newReputation), race, playerClass);
// final reputation shouldnt change
int32 FinalRep = oldDBRep + oldBaseRep;
int32 newDBRep = FinalRep - newBaseRep;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_REP_BY_FACTION);
stmt->setUInt32(0, uint16(team == TEAM_ALLIANCE ? reputation_alliance : reputation_horde));
stmt->setUInt32(0, newReputation);
stmt->setUInt32(1, lowGuid);
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_REP_FACTION_CHANGE);
stmt->setUInt16(0, uint16(team == TEAM_ALLIANCE ? reputation_alliance : reputation_horde));
stmt->setUInt16(0, uint16(newReputation));
stmt->setInt32(1, newDBRep);
stmt->setUInt16(2, uint16(team == TEAM_ALLIANCE ? reputation_horde : reputation_alliance));
stmt->setUInt16(2, uint16(oldReputation));
stmt->setUInt32(3, lowGuid);
trans->Append(stmt);
}

View File

@@ -457,6 +457,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
uint8 gender = GENDER_NONE;
uint8 race = RACE_NONE;
uint8 playerClass = 0;
uint8 level = 1;
SQLTransaction trans = CharacterDatabase.BeginTransaction();
while (!feof(fin))
@@ -531,6 +532,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
race = uint8(atol(getnth(line, 4).c_str()));
playerClass = uint8(atol(getnth(line, 5).c_str()));
gender = uint8(atol(getnth(line, 6).c_str()));
level = uint8(atol(getnth(line, 7).c_str()));
if (name == "")
{
// check if the original name already exists
@@ -674,7 +676,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
CharacterDatabase.CommitTransaction(trans);
// in case of name conflict player has to rename at login anyway
sWorld->AddCharacterNameData(guid, name, gender, race, playerClass);
sWorld->AddCharacterNameData(guid, name, gender, race, playerClass, level);
sObjectMgr->_hiItemGuid += items.size();
sObjectMgr->_mailId += mails.size();

View File

@@ -2937,7 +2937,7 @@ void World::LoadCharacterNameData()
{
sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Loading character name data");
QueryResult result = CharacterDatabase.Query("SELECT guid, name, race, gender, class FROM characters WHERE deleteDate IS NULL");
QueryResult result = CharacterDatabase.Query("SELECT guid, name, race, gender, class, level FROM characters WHERE deleteDate IS NULL");
if (!result)
{
sLog->outInfo(LOG_FILTER_SERVER_LOADING, "No character name data loaded, empty query");
@@ -2950,20 +2950,21 @@ void World::LoadCharacterNameData()
{
Field* fields = result->Fetch();
AddCharacterNameData(fields[0].GetUInt32(), fields[1].GetString(),
fields[3].GetUInt8() /*gender*/, fields[2].GetUInt8() /*race*/, fields[4].GetUInt8() /*class*/);
fields[3].GetUInt8() /*gender*/, fields[2].GetUInt8() /*race*/, fields[4].GetUInt8() /*class*/, fields[5].GetUInt8() /*level*/);
++count;
} while (result->NextRow());
sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Loaded name data for %u characters", count);
}
void World::AddCharacterNameData(uint32 guid, std::string const& name, uint8 gender, uint8 race, uint8 playerClass)
void World::AddCharacterNameData(uint32 guid, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level)
{
CharacterNameData& data = _characterNameDataMap[guid];
data.m_name = name;
data.m_race = race;
data.m_gender = gender;
data.m_class = playerClass;
data.m_level = level;
}
void World::UpdateCharacterNameData(uint32 guid, std::string const& name, uint8 gender /*= GENDER_NONE*/, uint8 race /*= RACE_NONE*/)
@@ -2981,6 +2982,15 @@ void World::UpdateCharacterNameData(uint32 guid, std::string const& name, uint8
itr->second.m_race = race;
}
void World::UpdateCharacterNameDataLevel(uint32 guid, uint8 level)
{
std::map<uint32, CharacterNameData>::iterator itr = _characterNameDataMap.find(guid);
if (itr == _characterNameDataMap.end())
return;
itr->second.m_level = level;
}
CharacterNameData const* World::GetCharacterNameData(uint32 guid) const
{
std::map<uint32, CharacterNameData>::const_iterator itr = _characterNameDataMap.find(guid);

View File

@@ -538,6 +538,7 @@ struct CharacterNameData
uint8 m_class;
uint8 m_race;
uint8 m_gender;
uint8 m_level;
};
/// The World
@@ -759,8 +760,9 @@ class World
bool isEventKillStart;
CharacterNameData const* GetCharacterNameData(uint32 guid) const;
void AddCharacterNameData(uint32 guid, std::string const& name, uint8 gender, uint8 race, uint8 playerClass);
void AddCharacterNameData(uint32 guid, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level);
void UpdateCharacterNameData(uint32 guid, std::string const& name, uint8 gender = GENDER_NONE, uint8 race = RACE_NONE);
void UpdateCharacterNameDataLevel(uint32 guid, uint8 level);
void DeleteCharaceterNameData(uint32 guid) { _characterNameDataMap.erase(guid); }
uint32 GetCleaningFlags() const { return m_CleaningFlags; }

View File

@@ -224,7 +224,7 @@ public:
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_NAME_DATA);
stmt->setUInt32(0, delInfo.lowGuid);
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
sWorld->AddCharacterNameData(delInfo.lowGuid, delInfo.name, (*result)[2].GetUInt8(), (*result)[0].GetUInt8(), (*result)[1].GetUInt8());
sWorld->AddCharacterNameData(delInfo.lowGuid, delInfo.name, (*result)[2].GetUInt8(), (*result)[0].GetUInt8(), (*result)[1].GetUInt8(), (*result)[2].GetUInt8());
}
static void HandleCharacterLevel(Player* player, uint64 playerGuid, uint32 oldLevel, uint32 newLevel, ChatHandler* handler)