chore(PlayerScript/Hook) : Add CanSetTradeItem Hook in PlayerScript (#18583)
* chore(PlayerScript/Hook) : Add CanSetTradeItem Hook in PlayerScript * Allowing non traded slots * Fix typo and codestyle
This commit is contained in:
@@ -708,6 +708,15 @@ void WorldSession::HandleSetTradeItemOpcode(WorldPacket& recvPacket)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PlayerScript Hook for checking traded items if we want to filter them in a custom module
|
||||||
|
if (!sScriptMgr->CanSetTradeItem(_player, item, tradeSlot))
|
||||||
|
{
|
||||||
|
// Do not send TRADE_STATUS_TRADE_CANCELED because it will cause double display of "Transaction canceled" notification
|
||||||
|
// On the trade initiator screen
|
||||||
|
SendTradeStatus(TRADE_STATUS_CLOSE_WINDOW);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
my_trade->SetItem(TradeSlots(tradeSlot), item);
|
my_trade->SetItem(TradeSlots(tradeSlot), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1508,6 +1508,19 @@ bool ScriptMgr::CanInitTrade(Player* player, Player* target)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScriptMgr::CanSetTradeItem(Player* player, Item* tradedItem, uint8 tradeSlot)
|
||||||
|
{
|
||||||
|
auto ret = IsValidBoolScript<PlayerScript>([&](PlayerScript* script)
|
||||||
|
{
|
||||||
|
return !script->CanSetTradeItem(player, tradedItem, tradeSlot);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ret && *ret)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptMgr::OnSetServerSideVisibility(Player* player, ServerSideVisibilityType& type, AccountTypes& sec)
|
void ScriptMgr::OnSetServerSideVisibility(Player* player, ServerSideVisibilityType& type, AccountTypes& sec)
|
||||||
{
|
{
|
||||||
ExecuteScript<PlayerScript>([&](PlayerScript* script)
|
ExecuteScript<PlayerScript>([&](PlayerScript* script)
|
||||||
|
|||||||
@@ -421,6 +421,16 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] virtual bool CanInitTrade(Player* /*player*/, Player* /*target*/) { return true; }
|
[[nodiscard]] virtual bool CanInitTrade(Player* /*player*/, Player* /*target*/) { return true; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This hook called just before finishing the handling of the action of a player setting an item in a trade slot
|
||||||
|
*
|
||||||
|
* @param player Contains information about the trade initiator Player
|
||||||
|
* @param tradedItem Contains information about the item set in the trade slot
|
||||||
|
*
|
||||||
|
* @return True if you want to continue setting the item in the trade slot, false if you want to cancel the trade
|
||||||
|
*/
|
||||||
|
[[nodiscard]] virtual bool CanSetTradeItem(Player* /*player*/, Item* /*tradedItem*/, uint8 /*tradeSlot*/) { return true; }
|
||||||
|
|
||||||
virtual void OnSetServerSideVisibility(Player* /*player*/, ServerSideVisibilityType& /*type*/, AccountTypes& /*sec*/) { }
|
virtual void OnSetServerSideVisibility(Player* /*player*/, ServerSideVisibilityType& /*type*/, AccountTypes& /*sec*/) { }
|
||||||
|
|
||||||
virtual void OnSetServerSideVisibilityDetect(Player* /*player*/, ServerSideVisibilityType& /*type*/, AccountTypes& /*sec*/) { }
|
virtual void OnSetServerSideVisibilityDetect(Player* /*player*/, ServerSideVisibilityType& /*type*/, AccountTypes& /*sec*/) { }
|
||||||
|
|||||||
@@ -440,6 +440,7 @@ public: /* PlayerScript */
|
|||||||
bool CanJoinLfg(Player* player, uint8 roles, lfg::LfgDungeonSet& dungeons, const std::string& comment);
|
bool CanJoinLfg(Player* player, uint8 roles, lfg::LfgDungeonSet& dungeons, const std::string& comment);
|
||||||
bool CanEnterMap(Player* player, MapEntry const* entry, InstanceTemplate const* instance, MapDifficulty const* mapDiff, bool loginCheck);
|
bool CanEnterMap(Player* player, MapEntry const* entry, InstanceTemplate const* instance, MapDifficulty const* mapDiff, bool loginCheck);
|
||||||
bool CanInitTrade(Player* player, Player* target);
|
bool CanInitTrade(Player* player, Player* target);
|
||||||
|
bool CanSetTradeItem(Player* player, Item* tradedItem, uint8 tradeSlot);
|
||||||
void OnSetServerSideVisibility(Player* player, ServerSideVisibilityType& type, AccountTypes& sec);
|
void OnSetServerSideVisibility(Player* player, ServerSideVisibilityType& type, AccountTypes& sec);
|
||||||
void OnSetServerSideVisibilityDetect(Player* player, ServerSideVisibilityType& type, AccountTypes& sec);
|
void OnSetServerSideVisibilityDetect(Player* player, ServerSideVisibilityType& type, AccountTypes& sec);
|
||||||
void OnPlayerResurrect(Player* player, float restore_percent, bool applySickness);
|
void OnPlayerResurrect(Player* player, float restore_percent, bool applySickness);
|
||||||
|
|||||||
Reference in New Issue
Block a user