From 44b7a0666c78dc99ab0bbc94045abb6685b3ad86 Mon Sep 17 00:00:00 2001 From: ZhengPeiRu21 <98835050+ZhengPeiRu21@users.noreply.github.com> Date: Thu, 24 Mar 2022 03:27:15 -0600 Subject: [PATCH] feat(Scripting/Hooks): implement OnQuestComputeXP() hook (#10934) --- doc/changelog/pendings/changes_1647137971165231200.md | 7 +++++++ src/server/game/Entities/Player/PlayerQuest.cpp | 1 + src/server/game/Scripting/ScriptDefines/PlayerScript.cpp | 7 +++++++ src/server/game/Scripting/ScriptMgr.h | 4 ++++ 4 files changed, 19 insertions(+) create mode 100644 doc/changelog/pendings/changes_1647137971165231200.md diff --git a/doc/changelog/pendings/changes_1647137971165231200.md b/doc/changelog/pendings/changes_1647137971165231200.md new file mode 100644 index 000000000..86f51b9af --- /dev/null +++ b/doc/changelog/pendings/changes_1647137971165231200.md @@ -0,0 +1,7 @@ +### Added + +- New hook for OnQuestComputeXP(). The intended use is to change the XP values for certain quests programmatically. The hook is triggered after XP calculation and before rewarding XP or gold to the player. + +### How to upgrade + +- No special changes needed. The new hook is available for use and should not interfere with any existing hooks or logic. diff --git a/src/server/game/Entities/Player/PlayerQuest.cpp b/src/server/game/Entities/Player/PlayerQuest.cpp index 88c640c82..037d4733d 100644 --- a/src/server/game/Entities/Player/PlayerQuest.cpp +++ b/src/server/game/Entities/Player/PlayerQuest.cpp @@ -737,6 +737,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver, for (Unit::AuraEffectList::const_iterator i = ModXPPctAuras.begin(); i != ModXPPctAuras.end(); ++i) AddPct(XP, (*i)->GetAmount()); + sScriptMgr->OnQuestComputeXP(this, quest, XP); int32 moneyRew = 0; if (getLevel() >= sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL) || sScriptMgr->ShouldBeRewardedWithMoneyInsteadOfExp(this)) { diff --git a/src/server/game/Scripting/ScriptDefines/PlayerScript.cpp b/src/server/game/Scripting/ScriptDefines/PlayerScript.cpp index 1f2bcd9b3..959fc2b35 100644 --- a/src/server/game/Scripting/ScriptDefines/PlayerScript.cpp +++ b/src/server/game/Scripting/ScriptDefines/PlayerScript.cpp @@ -729,6 +729,13 @@ bool ScriptMgr::OnBeforePlayerQuestComplete(Player* player, uint32 quest_id) return true; } +void ScriptMgr::OnQuestComputeXP(Player* player, Quest const* quest, uint32& xpValue) +{ + ExecuteScript([&](PlayerScript* script) + { + script->OnQuestComputeXP(player, quest, xpValue); + }); +} void ScriptMgr::OnBeforeStoreOrEquipNewItem(Player* player, uint32 vendorslot, uint32& item, uint8 count, uint8 bag, uint8 slot, ItemTemplate const* pProto, Creature* pVendor, VendorItem const* crItem, bool bStore) { diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 8400cd7f9..bf874c096 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -1157,6 +1157,9 @@ public: // After completed a quest [[nodiscard]] virtual bool OnBeforeQuestComplete(Player* /*player*/, uint32 /*quest_id*/) { return true; } + // Called after computing the XP reward value for a quest + virtual void OnQuestComputeXP(Player* /*player*/, Quest const* /*quest*/, uint32& /*xpValue*/) { } + // Before durability repair action, you can even modify the discount value virtual void OnBeforeDurabilityRepair(Player* /*player*/, ObjectGuid /*npcGUID*/, ObjectGuid /*itemGUID*/, float&/*discountMod*/, uint8 /*guildBank*/) { } @@ -2221,6 +2224,7 @@ public: /* PlayerScript */ void OnCreateItem(Player* player, Item* item, uint32 count); void OnQuestRewardItem(Player* player, Item* item, uint32 count); bool OnBeforePlayerQuestComplete(Player* player, uint32 quest_id); + void OnQuestComputeXP(Player* player, Quest const* quest, uint32& xpValue); void OnBeforePlayerDurabilityRepair(Player* player, ObjectGuid npcGUID, ObjectGuid itemGUID, float& discountMod, uint8 guildBank); void OnBeforeBuyItemFromVendor(Player* player, ObjectGuid vendorguid, uint32 vendorslot, uint32& item, uint8 count, uint8 bag, uint8 slot); void OnBeforeStoreOrEquipNewItem(Player* player, uint32 vendorslot, uint32& item, uint8 count, uint8 bag, uint8 slot, ItemTemplate const* pProto, Creature* pVendor, VendorItem const* crItem, bool bStore);