Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Core/Entities): Add OnPlayerSendListInventory script hook #21676

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/server/game/Handlers/ItemHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,8 @@ void WorldSession::SendListInventory(ObjectGuid vendorGuid, uint32 vendorEntry)
{
LOG_DEBUG("network", "WORLD: Sent SMSG_LIST_INVENTORY");

sScriptMgr->OnPlayerSendListInventory(GetPlayer(), vendorGuid, vendorEntry);

Creature* vendor = GetPlayer()->GetNPCIfCanInteractWith(vendorGuid, UNIT_NPC_FLAG_VENDOR);
if (!vendor)
{
Expand Down
5 changes: 5 additions & 0 deletions src/server/game/Scripting/ScriptDefines/PlayerScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,11 @@ bool ScriptMgr::OnPlayerCanGiveLevel(Player* player, uint8 newLevel)
CALL_ENABLED_BOOLEAN_HOOKS(PlayerScript, PLAYERHOOK_ON_CAN_GIVE_LEVEL, !script->OnPlayerCanGiveLevel(player, newLevel));
}

void ScriptMgr::OnPlayerSendListInventory(Player* player, ObjectGuid vendorGuid, uint32 vendorEntry)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about changing it to uint32& vendorEntry so that it can be manipulated in the hook? to my understanding this could be used to swap out the vendor lists of vendors maybe

{
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_SEND_LIST_INVENTORY, script->OnPlayerSendListInventory(player, vendorGuid, vendorEntry));
}

PlayerScript::PlayerScript(const char* name, std::vector<uint16> enabledHooks)
: ScriptObject(name, PLAYERHOOK_END)
{
Expand Down
10 changes: 10 additions & 0 deletions src/server/game/Scripting/ScriptDefines/PlayerScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ enum PlayerHook
PLAYERHOOK_ON_UPDATE_SKILL,
PLAYERHOOK_CAN_RESURRECT,
PLAYERHOOK_ON_CAN_GIVE_LEVEL,
PLAYERHOOK_ON_SEND_LIST_INVENTORY,
PLAYERHOOK_END
};

Expand Down Expand Up @@ -793,6 +794,15 @@ class PlayerScript : public ScriptObject
* @return true if player is allowed to gain the new level
*/
virtual bool OnPlayerCanGiveLevel(Player* /*player*/, uint8 /*newLevel*/) { return true; }

/**
* @brief This hook is called whenever a player interacts with a vendor, and is then shown the vendor list
*
* @param player Contains information about the Player
* @param vendorGuid Guid of the vendor player is interacting with
* @param vendorEntry Entry of the vendor player is interacting with
*/
virtual void OnPlayerSendListInventory(Player* /*player*/, ObjectGuid /*vendorGuid*/, uint32 /*vendorEntry*/) {}
};

#endif
1 change: 1 addition & 0 deletions src/server/game/Scripting/ScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ class ScriptMgr
void OnPlayerUpdateSkill(Player* player, uint32 skillId, uint32 value, uint32 max, uint32 step, uint32 newValue);
bool OnPlayerCanResurrect(Player* player);
bool OnPlayerCanGiveLevel(Player* player, uint8 newLevel);
void OnPlayerSendListInventory(Player* player, ObjectGuid vendorGuid, uint32 vendorEntry);

// Anti cheat
void AnticheatSetCanFlybyServer(Player* player, bool apply);
Expand Down