Fix ^petsettype to account for usable levels of spells and remove hardcoded level limits.

This commit is contained in:
nytmyr
2024-12-20 13:09:42 -06:00
parent 1d0899fa0a
commit 62111da16d
4 changed files with 388 additions and 84 deletions
@@ -252,6 +252,7 @@ UPDATE `bot_command_settings` SET `aliases`= CASE WHEN LENGTH(`aliases`) > 0 THE
UPDATE `bot_command_settings` SET `aliases`= CASE WHEN LENGTH(`aliases`) > 0 THEN CONCAT(`aliases`, '|ir') ELSE 'invremove|ir' END WHERE `bot_command`='inventoryremove' AND `aliases` NOT LIKE '%ir%';
UPDATE `bot_command_settings` SET `aliases`= CASE WHEN LENGTH(`aliases`) > 0 THEN CONCAT(`aliases`, '|iw') ELSE 'invwindow|iw' END WHERE `bot_command`='inventorywindow' AND `aliases` NOT LIKE '%iw%';
UPDATE `bot_command_settings` SET `aliases`= CASE WHEN LENGTH(`aliases`) > 0 THEN CONCAT(`aliases`, '|iu') ELSE 'iu' END WHERE `bot_command`='itemuse' AND `aliases` NOT LIKE '%iu%';
UPDATE `bot_command_settings` SET `aliases`= CASE WHEN LENGTH(`aliases`) > 0 THEN CONCAT(`aliases`, '|pst') ELSE 'pset||pst' END WHERE `bot_command`='petsettype' AND `aliases` NOT LIKE '%pst%';
UPDATE `bot_command_settings` SET `aliases`= 'mmr' WHERE `bot_command`='maxmeleerange';
UPDATE `bot_command_settings` SET `aliases`= CASE WHEN LENGTH(`aliases`) > 0 THEN CONCAT(`aliases`, '|pp') ELSE 'pp' END WHERE `bot_command`='pickpocket' AND `aliases` NOT LIKE '%pp%';
UPDATE `bot_command_settings` SET `aliases`= 'sithp' WHERE `bot_command`='sithppercent';
+1
View File
@@ -838,6 +838,7 @@ RULE_BOOL(Bots, AllowMagicianEpicPet, false, "If enabled, magician bots can summ
RULE_INT(Bots, AllowMagicianEpicPetLevel, 50, "If AllowMagicianEpicPet is enabled, bots can start using their epic pets at this level")
RULE_INT(Bots, RequiredMagicianEpicPetItemID, 28034, "If AllowMagicianEpicPet is enabled and this is set, bots will be required to have this item ID equipped to cast their epic. Takes in to account AllowMagicianEpicPetLevel as well. Set to 0 to disable requirement")
RULE_STRING(Bots, EpicPetSpellName, "", "'teleport_zone' in the spell to be cast for epic pets. This must be in their spell list to cast.")
RULE_INT(Bots, ReclaimEnergySpellID, 331, "Spell ID for reclaim energy when using ^petsettype. Default 331")
RULE_BOOL(Bots, UseSpellPulling, true, "If enabled bots will use a spell to pull when within range. Uses PullSpellID.")
RULE_INT(Bots, PullSpellID, 5225, "Default 5225 - Throw Stone. Spell that will be cast to pull by bots")
RULE_BOOL(Bots, AllowRangedPulling, true, "If enabled bots will pull with their ranged items if set to ranged.")
+300 -40
View File
@@ -1,4 +1,5 @@
#include "../bot_command.h"
#include "../bot.h"
void bot_command_pet(Client *c, const Seperator *sep)
{
@@ -95,82 +96,175 @@ void bot_command_pet_remove(Client *c, const Seperator *sep)
void bot_command_pet_set_type(Client *c, const Seperator *sep)
{
if (helper_command_alias_fail(c, "bot_command_pet_set_type", sep->arg[0], "petsettype"))
return;
if (helper_is_help_or_usage(sep->arg[1])) {
c->Message(Chat::White, "usage: %s [type: auto | water | fire | air | earth | monster | epic] ([actionable: target | byname] ([actionable_name]))", sep->arg[0]);
c->Message(Chat::White, "if set to 'auto', bots will choose their own pet type");
c->Message(Chat::White, "requires one of the following bot classes:");
c->Message(Chat::White, "Magician(1)");
if (helper_command_alias_fail(c, "bot_command_pet_set_type", sep->arg[0], "petsettype")) {
return;
}
int ab_mask = (ActionableBots::ABM_Target | ActionableBots::ABM_ByName); // this can be expanded without code modification
std::string pet_arg = sep->arg[1];
if (helper_is_help_or_usage(sep->arg[1])) {
std::vector<std::string> description =
{
"Allows you to change the type of pet Magician bots will cast"
};
std::vector<std::string> notes = {};
std::vector<std::string> example_format =
{
fmt::format(
"{} [current | water | fire | air | earth | monster | epic] [actionable, default: target]"
, sep->arg[0]
)
};
std::vector<std::string> examples_one =
{
"To set all spawned bots to use Water pets:",
fmt::format(
"{} fire spawned",
sep->arg[0]
)
};
std::vector<std::string> examples_two =
{
"To set Magelulz to use Fire pets:",
fmt::format(
"{} fire byname Magelulz",
sep->arg[0]
)
};
std::vector<std::string> examples_three =
{
"To check the current pet type for all bots:",
fmt::format(
"{} current spawned",
sep->arg[0]
)
};
std::vector<std::string> actionables =
{
"target, byname, ownergroup, ownerraid, targetgroup, namesgroup, healrotationtargets, mmr, byclass, byrace, spawned"
};
std::vector<std::string> options = { };
std::vector<std::string> options_one = { };
std::vector<std::string> options_two = { };
std::vector<std::string> options_three = { };
std::string popup_text = c->SendCommandHelpWindow(
c,
description,
notes,
example_format,
examples_one, examples_two, examples_three,
actionables,
options,
options_one, options_two, options_three
);
popup_text = DialogueWindow::Table(popup_text);
c->SendPopupToClient(sep->arg[0], popup_text.c_str());
if (RuleB(Bots, SendClassRaceOnHelp)) {
c->Message(
Chat::Yellow,
fmt::format(
"Use {} for information about race/class IDs.",
Saylink::Silent("^classracelist")
).c_str()
);
}
return;
}
std::string arg1 = sep->arg[1];
int ab_arg = 2;
bool current_check = false;
uint8 pet_type = 255;
uint8 level_req = 255;
if (!pet_arg.compare("auto")) {
if (!arg1.compare("auto")) {
pet_type = 0;
level_req = 1;
}
else if (!pet_arg.compare("water")) {
else if (!arg1.compare("water")) {
pet_type = 1;
level_req = 1;
}
else if (!pet_arg.compare("fire")) {
else if (!arg1.compare("fire")) {
pet_type = 2;
level_req = 3;
}
else if (!pet_arg.compare("air")) {
else if (!arg1.compare("air")) {
pet_type = 3;
level_req = 4;
}
else if (!pet_arg.compare("earth")) {
else if (!arg1.compare("earth")) {
pet_type = 4;
level_req = 5;
}
else if (!pet_arg.compare("monster")) {
else if (!arg1.compare("monster")) {
pet_type = 5;
level_req = 30;
}
else if (!pet_arg.compare("epic")) {
pet_type = 6;
else if (!arg1.compare("epic")) {
if (!RuleB(Bots, AllowMagicianEpicPet)) {
c->Message(Chat::Yellow, "Epic pets are currently disabled for bots.");
return;
}
level_req = RuleI(Bots,AllowMagicianEpicPetLevel);
pet_type = 6;
}
else if (!arg1.compare("current")) {
current_check = true;
}
if (pet_type == 255) {
c->Message(Chat::White, "You must specify a pet [type: auto | water | fire | air | earth | monster | epic]");
if (!current_check && pet_type == 255) {
c->Message(
Chat::Yellow,
fmt::format(
"You must specify a pet [type: auto | water | fire | air | earth | monster | epic]. Use {} for information regarding this command.",
Saylink::Silent(
fmt::format("{} help", sep->arg[0])
)
).c_str()
);
return;
}
const int ab_mask = ActionableBots::ABM_Type1;
std::string actionableArg = sep->arg[ab_arg];
if (actionableArg.empty()) {
actionableArg = "target";
}
std::string class_race_arg = sep->arg[ab_arg];
bool class_race_check = false;
if (!class_race_arg.compare("byclass") || !class_race_arg.compare("byrace")) {
class_race_check = true;
}
std::list<Bot*> sbl;
if (ActionableBots::PopulateSBL(c, sep->arg[2], sbl, ab_mask, sep->arg[3]) == ActionableBots::ABT_None)
return;
uint16 class_mask = player_class_bitmasks[Class::Magician];
ActionableBots::Filter_ByClasses(c, sbl, class_mask);
if (sbl.empty()) {
c->Message(Chat::White, "You have no spawned Magician bots");
if (ActionableBots::PopulateSBL(c, actionableArg, sbl, ab_mask, !class_race_check ? sep->arg[ab_arg + 1] : nullptr, class_race_check ? atoi(sep->arg[ab_arg + 1]) : 0) == ActionableBots::ABT_None) {
return;
}
ActionableBots::Filter_ByMinLevel(c, sbl, level_req);
if (sbl.empty()) {
c->Message(Chat::White, "You have no spawned Magician bots capable of using this pet type: '%s'", pet_arg.c_str());
return;
}
sbl.remove(nullptr);
std::string currentType;
uint16 reclaim_energy_id = RuleI(Bots, ReclaimEnergySpellID);
bool isSuccess = false;
uint16 successCount = 0;
Bot* firstFound = nullptr;
uint16 reclaim_energy_id = 331;
for (auto bot_iter : sbl) {
if (!bot_iter)
if (bot_iter->GetClass() != Class::Magician) {
continue;
}
if (RuleI(Bots, RequiredMagicianEpicPetItemID) > 0) {
if (!bot_iter->IsInGroupOrRaid(c)) {
continue;
}
if (pet_type == 6 && RuleI(Bots, RequiredMagicianEpicPetItemID) > 0) {
bool has_item = bot_iter->HasBotItem(RuleI(Bots, RequiredMagicianEpicPetItemID)) != INVALID_INDEX;
if (!has_item) {
@@ -187,11 +281,177 @@ void bot_command_pet_set_type(Client *c, const Seperator *sep)
}
}
if (current_check) {
switch (bot_iter->GetPetChooserID()) {
case 0:
currentType = "auto";
break;
case SumWater:
currentType = "water";
break;
case SumFire:
currentType = "fire";
break;
case SumAir:
currentType = "air";
break;
case SumEarth:
currentType = "earth";
break;
case MonsterSum:
currentType = "monster";
break;
case SumMageMultiElement:
currentType = "epic";
break;
default:
currentType = "null";
break;
}
c->Message(
Chat::Green,
fmt::format(
"{} says, 'I'm currently summoning {} pets.'",
bot_iter->GetCleanName(),
currentType
).c_str()
);
continue;
}
uint8 airMinLevel = 255;
uint8 fireMinLevel = 255;
uint8 waterMinLevel = 255;
uint8 earthMinLevel = 255;
uint8 monsterMinLevel = 255;
uint8 epicMinLevel = 255;
std::list<BotSpell> botSpellList = bot_iter->GetBotSpellsBySpellType(bot_iter, BotSpellTypes::Pet);
for (const auto& s : botSpellList) {
if (!IsValidSpell(s.SpellId)) {
continue;
}
if (!IsEffectInSpell(s.SpellId, SE_SummonPet)) {
continue;
}
auto spell = spells[s.SpellId];
if (!strncmp(spell.teleport_zone, "SumWater", 8) && spell.classes[Class::Magician - 1] < waterMinLevel) {
waterMinLevel = spell.classes[Class::Magician - 1];
}
else if (!strncmp(spell.teleport_zone, "SumFire", 7) && spell.classes[Class::Magician - 1] < fireMinLevel) {
fireMinLevel = spell.classes[Class::Magician - 1];
}
else if (!strncmp(spell.teleport_zone, "SumAir", 6) && spell.classes[Class::Magician - 1] < airMinLevel) {
airMinLevel = spell.classes[Class::Magician - 1];
}
else if (!strncmp(spell.teleport_zone, "SumEarth", 8) && spell.classes[Class::Magician - 1] < earthMinLevel) {
earthMinLevel = spell.classes[Class::Magician - 1];
}
else if (!strncmp(spell.teleport_zone, "MonsterSum", 10) && spell.classes[Class::Magician - 1] < monsterMinLevel) {
monsterMinLevel = spell.classes[Class::Magician - 1];
}
}
uint8 minLevel = std::min({
waterMinLevel,
fireMinLevel,
airMinLevel,
earthMinLevel,
monsterMinLevel
});
epicMinLevel = RuleI(Bots, AllowMagicianEpicPetLevel);
LogTestDebug("{} says, 'minLevel = {} | waterMinLevel = {} | fireMinLevel = {} | airMinLevel = {} | earthMinLevel = {} | monsterMinLevel = {} | epicMinLevel = {}'",
bot_iter->GetCleanName(),
minLevel,
waterMinLevel,
fireMinLevel,
airMinLevel,
earthMinLevel,
monsterMinLevel,
epicMinLevel
); //deleteme
switch (pet_type) {
case 0:
level_req = minLevel;
break;
case SumWater:
level_req = waterMinLevel;
break;
case SumFire:
level_req = fireMinLevel;
break;
case SumAir:
level_req = airMinLevel;
break;
case SumEarth:
level_req = earthMinLevel;
break;
case MonsterSum:
level_req = monsterMinLevel;
break;
case SumMageMultiElement:
level_req = epicMinLevel;
break;
default:
break;
}
if (bot_iter->GetLevel() < level_req) {
continue;
}
bot_iter->SetPetChooserID(pet_type);
if (bot_iter->GetPet()) {
auto pet_id = bot_iter->GetPetID();
bot_iter->SetPetID(0);
bot_iter->CastSpell(reclaim_energy_id, pet_id);
}
if (!firstFound) {
firstFound = bot_iter;
}
isSuccess = true;
++successCount;
}
if (current_check) {
return;
}
if (!isSuccess) {
c->Message(Chat::Yellow, "No bots were selected.");
return;
}
if (successCount == 1 && firstFound) {
c->Message(
Chat::Green,
fmt::format(
"{} says, 'I will now summon {} pets.'",
firstFound->GetCleanName(),
currentType
).c_str()
);
}
else {
c->Message(
Chat::Green,
fmt::format(
"{} of your bots will now summon {} pets.",
successCount,
arg1
).c_str()
);
}
}
+86 -44
View File
@@ -1541,9 +1541,17 @@ std::string Bot::GetBotMagicianPetType(Bot* botCaster) {
std::string result;
if (botCaster) {
uint8 petType = botCaster->GetPetChooserID();
uint8 botLevel = botCaster->GetLevel();
bool epicAllowed = false;
std::string epicSpellName = RuleS(Bots, EpicPetSpellName);
if (epicSpellName.empty()) {
epicSpellName = "SumMageMultiElement";
}
if (RuleB(Bots, AllowMagicianEpicPet)) {
if (botCaster->GetLevel() >= RuleI(Bots, AllowMagicianEpicPetLevel)) {
if (botLevel >= RuleI(Bots, AllowMagicianEpicPetLevel)) {
if (!RuleI(Bots, RequiredMagicianEpicPetItemID)) {
epicAllowed = true;
}
@@ -1557,8 +1565,8 @@ std::string Bot::GetBotMagicianPetType(Bot* botCaster) {
}
}
if (botCaster->GetPetChooserID() > 0) {
switch (botCaster->GetPetChooserID()) {
if (petType > 0) {
switch (petType) {
case SumWater:
result = std::string("SumWater");
break;
@@ -1576,66 +1584,100 @@ std::string Bot::GetBotMagicianPetType(Bot* botCaster) {
break;
case SumMageMultiElement:
if (epicAllowed) {
result = std::string(RuleS(Bots, EpicPetSpellName));
if (result.empty()) {
result = "SumMageMultiElement";
}
result = epicSpellName;
}
else {
result = std::string("MonsterSum");
botCaster->SetPetChooserID(0);
}
break;
}
}
else {
if (epicAllowed) {
result = std::string(RuleS(Bots, EpicPetSpellName));
uint8 airMinLevel = 255;
uint8 fireMinLevel = 255;
uint8 waterMinLevel = 255;
uint8 earthMinLevel = 255;
uint8 monsterMinLevel = 255;
uint8 epicMinLevel = 255;
std::list<BotSpell> botSpellList = botCaster->GetBotSpellsBySpellType(botCaster, BotSpellTypes::Pet);
if (result.empty()) {
result = "SumMageMultiElement";
for (const auto& s : botSpellList) {
if (!IsValidSpell(s.SpellId)) {
continue;
}
if (!IsEffectInSpell(s.SpellId, SE_SummonPet)) {
continue;
}
auto spell = spells[s.SpellId];
if (!strncmp(spell.teleport_zone, "SumWater", 8) && spell.classes[Class::Magician - 1] < waterMinLevel) {
waterMinLevel = spell.classes[Class::Magician - 1];
}
else if (!strncmp(spell.teleport_zone, "SumFire", 7) && spell.classes[Class::Magician - 1] < fireMinLevel) {
fireMinLevel = spell.classes[Class::Magician - 1];
}
else if (!strncmp(spell.teleport_zone, "SumAir", 6) && spell.classes[Class::Magician - 1] < airMinLevel) {
airMinLevel = spell.classes[Class::Magician - 1];
}
else if (!strncmp(spell.teleport_zone, "SumEarth", 8) && spell.classes[Class::Magician - 1] < earthMinLevel) {
earthMinLevel = spell.classes[Class::Magician - 1];
}
else if (!strncmp(spell.teleport_zone, "MonsterSum", 10) && spell.classes[Class::Magician - 1] < monsterMinLevel) {
monsterMinLevel = spell.classes[Class::Magician - 1];
}
else if (!strncmp(spell.teleport_zone, epicSpellName.c_str(), epicSpellName.length()) && spell.classes[Class::Magician - 1] < epicMinLevel) {
epicMinLevel = spell.classes[Class::Magician - 1];
}
}
if (epicAllowed) {
epicMinLevel = std::max(int(epicMinLevel), RuleI(Bots, AllowMagicianEpicPetLevel));
if (botLevel >= epicMinLevel) {
result = epicSpellName;
}
}
else {
if (botCaster->GetLevel() == 2) {
result = std::string("SumWater");
}
else if (botCaster->GetLevel() == 3) {
result = std::string("SumFire");
}
else if (botCaster->GetLevel() == 4) {
result = std::string("SumAir");
}
else if (botCaster->GetLevel() == 5) {
result = std::string("SumEarth");
}
else {
int counter;
bool found = false;
uint8 count = 0;
if (botCaster->GetLevel() < 30) {
counter = zone->random.Int(1, 4);
}
else {
counter = zone->random.Int(1, 5);
}
while (count <= 4 && !found) {
int counter = zone->random.Int(1, 4);
switch (counter) {
case 1:
result = std::string("SumWater");
case SumWater:
if (botLevel >= waterMinLevel) {
result = std::string("SumWater");
}
found = true;
break;
case 2:
result = std::string("SumFire");
case SumFire:
if (botLevel >= fireMinLevel) {
result = std::string("SumFire");
}
found = true;
break;
case 3:
result = std::string("SumAir");
case SumAir:
if (botLevel >= airMinLevel) {
result = std::string("SumAir");
}
found = true;
break;
case 4:
result = std::string("SumEarth");
break;
default:
result = std::string("MonsterSum");
case SumEarth:
if (botLevel >= earthMinLevel) {
result = std::string("SumEarth");
}
found = true;
break;
}
++count;
}
}
}