61template<
typename T,
typename F,
typename... Rest>
64 auto itr = thresholds.begin();
65 auto end = thresholds.end();
67 while (itr != end && standing >= thresholdExtractor(*itr))
98 TC_LOG_ERROR(
"misc",
"ReputationMgr::IsAtWar: Can't get AtWar flag of {} for unknown faction (faction id) #{}.",
_player->
GetName(), faction_id);
121 TC_LOG_ERROR(
"misc",
"ReputationMgr::GetReputation: Can't get reputation of {} for unknown faction (faction id) #{}.",
_player->
GetName(), faction_id);
140 return (*friendshipReactions->begin())->ReactionThreshold;
158 int32 cap = reputation + paragonReputation->LevelThreshold - reputation % paragonReputation->LevelThreshold - 1;
161 cap += paragonReputation->LevelThreshold;
175 return (*friendshipReactions->rbegin())->ReactionThreshold;
216 auto itr = friendshipReactions->begin();
217 std::advance(itr,
uint32(rank));
249 if (!paragonFactionEntry)
253 return GetReputation(paragonFactionEntry) / paragonReputation->LevelThreshold;
273 if (!renownFactionEntry)
296 if (!renownFactionEntry)
341 auto getStandingForPacket = [](
FactionState const* state)
343 return state->VisualStandingIncrease ? state->VisualStandingIncrease : state->Standing;
349 for (
auto& [reputationIndex, state] :
_factions)
353 state.needSend =
false;
355 setFactionStanding.
Faction.emplace_back(
int32(state.ReputationListID), getStandingForPacket(&state), state.ID);
369 for (FactionStateList::iterator itr =
_factions.begin(); itr !=
_factions.end(); ++itr)
373 factionData.
Flags = itr->second.Flags.AsUnderlyingType();
374 factionData.
Standing = itr->second.Standing;
379 itr->second.needSend =
false;
407 if (factionEntry->CanHaveReputation())
410 newFaction.
ID = factionEntry->ID;
421 if (!factionEntry->FriendshipRepID)
440 if (repTemplate->faction[i])
445 int32 spilloverRep =
int32(standing * repTemplate->faction_rate[i]);
453 float spillOverRepOut = float(standing);
455 std::vector<uint32>
const* flist =
sDB2Manager.GetFactionTeamList(factionEntry->
ID);
462 FactionStateList::iterator parentState =
_factions.find(parent->ReputationIndex);
477 for (std::vector<uint32>::const_iterator itr = flist->begin(); itr != flist->end(); ++itr)
481 if (factionEntryCalc == factionEntry ||
GetRank(factionEntryCalc) >
ReputationRank(factionEntryCalc->ParentFactionCap[0]))
483 int32 spilloverRep =
int32(spillOverRepOut * factionEntryCalc->ParentFactionMod[0]);
484 if (spilloverRep != 0 || !incremental)
496 FactionEntry const* primaryFactionToModify = factionEntry;
524 itr->second.needSend =
false;
525 itr->second.needSave =
false;
530 int32 oldStanding = itr->second.Standing + baseRep;
536 standing += oldStanding;
553 if (newRank > oldRank)
563 int32 newStanding = 0;
564 int32 reputationChange = standing - oldStanding;
567 newStanding = standing - baseRep;
575 int32 totalReputation = (oldRenownLevel * renownLevelThreshold) + (standing - baseRep);
576 int32 newRenownLevel = totalReputation / renownLevelThreshold;
577 newStanding = totalReputation % renownLevelThreshold;
582 reputationChange += (
GetRenownMaxLevel(factionEntry) * renownLevelThreshold) - totalReputation;
585 itr->second.VisualStandingIncrease = reputationChange;
588 if (oldRenownLevel != newRenownLevel)
595 itr->second.Standing = newStanding;
596 itr->second.needSend =
true;
597 itr->second.needSave =
true;
602 if (paragonReputation)
606 if (oldParagonLevel != newParagonLevel)
624 if (!factionTemplateEntry->
Faction)
672 FactionStateList::iterator itr =
_factions.find(repListID);
704 FactionStateList::iterator itr =
_factions.find(repListID);
741 Field* fields = result->Fetch();
782 if (faction->
Flags == dbFactionFlags)
789 while (result->NextRow());
795 for (FactionStateList::iterator itr =
_factions.begin(); itr !=
_factions.end(); ++itr)
797 if (itr->second.needSave)
807 stmt->
setInt32(2, itr->second.Standing);
808 stmt->
setUInt16(3, itr->second.Flags.AsUnderlyingType());
811 itr->second.needSave =
false;
840 for (
int32 i = 0; i < 4; i++)
860 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)
TC_GAME_API uint32 const ReputationRankStrIndex[MAX_REPUTATION_RANK]
#define MAX_REPUTATION_RANK
#define MIN_REPUTATION_RANK
#define MAX_SPILLOVER_FACTIONS
ObjectGuid const & GetGUID() const
std::set< FriendshipRepReactionEntry const *, FriendshipRepReactionEntryComparator > FriendshipRepReactionSet
constexpr bool HasFlag(T flag) const
Class used to access individual fields of database query result.
uint16 GetUInt16() const noexcept
int32 GetInt32() const noexcept
LowType GetCounter() const
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
auto MapGetValuePtr(M &map, typename M::key_type const &key)
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