From fcf0ee2d6271184537f21c656d3c146870136af5 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 20 May 2024 22:32:10 +0100 Subject: [PATCH] Do not consume oil/stones when item cheat is enabled --- playerbot/strategy/actions/ImbueAction.cpp | 153 ++++++++++----------- playerbot/strategy/actions/ImbueAction.h | 8 +- 2 files changed, 78 insertions(+), 83 deletions(-) diff --git a/playerbot/strategy/actions/ImbueAction.cpp b/playerbot/strategy/actions/ImbueAction.cpp index b12bcb75..7cefbabb 100644 --- a/playerbot/strategy/actions/ImbueAction.cpp +++ b/playerbot/strategy/actions/ImbueAction.cpp @@ -1,13 +1,14 @@ - #include "playerbot/playerbot.h" #include "ImbueAction.h" #include "playerbot/PlayerbotAI.h" #include "playerbot/PlayerbotAIConfig.h" #include "playerbot/ServerFacade.h" + using namespace ai; bool ImbueWithStoneAction::Execute(Event& event) { + Player* requester = event.getOwner(); if (bot->IsInCombat()) return false; @@ -20,29 +21,25 @@ bool ImbueWithStoneAction::Execute(Event& event) bot->SetStandState(UNIT_STAND_STATE_STAND); // Search and apply stone to weapons - // Mainhand ... - Item * stone, *weapon; - weapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); - if (weapon && weapon->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT) == 0) + // Mainhand + Item* mainWeapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + if (mainWeapon && mainWeapon->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT) == 0) { - stone = ai->FindStoneFor(weapon); + Item* stone = ai->FindStoneFor(mainWeapon); if (stone) { - ai->ImbueItem(stone, EQUIPMENT_SLOT_MAINHAND); - SetDuration(sPlayerbotAIConfig.globalCoolDown); - return true; + return UseItem(requester, stone->GetEntry(), mainWeapon); } } - //... and offhand - weapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); - if (weapon && weapon->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT) == 0) + + // Offhand + Item* secondaryWeapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); + if (secondaryWeapon && secondaryWeapon->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT) == 0) { - stone = ai->FindStoneFor(weapon); + Item* stone = ai->FindStoneFor(secondaryWeapon); if (stone) { - ai->ImbueItem(stone, EQUIPMENT_SLOT_OFFHAND); - SetDuration(sPlayerbotAIConfig.globalCoolDown); - return true; + return UseItem(requester, stone->GetEntry(), secondaryWeapon); } } @@ -52,21 +49,21 @@ bool ImbueWithStoneAction::Execute(Event& event) bool ImbueWithStoneAction::isUseful() { // Search and apply stone to weapons - // Mainhand ... - Item* weapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); - if (weapon && weapon->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT) == 0) + // Mainhand + Item* mainWeapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + if (mainWeapon && mainWeapon->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT) == 0) { - if (ai->FindStoneFor(weapon)) + if (ai->FindStoneFor(mainWeapon)) { return true; } } - //... and offhand - weapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); - if (weapon && weapon->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT) == 0) + // Offhand + Item* secondaryWeapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); + if (secondaryWeapon && secondaryWeapon->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT) == 0) { - if (ai->FindStoneFor(weapon)) + if (ai->FindStoneFor(secondaryWeapon)) { return true; } @@ -77,32 +74,30 @@ bool ImbueWithStoneAction::isUseful() bool ImbueWithOilAction::Execute(Event& event) { - if (bot->IsInCombat()) - return false; - - // remove stealth - if (bot->HasAura(SPELL_AURA_MOD_STEALTH)) - bot->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH); - - // hp check - if (bot->getStandState() != UNIT_STAND_STATE_STAND) - bot->SetStandState(UNIT_STAND_STATE_STAND); - - // Search and apply oil to weapons - Item* oil, *weapon; - weapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); - if (weapon && weapon->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT) == 0) - { - oil = ai->FindOilFor(weapon); - if (oil) - { - ai->ImbueItem(oil, EQUIPMENT_SLOT_MAINHAND); - SetDuration(sPlayerbotAIConfig.globalCoolDown); - return true; - } - } - - return false; + Player* requester = event.getOwner(); + if (bot->IsInCombat()) + return false; + + // remove stealth + if (bot->HasAura(SPELL_AURA_MOD_STEALTH)) + bot->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH); + + // hp check + if (bot->getStandState() != UNIT_STAND_STATE_STAND) + bot->SetStandState(UNIT_STAND_STATE_STAND); + + // Search and apply oil to weapons + Item* weapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + if (weapon && weapon->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT) == 0) + { + Item* oil = ai->FindOilFor(weapon); + if (oil) + { + return UseItem(requester, oil->GetEntry(), weapon); + } + } + + return false; } bool ImbueWithOilAction::isUseful() @@ -121,33 +116,33 @@ bool ImbueWithOilAction::isUseful() bool TryEmergencyAction::Execute(Event& event) { - // Do not use consumable if bot can heal self - if ((ai->IsHeal(bot)) && (ai->GetManaPercent() > 20)) - return false; - - // If bot does not have aggro: use bandage instead of potion/stone/crystal - if ((!(AI_VALUE(uint8, "my attacker count") >= 1)) && !bot->HasAura(11196)) // Recently bandaged - { - Item* bandage = ai->FindBandage(); - if (bandage) - { - ai->ImbueItem(bandage, bot); - SetDuration(sPlayerbotAIConfig.globalCoolDown); - return true; - } - } - - // Else loop over the list of health consumable to pick one - Item* healthItem; - for (uint8 i = 0; i < countof(uPriorizedHealingItemIds); ++i) - { - healthItem = ai->FindConsumable(uPriorizedHealingItemIds[i]); - if (healthItem) - { - ai->ImbueItem(healthItem); - return true; - } - } - - return false; + // Do not use consumable if bot can heal self + if (ai->IsHeal(bot) && ai->GetManaPercent() > 20) + return false; + + // If bot does not have aggro: use bandage instead of potion/stone/crystal + if (!(AI_VALUE(uint8, "my attacker count") >= 1) && !bot->HasAura(11196)) // Recently bandaged + { + Item* bandage = ai->FindBandage(); + if (bandage) + { + ai->ImbueItem(bandage, bot); + SetDuration(sPlayerbotAIConfig.globalCoolDown); + return true; + } + } + + // Else loop over the list of health consumable to pick one + Item* healthItem = nullptr; + for (uint8 i = 0; i < countof(uPriorizedHealingItemIds); ++i) + { + healthItem = ai->FindConsumable(uPriorizedHealingItemIds[i]); + if (healthItem) + { + ai->ImbueItem(healthItem); + return true; + } + } + + return false; } diff --git a/playerbot/strategy/actions/ImbueAction.h b/playerbot/strategy/actions/ImbueAction.h index 8cc1b3d1..05cb8c6b 100644 --- a/playerbot/strategy/actions/ImbueAction.h +++ b/playerbot/strategy/actions/ImbueAction.h @@ -6,18 +6,18 @@ namespace ai { - class ImbueWithStoneAction : public Action + class ImbueWithStoneAction : public UseAction { public: - ImbueWithStoneAction(PlayerbotAI* ai) : Action(ai, "apply stone") {} + ImbueWithStoneAction(PlayerbotAI* ai) : UseAction(ai, "apply stone") {} bool Execute(Event& event) override; bool isUseful() override; }; - class ImbueWithOilAction : public Action + class ImbueWithOilAction : public UseAction { public: - ImbueWithOilAction(PlayerbotAI* ai) : Action(ai, "apply oil") {} + ImbueWithOilAction(PlayerbotAI* ai) : UseAction(ai, "apply oil") {} bool Execute(Event& event) override; bool isUseful() override; };