From 2ca686fc9a661092d01e31d44e84977dfde5b714 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 12 May 2024 00:22:13 +0800 Subject: [PATCH] [Command] Command autogear --- conf/playerbots.conf.dist | 12 +++++++++ src/PlayerbotAIConfig.cpp | 3 +++ src/PlayerbotAIConfig.h | 1 + src/PlayerbotFactory.cpp | 11 +++++++- src/PlayerbotMgr.cpp | 2 +- src/strategy/actions/ChatActionContext.h | 2 ++ src/strategy/actions/TrainerAction.cpp | 27 +++++++++++++++++-- src/strategy/actions/TrainerAction.h | 8 ++++++ .../generic/ChatCommandHandlerStrategy.cpp | 1 + src/strategy/triggers/ChatTriggerContext.h | 2 ++ 10 files changed, 65 insertions(+), 4 deletions(-) diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index 213f08ef..66ab5e0b 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -167,6 +167,18 @@ AiPlayerbot.AddClassCommand = 1 # default: 1 (enable) AiPlayerbot.MaintenanceCommand = 1 +# Enable/Disable autogear command, auto upgrade player bots gears, the quality is limited by AutoGearQualityLimit and AutoGearScoreLimit +# default: 1 (enable) +AiPlayerbot.AutoGearCommand = 1 + +# Equips quality limitation for auto gear command (1 = normal, 2 = uncommon, 3 = rare, 4 = epic, 5 = legendary) +# default: 3 (rare) +AiPlayerbot.AutoGearQualityLimit = 3 + +# Equips quality limitation for auto gear command (0 = no limit) +# default: 0 (no limit) +AiPlayerbot.AutoGearScoreLimit = 0 + # Automation # Bots keep looting when group loop method is free for all diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index 851ff06f..2b824f97 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -276,6 +276,9 @@ bool PlayerbotAIConfig::Initialize() autoInitEquipLevelLimitRatio = sConfigMgr->GetOption("AiPlayerbot.AutoInitEquipLevelLimitRatio", 1.0); addClassCommand = sConfigMgr->GetOption("AiPlayerbot.AddClassCommand", 1); maintenanceCommand = sConfigMgr->GetOption("AiPlayerbot.MaintenanceCommand", 1); + autoGearCommand = sConfigMgr->GetOption("AiPlayerbot.AutoGearCommand", 1); + autoGearQualityLimit = sConfigMgr->GetOption("AiPlayerbot.autoGearQualityLimit", 3); + autoGearScoreLimit = sConfigMgr->GetOption("AiPlayerbot.AutoGearScoreLimit", 0); playerbotsXPrate = sConfigMgr->GetOption("AiPlayerbot.KillXPRate", 1); botActiveAlone = sConfigMgr->GetOption("AiPlayerbot.BotActiveAlone", 10); diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index 6ee58fc6..3fbdf45c 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -212,6 +212,7 @@ class PlayerbotAIConfig float autoInitEquipLevelLimitRatio; int32 addClassCommand; int32 maintenanceCommand; + int32 autoGearCommand, autoGearQualityLimit, autoGearScoreLimit; std::string const GetTimestampStr(); bool hasLog(std::string const fileName) { return std::find(allowedLogFiles.begin(), allowedLogFiles.end(), fileName) != allowedLogFiles.end(); }; diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 32ceda4f..542983d8 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -1523,6 +1523,10 @@ void PlayerbotFactory::InitEquipment(bool incremental) uint32 newItemId = ids[index]; uint16 dest; + + if (oldItem && oldItem->GetTemplate()->ItemId == newItemId) + continue; + if (!CanEquipUnseenItem(slot, dest, newItemId)) continue; @@ -1537,10 +1541,15 @@ void PlayerbotFactory::InitEquipment(bool incremental) } if (oldItem) { + // uint8 dstBag = NULL_BAG; + // WorldPacket packet(CMSG_AUTOSTORE_BAG_ITEM, 3); + // packet << INVENTORY_SLOT_BAG_0 << slot << dstBag; + // bot->GetSession()->HandleAutoStoreBagItemOpcode(packet); bot->DestroyItem(INVENTORY_SLOT_BAG_0, slot, true); } uint16 dest; - if (!CanEquipUnseenItem(slot, dest, bestItemForSlot)) { + if (!CanEquipUnseenItem(slot, dest, bestItemForSlot)) + { continue; } Item* newItem = bot->EquipNewItem(dest, bestItemForSlot, true); diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index 325ebacc..c8377721 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -364,9 +364,9 @@ Player* PlayerbotHolder::GetPlayerBot(ObjectGuid::LowType lowGuid) const void PlayerbotHolder::OnBotLogin(Player* const bot) { sPlayerbotsMgr->AddPlayerbotData(bot, true); + playerBots[bot->GetGUID()] = bot; OnBotLoginInternal(bot); - playerBots[bot->GetGUID()] = bot; PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot); if (!botAI) { diff --git a/src/strategy/actions/ChatActionContext.h b/src/strategy/actions/ChatActionContext.h index ba1438ca..2930dae0 100644 --- a/src/strategy/actions/ChatActionContext.h +++ b/src/strategy/actions/ChatActionContext.h @@ -115,6 +115,7 @@ class ChatActionContext : public NamedObjectContext creators["de"] = &ChatActionContext::dead; creators["trainer"] = &ChatActionContext::trainer; creators["maintenance"] = &ChatActionContext::maintenance; + creators["autogear"] = &ChatActionContext::autogear; creators["equip upgrade"] = &ChatActionContext::equip_upgrade; creators["attack my target"] = &ChatActionContext::attack_my_target; creators["chat"] = &ChatActionContext::chat; @@ -214,6 +215,7 @@ class ChatActionContext : public NamedObjectContext static Action* attack_my_target(PlayerbotAI* botAI) { return new AttackMyTargetAction(botAI); } static Action* trainer(PlayerbotAI* botAI) { return new TrainerAction(botAI); } static Action* maintenance(PlayerbotAI* botAI) { return new MaintenanceAction(botAI); } + static Action* autogear(PlayerbotAI* botAI) { return new AutoGearAction(botAI); } static Action* equip_upgrade(PlayerbotAI* botAI) { return new EquipUpgradeAction(botAI); } static Action* co(PlayerbotAI* botAI) { return new ChangeCombatStrategyAction(botAI); } static Action* nc(PlayerbotAI* botAI) { return new ChangeNonCombatStrategyAction(botAI); } diff --git a/src/strategy/actions/TrainerAction.cpp b/src/strategy/actions/TrainerAction.cpp index c44de09c..de3fea5d 100644 --- a/src/strategy/actions/TrainerAction.cpp +++ b/src/strategy/actions/TrainerAction.cpp @@ -150,9 +150,11 @@ void TrainerAction::TellFooter(uint32 totalCost) bool MaintenanceAction::Execute(Event event) { - if (!sPlayerbotAIConfig->maintenanceCommand) + if (!sPlayerbotAIConfig->maintenanceCommand) { + botAI->TellMaster("maintenance command is not allowed, please check the configuration."); return false; - botAI->TellMaster("maintenance"); + } + botAI->TellMaster("I'm maintaining"); PlayerbotFactory factory(bot, bot->GetLevel()); factory.InitBags(false); factory.InitAmmo(); @@ -171,4 +173,25 @@ bool MaintenanceAction::Execute(Event event) } bot->DurabilityRepairAll(false, 1.0f, false); return true; +} + +bool AutoGearAction::Execute(Event event) +{ + if (!sPlayerbotAIConfig->autoGearCommand) { + botAI->TellMaster("autogear command is not allowed, please check the configuration."); + return false; + } + botAI->TellMaster("I'm auto gearing"); + uint32 gs = sPlayerbotAIConfig->autoGearScoreLimit == 0 ? 0 : + PlayerbotFactory::CalcMixedGearScore(sPlayerbotAIConfig->autoGearScoreLimit, sPlayerbotAIConfig->autoGearQualityLimit); + PlayerbotFactory factory(bot, + bot->GetLevel(), + sPlayerbotAIConfig->autoGearQualityLimit, + gs); + factory.InitEquipment(true); + if (bot->getLevel() >= sPlayerbotAIConfig->minEnchantingBotLevel) { + factory.ApplyEnchantAndGemsNew(); + } + bot->DurabilityRepairAll(false, 1.0f, false); + return true; } \ No newline at end of file diff --git a/src/strategy/actions/TrainerAction.h b/src/strategy/actions/TrainerAction.h index 079c2f52..ea1f6e66 100644 --- a/src/strategy/actions/TrainerAction.h +++ b/src/strategy/actions/TrainerAction.h @@ -34,4 +34,12 @@ class MaintenanceAction : public Action MaintenanceAction(PlayerbotAI* botAI) : Action(botAI, "maintenance") { } bool Execute(Event event) override; }; + +class AutoGearAction : public Action +{ + public: + AutoGearAction(PlayerbotAI* botAI) : Action(botAI, "autogear") { } + bool Execute(Event event) override; +}; + #endif diff --git a/src/strategy/generic/ChatCommandHandlerStrategy.cpp b/src/strategy/generic/ChatCommandHandlerStrategy.cpp index 5ce52136..bbb1c1a4 100644 --- a/src/strategy/generic/ChatCommandHandlerStrategy.cpp +++ b/src/strategy/generic/ChatCommandHandlerStrategy.cpp @@ -89,6 +89,7 @@ ChatCommandHandlerStrategy::ChatCommandHandlerStrategy(PlayerbotAI* botAI) : Pas supported.push_back("de"); supported.push_back("trainer"); supported.push_back("maintenance"); + supported.push_back("autogear"); supported.push_back("equip upgrade"); supported.push_back("chat"); supported.push_back("home"); diff --git a/src/strategy/triggers/ChatTriggerContext.h b/src/strategy/triggers/ChatTriggerContext.h index 482840c8..c0721390 100644 --- a/src/strategy/triggers/ChatTriggerContext.h +++ b/src/strategy/triggers/ChatTriggerContext.h @@ -55,6 +55,7 @@ class ChatTriggerContext : public NamedObjectContext creators["de"] = &ChatTriggerContext::dead; creators["trainer"] = &ChatTriggerContext::trainer; creators["maintenance"] = &ChatTriggerContext::maintenance; + creators["autogear"] = &ChatTriggerContext::autogear; creators["equip upgrade"] = &ChatTriggerContext::equip_upgrade; creators["attack"] = &ChatTriggerContext::attack; creators["chat"] = &ChatTriggerContext::chat; @@ -167,6 +168,7 @@ class ChatTriggerContext : public NamedObjectContext static Trigger* attack(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "attack"); } static Trigger* trainer(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "trainer"); } static Trigger* maintenance(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "maintenance"); } + static Trigger* autogear(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "autogear"); } static Trigger* equip_upgrade(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "equip upgrade"); } static Trigger* co(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "co"); } static Trigger* nc(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "nc"); }