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);
145 return (*friendshipReactions->begin())->ReactionThreshold;
163 int32 cap = reputation + paragonReputation->LevelThreshold - reputation % paragonReputation->LevelThreshold - 1;
166 cap += paragonReputation->LevelThreshold;
180 return (*friendshipReactions->rbegin())->ReactionThreshold;
220 auto itr = friendshipReactions->begin();
221 std::advance(itr,
uint32(rank));
253 if (!paragonFactionEntry)
257 return GetReputation(paragonFactionEntry) / paragonReputation->LevelThreshold;
277 if (!renownFactionEntry)
299 if (!renownFactionEntry)
340 auto getStandingForPacket = [](
FactionState const* state)
342 return state->VisualStandingIncrease ? state->VisualStandingIncrease : state->Standing;
348 for (
auto& [reputationIndex, state] :
_factions)
352 state.needSend =
false;
354 setFactionStanding.
Faction.emplace_back(
int32(state.ReputationListID), getStandingForPacket(&state), state.ID);
368 for (FactionStateList::iterator itr =
_factions.begin(); itr !=
_factions.end(); ++itr)
372 factionData.
Flags = itr->second.Flags.AsUnderlyingType();
373 factionData.
Standing = itr->second.Standing;
378 itr->second.needSend =
false;
406 if (factionEntry->CanHaveReputation())
409 newFaction.
ID = factionEntry->ID;
420 if (!factionEntry->FriendshipRepID)
439 if (repTemplate->faction[i])
444 int32 spilloverRep =
int32(standing * repTemplate->faction_rate[i]);
452 float spillOverRepOut = float(standing);
454 std::vector<uint32>
const* flist =
sDB2Manager.GetFactionTeamList(factionEntry->
ID);
461 FactionStateList::iterator parentState =
_factions.find(parent->ReputationIndex);
476 for (std::vector<uint32>::const_iterator itr = flist->begin(); itr != flist->end(); ++itr)
480 if (factionEntryCalc == factionEntry ||
GetRank(factionEntryCalc) >
ReputationRank(factionEntryCalc->ParentFactionCap[0]))
482 int32 spilloverRep =
int32(spillOverRepOut * factionEntryCalc->ParentFactionMod[0]);
483 if (spilloverRep != 0 || !incremental)
495 FactionEntry const* primaryFactionToModify = factionEntry;
523 itr->second.needSend =
false;
524 itr->second.needSave =
false;
529 int32 oldStanding = itr->second.Standing + baseRep;
535 standing += oldStanding;
551 else if (newRank > oldRank)
554 if (newRank > oldRank)
564 int32 newStanding = 0;
565 int32 reputationChange = standing - oldStanding;
568 newStanding = standing - baseRep;
576 int32 totalReputation = (oldRenownLevel * renownLevelThreshold) + (standing - baseRep);
577 int32 newRenownLevel = totalReputation / renownLevelThreshold;
578 newStanding = totalReputation % renownLevelThreshold;
583 reputationChange += (
GetRenownMaxLevel(factionEntry) * renownLevelThreshold) - totalReputation;
586 itr->second.VisualStandingIncrease = reputationChange;
589 if (oldRenownLevel != newRenownLevel)
596 itr->second.Standing = newStanding;
597 itr->second.needSend =
true;
598 itr->second.needSave =
true;
603 if (paragonReputation)
607 if (oldParagonLevel != newParagonLevel)
625 if (!factionTemplateEntry->
Faction)
673 FactionStateList::iterator itr =
_factions.find(repListID);
705 FactionStateList::iterator itr =
_factions.find(repListID);
742 Field* fields = result->Fetch();
783 if (faction->
Flags == dbFactionFlags)
790 while (result->NextRow());
796 for (FactionStateList::iterator itr =
_factions.begin(); itr !=
_factions.end(); ++itr)
798 if (itr->second.needSave)
808 stmt->
setInt32(2, itr->second.Standing);
809 stmt->
setUInt16(3, itr->second.Flags.AsUnderlyingType());
812 itr->second.needSave =
false;
844 std::array<Trinity::RaceMask<int32, 2>
const*, 4> reputationRaceMask =
852 uint32 classMask = 1 << (playerClass - 1);
853 for (
int32 i = 0; i < 4; ++i)
855 if ((reputationRaceMask[i]->IsEmpty() || reputationRaceMask[i]->HasRace(race))
872 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)
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
Trinity::RaceMask< int32, 2 > ReputationRaceMask2
Trinity::RaceMask< int32, 2 > ReputationRaceMask3
Trinity::RaceMask< int32, 2 > ReputationRaceMask1
bool CanHaveReputation() const
Trinity::RaceMask< int32, 2 > ReputationRaceMask4
std::array< float, 2 > ParentFactionMod
std::array< uint16, 4 > ReputationFlags
RepListID ReputationListID
EnumFlag< ReputationFlags > Flags
int32 VisualStandingIncrease