|
楼主 |
发表于 2024-4-1 14:06:04
|
显示全部楼层
机器人(Playerbot)
需要提前说明的是游戏中机器人分为二个类型:随机机器人(random bots)和召唤机器人(summoned bots)。
随机机器人是服务器初始化时自动生成的在线角色,而召唤机器人是通过.playerbot bot addclass CLASSNAME(warrior/paladin/hunter/rogue/priest/shaman/mage/warlock/druid/dk)指令创建的角色和使用.playerbot bot login NAME上线的角色。相关代码:
if (!strcmp(cmd, "addclass")
{
if (sPlayerbotAIConfig->addClassCommand == 0 && master->GetSession()->GetSecurity() < SEC_GAMEMASTER) {
messages.push_back("You do not have permission to create bot by addclass command"
return messages;
}
if (!charname) {
messages.push_back("addclass: invalid CLASSNAME(warrior/paladin/hunter/rogue/priest/shaman/mage/warlock/druid/dk)"
return messages;
}
uint8 claz;
if (!strcmp(charname, "warrior"))
{
claz = 1;
}
else if (!strcmp(charname, "paladin"))
{
claz = 2;
}
else if (!strcmp(charname, "hunter"))
{
claz = 3;
}
else if (!strcmp(charname, "rogue"))
{
claz = 4;
}
else if (!strcmp(charname, "priest"))
{
claz = 5;
}
else if (!strcmp(charname, "shaman"))
{
claz = 7;
}
else if (!strcmp(charname, "mage"))
{
claz = 8;
}
else if (!strcmp(charname, "warlock"))
{
claz = 9;
}
else if (!strcmp(charname, "druid"))
{
claz = 11;
}
else if (!strcmp(charname, "dk"))
{
claz = 6;
}
else
{
messages.push_back("Error: Invalid Class. Try again.");
return messages;
}
uint8 master_race = master->getRace();
std::string race_limit;
switch (master_race)
{
case 1:
case 3:
case 4:
case 7:
case 11:
race_limit = "1, 3, 4, 7, 11";
break;
case 2:
case 5:
case 6:
case 8:
case 10:
race_limit = "2, 5, 6, 8, 10";
break;
}
// find a bot fit conditions and not in any guild
QueryResult results = CharacterDatabase.Query("SELECT guid FROM characters "
"WHERE name IN (SELECT name FROM playerbots_names) AND class = '{}' AND online = 0 AND race IN ({}) AND guid NOT IN ( SELECT guid FROM guild_member ) "
"ORDER BY account DESC LIMIT 1", claz, race_limit);
if (results)
{
Field* fields = results->Fetch();
ObjectGuid guid = ObjectGuid(HighGuid:layer, fields[0].Get<uint32>());
AddPlayerBot(guid, master->GetSession()->GetAccountId());
messages.push_back("addclass " + std::string(charname) + " ok");
return messages;
}
messages.push_back("addclass failed.");
return messages;
}
随机机器人和召唤机器人的核心区别有几点:
随机机器人可以自己上下线,自己和玩家一样正常的游戏,而召唤机器人不会自己上线练级,而且在召唤的玩家下线后会自动下线。
你可以使用.playerbot bot init指令来初始化召唤机器人的等级、装备、天赋,深度定制机器人,但无法这样控制随机机器人。
随机机器人类似其它独立的玩家,你不能强制交易他们的物品,而召唤机器人和你的小号都是可以随意交易的。
关于bot init指令的用法后面介绍,这里我们先跳过。比较特别的是玩家同一个账号下的小号也是可以当机器人对待的,小号综合了随机机器人和召唤机器人的特点, |
|