Merge branch 'master' into Playerbot

This commit is contained in:
Yunfan Li
2024-03-28 19:15:09 +08:00
36 changed files with 3768 additions and 729 deletions

View File

@@ -68,6 +68,8 @@ namespace AccountMgr
if (!result)
return AOR_NAME_NOT_EXIST;
sScriptMgr->OnBeforeAccountDelete(accountId);
// Obtain accounts characters
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARS_BY_ACCOUNT_ID);
stmt->SetData(0, accountId);

View File

@@ -708,6 +708,15 @@ void WorldSession::HandleSetTradeItemOpcode(WorldPacket& recvPacket)
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);
}

View File

@@ -27,6 +27,14 @@ void ScriptMgr::OnAccountLogin(uint32 accountId)
});
}
void ScriptMgr::OnBeforeAccountDelete(uint32 accountId)
{
ExecuteScript<AccountScript>([&](AccountScript* script)
{
script->OnBeforeAccountDelete(accountId);
});
}
//void ScriptMgr::OnAccountLogout(uint32 accountId)
//{
// ExecuteScript<AccountScript>([&](AccountScript* script)

View File

@@ -29,6 +29,9 @@ public:
// Called when an account logged in successfully
virtual void OnAccountLogin(uint32 /*accountId*/) { }
// Called when an account is about to be deleted
virtual void OnBeforeAccountDelete(uint32 /*accountId*/) { }
// Called when an ip logged in successfully
virtual void OnLastIpUpdate(uint32 /*accountId*/, std::string /*ip*/) { }

View File

@@ -1516,6 +1516,19 @@ bool ScriptMgr::CanInitTrade(Player* player, Player* target)
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)
{
ExecuteScript<PlayerScript>([&](PlayerScript* script)

View File

@@ -422,6 +422,16 @@ public:
[[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 OnSetServerSideVisibilityDetect(Player* /*player*/, ServerSideVisibilityType& /*type*/, AccountTypes& /*sec*/) { }

View File

@@ -473,6 +473,7 @@ public: /* PlayerScript */
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 CanInitTrade(Player* player, Player* target);
bool CanSetTradeItem(Player* player, Item* tradedItem, uint8 tradeSlot);
void OnSetServerSideVisibility(Player* player, ServerSideVisibilityType& type, AccountTypes& sec);
void OnSetServerSideVisibilityDetect(Player* player, ServerSideVisibilityType& type, AccountTypes& sec);
void OnPlayerResurrect(Player* player, float restore_percent, bool applySickness);
@@ -502,6 +503,7 @@ public: /* PlayerScript */
public: /* AccountScript */
void OnAccountLogin(uint32 accountId);
void OnBeforeAccountDelete(uint32 accountId);
void OnLastIpUpdate(uint32 accountId, std::string ip);
void OnFailedAccountLogin(uint32 accountId);
void OnEmailChange(uint32 accountId);