feat(Core/Player): Add hooks for reputation price discount calculation. (#24666)

This commit is contained in:
Benjamin Jackson
2026-02-15 17:44:44 -05:00
committed by GitHub
parent 24f84ee849
commit 1e47f701ac
4 changed files with 46 additions and 4 deletions

View File

@@ -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

View File

@@ -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<uint16> enabledHooks)
: ScriptObject(name, PLAYERHOOK_END)
{

View File

@@ -20,6 +20,7 @@
#include "ScriptObject.h"
#include "SharedDefines.h"
#include "DBCStructure.h"
#include <vector>
// 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

View File

@@ -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);