Skip to content

Commit

Permalink
Do not consume oil/stones when item cheat is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
davidonete committed May 20, 2024
1 parent 2daf7a3 commit fcf0ee2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 83 deletions.
153 changes: 74 additions & 79 deletions playerbot/strategy/actions/ImbueAction.cpp
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
}
}

Expand All @@ -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;
}
Expand All @@ -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()
Expand All @@ -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;
}
8 changes: 4 additions & 4 deletions playerbot/strategy/actions/ImbueAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit fcf0ee2

Please sign in to comment.