60template<
typename T,
typename F,
typename... Rest>
63 auto itr = thresholds.begin();
64 auto end = thresholds.end();
66 while (itr != end && standing >= thresholdExtractor(*itr))
97 TC_LOG_ERROR(
"misc",
"ReputationMgr::IsAtWar: Can't get AtWar flag of {} for unknown faction (faction id) #{}.",
_player->
GetName(), faction_id);
120 TC_LOG_ERROR(
"misc",
"ReputationMgr::GetReputation: Can't get reputation of {} for unknown faction (faction id) #{}.",
_player->
GetName(), faction_id);
139 return (*friendshipReactions->begin())->ReactionThreshold;
157 int32 cap = reputation + paragonReputation->LevelThreshold - reputation % paragonReputation->LevelThreshold - 1;
160 cap += paragonReputation->LevelThreshold;
174 return (*friendshipReactions->rbegin())->ReactionThreshold;
215 auto itr = friendshipReactions->begin();
216 std::advance(itr,
uint32(rank));
243 if (!paragonFactionEntry)
247 return GetReputation(paragonFactionEntry) / paragonReputation->LevelThreshold;
267 if (!renownFactionEntry)
290 if (!renownFactionEntry)
335 auto getStandingForPacket = [](
FactionState const* state)
337 return state->VisualStandingIncrease ? state->VisualStandingIncrease : state->Standing;
343 for (
auto& [reputationIndex, state] :
_factions)
347 state.needSend =
false;
349 setFactionStanding.
Faction.emplace_back(
int32(state.ReputationListID), getStandingForPacket(&state));
363 for (FactionStateList::iterator itr =
_factions.begin(); itr !=
_factions.end(); ++itr)
367 factionData.
Flags = itr->second.Flags.AsUnderlyingType();
368 factionData.
Standing = itr->second.Standing;
373 itr->second.needSend =
false;
401 if (factionEntry->CanHaveReputation())
404 newFaction.
ID = factionEntry->ID;
415 if (!factionEntry->FriendshipRepID)
434 if (repTemplate->faction[i])
439 int32 spilloverRep =
int32(standing * repTemplate->faction_rate[i]);
447 float spillOverRepOut = float(standing);
449 std::vector<uint32>
const* flist =
sDB2Manager.GetFactionTeamList(factionEntry->
ID);
456 FactionStateList::iterator parentState =
_factions.find(parent->ReputationIndex);
471 for (std::vector<uint32>::const_iterator itr = flist->begin(); itr != flist->end(); ++itr)
475 if (factionEntryCalc == factionEntry ||
GetRank(factionEntryCalc) >
ReputationRank(factionEntryCalc->ParentFactionCap[0]))
477 int32 spilloverRep =
int32(spillOverRepOut * factionEntryCalc->ParentFactionMod[0]);
478 if (spilloverRep != 0 || !incremental)
490 FactionEntry const* primaryFactionToModify = factionEntry;
518 itr->second.needSend =
false;
519 itr->second.needSave =
false;
524 int32 oldStanding = itr->second.Standing + baseRep;
530 standing += oldStanding;
547 if (newRank > oldRank)
557 int32 newStanding = 0;
558 int32 reputationChange = standing - oldStanding;
561 newStanding = standing - baseRep;
569 int32 totalReputation = (oldRenownLevel * renownLevelThreshold) + (standing - baseRep);
570 int32 newRenownLevel = totalReputation / renownLevelThreshold;
571 newStanding = totalReputation % renownLevelThreshold;
576 reputationChange += (
GetRenownMaxLevel(factionEntry) * renownLevelThreshold) - totalReputation;
579 itr->second.VisualStandingIncrease = reputationChange;
582 if (oldRenownLevel != newRenownLevel)
589 itr->second.Standing = newStanding;
590 itr->second.needSend =
true;
591 itr->second.needSave =
true;
596 if (paragonReputation)
600 if (oldParagonLevel != newParagonLevel)
618 if (!factionTemplateEntry->
Faction)
666 FactionStateList::iterator itr =
_factions.find(repListID);
698 FactionStateList::iterator itr =
_factions.find(repListID);
735 Field* fields = result->Fetch();
776 if (faction->
Flags == dbFactionFlags)
783 while (result->NextRow());
789 for (FactionStateList::iterator itr =
_factions.begin(); itr !=
_factions.end(); ++itr)
791 if (itr->second.needSave)
801 stmt->
setInt32(2, itr->second.Standing);
802 stmt->
setUInt16(3, itr->second.Flags.AsUnderlyingType());
805 itr->second.needSave =
false;
834 for (
int32 i = 0; i < 4; i++)
854 if (!paragonReputation)
@ CHAR_INS_CHAR_REPUTATION_BY_FACTION
@ CHAR_DEL_CHAR_REPUTATION_BY_FACTION
DB2Storage< CurrencyTypesEntry > sCurrencyTypesStore("CurrencyTypes.db2", &CurrencyTypesLoadInfo::Instance)
DB2Storage< FactionEntry > sFactionStore("Faction.db2", &FactionLoadInfo::Instance)
@ TotalFactionsEncountered
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
#define TC_LOG_ERROR(filterType__, message__,...)
uint32 const ReputationRankStrIndex[MAX_REPUTATION_RANK]
static int32 ReputationToRankHelper(std::set< T, Rest... > const &thresholds, int32 standing, F thresholdExtractor)
#define MAX_REPUTATION_RANK
#define MIN_REPUTATION_RANK
#define MAX_SPILLOVER_FACTIONS
std::set< FriendshipRepReactionEntry const *, FriendshipRepReactionEntryComparator > FriendshipRepReactionSet
constexpr bool HasFlag(T flag) const
Class used to access individual fields of database query result.
LowType GetCounter() const
static ObjectGuid GetGUID(Object const *o)
void SendDirectMessage(WorldPacket const *data) const
void ReputationChanged(FactionEntry const *factionEntry, int32 change)
void SetVisibleForcedReaction(uint32 factionId, ReputationRank rank)
WorldSession * GetSession() const
void UpdateCriteria(CriteriaType type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, WorldObject *ref=nullptr)
void AddQuestAndCheckCompletion(Quest const *quest, Object *questGiver)
QuestStatus GetQuestStatus(uint32 quest_id) const
ReputationRank GetReputationRank(uint32 faction_id) const
void RemoveVisibleForcedReaction(uint32 factionId)
int32 GetQuestMinLevel(Quest const *quest) const
void ModifyCurrency(uint32 id, int32 amount, CurrencyGainSource gainSource=CurrencyGainSource::Cheat, CurrencyDestroyReason destroyReason=CurrencyDestroyReason::Cheat)
Modify currency amount.
uint32 GetCurrencyQuantity(uint32 id) const
uint32 GetCurrencyMaxQuantity(CurrencyTypesEntry const *currency, bool onLoad=false, bool onUpdateVersion=false) const
void setUInt16(uint8 index, uint16 value)
void setUInt64(uint8 index, uint64 value)
void setInt32(uint8 index, int32 value)
bool HasMaximumRenownReputation(FactionEntry const *factionEntry) const
bool IsParagonReputation(FactionEntry const *factionEntry) const
std::string GetReputationRankName(FactionEntry const *factionEntry) const
uint8 _honoredFactionCount
ReputationRank GetBaseRank(FactionEntry const *factionEntry) const
int32 GetFactionDataIndexForRaceAndClass(FactionEntry const *factionEntry) const
int32 GetRenownLevelThreshold(FactionEntry const *renownFactionEntry) const
void SetVisible(FactionTemplateEntry const *factionTemplateEntry)
int32 GetBaseReputation(FactionEntry const *factionEntry) const
int32 GetMaxReputation(FactionEntry const *factionEntry) const
uint8 _visibleFactionCount
ReputationFlags GetDefaultStateFlags(FactionEntry const *factionEntry) const
bool CanGainParagonReputationForFaction(FactionEntry const *factionEntry) const
void SetAtWar(RepListID repListID, bool on)
void SendState(FactionState const *faction)
int32 GetReputation(uint32 faction_id) const
bool SetReputation(FactionEntry const *factionEntry, int32 standing)
int32 GetRenownLevel(FactionEntry const *renownFactionEntry) const
void ApplyForceReaction(uint32 faction_id, ReputationRank rank, bool apply)
ReputationRank GetRank(FactionEntry const *factionEntry) const
int32 GetMinReputation(FactionEntry const *factionEntry) const
void SendInitialReputations()
static ReputationRank ReputationToRank(FactionEntry const *factionEntry, int32 standing)
uint8 _exaltedFactionCount
FactionState const * GetState(FactionEntry const *factionEntry) const
uint8 _reveredFactionCount
FactionStateList _factions
ForcedReactions _forcedReactions
static const int32 Reputation_Bottom
void SendVisible(FactionState const *faction, bool visible=true) const
bool IsAtWar(uint32 faction_id) const
bool SetOneFactionReputation(FactionEntry const *factionEntry, int32 standing, bool incremental)
Public for chat command needs.
bool _sendFactionIncreased
Play visual effect on next SMSG_SET_FACTION_STANDING sent.
int32 GetParagonLevel(uint32 paragonFactionId) const
int32 GetRenownMaxLevel(FactionEntry const *renownFactionEntry) const
bool IsRenownReputation(FactionEntry const *factionEntry) const
static std::set< int32 > const ReputationRankThresholds
void UpdateRankCounters(ReputationRank old_rank, ReputationRank new_rank)
static const int32 Reputation_Cap
void LoadFromDB(PreparedQueryResult result)
ReputationRank const * GetForcedRankIfAny(FactionTemplateEntry const *factionTemplateEntry) const
void SetInactive(RepListID repListID, bool on)
void SaveToDB(CharacterDatabaseTransaction trans)
uint32 GetClassMask() const
std::string const & GetName() const
WorldPacket const * Write() override
WorldPacket const * Write() override
std::vector< FactionData > Factions
std::vector< FactionBonusData > Bonuses
WorldPacket const * Write() override
float BonusFromAchievementSystem
std::vector< FactionStandingData > Faction
LocaleConstant GetSessionDbcLocale() const
bool PlayerLoading() const
std::array< int32, 4 > ReputationBase
std::array< int32, 4 > ReputationMax
std::array< int16, 4 > ReputationClassMask
bool CanHaveReputation() const
std::array< float, 2 > ParentFactionMod
std::array< uint16, 4 > ReputationFlags
std::array< Trinity::RaceMask< int64 >, 4 > ReputationRaceMask
RepListID ReputationListID
EnumFlag< ReputationFlags > Flags
int32 VisualStandingIncrease