Hello World

吞风吻雨葬落日 欺山赶海踏雪径

0%

AzerothCore PlayerBots编译记录

最近虽然乌龟服上线了,但是不用加速器还是太卡,继续玩回自己的开源服。
这次是把22年遗留下来的PlayerBots 卡顿的问题解决下,顺便更新一版本,说不定最新版的性能会更好一些。

编译

编译基本上和原版类似,注意需要使用对应的 azerothcore版本。
MOD是 mod-playerbots ,但是我这边选择更新更频繁的 FORK版本
为了后续方便扩展,这边还是打上Eluna的MOD: mod-eluna

当前时间2023年10月2日 21:53:12 的源码直接编译是有错误的,MOD的源码需要简单改两个地方:
20231002215601.png

直接编译跑一下。发现还是卡顿,但是明显比以前好很多了,看console输出比较频繁,应该是机器人太多了,减少机器人个数,同时增加机器人更新时间。
修改\configs\modules\playerbots.conf 文件:

1
2
3
4
5
6
AiPlayerbot.RandomBotUpdateInterval = 60
# Random bot count
AiPlayerbot.MinRandomBots = 50
AiPlayerbot.MaxRandomBots = 50
AiPlayerbot.RandomBotMinLevel = 1
AiPlayerbot.RandomBotMaxLevel = 80

之后重启尝试一下,的确不卡了。 但是有个新问题,机器人怎么控制?!这里官方建议使用插件 unbot-addon
ps. 最后我是和 wow-addon-playerbots 一起使用的。

插件修改

unbot-addon 在点击按钮的时候总是会报lua脚本错误,仔细看下是下面的InspectFramenil

1
2
3
4
5
6
7
8
9
10
function CommandUnBotSetting(index)
UnBotHideAllSubFrame();
UnBotCloseAllBagsFrame();
OnlineFrame:Hide();
NPCFrame:Hide();

if ( InspectFrame:IsShown()) then
DisplayInfomation("InspectFrame_Show "..UnitName(InspectFrame.unit)..", Name "..InspectFrame:GetName());
end
end

直接改成下面代码

1
2
3
if (InspectFrame and InspectFrame:IsShown()) then
DisplayInfomation("InspectFrame_Show "..UnitName(InspectFrame.unit)..", Name "..InspectFrame:GetName());
end

然后是这个函数被作者注释掉了,但是却还有引用:

1
2
3
4
5
6
7
8
9
10
11
function InspectFrame_Show(unit)
HideUIPanel(InspectFrame);
if ( CanInspect(unit, true) ) then
NotifyInspect(unit);
InspectFrame.unit = unit;
InspectSwitchTabs(1);
ShowUIPanel(InspectFrame);
InspectFrame_UpdateTalentTab();
DisplayInfomation("InspectFrame_Show "..UnitName(unit));
end
end

这里起初我也不太懂,但是如果只是把调用点全部去除的话 查看机器人装备的功能就失效了。这时候就只能祭出我正常多年的魔兽世界编程宝典 - World of Warcraft Programming: A Guide and Reference for Creating WoW Addons
同时也全局搜索了下现有的多玩插件与大脚插件相关内容,发现这个InspectFrame 其实就是装备查看的UI框架。同时在多玩中的DuowanMove 插件发现了这些框架是按需加载的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
local Blizzard_LoadOnDemand = {
["Blizzard_InspectUI"] = {"InspectFrame"},
["Blizzard_GuildBankUI"] = {"GuildBankFrame"},
["Blizzard_TradeSkillUI"] = {"TradeSkillFrame"},
["Blizzard_ItemSocketingUI"] = {"ItemSocketingFrame"},
["Blizzard_BarbershopUI"] = {"BarberShopFrame"},
["Blizzard_GlyphUI"] = {"SpellBookFrame", "GlyphFrame"},
["Blizzard_MacroUI"] = {"MacroFrame"},
["Blizzard_AchievementUI"] = {"AchievementFrame", "AchievementFrameHeader"},
["Blizzard_TalentUI"] = {"PlayerTalentFrame"},
["Blizzard_Calendar"] = {"CalendarFrame"},
["Blizzard_TrainerUI"] = {"ClassTrainerFrame"},
["Blizzard_BindingUI"] = {"KeyBindingFrame"},
["Blizzard_AuctionUI"] = {"AuctionFrame"},
["Blizzard_TimeManager"] = {"TimeManagerFrame"},
};

local function checkBlizzLoaded()
for a, t in pairs(Blizzard_LoadOnDemand) do
if (IsAddOnLoaded(a)) then
SetMoveHandler(_G[t[1]], _G[t[2]]);
end
end
end

这里有一个函数成为了破局点IsAddOnLoaded(a)。 这个函数在编程脚本中是可以直接搜索到到

1
2
3
4
5
6
7
8
IsAddOnLoaded
Returns whether an addon is currently loaded.
loaded = IsAddOnLoaded(“name“) or IsAddOnLoaded(index)
Arguments:
name—Name of an addon (name of the addon’s folder and TOC file, not the Title found in the TOC) (string)
index—Index of an addon in the addon list (between 1 and GetNumAddOns()) (number)
Returns:
loaded—1 if the addon is loaded; otherwise nil (1nil)

这里是判断这个组件有没有被加载,继续搜索会发现一个叫做 LoadAddOn 的函数,这个是主动加载插件的。所以这里修改一下插件代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function InspectFrame_Show(unit)
if(InspectFrame) then
DoInspectFrameShow(unit);
else
if( IsAddOnLoaded("Blizzard_InspectUI") == nil) then
local loaded, reason = LoadAddOn("Blizzard_InspectUI");
if( loaded == nil) then
DisplayInfomation("窗口初始化失败:"..reason);
else
DoInspectFrameShow(unit);
end
end
end
end

function DoInspectFrameShow(unit)
if(InspectFrame) then
HideUIPanel(InspectFrame);
if ( CanInspect(unit, true) ) then
NotifyInspect(unit);
InspectFrame.unit = unit;
InspectSwitchTabs(1);
ShowUIPanel(InspectFrame);
InspectFrame_UpdateTalentTab();
DisplayInfomation("InspectFrame_Show "..UnitName(unit));
end
end
end

在没有加载的时候手动加载一下即可。 自此,PlayerBots 版本的AzerothCore就可以畅玩了,同时也给插件作者提个PR

20231002215602.png