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)
345 auto getStandingForPacket = [](
FactionState const* state)
347 return state->VisualStandingIncrease ? state->VisualStandingIncrease : state->Standing;
353 for (
auto& [reputationIndex, state] :
_factions)
357 state.needSend =
false;
359 setFactionStanding.
Faction.emplace_back(
int32(state.ReputationListID), getStandingForPacket(&state));
373 for (FactionStateList::iterator itr =
_factions.begin(); itr !=
_factions.end(); ++itr)
375 initFactions.
FactionFlags[itr->first] = itr->second.Flags.AsUnderlyingType();
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;
552 if (newRank > oldRank)
562 int32 newStanding = 0;
563 int32 reputationChange = standing - oldStanding;
566 newStanding = standing - baseRep;
574 int32 totalReputation = (oldRenownLevel * renownLevelThreshold) + (standing - baseRep);
575 int32 newRenownLevel = totalReputation / renownLevelThreshold;
576 newStanding = totalReputation % renownLevelThreshold;
581 reputationChange += (
GetRenownMaxLevel(factionEntry) * renownLevelThreshold) - totalReputation;
584 itr->second.VisualStandingIncrease = reputationChange;
587 if (oldRenownLevel != newRenownLevel)
594 itr->second.Standing = newStanding;
595 itr->second.needSend =
true;
596 itr->second.needSave =
true;
601 if (paragonReputation)
605 if (oldParagonLevel != newParagonLevel)
623 if (!factionTemplateEntry->
Faction)
671 FactionStateList::iterator itr =
_factions.find(repListID);
703 FactionStateList::iterator itr =
_factions.find(repListID);
740 Field* fields = result->Fetch();
781 if (faction->
Flags == dbFactionFlags)
788 while (result->NextRow());
794 for (FactionStateList::iterator itr =
_factions.begin(); itr !=
_factions.end(); ++itr)
796 if (itr->second.needSave)
806 stmt->
setInt32(2, itr->second.Standing);
807 stmt->
setUInt16(3, itr->second.Flags.AsUnderlyingType());
810 itr->second.needSave =
false;
839 for (
int32 i = 0; i < 4; i++)
859 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__,...)
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)
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
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 setInt32(const uint8 index, const int32 value)
void setUInt16(const uint8 index, const uint16 value)
void setUInt64(const uint8 index, const uint64 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 SendForceReactions()
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::array< int32, FactionCount > FactionStandings
std::array< uint16, FactionCount > FactionFlags
WorldPacket const * Write() override
float BonusFromAchievementSystem
std::vector< FactionStandingData > Faction
WorldPacket const * Write() override
std::vector< ForcedReaction > Reactions
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