[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
+155 -38
View File
@@ -73,6 +73,7 @@
#include "titles.h"
#include "water_map.h"
#include "worldserver.h"
#include "dialogue_window.h"
#include <fmt/format.h>
@@ -1362,6 +1363,7 @@ int bot_command_init(void)
bot_command_add("cure", "Orders a bot to remove any ailments", AccountStatus::Player, bot_command_cure) ||
bot_command_add("defensive", "Orders a bot to use a defensive discipline", AccountStatus::Player, bot_command_defensive) ||
bot_command_add("depart", "Orders a bot to open a magical doorway to a specified destination", AccountStatus::Player, bot_command_depart) ||
bot_command_add("enforcespelllist", "Toggles your Bot to cast only spells in their spell settings list.", AccountStatus::Player, bot_command_enforce_spell_list) ||
bot_command_add("escape", "Orders a bot to send a target group to a safe location within the zone", AccountStatus::Player, bot_command_escape) ||
bot_command_add("findaliases", "Find available aliases for a bot command", AccountStatus::Player, bot_command_find_aliases) ||
bot_command_add("follow", "Orders bots to follow a designated target (option 'chain' auto-links eligible spawned bots)", AccountStatus::Player, bot_command_follow) ||
@@ -1416,12 +1418,13 @@ int bot_command_init(void)
bot_command_add("rune", "Orders a bot to cast a rune of protection", AccountStatus::Player, bot_command_rune) ||
bot_command_add("sendhome", "Orders a bot to open a magical doorway home", AccountStatus::Player, bot_command_send_home) ||
bot_command_add("size", "Orders a bot to change a player's size", AccountStatus::Player, bot_command_size) ||
bot_command_add("spelllist", "Lists a Caster of Hybrid bot's spells", AccountStatus::Player, bot_command_spell_list) ||
bot_command_add("spellsettingsadd", "Add a bot spell setting for a Caster or Hybrid bot", AccountStatus::Player, bot_command_spell_settings_add) ||
bot_command_add("spellsettingsdelete", "Delete a bot spell setting from a Caster or Hybrid bot", AccountStatus::Player, bot_command_spell_settings_delete) ||
bot_command_add("spellsettingslist", "Lists a Caster or Hybrid bot's spell settings", AccountStatus::Player, bot_command_spell_settings_list) ||
bot_command_add("spellsettingstoggle", "Toggle a bot spell for a Caster or Hybrid bot", AccountStatus::Player, bot_command_spell_settings_toggle) ||
bot_command_add("spellsettingsupdate", "Update a bot spell setting for a Caster or Hybrid bot", AccountStatus::Player, bot_command_spell_settings_update) ||
bot_command_add("spellinfo", "Opens a dialogue window with spell info", AccountStatus::Player, bot_spell_info_dialogue_window) ||
bot_command_add("spelllist", "Lists all Spells learned by the Bot.", AccountStatus::Player, bot_command_spell_list) ||
bot_command_add("spellsettingsadd", "Add a bot spell setting entry", AccountStatus::Player, bot_command_spell_settings_add) ||
bot_command_add("spellsettingsdelete", "Delete a bot spell setting entry", AccountStatus::Player, bot_command_spell_settings_delete) ||
bot_command_add("spellsettingslist", "Lists a bot's spell setting entries", AccountStatus::Player, bot_command_spell_settings_list) ||
bot_command_add("spellsettingstoggle", "Toggle a bot spells use", AccountStatus::Player, bot_command_spell_settings_toggle) ||
bot_command_add("spellsettingsupdate", "Update a bot spell setting entry", AccountStatus::Player, bot_command_spell_settings_update) ||
bot_command_add("summoncorpse", "Orders a bot to summon a corpse to its feet", AccountStatus::Player, bot_command_summon_corpse) ||
bot_command_add("suspend", "Suspends a bot's AI processing until released", AccountStatus::Player, bot_command_suspend) ||
bot_command_add("taunt", "Toggles taunt use by a bot", AccountStatus::Player, bot_command_taunt) ||
@@ -6683,6 +6686,20 @@ void bot_subcommand_bot_spawn(Client *c, const Seperator *sep)
return;
}
my_bot->GetBotOwnerDataBuckets();
my_bot->GetBotDataBuckets();
my_bot->LoadBotSpellSettings();
if (!my_bot->AI_AddBotSpells(my_bot->GetBotSpellID())) {
c->Message(
Chat::White,
fmt::format(
"Failed to load spells for '{}' (ID {}).",
bot_name,
bot_id
).c_str()
);
}
static std::string bot_spawn_message[17] = {
"I am ready to fight!", // DEFAULT
"A solid weapon is my ally!", // WARRIOR
@@ -10242,7 +10259,7 @@ void bot_command_spell_list(Client* c, const Seperator *sep)
c->Message(
Chat::White,
fmt::format(
"Usage: {} [Spell ID] [Priority] [Min Level] [Max Level] [Min HP] [Max HP]",
"Usage: {} [Min Level] (Level is optional)",
sep->arg[0]
).c_str()
);
@@ -10255,7 +10272,13 @@ void bot_command_spell_list(Client* c, const Seperator *sep)
return;
}
my_bot->ListBotSpells();
uint8 min_level = 0;
if (sep->IsNumber(1)) {
min_level = static_cast<uint8>(std::stoul(sep->arg[1]));
}
my_bot->ListBotSpells(min_level);
}
void bot_command_spell_settings_add(Client *c, const Seperator *sep)
@@ -10268,7 +10291,7 @@ void bot_command_spell_settings_add(Client *c, const Seperator *sep)
c->Message(
Chat::White,
fmt::format(
"Usage: {} [Spell ID] [Priority] [Min Level] [Max Level] [Min HP] [Max HP]",
"Usage: {} [Spell ID] [Priority] [Min HP] [Max HP]",
sep->arg[0]
).c_str()
);
@@ -10283,18 +10306,16 @@ void bot_command_spell_settings_add(Client *c, const Seperator *sep)
auto arguments = sep->argnum;
if (
arguments < 6 ||
arguments < 4 ||
!sep->IsNumber(1) ||
!sep->IsNumber(2) ||
!sep->IsNumber(3) ||
!sep->IsNumber(4) ||
!sep->IsNumber(5) ||
!sep->IsNumber(6)
!sep->IsNumber(4)
) {
c->Message(
Chat::White,
fmt::format(
"Usage: {} [Spell ID] [Priority] [Min Level] [Max Level] [Min HP] [Max HP]",
"Usage: {} [Spell ID] [Priority] [Min HP] [Max HP]",
sep->arg[0]
).c_str()
);
@@ -10329,16 +10350,12 @@ void bot_command_spell_settings_add(Client *c, const Seperator *sep)
}
auto priority = static_cast<int16>(std::stoi(sep->arg[2]));
auto min_level = static_cast<uint8>(std::stoul(sep->arg[3]));
auto max_level = static_cast<uint8>(std::stoul(sep->arg[4]));
auto min_hp = static_cast<int8>(EQ::Clamp(std::stoi(sep->arg[5]), -1, 99));
auto max_hp = static_cast<int8>(EQ::Clamp(std::stoi(sep->arg[6]), -1, 100));
auto min_hp = static_cast<int8>(EQ::Clamp(std::stoi(sep->arg[3]), -1, 99));
auto max_hp = static_cast<int8>(EQ::Clamp(std::stoi(sep->arg[4]), -1, 100));
BotSpellSetting bs;
bs.priority = priority;
bs.min_level = min_level;
bs.max_level = max_level;
bs.min_hp = min_hp;
bs.max_hp = max_hp;
@@ -10375,9 +10392,8 @@ void bot_command_spell_settings_add(Client *c, const Seperator *sep)
c->Message(
Chat::White,
fmt::format(
"Spell Setting Added | Priority: {} Levels: {} Health: {}",
"Spell Setting Added | Priority: {} Health: {}",
priority,
my_bot->GetLevelString(min_level, max_level),
my_bot->GetHPString(min_hp, max_hp)
).c_str()
);
@@ -10555,8 +10571,6 @@ void bot_command_spell_settings_toggle(Client *c, const Seperator *sep)
BotSpellSetting bs;
bs.priority = obs->priority;
bs.min_level = obs->min_level;
bs.max_level = obs->max_level;
bs.min_hp = obs->min_hp;
bs.max_hp = obs->max_hp;
bs.is_enabled = toggle;
@@ -10605,7 +10619,7 @@ void bot_command_spell_settings_update(Client *c, const Seperator *sep)
c->Message(
Chat::White,
fmt::format(
"Usage: {} [Spell ID] [Priority] [Min Level] [Max Level] [Min HP] [Max HP]",
"Usage: {} [Spell ID] [Priority] [Min HP] [Max HP]",
sep->arg[0]
).c_str()
);
@@ -10620,18 +10634,16 @@ void bot_command_spell_settings_update(Client *c, const Seperator *sep)
auto arguments = sep->argnum;
if (
arguments < 6 ||
arguments < 4 ||
!sep->IsNumber(1) ||
!sep->IsNumber(2) ||
!sep->IsNumber(3) ||
!sep->IsNumber(4) ||
!sep->IsNumber(5) ||
!sep->IsNumber(6)
!sep->IsNumber(4)
) {
c->Message(
Chat::White,
fmt::format(
"Usage: {} [Spell ID] [Priority] [Min Level] [Max Level] [Min HP] [Max HP]",
"Usage: {} [Spell ID] [Priority] [Min HP] [Max HP]",
sep->arg[0]
).c_str()
);
@@ -10652,16 +10664,12 @@ void bot_command_spell_settings_update(Client *c, const Seperator *sep)
}
auto priority = static_cast<int16>(std::stoi(sep->arg[2]));
auto min_level = static_cast<uint8>(std::stoul(sep->arg[3]));
auto max_level = static_cast<uint8>(std::stoul(sep->arg[4]));
auto min_hp = static_cast<int8>(EQ::Clamp(std::stoi(sep->arg[5]), -1, 99));
auto max_hp = static_cast<int8>(EQ::Clamp(std::stoi(sep->arg[6]), -1, 100));
auto min_hp = static_cast<int8>(EQ::Clamp(std::stoi(sep->arg[3]), -1, 99));
auto max_hp = static_cast<int8>(EQ::Clamp(std::stoi(sep->arg[4]), -1, 100));
BotSpellSetting bs;
bs.priority = priority;
bs.min_level = min_level;
bs.max_level = max_level;
bs.min_hp = min_hp;
bs.max_hp = max_hp;
@@ -10698,12 +10706,121 @@ void bot_command_spell_settings_update(Client *c, const Seperator *sep)
c->Message(
Chat::White,
fmt::format(
"Spell Setting Updated | Priority: {} Levels: {} Health: {}",
"Spell Setting Updated | Priority: {} Health: {}",
priority,
my_bot->GetLevelString(min_level, max_level),
my_bot->GetHPString(min_hp, max_hp)
).c_str()
);
}
void bot_spell_info_dialogue_window(Client* c, const Seperator *sep)
{
if (helper_command_alias_fail(c, "bot_spell_info_dialogue_window", sep->arg[0], "spellinfo")) {
return;
}
auto arguments = sep->argnum;
if (
arguments < 1 ||
!sep->IsNumber(1)
) {
c->Message(
Chat::White,
fmt::format(
"Usage: {} [Spell ID]",
sep->arg[0]
).c_str()
);
return;
}
auto my_bot = ActionableBots::AsTarget_ByBot(c);
if (!my_bot) {
c->Message(Chat::White, "You must target a bot that you own to use this command.");
return;
}
auto spell_id = static_cast<uint16>(std::stoul(sep->arg[1]));
auto min_level = spells[spell_id].classes;
auto class_level = min_level[my_bot->GetBotClass() - 1];
if (class_level > my_bot->GetLevel()) {
c->Message(Chat::White, "This is not a usable spell by your bot.");
return;
}
auto results = database.QueryDatabase(
fmt::format(
"SELECT value FROM db_str WHERE id = {} and type = 6 LIMIT 1",
spells[spell_id].effect_description_id
)
);
if (!results.Success() || !results.RowCount()) {
c->Message(Chat::White, "No Spell Information Available for this.");
return;
}
auto row = results.begin();
std::string spell_desc = row[0];
auto m = DialogueWindow::TableRow(
DialogueWindow::TableCell("Spell Effect: ") +
DialogueWindow::TableCell(spell_desc)
);
m += DialogueWindow::TableRow(
DialogueWindow::TableCell("Spell Level: ") +
DialogueWindow::TableCell(fmt::format("{}", class_level))
);
c->SendPopupToClient(
fmt::format(
"Spell: {}", spells[spell_id].name
).c_str(),
DialogueWindow::Table(m).c_str()
);
}
void bot_command_enforce_spell_list(Client* c, const Seperator *sep)
{
if (helper_command_alias_fail(c, "bot_command_enforce_spell_list", sep->arg[0], "enforcespelllist")) {
return;
}
if (helper_is_help_or_usage(sep->arg[1])) {
c->Message(
Chat::White,
fmt::format(
"Usage: {} [True/False]",
sep->arg[0]
).c_str()
);
return;
}
auto my_bot = ActionableBots::AsTarget_ByBot(c);
if (!my_bot) {
c->Message(Chat::White, "You must target a bot that you own to use this command.");
return;
}
bool toggle = (
sep->IsNumber(1) ?
(std::stoi(sep->arg[1]) ? true : false) :
atobool(sep->arg[1])
);
my_bot->SetBotEnforceSpellSetting(toggle, true);
c->Message(
Chat::White,
fmt::format(
"{}'s Spell Settings List entries are now {}.",
my_bot->GetCleanName(),
toggle ? "enforced" : "optional"
).c_str()
);
}
#endif // BOTS