Skip to content

Commit

Permalink
Add option to configure the chance for bots to use potions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidonete committed Oct 15, 2023
1 parent b74c181 commit 13ae919
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions playerbot/PlayerbotAIConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ bool PlayerbotAIConfig::Initialize()
randomGearLoweringChance = config.GetFloatDefault("AiPlayerbot.RandomGearLoweringChance", 0.15f);
randomBotMaxLevelChance = config.GetFloatDefault("AiPlayerbot.RandomBotMaxLevelChance", 0.15f);
randomBotRpgChance = config.GetFloatDefault("AiPlayerbot.RandomBotRpgChance", 0.35f);
usePotionChance = config.GetFloatDefault("AiPlayerbot.UsePotionChance", 1.0f);

iterationsPerTick = config.GetIntDefault("AiPlayerbot.IterationsPerTick", 100);

Expand Down
1 change: 1 addition & 0 deletions playerbot/PlayerbotAIConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class PlayerbotAIConfig
float randomGearLoweringChance;
float randomBotMaxLevelChance;
float randomBotRpgChance;
float usePotionChance;
uint32 minRandomBots, maxRandomBots;
uint32 randomBotUpdateInterval, randomBotCountChangeMinInterval, randomBotCountChangeMaxInterval;
uint32 loginBoostPercentage;
Expand Down
3 changes: 3 additions & 0 deletions playerbot/aiplayerbot.conf.dist.in
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ AiPlayerbot.RandomBotMaxLevelChance = 0.15
# Chance bot chooses RPG (Teleport to random camp for their level) instead of grinding
AiPlayerbot.RandomBotRpgChance = 0.20

# Chance for bot to use potions
#AiPlayerbot.UsePotionChance = 1.0

# Bots will speed up when following to stay close.
# AiPlayerbot.BoostFollow = 1

Expand Down
3 changes: 3 additions & 0 deletions playerbot/aiplayerbot.conf.dist.in.tbc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ AiPlayerbot.RandomBotMaxLevelChance = 0.15
# Chance bot chooses RPG (Teleport to random camp for their level) instead of grinding
AiPlayerbot.RandomBotRpgChance = 0.20

# Chance for bot to use potions
#AiPlayerbot.UsePotionChance = 1.0

# Bots will speed up when following to stay close.
# AiPlayerbot.BoostFollow = 1

Expand Down
3 changes: 3 additions & 0 deletions playerbot/aiplayerbot.conf.dist.in.wotlk
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ AiPlayerbot.RandomBotMaxLevelChance = 0.15
# Chance bot chooses RPG (Teleport to random camp for their level) instead of grinding
AiPlayerbot.RandomBotRpgChance = 0.20

# Chance for bot to use potions
#AiPlayerbot.UsePotionChance = 1.0

# Bots will speed up when following to stay close.
# AiPlayerbot.BoostFollow = 1

Expand Down
45 changes: 45 additions & 0 deletions playerbot/strategy/actions/UseItemAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,51 @@ namespace ai
return items.front()->GetProto()->ItemId;
}

bool Execute(Event& event) override
{
// Check the chance of using a potion
const bool shouldUsePotion = frand(0.0f, 1.0f) < sPlayerbotAIConfig.usePotionChance;

if (shouldUsePotion)
{
return UseItemIdAction::Execute(event);
}
else
{
// Force potion cooldown to prevent spamming this action
const ItemPrototype* proto = sObjectMgr.GetItemPrototype(GetItemId());
if (proto)
{
for (int i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
{
_Spell const& spellData = proto->Spells[i];
if (spellData.SpellId)
{
// wrong triggering type
#ifdef MANGOSBOT_ZERO
if (spellData.SpellTrigger != ITEM_SPELLTRIGGER_ON_USE && spellData.SpellTrigger != ITEM_SPELLTRIGGER_ON_NO_DELAY_USE)
#else
if (spellData.SpellTrigger != ITEM_SPELLTRIGGER_ON_USE)
#endif
{
continue;
}

const SpellEntry* spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(spellData.SpellId);
if (spellInfo)
{
bot->RemoveSpellCooldown(*spellInfo, false);
bot->AddCooldown(*spellInfo, proto, false);
break;
}
}
}
}
}

return true;
}

private:
SpellEffects effect;
};
Expand Down

0 comments on commit 13ae919

Please sign in to comment.