[Bots] Expanded Bot Spell Settings List. (#2606)

* [Bots] Expanded Bot Spell List Settings

* [Bots] Expanded Bot Spell List Settings

* Fixes/formatting

* typo

* Formatting & update SpellInfo Command

* Spelling

* Typo
This commit is contained in:
Aeadoin
2022-12-03 12:15:57 -05:00
committed by GitHub
parent 35d22913b9
commit 61b91d92c3
12 changed files with 504 additions and 386 deletions
+48 -73
View File
@@ -406,11 +406,6 @@ Bot::Bot(uint32 botID, uint32 botOwnerCharacterID, uint32 botSpellsID, double to
bot_owner->Message(Chat::White, "&s for '%s'", BotDatabase::fail::LoadBuffs(), GetCleanName());
}
GetBotOwnerDataBuckets();
GetBotDataBuckets();
LoadBotSpellSettings();
AI_AddBotSpells(GetBotSpellID());
CalcBotStats(false);
hp_regen = CalcHPRegen();
mana_regen = CalcManaRegen();
@@ -10606,6 +10601,27 @@ void Bot::SetExpansionBitmask(int expansion_bitmask, bool save)
LoadAAs();
}
void Bot::SetBotEnforceSpellSetting(bool enforce_spell_settings, bool save)
{
m_enforce_spell_settings = enforce_spell_settings;
if (save) {
if (!database.botdb.SaveEnforceSpellSetting(GetBotID(), enforce_spell_settings)) {
if (GetBotOwner() && GetBotOwner()->IsClient()) {
GetBotOwner()->CastToClient()->Message(
Chat::White,
fmt::format(
"Failed to save enforce spell settings for {}.",
GetCleanName()
).c_str()
);
}
}
}
LoadBotSpellSettings();
AI_AddBotSpells(GetBotSpellID());
}
bool Bot::AddBotSpellSetting(uint16 spell_id, BotSpellSetting* bs)
{
if (!IsValidSpell(spell_id) || !bs) {
@@ -10623,8 +10639,6 @@ bool Bot::AddBotSpellSetting(uint16 spell_id, BotSpellSetting* bs)
s.bot_id = GetBotID();
s.priority = bs->priority;
s.min_level = bs->min_level;
s.max_level = bs->max_level;
s.min_hp = bs->min_hp;
s.max_hp = bs->max_hp;
s.is_enabled = bs->is_enabled;
@@ -10675,7 +10689,7 @@ BotSpellSetting* Bot::GetBotSpellSetting(uint16 spell_id)
return nullptr;
}
void Bot::ListBotSpells()
void Bot::ListBotSpells(uint8 min_level)
{
auto bot_owner = GetBotOwner();
if (!bot_owner) {
@@ -10697,28 +10711,25 @@ void Bot::ListBotSpells()
auto spell_number = 1;
for (const auto& s : AIBot_spells) {
bot_owner->Message(
Chat::White,
fmt::format(
"Spell {} | Spell: {} ({})",
spell_number,
spells[s.spellid].name,
s.spellid
).c_str()
);
auto b = bot_spell_settings.find(s.spellid);
if (b == bot_spell_settings.end() && s.minlevel >= min_level) {
bot_owner->Message(
Chat::White,
fmt::format(
"Spell {} | Spell: {} | Add Spell: {}",
spell_number,
Saylink::Silent(
fmt::format("^spellinfo {}", s.spellid),
spells[s.spellid].name
),
Saylink::Silent(
fmt::format("^spellsettingsadd {} {} {} {}", s.spellid, s.priority, s.min_hp, s.max_hp), "Add")
).c_str()
);
bot_owner->Message(
Chat::White,
fmt::format(
"Spell {} | Priority: {} Health: {}",
spell_number,
s.priority,
GetHPString(s.min_hp, s.max_hp)
).c_str()
);
spell_count++;
spell_number++;
spell_count++;
spell_number++;
}
}
bot_owner->Message(
@@ -10757,22 +10768,15 @@ void Bot::ListBotSpellSettings()
bot_owner->Message(
Chat::White,
fmt::format(
"Setting {} | Spell: {} ({}) Enabled: {}",
"Setting {} | Spell: {} | State: {} | {}",
setting_number,
spells[bs.first].name,
bs.first,
bs.second.is_enabled ? "Yes" : "No"
).c_str()
);
bot_owner->Message(
Chat::White,
fmt::format(
"Setting {} | Priority: {} Levels: {} Health: {}",
setting_number,
bs.second.priority,
GetLevelString(bs.second.min_level, bs.second.max_level),
GetHPString(bs.second.min_hp, bs.second.max_hp)
Saylink::Silent(fmt::format("^spellinfo {}", bs.first), spells[bs.first].name),
Saylink::Silent(
fmt::format("^spellsettingstoggle {} {}",
bs.first, bs.second.is_enabled ? "False" : "True"),
bs.second.is_enabled ? "Enabled" : "Disabled"
),
Saylink::Silent(fmt::format("^spellsettingsdelete {}", bs.first), "Remove")
).c_str()
);
@@ -10804,12 +10808,9 @@ void Bot::LoadBotSpellSettings()
BotSpellSetting b;
b.priority = e.priority;
b.min_level = e.min_level;
b.max_level = e.max_level;
b.min_hp = e.min_hp;
b.max_hp = e.max_hp;
b.is_enabled = e.is_enabled;
bot_spell_settings[e.spell_id] = b;
}
}
@@ -10825,8 +10826,6 @@ bool Bot::UpdateBotSpellSetting(uint16 spell_id, BotSpellSetting* bs)
s.spell_id = spell_id;
s.bot_id = GetBotID();
s.priority = bs->priority;
s.min_level = bs->min_level;
s.max_level = bs->max_level;
s.min_hp = bs->min_hp;
s.max_hp = bs->max_hp;
s.is_enabled = bs->is_enabled;
@@ -10844,30 +10843,6 @@ bool Bot::UpdateBotSpellSetting(uint16 spell_id, BotSpellSetting* bs)
return true;
}
std::string Bot::GetLevelString(uint8 min_level, uint8 max_level)
{
std::string level_string = "Any";
if (min_level && max_level) {
level_string = fmt::format(
"{} to {}",
min_level,
max_level
);
} else if (min_level && !max_level) {
level_string = fmt::format(
"{}+",
min_level
);
} else if (!min_level && max_level) {
level_string = fmt::format(
"1 to {}",
max_level
);
}
return level_string;
}
std::string Bot::GetHPString(int8 min_hp, int8 max_hp)
{
std::string hp_string = "Any";