diff options
| author | Shauren <shauren.trinity@gmail.com> | 2025-06-22 21:56:58 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2025-06-22 21:56:58 +0200 |
| commit | e59059e1bd2f67691e2da0105771b0cb55b123a4 (patch) | |
| tree | 4f4864f8aae63eeafac29f440e0ce64a027c4108 /src/server/game/Scripting | |
| parent | 7ca6b226a7420ff38e3a4f17a3758393d68629e3 (diff) | |
Core/Players: PlayerChoice improvements
* Add missing choice properties to database (InfiniteRange, ShowChoicesAsList)
* Allow limiiting the number of responses sent at the same time
* Fixed duration sent in SMSG_DISPLAY_PLAYER_CHOICE
* Remove dynamically generated response identifiers from database
* Remove auto rewarding choice responses
* Change response scripts to be bound to scriptname
Diffstat (limited to 'src/server/game/Scripting')
| -rw-r--r-- | src/server/game/Scripting/ScriptMgr.cpp | 30 | ||||
| -rw-r--r-- | src/server/game/Scripting/ScriptMgr.h | 27 |
2 files changed, 47 insertions, 10 deletions
diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 3135dce1a22..09e3f4eca11 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -39,6 +39,7 @@ #include "ObjectMgr.h" #include "OutdoorPvPMgr.h" #include "Player.h" +#include "PlayerChoice.h" #include "ScriptReloadMgr.h" #include "ScriptSystem.h" #include "SmartAI.h" @@ -142,6 +143,10 @@ template<> struct is_script_database_bound<EventScript> : std::true_type { }; +template<> +struct is_script_database_bound<PlayerChoiceScript> + : std::true_type { }; + enum Spells { SPELL_HOTSWAP_VISUAL_SPELL_EFFECT = 40162 // 59084 @@ -2150,9 +2155,13 @@ void ScriptMgr::OnMovieComplete(Player* player, uint32 movieId) FOREACH_SCRIPT(PlayerScript)->OnMovieComplete(player, movieId); } -void ScriptMgr::OnPlayerChoiceResponse(Player* player, uint32 choiceId, uint32 responseId) +void ScriptMgr::OnPlayerChoiceResponse(WorldObject* object, Player* player, PlayerChoice const* choice, PlayerChoiceResponse const* response, uint16 clientIdentifier) { - FOREACH_SCRIPT(PlayerScript)->OnPlayerChoiceResponse(player, choiceId, responseId); + ASSERT(choice); + ASSERT(response); + + GET_SCRIPT(PlayerChoiceScript, choice->ScriptId, tmpscript); + tmpscript->OnResponse(object, player, choice, response, clientIdentifier); } // Account @@ -3020,10 +3029,6 @@ void PlayerScript::OnMovieComplete(Player* /*player*/, uint32 /*movieId*/) { } -void PlayerScript::OnPlayerChoiceResponse(Player* /*player*/, uint32 /*choiceId*/, uint32 /*responseId*/) -{ -} - AccountScript::AccountScript(char const* name) noexcept : ScriptObject(name) { @@ -3232,6 +3237,18 @@ void EventScript::OnTrigger(WorldObject* /*object*/, WorldObject* /*invoker*/, u { } +PlayerChoiceScript::PlayerChoiceScript(char const* name) noexcept + : ScriptObject(name) +{ + ScriptRegistry<PlayerChoiceScript>::Instance()->AddScript(this); +} + +PlayerChoiceScript::~PlayerChoiceScript() = default; + +void PlayerChoiceScript::OnResponse(WorldObject* /*object*/, Player* /*player*/, PlayerChoice const* /*choice*/, PlayerChoiceResponse const* /*response*/, uint16 /*clientIdentifier*/) +{ +} + // Specialize for each script type class like so: template class TC_GAME_API ScriptRegistry<SpellScriptLoader>; template class TC_GAME_API ScriptRegistry<ServerScript>; @@ -3266,3 +3283,4 @@ template class TC_GAME_API ScriptRegistry<SceneScript>; template class TC_GAME_API ScriptRegistry<QuestScript>; template class TC_GAME_API ScriptRegistry<WorldStateScript>; template class TC_GAME_API ScriptRegistry<EventScript>; +template class TC_GAME_API ScriptRegistry<PlayerChoiceScript>; diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 482d687f659..2e711c9ffae 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -76,6 +76,8 @@ struct CreatureTemplate; struct CreatureData; struct ItemTemplate; struct MapEntry; +struct PlayerChoice; +struct PlayerChoiceResponse; struct Position; struct QuestObjective; struct SceneTemplate; @@ -789,9 +791,6 @@ class TC_GAME_API PlayerScript : public ScriptObject // Called when a player completes a movie virtual void OnMovieComplete(Player* player, uint32 movieId); - - // Called when a player choose a response from a PlayerChoice - virtual void OnPlayerChoiceResponse(Player* player, uint32 choiceId, uint32 responseId); }; class TC_GAME_API AccountScript : public ScriptObject @@ -991,6 +990,26 @@ class TC_GAME_API EventScript : public ScriptObject virtual void OnTrigger(WorldObject* object, WorldObject* invoker, uint32 eventId); }; +class TC_GAME_API PlayerChoiceScript : public ScriptObject +{ + protected: + + explicit PlayerChoiceScript(char const* name) noexcept; + + public: + + ~PlayerChoiceScript(); + + /** + * @param object Source object of the PlayerChoice (can be nullptr) + * @param player Player making the choice + * @param choice Database template of PlayerChoice + * @param response Database template of selected PlayerChoice response + * @param clientIdentifier Dynamically generated identifier of the response, changes every time PlayerChoice is sent to player + */ + virtual void OnResponse(WorldObject* object, Player* player, PlayerChoice const* choice, PlayerChoiceResponse const* response, uint16 clientIdentifier); +}; + // Manages registration, loading, and execution of scripts. class TC_GAME_API ScriptMgr { @@ -1226,7 +1245,7 @@ class TC_GAME_API ScriptMgr void OnQuestStatusChange(Player* player, uint32 questId); void OnPlayerRepop(Player* player); void OnMovieComplete(Player* player, uint32 movieId); - void OnPlayerChoiceResponse(Player* player, uint32 choiceId, uint32 responseId); + void OnPlayerChoiceResponse(WorldObject* object, Player* player, PlayerChoice const* choice, PlayerChoiceResponse const* response, uint16 clientIdentifier); public: /* AccountScript */ |
