diff --git a/playerbot/PlayerbotAIConfig.cpp b/playerbot/PlayerbotAIConfig.cpp index 6fc1381bb..6137925cd 100644 --- a/playerbot/PlayerbotAIConfig.cpp +++ b/playerbot/PlayerbotAIConfig.cpp @@ -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); diff --git a/playerbot/PlayerbotAIConfig.h b/playerbot/PlayerbotAIConfig.h index 227589d1c..00d519669 100644 --- a/playerbot/PlayerbotAIConfig.h +++ b/playerbot/PlayerbotAIConfig.h @@ -90,6 +90,7 @@ class PlayerbotAIConfig float randomGearLoweringChance; float randomBotMaxLevelChance; float randomBotRpgChance; + float usePotionChance; uint32 minRandomBots, maxRandomBots; uint32 randomBotUpdateInterval, randomBotCountChangeMinInterval, randomBotCountChangeMaxInterval; uint32 loginBoostPercentage; diff --git a/playerbot/aiplayerbot.conf.dist.in b/playerbot/aiplayerbot.conf.dist.in index 0e7ecdfe5..f1b4d237f 100644 --- a/playerbot/aiplayerbot.conf.dist.in +++ b/playerbot/aiplayerbot.conf.dist.in @@ -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 diff --git a/playerbot/aiplayerbot.conf.dist.in.tbc b/playerbot/aiplayerbot.conf.dist.in.tbc index f5f0fe02c..439af37ae 100644 --- a/playerbot/aiplayerbot.conf.dist.in.tbc +++ b/playerbot/aiplayerbot.conf.dist.in.tbc @@ -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 diff --git a/playerbot/aiplayerbot.conf.dist.in.wotlk b/playerbot/aiplayerbot.conf.dist.in.wotlk index 79db1b0d0..10815f740 100644 --- a/playerbot/aiplayerbot.conf.dist.in.wotlk +++ b/playerbot/aiplayerbot.conf.dist.in.wotlk @@ -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 diff --git a/playerbot/strategy/actions/UseItemAction.h b/playerbot/strategy/actions/UseItemAction.h index a36d42e78..c541ecbb4 100644 --- a/playerbot/strategy/actions/UseItemAction.h +++ b/playerbot/strategy/actions/UseItemAction.h @@ -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(spellData.SpellId); + if (spellInfo) + { + bot->RemoveSpellCooldown(*spellInfo, false); + bot->AddCooldown(*spellInfo, proto, false); + break; + } + } + } + } + } + + return true; + } + private: SpellEffects effect; };