diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..e0c1fe2d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,35 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: liyunfan1223 + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**Commit hash** +The hash of the current commit. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..bbcbbe7d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/README.md b/README.md index aeeccbdb..f657b34e 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,18 @@ It's essential to note that there is still a significant amount of work to be do For enhanced control over the bots and to simplify command usage, you can also make use of our addon: [Unbot Addon](https://github.com/liyunfan1223/unbot-addon). Currently, this addon offers better support only for Simplified Chinese client. +## Frequently Asked Questions + +**Why won't my bot cast spells?** + +- Ensure the presence of the required English DBC file (enUS). + +**Compilation failed on Windows?** + +- Developed primarily on Linux, I may miss cross-platform compilation issues. Feel free to report them. + +- Future plans include implementing an auto build workflow to prevent such issues. + ## Acknowledgements The code for this module is ported from [ZhengPeiRu21/mod-playerbots](https://github.com/ZhengPeiRu21/mod-playerbots) and [celguar/mangosbot-bots](https://github.com/celguar/mangosbot-bots). We extend our gratitude to @ZhengPeiRu21 and @celguar for the continued efforts in maintaining the module. diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index f12d4376..d2785ad4 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -44,6 +44,13 @@ AiPlayerbot.MaxRandomBots = 50 AiPlayerbot.RandomBotMinLevel = 1 AiPlayerbot.RandomBotMaxLevel = 80 +# Enable/Disable rotation of bots (randomly select a bot from the bots pool to go online and rotate them periodically) +# default: 0 (disable, the online bots are fixed) +AiPlayerbot.EnableRotation = 0 + +# Bots pool size for rotation (should be less than RandomBotAccountCount * 10) +AiPlayerbot.RotationPoolSize = 500 + # Accounts to create for random bots AiPlayerbot.RandomBotAccountPrefix = "rndbot" AiPlayerbot.RandomBotAccountCount = 200 @@ -251,7 +258,7 @@ AiPlayerbot.LootDelay = 1000 # Distances AiPlayerbot.FarDistance = 20.0 -AiPlayerbot.SightDistance = 100.0 +AiPlayerbot.SightDistance = 75.0 AiPlayerbot.SpellDistance = 28.5 AiPlayerbot.ShootDistance = 5.0 AiPlayerbot.ReactDistance = 150.0 @@ -338,7 +345,7 @@ AiPlayerbot.RandomBotUpdateInterval = 20 AiPlayerbot.RandomBotCountChangeMinInterval = 1800 AiPlayerbot.RandomBotCountChangeMaxInterval = 7200 AiPlayerbot.MinRandomBotInWorldTime = 3600 -AiPlayerbot.MaxRandomBotInWorldTime = 1209600 +AiPlayerbot.MaxRandomBotInWorldTime = 43200 AiPlayerbot.MinRandomBotRandomizeTime = 302400 AiPlayerbot.MaxRandomRandomizeTime = 1209600 AiPlayerbot.RandomBotsPerInterval = 500 @@ -350,6 +357,7 @@ AiPlayerbot.MinRandomBotReviveTime = 60 AiPlayerbot.MaxRandomBotReviveTime = 300 AiPlayerbot.MinRandomBotTeleportInterval = 3600 AiPlayerbot.MaxRandomBotTeleportInterval = 18000 +AiPlayerbot.RandomBotInWorldWithRotaionDisabled = 31104000 # How far random bots are teleported after death AiPlayerbot.RandomBotTeleportDistance = 100 diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index a60c845d..d7033d41 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -124,6 +124,7 @@ bool PlayerbotAIConfig::Initialize() maxRandomBotReviveTime = sConfigMgr->GetOption("AiPlayerbot.MaxRandomBotReviveTime", 5 * MINUTE); minRandomBotTeleportInterval = sConfigMgr->GetOption("AiPlayerbot.MinRandomBotTeleportInterval", 1 * HOUR); maxRandomBotTeleportInterval = sConfigMgr->GetOption("AiPlayerbot.MaxRandomBotTeleportInterval", 5 * HOUR); + randomBotInWorldWithRotaionDisabled = sConfigMgr->GetOption("AiPlayerbot.RandomBotInWorldWithRotaionDisabled", 1 * YEAR); randomBotTeleportDistance = sConfigMgr->GetOption("AiPlayerbot.RandomBotTeleportDistance", 100); randomBotsPerInterval = sConfigMgr->GetOption("AiPlayerbot.RandomBotsPerInterval", MINUTE); minRandomBotsPriceChangeInterval = sConfigMgr->GetOption("AiPlayerbot.MinRandomBotsPriceChangeInterval", 2 * HOUR); @@ -328,6 +329,8 @@ bool PlayerbotAIConfig::Initialize() randombotsWalkingRPGInDoors = sConfigMgr->GetOption("AiPlayerbot.RandombotsWalkingRPG.InDoors", false); minEnchantingBotLevel = sConfigMgr->GetOption("AiPlayerbot.MinEnchantingBotLevel", 60); randombotStartingLevel = sConfigMgr->GetOption("AiPlayerbot.RandombotStartingLevel", 5); + enableRotation = sConfigMgr->GetOption("AiPlayerbot.EnableRotation", false); + rotationPoolSize = sConfigMgr->GetOption("AiPlayerbot.RotationPoolSize", 500); gearscorecheck = sConfigMgr->GetOption("AiPlayerbot.GearScoreCheck", false); randomBotPreQuests = sConfigMgr->GetOption("AiPlayerbot.PreQuests", true); diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index ca6477ce..0d6367cb 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -70,6 +70,7 @@ class PlayerbotAIConfig uint32 minRandomBotChangeStrategyTime, maxRandomBotChangeStrategyTime; uint32 minRandomBotReviveTime, maxRandomBotReviveTime; uint32 minRandomBotTeleportInterval, maxRandomBotTeleportInterval; + uint32 randomBotInWorldWithRotaionDisabled; uint32 minRandomBotPvpTime, maxRandomBotPvpTime; uint32 randomBotsPerInterval; uint32 minRandomBotsPriceChangeInterval, maxRandomBotsPriceChangeInterval; @@ -108,6 +109,8 @@ class PlayerbotAIConfig bool randombotsWalkingRPGInDoors; uint32 minEnchantingBotLevel; uint32 randombotStartingLevel; + bool enableRotation; + uint32 rotationPoolSize; bool gearscorecheck; bool randomBotPreQuests; diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 6901eb0c..3958deef 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -541,6 +541,7 @@ void PlayerbotFactory::InitPetTalents() // LOG_INFO("playerbots", "{} init pet talents failed with petTalentType < 0({})", bot->GetName().c_str(), pet_family->petTalentType); return; } + pet->resetTalents(); std::map > spells; for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) { @@ -798,7 +799,9 @@ void PlayerbotFactory::InitTalentsTree(bool increment/*false*/, bool use_templat { uint32 specNo; uint8 cls = bot->getClass(); - if (increment && bot->GetFreeTalentPoints() <= 2) { + std::map tabs = AiFactory::GetPlayerSpecTabs(bot); + uint32 total_tabs = tabs[0] + tabs[1] + tabs[2]; + if (increment && bot->GetFreeTalentPoints() <= 2 && total_tabs != 0) { specNo = AiFactory::GetPlayerSpecTab(bot); } else { uint32 point = urand(0, 100); diff --git a/src/RandomPlayerbotFactory.cpp b/src/RandomPlayerbotFactory.cpp index 1c56bcd7..20ef853b 100644 --- a/src/RandomPlayerbotFactory.cpp +++ b/src/RandomPlayerbotFactory.cpp @@ -287,10 +287,10 @@ void RandomPlayerbotFactory::CreateRandomBots() } PlayerbotsDatabase.Execute(PlayerbotsDatabase.GetPreparedStatement(PLAYERBOTS_DEL_RANDOM_BOTS)); - CharacterDatabase.Execute("UPDATE playerbots_names SET in_use=0 WHERE in_use=1"); + CharacterDatabase.DirectExecute("UPDATE playerbots_names SET in_use = 0 WHERE in_use = 1"); /* TODO(yunfan): we need to sleep here to wait for async account deleted, or the newly account won't be created correctly the better way is turning the async db operation to sync db operation */ - std::this_thread::sleep_for(100ms * sPlayerbotAIConfig->randomBotAccountCount); + std::this_thread::sleep_for(10ms * sPlayerbotAIConfig->randomBotAccountCount); LOG_INFO("playerbots", "Random bot characters deleted."); LOG_INFO("playerbots", "Please reset the AiPlayerbot.DeleteRandomBotAccounts to 0 and restart the server..."); World::StopNow(SHUTDOWN_EXIT_CODE); @@ -335,7 +335,7 @@ void RandomPlayerbotFactory::CreateRandomBots() if (account_creation) { /* wait for async accounts create to make character create correctly, same as account delete */ - std::this_thread::sleep_for(100ms * sPlayerbotAIConfig->randomBotAccountCount); + std::this_thread::sleep_for(10ms * sPlayerbotAIConfig->randomBotAccountCount); } LOG_INFO("playerbots", "Creating random bot characters..."); @@ -403,7 +403,7 @@ void RandomPlayerbotFactory::CreateRandomBots() if (bot_creation) { LOG_INFO("playerbots", "Waiting for {} characters loading into database...", totalCharCount); /* wait for characters load into database, or characters will fail to loggin */ - std::this_thread::sleep_for(15ms * totalCharCount); + std::this_thread::sleep_for(10s); } for (WorldSession* session : sessionBots) diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index b5f79f00..3d8ddf73 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -337,6 +337,11 @@ uint32 RandomPlayerbotMgr::AddRandomBots() for (std::vector::iterator i = sPlayerbotAIConfig->randomBotAccounts.begin(); i != sPlayerbotAIConfig->randomBotAccounts.end(); i++) { uint32 accountId = *i; + if (sPlayerbotAIConfig->enableRotation) { + uint32 limit = std::min((uint32)sPlayerbotAIConfig->randomBotAccounts.size(), sPlayerbotAIConfig->rotationPoolSize / 10 + 1); + uint32 index = urand(0, limit); + accountId = sPlayerbotAIConfig->randomBotAccounts[index]; + } CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARS_BY_ACCOUNT_ID); stmt->SetData(0, accountId); PreparedQueryResult result = CharacterDatabase.Query(stmt); @@ -359,8 +364,12 @@ uint32 RandomPlayerbotMgr::AddRandomBots() if (std::find(currentBots.begin(), currentBots.end(), guid) != currentBots.end()) continue; - - SetEventValue(guid, "add", 1, urand(sPlayerbotAIConfig->minRandomBotInWorldTime, sPlayerbotAIConfig->maxRandomBotInWorldTime)); + + uint32 add_time = sPlayerbotAIConfig->enableRotation ? + urand(sPlayerbotAIConfig->minRandomBotInWorldTime, sPlayerbotAIConfig->maxRandomBotInWorldTime) : + sPlayerbotAIConfig->randomBotInWorldWithRotaionDisabled; + + SetEventValue(guid, "add", 1, add_time); SetEventValue(guid, "logout", 0, 0); currentBots.push_back(guid); @@ -969,8 +978,8 @@ void RandomPlayerbotMgr::Revive(Player* player) SetEventValue(bot, "revive", 0, 0); - RandomTeleportGrindForLevel(player); Refresh(player); + RandomTeleportGrindForLevel(player); } void RandomPlayerbotMgr::RandomTeleport(Player* bot, std::vector& locs, bool hearth) diff --git a/src/strategy/actions/ChangeTalentsAction.cpp b/src/strategy/actions/ChangeTalentsAction.cpp index ea304b50..4d3c5aba 100644 --- a/src/strategy/actions/ChangeTalentsAction.cpp +++ b/src/strategy/actions/ChangeTalentsAction.cpp @@ -337,7 +337,7 @@ bool AutoSetTalentsAction::Execute(Event event) PlayerbotFactory factory(bot, bot->GetLevel()); factory.InitTalentsTree(true, true, true); - + factory.InitPetTalents(); botAI->TellMaster(out); return true; diff --git a/src/strategy/actions/QuestAction.cpp b/src/strategy/actions/QuestAction.cpp index b2b52e5c..e602afd9 100644 --- a/src/strategy/actions/QuestAction.cpp +++ b/src/strategy/actions/QuestAction.cpp @@ -179,7 +179,7 @@ bool QuestAction::AcceptQuest(Quest const* quest, ObjectGuid questGiver) p.rpos(0); bot->GetSession()->HandleQuestgiverAcceptQuestOpcode(p); - if (bot->GetQuestStatus(questId) == QUEST_STATUS_NONE && !sPlayerbotAIConfig->syncQuestWithPlayer) + if (bot->GetQuestStatus(questId ) == QUEST_STATUS_NONE && sPlayerbotAIConfig->syncQuestWithPlayer) { Object* pObject = ObjectAccessor::GetObjectByTypeMask(*bot, questGiver, TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT | TYPEMASK_ITEM); bot->AddQuest(quest, pObject); @@ -191,6 +191,7 @@ bool QuestAction::AcceptQuest(Quest const* quest, ObjectGuid questGiver) botAI->TellMaster(out); return true; } + out << "Cannot accept"; } out << " " << chat->FormatQuest(quest); diff --git a/src/strategy/actions/QuestConfirmAcceptAction.cpp b/src/strategy/actions/QuestConfirmAcceptAction.cpp index ab580432..a3bd6bb9 100644 --- a/src/strategy/actions/QuestConfirmAcceptAction.cpp +++ b/src/strategy/actions/QuestConfirmAcceptAction.cpp @@ -13,6 +13,9 @@ bool QuestConfirmAcceptAction::Execute(Event event) if (!quest || !bot->CanAddQuest(quest, true)) { return false; } + std::ostringstream out; + out << "Quest: " << chat->FormatQuest(quest) << " confirm accept"; + botAI->TellMaster(out); bot->GetSession()->HandleQuestConfirmAccept(sendPacket); return true; } \ No newline at end of file diff --git a/src/strategy/actions/QuestConfirmAcceptAction.h b/src/strategy/actions/QuestConfirmAcceptAction.h index ced56e2c..5b10b292 100644 --- a/src/strategy/actions/QuestConfirmAcceptAction.h +++ b/src/strategy/actions/QuestConfirmAcceptAction.h @@ -16,10 +16,10 @@ class Player; class PlayerbotAI; class WorldObject; -class QuestConfirmAcceptAction : public QuestAction +class QuestConfirmAcceptAction : public Action { public: - QuestConfirmAcceptAction(PlayerbotAI* botAI) : QuestAction(botAI, "quest confirm accept") {} + QuestConfirmAcceptAction(PlayerbotAI* botAI) : Action(botAI, "quest confirm accept") {} bool Execute(Event event) override; }; diff --git a/src/strategy/actions/TalkToQuestGiverAction.cpp b/src/strategy/actions/TalkToQuestGiverAction.cpp index a26eb583..a0e1b62e 100644 --- a/src/strategy/actions/TalkToQuestGiverAction.cpp +++ b/src/strategy/actions/TalkToQuestGiverAction.cpp @@ -8,6 +8,7 @@ #include "ItemUsageValue.h" #include "Object.h" #include "Playerbots.h" +#include "QuestDef.h" #include "WorldPacket.h" void TalkToQuestGiverAction::ProcessQuest(Quest const* quest, Object* questGiver) @@ -238,6 +239,7 @@ bool TurnInQueryQuestAction::Execute(Event event) } } std::ostringstream out; + out << "Quest "; switch (status) { case QUEST_STATUS_COMPLETE: @@ -252,6 +254,9 @@ bool TurnInQueryQuestAction::Execute(Event event) case QUEST_STATUS_FAILED: out << "|cffff0000Failed|r"; break; + case QUEST_STATUS_REWARDED: + out << "|cffff0000Rewarded|r"; + break; } out << ": " << chat->FormatQuest(quest); diff --git a/src/strategy/actions/WorldPacketActionContext.h b/src/strategy/actions/WorldPacketActionContext.h index 2fa38164..4646da2f 100644 --- a/src/strategy/actions/WorldPacketActionContext.h +++ b/src/strategy/actions/WorldPacketActionContext.h @@ -24,6 +24,7 @@ #include "QuestAction.h" #include "PassLeadershipToMasterAction.h" #include "PetitionSignAction.h" +#include "QuestConfirmAcceptAction.h" #include "ReadyCheckAction.h" #include "RememberTaxiAction.h" #include "ReviveFromCorpseAction.h" @@ -36,6 +37,7 @@ #include "TradeStatusAction.h" #include "UseMeetingStoneAction.h" #include "NamedObjectContext.h" +#include "QuestConfirmAcceptAction.h" class PlayerbotAI; @@ -92,6 +94,7 @@ class WorldPacketActionContext : public NamedObjectContext creators["see spell"] = &WorldPacketActionContext::see_spell; creators["arena team accept"] = &WorldPacketActionContext::arena_team_accept; creators["turn in query quest"] = &WorldPacketActionContext::turn_in_query_quest; + creators["quest confirm accept"] = &WorldPacketActionContext::quest_confirm_accept; } private: @@ -143,6 +146,7 @@ class WorldPacketActionContext : public NamedObjectContext static Action* see_spell(PlayerbotAI* botAI) { return new SeeSpellAction(botAI); } static Action* arena_team_accept(PlayerbotAI* botAI) { return new ArenaTeamAcceptAction(botAI); } static Action* turn_in_query_quest(PlayerbotAI* botAI) { return new TurnInQueryQuestAction(botAI); } + static Action* quest_confirm_accept(PlayerbotAI* botAI) { return new QuestConfirmAcceptAction(botAI); } }; #endif diff --git a/src/strategy/hunter/GenericHunterStrategy.cpp b/src/strategy/hunter/GenericHunterStrategy.cpp index 41fa670e..cb8afa7d 100644 --- a/src/strategy/hunter/GenericHunterStrategy.cpp +++ b/src/strategy/hunter/GenericHunterStrategy.cpp @@ -79,7 +79,6 @@ void GenericHunterStrategy::InitTriggers(std::vector& triggers) { CombatStrategy::InitTriggers(triggers); - // triggers.push_back(new TriggerNode("enemy too close for auto shot", NextAction::array(0, new NextAction("switch to melee", ACTION_HIGH), nullptr))); triggers.push_back(new TriggerNode("enemy is close", NextAction::array(0, new NextAction("wing clip", ACTION_HIGH + 1), diff --git a/src/strategy/triggers/RangeTriggers.cpp b/src/strategy/triggers/RangeTriggers.cpp index 64089665..2d02ee5f 100644 --- a/src/strategy/triggers/RangeTriggers.cpp +++ b/src/strategy/triggers/RangeTriggers.cpp @@ -4,6 +4,7 @@ #include "RangeTriggers.h" #include "MoveSplineInit.h" +#include "PlayerbotAIConfig.h" #include "Playerbots.h" #include "ServerFacade.h" @@ -16,8 +17,8 @@ bool EnemyTooCloseForSpellTrigger::IsActive() { Unit* target = AI_VALUE(Unit*, "current target"); return target && (target->GetVictim() != bot || target->isFrozen() || !target->CanFreeMove()) && - target->GetObjectSize() <= 10.0f && - AI_VALUE2(float, "distance", "current target") <= sPlayerbotAIConfig->tooCloseDistance; + target->GetObjectSize() <= 10.0f && + target->IsWithinCombatRange(bot, MIN_MELEE_REACH); // Unit* target = AI_VALUE(Unit*, "current target"); // if (!target) { // return false; @@ -79,7 +80,9 @@ bool EnemyTooCloseForAutoShotTrigger::IsActive() bool EnemyTooCloseForShootTrigger::IsActive() { Unit* target = AI_VALUE(Unit*, "current target"); - return target && (target->GetVictim() != bot || target->isFrozen() || !target->CanFreeMove()) && AI_VALUE2(float, "distance", "current target") <= sPlayerbotAIConfig->shootDistance; + // target->IsWithinCombatRange() + + return target && (target->GetVictim() != bot || target->isFrozen() || !target->CanFreeMove()) && target->IsWithinCombatRange(bot, MIN_MELEE_REACH); // Unit* target = AI_VALUE(Unit*, "current target"); // if (!target)