From 1e47f701accc4ed62b8aa9cc0167ec1dc82b68bb Mon Sep 17 00:00:00 2001 From: Benjamin Jackson <38561765+heyitsbench@users.noreply.github.com> Date: Sun, 15 Feb 2026 17:44:44 -0500 Subject: [PATCH] feat(Core/Player): Add hooks for reputation price discount calculation. (#24666) --- src/server/game/Entities/Player/Player.cpp | 18 +++++++++++++---- .../Scripting/ScriptDefines/PlayerScript.cpp | 10 ++++++++++ .../Scripting/ScriptDefines/PlayerScript.h | 20 +++++++++++++++++++ src/server/game/Scripting/ScriptMgr.h | 2 ++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index d100bbc8b..47d15362a 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -12333,23 +12333,33 @@ bool Player::GetBGAccessByLevel(BattlegroundTypeId bgTypeId) const float Player::GetReputationPriceDiscount(Creature const* creature) const { - return GetReputationPriceDiscount(creature->GetFactionTemplateEntry()); + float discount = GetReputationPriceDiscount(creature->GetFactionTemplateEntry()); + sScriptMgr->OnPlayerGetReputationPriceDiscount(this, creature, discount); + return discount; } float Player::GetReputationPriceDiscount(FactionTemplateEntry const* factionTemplate) const { + float discount = 1.0f; + if (!factionTemplate || !factionTemplate->faction) { - return 1.0f; + sScriptMgr->OnPlayerGetReputationPriceDiscount(this, factionTemplate, discount); + return discount; } ReputationRank rank = GetReputationRank(factionTemplate->faction); + if (rank <= REP_NEUTRAL) { - return 1.0f; + sScriptMgr->OnPlayerGetReputationPriceDiscount(this, factionTemplate, discount); + return discount; } - return 1.0f - 0.05f * (rank - REP_NEUTRAL); + discount = discount - 0.05f * (rank - REP_NEUTRAL); + + sScriptMgr->OnPlayerGetReputationPriceDiscount(this, factionTemplate, discount); + return discount; } bool Player::IsSpellFitByClassAndRace(uint32 spell_id) const diff --git a/src/server/game/Scripting/ScriptDefines/PlayerScript.cpp b/src/server/game/Scripting/ScriptDefines/PlayerScript.cpp index 62439d284..d52bb272f 100644 --- a/src/server/game/Scripting/ScriptDefines/PlayerScript.cpp +++ b/src/server/game/Scripting/ScriptDefines/PlayerScript.cpp @@ -910,6 +910,16 @@ void ScriptMgr::OnPlayerSendListInventory(Player* player, ObjectGuid vendorGuid, CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_SEND_LIST_INVENTORY, script->OnPlayerSendListInventory(player, vendorGuid, vendorEntry)); } +void ScriptMgr::OnPlayerGetReputationPriceDiscount(Player const* player, Creature const* creature, float& discount) +{ + CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_GET_REPUTATION_PRICE_DISCOUNT, script->OnPlayerGetReputationPriceDiscount(player, creature, discount)); +} + +void ScriptMgr::OnPlayerGetReputationPriceDiscount(Player const* player, FactionTemplateEntry const* factionTemplate, float& discount) +{ + CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_GET_REPUTATION_PRICE_DISCOUNT, script->OnPlayerGetReputationPriceDiscount(player, factionTemplate, discount)); +} + PlayerScript::PlayerScript(const char* name, std::vector enabledHooks) : ScriptObject(name, PLAYERHOOK_END) { diff --git a/src/server/game/Scripting/ScriptDefines/PlayerScript.h b/src/server/game/Scripting/ScriptDefines/PlayerScript.h index 5ee56e7ac..c90c77410 100644 --- a/src/server/game/Scripting/ScriptDefines/PlayerScript.h +++ b/src/server/game/Scripting/ScriptDefines/PlayerScript.h @@ -20,6 +20,7 @@ #include "ScriptObject.h" #include "SharedDefines.h" +#include "DBCStructure.h" #include // TODO to remove @@ -207,6 +208,7 @@ enum PlayerHook PLAYERHOOK_ON_CAN_GIVE_LEVEL, PLAYERHOOK_ON_SEND_LIST_INVENTORY, PLAYERHOOK_ON_GIVE_REPUTATION, + PLAYERHOOK_ON_GET_REPUTATION_PRICE_DISCOUNT, PLAYERHOOK_END }; @@ -796,6 +798,24 @@ public: * @param vendorEntry Entry of the vendor player is interacting with */ virtual void OnPlayerSendListInventory(Player* /*player*/, ObjectGuid /*vendorGuid*/, uint32& /*vendorEntry*/) {} + + /** + * @brief This hook is called whenever a player attempts to buy items, repair, take taxis, or learn spells. This then uses this information to call OnPlayerGetReputationPriceDiscoun(Player, FactionTemplateEntry, float) + * + * @param player Contains information about the Player + * @param creature Contains information about the creature involved in the transaction + * @param discount Float value of the discount, as a multiplier of the base price + */ + virtual void OnPlayerGetReputationPriceDiscount(Player const* /*player*/, Creature const* /*creature*/, float& /*discount*/) {} + + /** + * @brief This hook is called whenever a player attempts to buy items, repair, take taxis, or learn spells. It is also called when continuing along taxis + * + * @param player Contains information about the Player + * @param factionTemplate Contains information about the faction template involved in the transaction. Can be null! + * @param discount Float value of the discount, as a multiplier of the base price + */ + virtual void OnPlayerGetReputationPriceDiscount(Player const* /*player*/, FactionTemplateEntry const* /*factionTemplate*/, float& /*discount*/) {} }; #endif diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 056a44a57..222dac69e 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -462,6 +462,8 @@ public: /* PlayerScript */ bool OnPlayerCanResurrect(Player* player); bool OnPlayerCanGiveLevel(Player* player, uint8 newLevel); void OnPlayerSendListInventory(Player* player, ObjectGuid vendorGuid, uint32& vendorEntry); + void OnPlayerGetReputationPriceDiscount(Player const* player, Creature const* creature, float& discount); + void OnPlayerGetReputationPriceDiscount(Player const* player, FactionTemplateEntry const* factionTemplate, float& discount); // Anti cheat void AnticheatSetCanFlybyServer(Player* player, bool apply);