Skip to content

Commit

Permalink
Merge pull request liyunfan1223#163 from liyunfan1223/healer_save_mana
Browse files Browse the repository at this point in the history
Healer save mana
  • Loading branch information
liyunfan1223 authored Mar 26, 2024
2 parents 68fdf57 + 98ad5a2 commit 47928a9
Show file tree
Hide file tree
Showing 20 changed files with 240 additions and 141 deletions.
10 changes: 10 additions & 0 deletions conf/playerbots.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ AiPlayerbot.LowMana = 15
AiPlayerbot.MediumMana = 40

# Random bot default strategies (applied after defaults)

# Enable healer bot save mana
# Default: 1 (enable)
AiPlayerbot.AutoSaveMana = 1

# Healer bot save mana threshold
# Default: 60 (60%)
AiPlayerbot.SaveManaThreshold = 60


AiPlayerbot.RandomBotCombatStrategies = "+dps,+dps assist,-threat"
# AiPlayerbot.RandomBotNonCombatStrategies = "+grind,+loot,+rpg,+custom::say"
AiPlayerbot.RandomBotNonCombatStrategies = ""
Expand Down
14 changes: 10 additions & 4 deletions src/AiFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "BattlegroundMgr.h"
#include "Item.h"
#include "PlayerbotAI.h"
#include "PlayerbotAIConfig.h"
#include "Playerbots.h"
#include "Engine.h"
#include "Group.h"
Expand Down Expand Up @@ -265,16 +266,19 @@ void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const fa
{
engine->addStrategies("racials", "chat", "default", "cast time", "duel", "boost", nullptr);
}

if (sPlayerbotAIConfig->autoSaveMana) {
engine->addStrategy("auto save mana");
}
switch (player->getClass())
{
case CLASS_PRIEST:
if (tab == 2)
{
engine->addStrategies("dps", "shadow debuff", "shadow aoe", "threat", nullptr);
}
else
else {
engine->addStrategies("heal", "threat", nullptr);
}

engine->addStrategies("dps assist", "cure", nullptr);
break;
Expand Down Expand Up @@ -426,7 +430,7 @@ void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const fa
engine->addStrategy("arena");
}

engine->addStrategies("boost", "racials", "chat", "default", "aoe", "potions", "conserve mana", "cast time", "dps assist", nullptr);
engine->addStrategies("boost", "racials", "chat", "default", "aoe", "potions", "cast time", "dps assist", nullptr);
engine->removeStrategy("custom::say");
engine->removeStrategy("flee");
engine->removeStrategy("threat");
Expand Down Expand Up @@ -532,7 +536,9 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const
nonCombatEngine->addStrategies("nc", "food", "chat", "follow",
"default", "quest", "loot", "gather", "duel", "buff", "mount", nullptr);
}

if (sPlayerbotAIConfig->autoSaveMana) {
nonCombatEngine->addStrategy("auto save mana");
}
if ((facade->IsRealPlayer() || sRandomPlayerbotMgr->IsRandomBot(player)) && !player->InBattleground())
{
Player* master = facade->GetMaster();
Expand Down
2 changes: 2 additions & 0 deletions src/PlayerbotAIConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ bool PlayerbotAIConfig::Initialize()
almostFullHealth = sConfigMgr->GetOption<int32>("AiPlayerbot.AlmostFullHealth", 85);
lowMana = sConfigMgr->GetOption<int32>("AiPlayerbot.LowMana", 15);
mediumMana = sConfigMgr->GetOption<int32>("AiPlayerbot.MediumMana", 40);
autoSaveMana = sConfigMgr->GetOption<bool>("AiPlayerbot.AutoSaveMana", true);
saveManaThreshold = sConfigMgr->GetOption<int32>("AiPlayerbot.SaveManaThreshold", 60);

randomGearLoweringChance = sConfigMgr->GetOption<float>("AiPlayerbot.RandomGearLoweringChance", 0.15f);
randomBotMaxLevelChance = sConfigMgr->GetOption<float>("AiPlayerbot.RandomBotMaxLevelChance", 0.15f);
Expand Down
12 changes: 12 additions & 0 deletions src/PlayerbotAIConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ enum class BotCheatMask : uint32
maxMask = 32
};

enum class HealingManaEfficiency : uint8
{
VERY_LOW = 1,
LOW = 2,
MEDIUM = 4,
HIGH = 8,
VERY_HIGH = 16,
SUPERIOR = 32
};

#define MAX_SPECNO 20

class PlayerbotAIConfig
Expand Down Expand Up @@ -51,6 +61,8 @@ class PlayerbotAIConfig
aoeRadius, rpgDistance, targetPosRecalcDistance, farDistance, healDistance, aggroDistance;
uint32 criticalHealth, lowHealth, mediumHealth, almostFullHealth;
uint32 lowMana, mediumMana;
bool autoSaveMana;
uint32 saveManaThreshold;

uint32 openGoSpell;
bool randomBotAutologin;
Expand Down
2 changes: 1 addition & 1 deletion src/PlayerbotFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void PlayerbotFactory::Init()
// continue;

enchantSpellIdCache.push_back(id);
LOG_INFO("playerbots", "Add {} to enchantment spells", id);
// LOG_INFO("playerbots", "Add {} to enchantment spells", id);
}
}
LOG_INFO("playerbots", "Loading {} enchantment spells", enchantSpellIdCache.size());
Expand Down
6 changes: 3 additions & 3 deletions src/strategy/AiObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ class clazz : public CastHealingSpellAction \
bool isUseful() override { return useful; } \
}

#define HEAL_PARTY_ACTION(clazz, spell) \
#define HEAL_PARTY_ACTION(clazz, spell, estAmount, manaEfficiency) \
class clazz : public HealPartyMemberAction \
{ \
public: \
clazz(PlayerbotAI* botAI) : HealPartyMemberAction(botAI, spell) { } \
clazz(PlayerbotAI* botAI) : HealPartyMemberAction(botAI, spell, estAmount, manaEfficiency) { } \
}

#define AOE_HEAL_ACTION(clazz, spell) \
#define AOE_HEAL_ACTION(clazz, spell, estAmount, manaEfficiency) \
class clazz : public CastAoeHealSpellAction \
{ \
public: \
Expand Down
6 changes: 4 additions & 2 deletions src/strategy/StrategyContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class StrategyContext : public NamedObjectContext<Strategy>
creators["gather"] = &StrategyContext::gather;
creators["emote"] = &StrategyContext::emote;
creators["passive"] = &StrategyContext::passive;
creators["conserve mana"] = &StrategyContext::conserve_mana;
// creators["conserve mana"] = &StrategyContext::conserve_mana;
creators["auto save mana"] = &StrategyContext::auto_save_mana;
creators["food"] = &StrategyContext::food;
creators["chat"] = &StrategyContext::chat;
creators["default"] = &StrategyContext::world_packet;
Expand Down Expand Up @@ -131,7 +132,8 @@ class StrategyContext : public NamedObjectContext<Strategy>
static Strategy* gather(PlayerbotAI* botAI) { return new GatherStrategy(botAI); }
static Strategy* emote(PlayerbotAI* botAI) { return new EmoteStrategy(botAI); }
static Strategy* passive(PlayerbotAI* botAI) { return new PassiveStrategy(botAI); }
static Strategy* conserve_mana(PlayerbotAI* botAI) { return new ConserveManaStrategy(botAI); }
// static Strategy* conserve_mana(PlayerbotAI* botAI) { return new ConserveManaStrategy(botAI); }
static Strategy* auto_save_mana(PlayerbotAI* botAI) { return new HealerAutoSaveManaStrategy(botAI); }
static Strategy* food(PlayerbotAI* botAI) { return new UseFoodStrategy(botAI); }
static Strategy* chat(PlayerbotAI* botAI) { return new ChatCommandHandlerStrategy(botAI); }
static Strategy* world_packet(PlayerbotAI* botAI) { return new WorldPacketHandlerStrategy(botAI); }
Expand Down
3 changes: 2 additions & 1 deletion src/strategy/actions/GenericSpellActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ bool CastEnchantItemAction::isPossible()
return spellId && AI_VALUE2(Item*, "item for spell", spellId);
}

CastHealingSpellAction::CastHealingSpellAction(PlayerbotAI* botAI, std::string const spell, uint8 estAmount) : CastAuraSpellAction(botAI, spell, true), estAmount(estAmount)
CastHealingSpellAction::CastHealingSpellAction(PlayerbotAI* botAI, std::string const spell, uint8 estAmount, HealingManaEfficiency manaEfficiency)
: CastAuraSpellAction(botAI, spell, true), estAmount(estAmount), manaEfficiency(manaEfficiency)
{
range = botAI->GetRange("heal");
}
Expand Down
15 changes: 9 additions & 6 deletions src/strategy/actions/GenericSpellActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,23 @@ class CastEnchantItemAction : public CastSpellAction
class CastHealingSpellAction : public CastAuraSpellAction
{
public:
CastHealingSpellAction(PlayerbotAI* botAI, std::string const spell, uint8 estAmount = 15.0f);
CastHealingSpellAction(PlayerbotAI* botAI, std::string const spell, uint8 estAmount = 15.0f, HealingManaEfficiency manaEfficiency = HealingManaEfficiency::MEDIUM);

std::string const GetTargetName() override { return "self target"; }
bool isUseful() override;
ActionThreatType getThreatType() override { return ActionThreatType::Aoe; }

protected:
// Yunfan: Mana efficiency tell the bot how to save mana. The higher the better.
HealingManaEfficiency manaEfficiency;
uint8 estAmount;

// protected:
};

class CastAoeHealSpellAction : public CastHealingSpellAction
{
public:
CastAoeHealSpellAction(PlayerbotAI* botAI, std::string const spell, uint8 estAmount = 15.0f) : CastHealingSpellAction(botAI, spell, estAmount) { }
CastAoeHealSpellAction(PlayerbotAI* botAI, std::string const spell, uint8 estAmount = 15.0f, HealingManaEfficiency manaEfficiency = HealingManaEfficiency::MEDIUM)
: CastHealingSpellAction(botAI, spell, estAmount, manaEfficiency) { }

std::string const GetTargetName() override { return "party member to heal"; }
bool isUseful() override;
Expand Down Expand Up @@ -142,8 +145,8 @@ class PartyMemberActionNameSupport
class HealPartyMemberAction : public CastHealingSpellAction, public PartyMemberActionNameSupport
{
public:
HealPartyMemberAction(PlayerbotAI* botAI, std::string const spell, uint8 estAmount = 15.0f) :
CastHealingSpellAction(botAI, spell, estAmount), PartyMemberActionNameSupport(spell) { }
HealPartyMemberAction(PlayerbotAI* botAI, std::string const spell, uint8 estAmount = 15.0f, HealingManaEfficiency manaEfficiency = HealingManaEfficiency::MEDIUM) :
CastHealingSpellAction(botAI, spell, estAmount, manaEfficiency), PartyMemberActionNameSupport(spell) { }

std::string const GetTargetName() override { return "party member to heal"; }
std::string const getName() override { return PartyMemberActionNameSupport::getName(); }
Expand Down
14 changes: 7 additions & 7 deletions src/strategy/druid/DruidActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ class CastHealingTouchAction : public CastHealingSpellAction
class CastRejuvenationOnPartyAction : public HealPartyMemberAction
{
public:
CastRejuvenationOnPartyAction(PlayerbotAI* botAI) : HealPartyMemberAction(botAI, "rejuvenation") { }
CastRejuvenationOnPartyAction(PlayerbotAI* botAI) : HealPartyMemberAction(botAI, "rejuvenation", 15.0f, HealingManaEfficiency::VERY_HIGH) { }
};

class CastRegrowthOnPartyAction : public HealPartyMemberAction
{
public:
CastRegrowthOnPartyAction(PlayerbotAI* botAI) : HealPartyMemberAction(botAI, "regrowth") { }
CastRegrowthOnPartyAction(PlayerbotAI* botAI) : HealPartyMemberAction(botAI, "regrowth", 35.0f, HealingManaEfficiency::HIGH) { }
};

class CastHealingTouchOnPartyAction : public HealPartyMemberAction
{
public:
CastHealingTouchOnPartyAction(PlayerbotAI* botAI) : HealPartyMemberAction(botAI, "healing touch") { }
CastHealingTouchOnPartyAction(PlayerbotAI* botAI) : HealPartyMemberAction(botAI, "healing touch", 50.0f, HealingManaEfficiency::LOW) { }
};

class CastReviveAction : public ResurrectPartyMemberAction
Expand Down Expand Up @@ -242,7 +242,7 @@ class CastInnervateAction : public CastSpellAction
class CastTranquilityAction : public CastAoeHealSpellAction
{
public:
CastTranquilityAction(PlayerbotAI* botAI) : CastAoeHealSpellAction(botAI, "tranquility") { }
CastTranquilityAction(PlayerbotAI* botAI) : CastAoeHealSpellAction(botAI, "tranquility", 15.0f, HealingManaEfficiency::MEDIUM) { }
};

class CastNaturesSwiftnessAction : public CastBuffSpellAction
Expand All @@ -254,19 +254,19 @@ class CastNaturesSwiftnessAction : public CastBuffSpellAction
class CastWildGrowthOnPartyAction : public HealPartyMemberAction
{
public:
CastWildGrowthOnPartyAction(PlayerbotAI* ai) : HealPartyMemberAction(ai, "wild growth") {}
CastWildGrowthOnPartyAction(PlayerbotAI* ai) : HealPartyMemberAction(ai, "wild growth", 15.0f, HealingManaEfficiency::VERY_HIGH) {}
};

class CastPartySwiftmendAction : public HealPartyMemberAction
{
public:
CastPartySwiftmendAction(PlayerbotAI* ai) : HealPartyMemberAction(ai, "swiftmend") {}
CastPartySwiftmendAction(PlayerbotAI* ai) : HealPartyMemberAction(ai, "swiftmend", 15.0f, HealingManaEfficiency::MEDIUM) {}
};

class CastPartyNourishAction : public HealPartyMemberAction
{
public:
CastPartyNourishAction(PlayerbotAI* ai) : HealPartyMemberAction(ai, "nourish") {}
CastPartyNourishAction(PlayerbotAI* ai) : HealPartyMemberAction(ai, "nourish", 25.0f, HealingManaEfficiency::LOW) {}
};

class CastDruidRemoveCurseOnPartyAction : public CurePartyMemberAction
Expand Down
Loading

0 comments on commit 47928a9

Please sign in to comment.