diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index eab4de36..d10f0348 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -104,6 +104,12 @@ AiPlayerbot.DeleteRandomBotAccounts = 0 # # +# Maximum number of bots added by one account +AiPlayerbot.MaxAddedBots = 40 + +# Maximum number of bots per class added by one account +AiPlayerbot.MaxAddedBotsPerClass = 10 + # Enable/Disable create bot by addclass command (0 = GM only, 1 = enable) # default: 1 (enable) AiPlayerbot.AddClassCommand = 1 @@ -331,7 +337,7 @@ AiPlayerbot.MediumMana = 40 # # Bots pick their quest reward (yes = picks first useful item, no = list all rewards, ask = pick useful item and lists if multiple) -AiPlayerbot.AutoPickReward = no +AiPlayerbot.AutoPickReward = yes # Sync quests with player (Bots will complete quests the moment you hand them in. Bots will ignore looting quest items.) # Default: 1 (enable) @@ -656,7 +662,7 @@ AiPlayerbot.RandomBotArenaTeamCount = 20 AiPlayerbot.DeleteRandomBotArenaTeams = 0 # PvP Restricted Zones (bots don't pvp) -AiPlayerbot.PvpProhibitedZoneIds = "2255,656,2361,2362,2363,976,35,2268,3425,392,541,1446,3828,3712,3738,3565,3539,3623,4152,3988,4658,4284,4418,4436,4275,4323,4395,3703,4298" # 33(stranglethorn vale),440(tanaris) +AiPlayerbot.PvpProhibitedZoneIds = "2255,656,2361,2362,2363,976,35,2268,3425,392,541,1446,3828,3712,3738,3565,3539,3623,4152,3988,4658,4284,4418,4436,4275,4323,4395,3703,4298" # PvP Restricted Areas (bots don't pvp) AiPlayerbot.PvpProhibitedAreaIds = "976,35,392" diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index a6bcf470..b28aeeba 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -283,6 +283,9 @@ bool PlayerbotAIConfig::Initialize() botRepairWhenSummon = sConfigMgr->GetOption("AiPlayerbot.BotRepairWhenSummon", true); autoInitOnly = sConfigMgr->GetOption("AiPlayerbot.AutoInitOnly", false); autoInitEquipLevelLimitRatio = sConfigMgr->GetOption("AiPlayerbot.AutoInitEquipLevelLimitRatio", 1.0); + + maxAddedBots = sConfigMgr->GetOption("AiPlayerbot.MaxAddedBots", 40); + maxAddedBotsPerClass = sConfigMgr->GetOption("AiPlayerbot.MaxAddedBotsPerClass", 10); addClassCommand = sConfigMgr->GetOption("AiPlayerbot.AddClassCommand", 1); maintenanceCommand = sConfigMgr->GetOption("AiPlayerbot.MaintenanceCommand", 1); autoGearCommand = sConfigMgr->GetOption("AiPlayerbot.AutoGearCommand", 1); diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index 17da007d..32bd1c59 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -224,6 +224,7 @@ class PlayerbotAIConfig bool botRepairWhenSummon; bool autoInitOnly; float autoInitEquipLevelLimitRatio; + int32 maxAddedBots, maxAddedBotsPerClass; int32 addClassCommand; int32 maintenanceCommand; int32 autoGearCommand, autoGearQualityLimit, autoGearScoreLimit; diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index 665c7fdf..2429e369 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -6,6 +6,8 @@ #include "CharacterPackets.h" #include "Common.h" #include "Define.h" +#include "Group.h" +#include "GroupMgr.h" #include "ObjectAccessor.h" #include "ObjectMgr.h" #include "PlayerbotAIConfig.h" @@ -19,6 +21,7 @@ #include "ChannelMgr.h" #include #include +#include #include PlayerbotHolder::PlayerbotHolder() : PlayerbotAIBase(false) @@ -89,25 +92,42 @@ void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder con Player* bot = botSession->GetPlayer(); if (!bot) { - LogoutPlayerBot(holder.GetGuid()); + botSession->LogoutPlayer(true); + delete botSession; // LOG_ERROR("playerbots", "Error logging in bot {}, please try to reset all random bots", holder.GetGuid().ToString().c_str()); return; } - sRandomPlayerbotMgr->OnPlayerLogin(bot); - uint32 masterAccount = holder.GetMasterAccountId(); WorldSession* masterSession = masterAccount ? sWorld->FindSession(masterAccount) : nullptr; + std::ostringstream out; bool allowed = false; - if (botAccountId == masterAccount) + if (botAccountId == masterAccount) { allowed = true; - else if (masterSession && sPlayerbotAIConfig->allowGuildBots && bot->GetGuildId() != 0 && bot->GetGuildId() == masterSession->GetPlayer()->GetGuildId()) + } else if (masterSession && sPlayerbotAIConfig->allowGuildBots && bot->GetGuildId() != 0 && bot->GetGuildId() == masterSession->GetPlayer()->GetGuildId()) { allowed = true; - else if (sPlayerbotAIConfig->IsInRandomAccountList(botAccountId)) + } else if (sPlayerbotAIConfig->IsInRandomAccountList(botAccountId)) { allowed = true; - + } else { + allowed = false; + out << "Failure: You are not allowed to control bot " << bot->GetName().c_str(); + } + if (allowed && masterSession) { + Player* player = masterSession->GetPlayer(); + PlayerbotMgr *mgr = GET_PLAYERBOT_MGR(player); + uint32 count = mgr->GetPlayerbotsCount(); + uint32 cls_count = mgr->GetPlayerbotsCountByClass(bot->getClass()); + if (count >= sPlayerbotAIConfig->maxAddedBots) { + allowed = false; + out << "Failure: You have added too many bots"; + } else if (cls_count >= sPlayerbotAIConfig->maxAddedBotsPerClass) { + allowed = false; + out << "Failure: You have added too many bots for this class"; + } + } if (allowed) { + sRandomPlayerbotMgr->OnPlayerLogin(bot); OnBotLogin(bot); } else @@ -115,10 +135,12 @@ void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder con if (masterSession) { ChatHandler ch(masterSession); - ch.PSendSysMessage("You are not allowed to control bot %s", bot->GetName()); + ch.SendSysMessage(out.str()); } - OnBotLogin(bot); - LogoutPlayerBot(bot->GetGUID()); + botSession->LogoutPlayer(true); + delete botSession; + // OnBotLogin(bot); + // LogoutPlayerBot(bot->GetGUID()); // LOG_ERROR("playerbots", "Attempt to add not allowed bot {}, please try to reset all random bots", bot->GetName()); } @@ -453,7 +475,22 @@ void PlayerbotHolder::OnBotLogin(Player* const bot) botAI->TellMaster("Hello!", PLAYERBOT_SECURITY_TALK); if (master && master->GetGroup() && !group) { - master->GetGroup()->AddMember(bot); + Group* mgroup = master->GetGroup(); + if (mgroup->GetMembersCount() >= 5) { + if (!mgroup->isRaidGroup() && !mgroup->isLFGGroup() && !mgroup->isBGGroup() && !mgroup->isBFGroup()) { + mgroup->ConvertToRaid(); + } + if (mgroup->isRaidGroup()) { + mgroup->AddMember(bot); + } + } else { + mgroup->AddMember(bot); + } + } else if (master && !group) { + Group* newGroup = new Group(); + newGroup->Create(master); + sGroupMgr->AddGroup(newGroup); + newGroup->AddMember(bot); } uint32 accountId = bot->GetSession()->GetAccountId(); @@ -1157,6 +1194,19 @@ std::string const PlayerbotHolder::LookupBots(Player* master) return ret_msg; } +uint32 PlayerbotHolder::GetPlayerbotsCountByClass(uint32 cls) +{ + uint32 count = 0; + for (PlayerBotMap::const_iterator it = GetPlayerBotsBegin(); it != GetPlayerBotsEnd(); ++it) + { + Player* const bot = it->second; + if (bot->getClass() == cls) { + count++; + } + } + return count; +} + PlayerbotMgr::PlayerbotMgr(Player* const master) : PlayerbotHolder(), master(master), lastErrorTell(0) { } diff --git a/src/PlayerbotMgr.h b/src/PlayerbotMgr.h index 16e1aa95..d430d414 100644 --- a/src/PlayerbotMgr.h +++ b/src/PlayerbotMgr.h @@ -48,7 +48,8 @@ class PlayerbotHolder : public PlayerbotAIBase uint32 GetAccountId(ObjectGuid guid); std::string const ListBots(Player* master); std::string const LookupBots(Player* master); - + uint32 GetPlayerbotsCount() { return playerBots.size(); } + uint32 GetPlayerbotsCountByClass(uint32 cls); protected: virtual void OnBotLoginInternal(Player* const bot) = 0; diff --git a/src/strategy/actions/QueryItemUsageAction.cpp b/src/strategy/actions/QueryItemUsageAction.cpp index 1357d914..2a894ced 100644 --- a/src/strategy/actions/QueryItemUsageAction.cpp +++ b/src/strategy/actions/QueryItemUsageAction.cpp @@ -137,6 +137,8 @@ std::string const QueryItemUsageAction::QueryItemUsage(ItemTemplate const* item) return "Auctionhouse"; case ITEM_USAGE_AMMO: return "Ammunition"; + default: + break; } return ""; diff --git a/src/strategy/actions/SayAction.cpp b/src/strategy/actions/SayAction.cpp index 074b4e22..02f03499 100644 --- a/src/strategy/actions/SayAction.cpp +++ b/src/strategy/actions/SayAction.cpp @@ -588,11 +588,12 @@ void ChatReplyAction::ChatReplyDo(Player* bot, uint32 type, uint32 guid1, uint32 if (ChannelMgr* cMgr = ChannelMgr::forTeam(bot->GetTeamId())) { std::string worldChan = "World"; - if (Channel* chn = cMgr->GetJoinChannel(worldChan.c_str(), 0)) + if (Channel* chn = cMgr->GetJoinChannel(worldChan.c_str(), 0)) { if (bot->GetTeamId() == TEAM_ALLIANCE) chn->Say(bot->GetGUID(), c, LANG_COMMON); else chn->Say(bot->GetGUID(), c, LANG_ORCISH); + } } } else diff --git a/src/strategy/actions/TrainerAction.cpp b/src/strategy/actions/TrainerAction.cpp index af1e7a7c..231dea7d 100644 --- a/src/strategy/actions/TrainerAction.cpp +++ b/src/strategy/actions/TrainerAction.cpp @@ -151,7 +151,7 @@ void TrainerAction::TellFooter(uint32 totalCost) bool MaintenanceAction::Execute(Event event) { if (!sPlayerbotAIConfig->maintenanceCommand) { - botAI->TellMaster("maintenance command is not allowed, please check the configuration."); + botAI->TellError("maintenance command is not allowed, please check the configuration."); return false; } botAI->TellMaster("I'm maintaining"); @@ -187,7 +187,7 @@ bool RemoveGlyphAction::Execute(Event event) bool AutoGearAction::Execute(Event event) { if (!sPlayerbotAIConfig->autoGearCommand) { - botAI->TellMaster("autogear command is not allowed, please check the configuration."); + botAI->TellError("autogear command is not allowed, please check the configuration."); return false; } botAI->TellMaster("I'm auto gearing"); diff --git a/src/strategy/rogue/GenericRogueNonCombatStrategy.cpp b/src/strategy/rogue/GenericRogueNonCombatStrategy.cpp index 74d95313..b28da727 100644 --- a/src/strategy/rogue/GenericRogueNonCombatStrategy.cpp +++ b/src/strategy/rogue/GenericRogueNonCombatStrategy.cpp @@ -51,5 +51,5 @@ void GenericRogueNonCombatStrategy::InitTriggers(std::vector& trig triggers.push_back(new TriggerNode( "often", - NextAction::array(0, new NextAction("unstealth", 10.0f), NULL))); + NextAction::array(0, new NextAction("unstealth", 30.0f), NULL))); }