From 62e0235e735b6ca265e11d6f0442deb73779f7d2 Mon Sep 17 00:00:00 2001 From: Yunfan Li <56597220+liyunfan1223@users.noreply.github.com> Date: Sat, 22 Feb 2025 12:08:53 +0800 Subject: [PATCH] Scripts and sessions update to align with acore (#987) --- src/PlayerbotAI.cpp | 2 +- src/PlayerbotMgr.cpp | 7 ++++--- src/PlayerbotTextMgr.cpp | 3 ++- src/Playerbots.cpp | 31 ++++++++----------------------- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index e1ad040d..f5a1720d 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -5431,7 +5431,7 @@ InventoryResult PlayerbotAI::CanEquipItem(uint8 slot, uint16& dest, Item* pItem, ItemTemplate const* pProto = pItem->GetTemplate(); if (pProto) { - if (!sScriptMgr->CanEquipItem(bot, slot, dest, pItem, swap, not_loading)) + if (!sScriptMgr->OnPlayerCanEquipItem(bot, slot, dest, pItem, swap, not_loading)) return EQUIP_ERR_CANT_DO_RIGHT_NOW; // item used diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index 8653c3d8..a4faaea3 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -32,6 +32,7 @@ #include "ChannelMgr.h" #include "BroadcastHelper.h" #include "PlayerbotDbStore.h" +#include "WorldSessionMgr.h" PlayerbotHolder::PlayerbotHolder() : PlayerbotAIBase(false) {} class PlayerbotLoginQueryHolder : public LoginQueryHolder @@ -64,7 +65,7 @@ void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId if (!accountId) return; - WorldSession* masterSession = masterAccountId ? sWorld->FindSession(masterAccountId) : nullptr; + WorldSession* masterSession = masterAccountId ? sWorldSessionMgr->FindSession(masterAccountId) : nullptr; Player* masterPlayer = masterSession ? masterSession->GetPlayer() : nullptr; bool isRndbot = !masterAccountId; @@ -115,7 +116,7 @@ void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId botLoading.insert(playerGuid); - if (WorldSession* masterSession = sWorld->FindSession(masterAccountId)) + if (WorldSession* masterSession = sWorldSessionMgr->FindSession(masterAccountId)) { masterSession->AddQueryHolderCallback(CharacterDatabase.DelayQueryHolder(holder)) .AfterComplete([this](SQLQueryHolderBase const& holder) @@ -151,7 +152,7 @@ void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder con } uint32 masterAccount = holder.GetMasterAccountId(); - WorldSession* masterSession = masterAccount ? sWorld->FindSession(masterAccount) : nullptr; + WorldSession* masterSession = masterAccount ? sWorldSessionMgr->FindSession(masterAccount) : nullptr; // Check if masterSession->GetPlayer() is valid Player* masterPlayer = masterSession ? masterSession->GetPlayer() : nullptr; diff --git a/src/PlayerbotTextMgr.cpp b/src/PlayerbotTextMgr.cpp index e78236d9..9a923de9 100644 --- a/src/PlayerbotTextMgr.cpp +++ b/src/PlayerbotTextMgr.cpp @@ -6,6 +6,7 @@ #include "PlayerbotTextMgr.h" #include "Playerbots.h" +#include "WorldSessionMgr.h" void PlayerbotTextMgr::replaceAll(std::string& str, const std::string& from, const std::string& to) { @@ -184,7 +185,7 @@ uint32 PlayerbotTextMgr::GetLocalePriority() uint32 topLocale = 0; // if no real players online, reset top locale - if (!sWorld->GetActiveSessionCount()) + if (!sWorldSessionMgr->GetActiveSessionCount()) { ResetLocalePriority(); return 0; diff --git a/src/Playerbots.cpp b/src/Playerbots.cpp index e495c61d..2b33feed 100644 --- a/src/Playerbots.cpp +++ b/src/Playerbots.cpp @@ -72,26 +72,12 @@ public: } }; -class PlayerbotsMetricScript : public MetricScript -{ -public: - PlayerbotsMetricScript() : MetricScript("PlayerbotsMetricScript") {} - - void OnMetricLogging() override - { - if (sMetric->IsEnabled()) - { - sMetric->LogValue("db_queue_playerbots", uint64(PlayerbotsDatabase.QueueSize()), {}); - } - } -}; - class PlayerbotsPlayerScript : public PlayerScript { public: PlayerbotsPlayerScript() : PlayerScript("PlayerbotsPlayerScript") {} - void OnLogin(Player* player) override + void OnPlayerLogin(Player* player) override { if (!player->GetSession()->IsBot()) { @@ -122,7 +108,7 @@ public: } } - void OnAfterUpdate(Player* player, uint32 diff) override + void OnPlayerAfterUpdate(Player* player, uint32 diff) override { if (PlayerbotAI* botAI = GET_PLAYERBOT_AI(player)) { @@ -135,7 +121,7 @@ public: } } - bool CanPlayerUseChat(Player* player, uint32 type, uint32 /*lang*/, std::string& msg, Player* receiver) override + bool OnPlayerCanUseChat(Player* player, uint32 type, uint32 /*lang*/, std::string& msg, Player* receiver) override { if (type == CHAT_MSG_WHISPER) { @@ -150,7 +136,7 @@ public: return true; } - void OnChat(Player* player, uint32 type, uint32 /*lang*/, std::string& msg, Group* group) override + void OnPlayerChat(Player* player, uint32 type, uint32 /*lang*/, std::string& msg, Group* group) override { for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next()) { @@ -164,7 +150,7 @@ public: } } - void OnChat(Player* player, uint32 type, uint32 /*lang*/, std::string& msg) override + void OnPlayerChat(Player* player, uint32 type, uint32 /*lang*/, std::string& msg) override { if (type == CHAT_MSG_GUILD) { @@ -185,7 +171,7 @@ public: } } - void OnChat(Player* player, uint32 type, uint32 /*lang*/, std::string& msg, Channel* channel) override + void OnPlayerChat(Player* player, uint32 type, uint32 /*lang*/, std::string& msg, Channel* channel) override { if (PlayerbotMgr* playerbotMgr = GET_PLAYERBOT_MGR(player)) { @@ -198,7 +184,7 @@ public: sRandomPlayerbotMgr->HandleCommand(type, msg, player); } - bool OnBeforeCriteriaProgress(Player* player, AchievementCriteriaEntry const* /*criteria*/) override + bool OnPlayerBeforeCriteriaProgress(Player* player, AchievementCriteriaEntry const* /*criteria*/) override { if (sRandomPlayerbotMgr->IsRandomBot(player)) { @@ -207,7 +193,7 @@ public: return true; } - bool OnBeforeAchiComplete(Player* player, AchievementEntry const* /*achievement*/) override + bool OnPlayerBeforeAchievementComplete(Player* player, AchievementEntry const* /*achievement*/) override { if (sRandomPlayerbotMgr->IsRandomBot(player)) { @@ -372,7 +358,6 @@ public: void AddPlayerbotsScripts() { new PlayerbotsDatabaseScript(); - new PlayerbotsMetricScript(); new PlayerbotsPlayerScript(); new PlayerbotsMiscScript(); new PlayerbotsServerScript();