fix(Core/Reputations): Faction rep gained by killing mobs is now prop… (#9737)

* fix(Core/Reputations): Faction rep gained by killing mobs is now properly rounded up.

Do not increase reputation rank if exceeds max rank cap.
Fixes #8718
This commit is contained in:
UltraNix
2022-02-05 11:37:00 +01:00
committed by GitHub
parent 7b041946e1
commit 0b02ba87fc
11 changed files with 91 additions and 42 deletions

View File

@@ -41,6 +41,17 @@ ReputationRank ReputationMgr::ReputationToRank(int32 standing)
return MIN_REPUTATION_RANK;
}
int32 ReputationMgr::ReputationRankToStanding(ReputationRank rank)
{
int32 standing = Reputation_Bottom;
for (uint8 i = MIN_REPUTATION_RANK; i <= rank; ++i)
{
standing += PointsInRank[i];
}
return std::max(standing - 1, Reputation_Bottom);
}
bool ReputationMgr::IsAtWar(uint32 faction_id) const
{
FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id);
@@ -271,6 +282,7 @@ void ReputationMgr::Initialize()
newFaction.Flags = GetDefaultStateFlags(factionEntry);
newFaction.needSend = true;
newFaction.needSave = true;
newFaction.roundedUp = false;
if (newFaction.Flags & FACTION_FLAG_VISIBLE)
++_visibleFactionCount;
@@ -282,7 +294,7 @@ void ReputationMgr::Initialize()
}
}
bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standing, bool incremental, bool spillOverOnly, bool noSpillOver)
bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, float standing, bool incremental, bool noSpillOver, Optional<ReputationRank> repMaxCap)
{
bool res = false;
@@ -298,7 +310,7 @@ bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standi
if (_player->GetReputationRank(repTemplate->faction[i]) <= ReputationRank(repTemplate->faction_rank[i]))
{
// bonuses are already given, so just modify standing by rate
int32 spilloverRep = int32(standing * repTemplate->faction_rate[i]);
float spilloverRep = standing * repTemplate->faction_rate[i];
SetOneFactionReputation(sFactionStore.LookupEntry(repTemplate->faction[i]), spilloverRep, incremental);
}
}
@@ -319,7 +331,7 @@ bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standi
// some team factions have own reputation standing, in this case do not spill to other sub-factions
if (parentState != _factions.end() && (parentState->second.Flags & FACTION_FLAG_SPECIAL))
{
SetOneFactionReputation(parent, int32(spillOverRepOut), incremental);
SetOneFactionReputation(parent, spillOverRepOut, incremental);
}
else // spill to "sister" factions
{
@@ -336,7 +348,7 @@ bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standi
{
if (factionEntryCalc == factionEntry || GetRank(factionEntryCalc) > ReputationRank(factionEntryCalc->spilloverMaxRankIn))
continue;
int32 spilloverRep = int32(spillOverRepOut * factionEntryCalc->spilloverRateIn);
float spilloverRep = spillOverRepOut * factionEntryCalc->spilloverRateIn;
if (spilloverRep != 0 || !incremental)
res = SetOneFactionReputation(factionEntryCalc, spilloverRep, incremental);
}
@@ -345,20 +357,25 @@ bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standi
}
}
bool spillOverOnly = repMaxCap ? GetRank(factionEntry) > *repMaxCap : false;
// spillover done, update faction itself
FactionStateList::iterator faction = _factions.find(factionEntry->reputationListID);
if (faction != _factions.end())
{
// Xinef: if we update spillover only, do not update main reputation (rank exceeds creature reward rate)
if (!spillOverOnly)
res = SetOneFactionReputation(factionEntry, standing, incremental);
{
res = SetOneFactionReputation(factionEntry, standing, incremental, repMaxCap);
}
// only this faction gets reported to client, even if it has no own visible standing
SendState(&faction->second);
}
return res;
}
bool ReputationMgr::SetOneFactionReputation(FactionEntry const* factionEntry, int32 standing, bool incremental)
bool ReputationMgr::SetOneFactionReputation(FactionEntry const* factionEntry, float stand, bool incremental, Optional<ReputationRank> repMaxCap)
{
FactionStateList::iterator itr = _factions.find(factionEntry->reputationListID);
if (itr != _factions.end())
@@ -367,8 +384,27 @@ bool ReputationMgr::SetOneFactionReputation(FactionEntry const* factionEntry, in
if (incremental)
{
// int32 *= float cause one point loss?
standing = int32(floor((float)standing * sWorld->getRate(RATE_REPUTATION_GAIN) + 0.5f));
stand *= sWorld->getRate(RATE_REPUTATION_GAIN);
}
int32 standing = 0;
float stand2;
if (fabs(modff(stand, &stand2)) < 1.f)
{
if (itr->second.roundedUp)
{
standing = static_cast<int32>(ceil(stand));
}
else
{
standing = static_cast<int32>(stand);
}
itr->second.roundedUp = !itr->second.roundedUp;
}
if (incremental)
{
standing += itr->second.Standing + BaseRep;
}
@@ -379,6 +415,11 @@ bool ReputationMgr::SetOneFactionReputation(FactionEntry const* factionEntry, in
ReputationRank old_rank = ReputationToRank(itr->second.Standing + BaseRep);
ReputationRank new_rank = ReputationToRank(standing);
if (repMaxCap && new_rank > *repMaxCap)
{
standing = ReputationRankToStanding(*repMaxCap);
new_rank = *repMaxCap;
}
if (sScriptMgr->OnPlayerReputationChange(_player, factionEntry->ID, standing, incremental))
{
@@ -574,6 +615,8 @@ void ReputationMgr::LoadFromDB(PreparedQueryResult result)
faction->needSend = false;
faction->needSave = false;
}
faction->roundedUp = false;
}
} while (result->NextRow());
}

View File

@@ -46,6 +46,7 @@ struct FactionState
uint8 Flags;
bool needSend;
bool needSave;
bool roundedUp;
};
typedef std::map<RepListID, FactionState> FactionStateList;
@@ -68,6 +69,8 @@ public: // statics
static const int32 Reputation_Bottom;
static ReputationRank ReputationToRank(int32 standing);
static int32 ReputationRankToStanding(ReputationRank rank);
public: // accessors
uint8 GetVisibleFactionCount() const { return _visibleFactionCount; }
uint8 GetHonoredFactionCount() const { return _honoredFactionCount; }
@@ -108,13 +111,13 @@ public: // accessors
}
public: // modifiers
bool SetReputation(FactionEntry const* factionEntry, int32 standing)
bool SetReputation(FactionEntry const* factionEntry, float standing)
{
return SetReputation(factionEntry, standing, false, false, false);
return SetReputation(factionEntry, standing, false);
}
bool ModifyReputation(FactionEntry const* factionEntry, int32 standing, bool spillOverOnly = false, bool noSpillOver = false)
bool ModifyReputation(FactionEntry const* factionEntry, float standing, bool noSpillOver = false, Optional<ReputationRank> repMaxCap = {})
{
return SetReputation(factionEntry, standing, true, spillOverOnly, noSpillOver);
return SetReputation(factionEntry, standing, true, noSpillOver, repMaxCap);
}
void SetVisible(FactionTemplateEntry const* factionTemplateEntry);
@@ -125,7 +128,7 @@ public: // modifiers
void ApplyForceReaction(uint32 faction_id, ReputationRank rank, bool apply);
//! Public for chat command needs
bool SetOneFactionReputation(FactionEntry const* factionEntry, int32 standing, bool incremental);
bool SetOneFactionReputation(FactionEntry const* factionEntry, float standing, bool incremental, Optional<ReputationRank> repMaxCap = { });
public: // senders
void SendInitialReputations();
@@ -136,7 +139,7 @@ public: // senders
private: // internal helper functions
void Initialize();
uint32 GetDefaultStateFlags(FactionEntry const* factionEntry) const;
bool SetReputation(FactionEntry const* factionEntry, int32 standing, bool incremental, bool spillOverOnly, bool noSpillOver = false);
bool SetReputation(FactionEntry const* factionEntry, float standing, bool incremental, bool noSpillOver = false, Optional<ReputationRank> repMaxCap = { });
void SetVisible(FactionState* faction);
void SetAtWar(FactionState* faction, bool atWar) const;
void SetInactive(FactionState* faction, bool inactive) const;