[10775] Use separate vars to indicate whether reputation needs to be sent or needs to be saved.

This commit is contained in:
Lynx3d 2010-11-21 23:46:01 +01:00
parent 7026dc0d1b
commit 10a1573c8e
3 changed files with 29 additions and 17 deletions

View file

@ -120,7 +120,7 @@ void ReputationMgr::SendForceReactions()
m_player->SendDirectMessage(&data);
}
void ReputationMgr::SendState(FactionState const* faction) const
void ReputationMgr::SendState(FactionState const* faction)
{
uint32 count = 1;
@ -134,13 +134,18 @@ void ReputationMgr::SendState(FactionState const* faction) const
data << (uint32) faction->ReputationListID;
data << (uint32) faction->Standing;
for(FactionStateList::const_iterator itr = m_factions.begin(); itr != m_factions.end(); ++itr)
for(FactionStateList::iterator itr = m_factions.begin(); itr != m_factions.end(); ++itr)
{
if (itr->second.Changed && itr->second.ReputationListID != faction->ReputationListID)
if (itr->second.needSend)
{
data << (uint32) itr->second.ReputationListID;
data << (uint32) itr->second.Standing;
++count;
itr->second.needSend = false;
if (itr->second.ReputationListID != faction->ReputationListID)
{
data << (uint32) itr->second.ReputationListID;
data << (uint32) itr->second.Standing;
++count;
}
}
}
@ -211,7 +216,8 @@ void ReputationMgr::Initialize()
newFaction.ReputationListID = factionEntry->reputationListID;
newFaction.Standing = 0;
newFaction.Flags = GetDefaultStateFlags(factionEntry);
newFaction.Changed = true;
newFaction.needSend = true;
newFaction.needSave = true;
if( newFaction.Flags & FACTION_FLAG_VISIBLE )
++m_visibleFactionCount;
@ -311,7 +317,8 @@ bool ReputationMgr::SetOneFactionReputation(FactionEntry const* factionEntry, in
ReputationRank new_rank = ReputationToRank(standing);
itr->second.Standing = standing - BaseRep;
itr->second.Changed = true;
itr->second.needSend = true;
itr->second.needSave = true;
SetVisible(&itr->second);
@ -364,7 +371,8 @@ void ReputationMgr::SetVisible(FactionState* faction)
return;
faction->Flags |= FACTION_FLAG_VISIBLE;
faction->Changed = true;
faction->needSend = true;
faction->needSave = true;
++m_visibleFactionCount;
@ -399,7 +407,8 @@ void ReputationMgr::SetAtWar(FactionState* faction, bool atWar)
else
faction->Flags &= ~FACTION_FLAG_AT_WAR;
faction->Changed = true;
faction->needSend = true;
faction->needSave = true;
}
void ReputationMgr::SetInactive( RepListID repListID, bool on )
@ -426,7 +435,8 @@ void ReputationMgr::SetInactive(FactionState* faction, bool inactive)
else
faction->Flags &= ~FACTION_FLAG_INACTIVE;
faction->Changed = true;
faction->needSend = true;
faction->needSave = true;
}
void ReputationMgr::LoadFromDB(QueryResult *result)
@ -479,7 +489,8 @@ void ReputationMgr::LoadFromDB(QueryResult *result)
// reset changed flag if values similar to saved in DB
if(faction->Flags==dbFactionFlags)
faction->Changed = false;
faction->needSend = false;
faction->needSave = false;
}
}
while( result->NextRow() );
@ -492,11 +503,11 @@ void ReputationMgr::SaveToDB()
{
for(FactionStateList::iterator itr = m_factions.begin(); itr != m_factions.end(); ++itr)
{
if (itr->second.Changed)
if (itr->second.needSave)
{
CharacterDatabase.PExecute("DELETE FROM character_reputation WHERE guid = '%u' AND faction='%u'", m_player->GetGUIDLow(), itr->second.ID);
CharacterDatabase.PExecute("INSERT INTO character_reputation (guid,faction,standing,flags) VALUES ('%u', '%u', '%i', '%u')", m_player->GetGUIDLow(), itr->second.ID, itr->second.Standing, itr->second.Flags);
itr->second.Changed = false;
itr->second.needSave = false;
}
}
}