mirror of
https://github.com/mangosfour/server.git
synced 2025-12-12 01:37:00 +00:00
[7543] Avoid code duplication in ReputationMgr.
This commit is contained in:
parent
6a649f43ee
commit
4f17a6a4e2
3 changed files with 24 additions and 64 deletions
|
|
@ -217,7 +217,7 @@ void ReputationMgr::Initilize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standing)
|
bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standing, bool incremental)
|
||||||
{
|
{
|
||||||
SimpleFactionsList const* flist = GetFactionTeamList(factionEntry->ID);
|
SimpleFactionsList const* flist = GetFactionTeamList(factionEntry->ID);
|
||||||
if (flist)
|
if (flist)
|
||||||
|
|
@ -227,26 +227,29 @@ bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standi
|
||||||
{
|
{
|
||||||
FactionEntry const *factionEntryCalc = sFactionStore.LookupEntry(*itr);
|
FactionEntry const *factionEntryCalc = sFactionStore.LookupEntry(*itr);
|
||||||
if(factionEntryCalc)
|
if(factionEntryCalc)
|
||||||
res = SetOneFactionReputation(factionEntryCalc, standing);
|
res = SetOneFactionReputation(factionEntryCalc, standing, incremental);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return SetOneFactionReputation(factionEntry, standing);
|
return SetOneFactionReputation(factionEntry, standing, incremental);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReputationMgr::SetOneFactionReputation(FactionEntry const* factionEntry, int32 standing)
|
bool ReputationMgr::SetOneFactionReputation(FactionEntry const* factionEntry, int32 standing, bool incremental)
|
||||||
{
|
{
|
||||||
FactionStateList::iterator itr = m_factions.find(factionEntry->reputationListID);
|
FactionStateList::iterator itr = m_factions.find(factionEntry->reputationListID);
|
||||||
if (itr != m_factions.end())
|
if (itr != m_factions.end())
|
||||||
{
|
{
|
||||||
|
int32 BaseRep = GetBaseReputation(factionEntry);
|
||||||
|
|
||||||
|
if(incremental)
|
||||||
|
standing += itr->second.Standing + BaseRep;
|
||||||
|
|
||||||
if (standing > Reputation_Cap)
|
if (standing > Reputation_Cap)
|
||||||
standing = Reputation_Cap;
|
standing = Reputation_Cap;
|
||||||
else
|
else if (standing < Reputation_Bottom)
|
||||||
if (standing < Reputation_Bottom)
|
standing = Reputation_Bottom;
|
||||||
standing = Reputation_Bottom;
|
|
||||||
|
|
||||||
int32 BaseRep = GetBaseReputation(factionEntry);
|
|
||||||
itr->second.Standing = standing - BaseRep;
|
itr->second.Standing = standing - BaseRep;
|
||||||
itr->second.Changed = true;
|
itr->second.Changed = true;
|
||||||
|
|
||||||
|
|
@ -258,57 +261,7 @@ bool ReputationMgr::SetOneFactionReputation(FactionEntry const* factionEntry, in
|
||||||
SendState(&itr->second);
|
SendState(&itr->second);
|
||||||
|
|
||||||
m_player->ReputationChanged(factionEntry);
|
m_player->ReputationChanged(factionEntry);
|
||||||
m_player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION,factionEntry->ID);
|
m_player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION, factionEntry->ID);
|
||||||
m_player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION,factionEntry->ID);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ReputationMgr::ModifyReputation(FactionEntry const* factionEntry, int32 standing)
|
|
||||||
{
|
|
||||||
SimpleFactionsList const* flist = GetFactionTeamList(factionEntry->ID);
|
|
||||||
if (flist)
|
|
||||||
{
|
|
||||||
bool res = false;
|
|
||||||
for (SimpleFactionsList::const_iterator itr = flist->begin();itr != flist->end();++itr)
|
|
||||||
{
|
|
||||||
FactionEntry const *factionEntryCalc = sFactionStore.LookupEntry(*itr);
|
|
||||||
if(factionEntryCalc)
|
|
||||||
res = ModifyOneFactionReputation(factionEntryCalc, standing);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return ModifyOneFactionReputation(factionEntry, standing);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ReputationMgr::ModifyOneFactionReputation(FactionEntry const* factionEntry, int32 standing)
|
|
||||||
{
|
|
||||||
FactionStateList::iterator itr = m_factions.find(factionEntry->reputationListID);
|
|
||||||
if (itr != m_factions.end())
|
|
||||||
{
|
|
||||||
int32 BaseRep = GetBaseReputation(factionEntry);
|
|
||||||
int32 new_rep = BaseRep + itr->second.Standing + standing;
|
|
||||||
|
|
||||||
if (new_rep > Reputation_Cap)
|
|
||||||
new_rep = Reputation_Cap;
|
|
||||||
else
|
|
||||||
if (new_rep < Reputation_Bottom)
|
|
||||||
new_rep = Reputation_Bottom;
|
|
||||||
|
|
||||||
if(ReputationToRank(new_rep) <= REP_HOSTILE)
|
|
||||||
SetAtWar(&itr->second,true);
|
|
||||||
|
|
||||||
itr->second.Standing = new_rep - BaseRep;
|
|
||||||
itr->second.Changed = true;
|
|
||||||
|
|
||||||
SetVisible(&itr->second);
|
|
||||||
SendState(&itr->second);
|
|
||||||
|
|
||||||
m_player->ReputationChanged(factionEntry);
|
|
||||||
|
|
||||||
m_player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION,factionEntry->ID);
|
|
||||||
m_player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION,factionEntry->ID);
|
m_player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION,factionEntry->ID);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -95,8 +95,14 @@ class ReputationMgr
|
||||||
}
|
}
|
||||||
|
|
||||||
public: // modifiers
|
public: // modifiers
|
||||||
bool SetReputation(FactionEntry const* factionEntry, int32 standing);
|
bool SetReputation(FactionEntry const* factionEntry, int32 standing)
|
||||||
bool ModifyReputation(FactionEntry const* factionEntry, int32 standing);
|
{
|
||||||
|
return SetReputation(factionEntry, standing, false);
|
||||||
|
}
|
||||||
|
bool ModifyReputation(FactionEntry const* factionEntry, int32 standing)
|
||||||
|
{
|
||||||
|
return SetReputation(factionEntry, standing, true);
|
||||||
|
}
|
||||||
|
|
||||||
void SetVisible(FactionTemplateEntry const* factionTemplateEntry);
|
void SetVisible(FactionTemplateEntry const* factionTemplateEntry);
|
||||||
void SetVisible(FactionEntry const* factionEntry);
|
void SetVisible(FactionEntry const* factionEntry);
|
||||||
|
|
@ -114,12 +120,13 @@ class ReputationMgr
|
||||||
private: // internal helper functions
|
private: // internal helper functions
|
||||||
void Initilize();
|
void Initilize();
|
||||||
uint32 GetDefaultStateFlags(const FactionEntry *factionEntry) const;
|
uint32 GetDefaultStateFlags(const FactionEntry *factionEntry) const;
|
||||||
bool SetOneFactionReputation(FactionEntry const* factionEntry, int32 standing);
|
bool SetReputation(FactionEntry const* factionEntry, int32 standing, bool incremental);
|
||||||
bool ModifyOneFactionReputation(FactionEntry const* factionEntry, int32 standing);
|
bool SetOneFactionReputation(FactionEntry const* factionEntry, int32 standing, bool incremental);
|
||||||
void SetVisible(FactionState* faction);
|
void SetVisible(FactionState* faction);
|
||||||
void SetAtWar(FactionState* faction, bool atWar);
|
void SetAtWar(FactionState* faction, bool atWar);
|
||||||
void SetInactive(FactionState* faction, bool inactive);
|
void SetInactive(FactionState* faction, bool inactive);
|
||||||
void SendVisible(FactionState const* faction) const;
|
void SendVisible(FactionState const* faction) const;
|
||||||
|
void UpdateRankCounters( ReputationRank old_rank, ReputationRank new_rank );
|
||||||
private:
|
private:
|
||||||
Player* m_player;
|
Player* m_player;
|
||||||
FactionStateList m_factions;
|
FactionStateList m_factions;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "7542"
|
#define REVISION_NR "7543"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue