Implement ^discipline

This commit is contained in:
nytmyr
2024-12-29 20:01:18 -06:00
parent 1c01b716d5
commit a0c2abfedf
10 changed files with 1311 additions and 50 deletions
+72 -38
View File
@@ -10826,7 +10826,13 @@ bool Bot::AttemptAICastSpell(uint16 spellType, Mob* tar) {
}
bool Bot::AttemptAACastSpell(Mob* tar, uint16 spell_id, AA::Rank* rank) {
if (!tar || spells[spell_id].target_type == ST_Self) {
if (!IsValidSpell(spell_id)) {
return false;
}
SPDat_Spell_Struct spell = spells[spell_id];
if (!tar || spell.target_type == ST_Self) {
tar = this;
}
@@ -10854,7 +10860,7 @@ bool Bot::AttemptAACastSpell(Mob* tar, uint16 spell_id, AA::Rank* rank) {
}
if (!CastChecks(spell_id, tar, UINT16_MAX)) {
GetBotOwner()->Message(Chat::Red, "%s says, 'Ability failed to cast. This could be due to this to any number of things: range, mana, immune, etc.'", GetCleanName());
GetBotOwner()->Message(Chat::Red, "%s says, 'Ability failed to cast. This could be due to this to any number of things: range, mana, immune, target type, etc.'", GetCleanName());
return false;
}
@@ -10866,7 +10872,7 @@ bool Bot::AttemptAACastSpell(Mob* tar, uint16 spell_id, AA::Rank* rank) {
fmt::format(
"Interrupting {}. I have been commanded to try to cast an AA - {} on {}.",
CastingSpellID() ? spells[CastingSpellID()].name : "my spell",
spells[spell_id].name,
spell.name,
tar->GetCleanName()
).c_str()
);
@@ -10893,7 +10899,7 @@ bool Bot::AttemptAACastSpell(Mob* tar, uint16 spell_id, AA::Rank* rank) {
SetSpellRecastTimer(spell_id, timer_duration);
}
else {
GetBotOwner()->Message(Chat::Red, "%s says, 'Ability failed to cast. This could be due to this to any number of things: range, mana, immune, etc.'", GetCleanName());
GetBotOwner()->Message(Chat::Red, "%s says, 'Ability failed to cast. This could be due to this to any number of things: range, mana, immune, target type, etc.'", GetCleanName());
return false;
}
@@ -10914,24 +10920,26 @@ bool Bot::AttemptAACastSpell(Mob* tar, uint16 spell_id, AA::Rank* rank) {
return true;
}
bool Bot::AttemptForcedCastSpell(Mob* tar, uint16 spell_id) {
SPDat_Spell_Struct spell = spells[spell_id];
uint16 forcedSpellID = spell.id;
bool Bot::AttemptForcedCastSpell(Mob* tar, uint16 spell_id, bool isDisc) {
if (!IsValidSpell(spell_id)) {
return false;
}
if (!tar || (spells[spell_id].target_type == ST_Self && tar != this)) {
LogTestDebug("{} set my target to myself for {} [#{}] due to !tar.", GetCleanName(), spell.name, forcedSpellID); //deleteme
SPDat_Spell_Struct spell = spells[spell_id];
if (!tar || (spell.target_type == ST_Self && tar != this)) {
tar = this;
}
if ((IsCharmSpell(forcedSpellID) || IsPetSpell(forcedSpellID) && HasPet())) {
if ((IsCharmSpell(spell_id) || IsPetSpell(spell_id) && HasPet())) {
return false;
}
if (IsResurrectSpell(forcedSpellID) && (!tar->IsCorpse() || !tar->CastToCorpse()->IsPlayerCorpse())) {
if (IsResurrectSpell(spell_id) && (!tar->IsCorpse() || !tar->CastToCorpse()->IsPlayerCorpse())) {
return false;
}
if (IsBeneficialSpell(forcedSpellID)) {
if (IsBeneficialSpell(spell_id)) {
if (
(tar->IsNPC() && !tar->GetOwner()) ||
(tar->GetOwner() && tar->GetOwner()->IsOfClientBot() && !GetBotOwner()->IsInGroupOrRaid(tar->GetOwner())) ||
@@ -10949,7 +10957,7 @@ bool Bot::AttemptForcedCastSpell(Mob* tar, uint16 spell_id) {
}
}
if (IsDetrimentalSpell(forcedSpellID) && (!GetBotOwner()->IsAttackAllowed(tar) || !IsAttackAllowed(tar))) {
if (IsDetrimentalSpell(spell_id) && (!GetBotOwner()->IsAttackAllowed(tar) || !IsAttackAllowed(tar))) {
GetBotOwner()->Message(
Chat::Yellow,
fmt::format(
@@ -10962,32 +10970,35 @@ bool Bot::AttemptForcedCastSpell(Mob* tar, uint16 spell_id) {
return false;
}
if (!CheckSpellRecastTimer(forcedSpellID)) {
LogTestDebug("{} failed CheckSpellRecastTimer for {} [#{}].", GetCleanName(), spell.name, forcedSpellID); //deleteme
return false;
if (!isDisc) {
if (!CheckSpellRecastTimer(spell_id)) {
return false;
}
}
if (
!RuleB(Bots, EnableBotTGB) &&
IsGroupSpell(forcedSpellID) &&
!IsTGBCompatibleSpell(forcedSpellID) &&
!IsInGroupOrRaid(tar, true)
!IsInGroupOrRaid(tar, true) &&
(
!RuleB(Bots, EnableBotTGB) ||
(
IsGroupSpell(spell_id) &&
!IsTGBCompatibleSpell(spell_id)
)
)
) {
LogTestDebug("{} failed TGB for {} [#{}].", GetCleanName(), spell.name, forcedSpellID); //deleteme
LogTestDebug("{} failed TGB for {} [#{}].", GetCleanName(), spell.name, spell_id); //deleteme
return false;
}
if (!DoLosChecks(this, tar)) {
LogTestDebug("{} failed LoS for {} [#{}].", GetCleanName(), spell.name, forcedSpellID); //deleteme
return false;
}
if (!CastChecks(forcedSpellID, tar, UINT16_MAX)) {
LogTestDebug("{} failed CastChecks for {} [#{}].", GetCleanName(), spell.name, forcedSpellID); //deleteme
if (!CastChecks(spell_id, tar, UINT16_MAX)) {
GetBotOwner()->Message(
Chat::Red,
fmt::format(
"{} says, 'Ability failed to cast. This could be due to this to any number of things: range, mana, immune, etc.'",
"{} says, 'Ability failed to cast. This could be due to this to any number of things: range, mana, immune, target type, etc.'",
GetBotOwner()->GetCleanName()
).c_str()
);
@@ -11009,27 +11020,53 @@ bool Bot::AttemptForcedCastSpell(Mob* tar, uint16 spell_id) {
InterruptSpell();
}
if (CastSpell(forcedSpellID, tar->GetID())) {
if (CastSpell(spell_id, tar->GetID())) {
BotGroupSay(
this,
fmt::format(
"Casting {} on {}.",
GetSpellName(forcedSpellID),
GetSpellName(spell_id),
(tar == this ? "myself" : tar->GetCleanName())
).c_str()
);
int timer_duration = CalcBuffDuration(tar, this, forcedSpellID);
int timer_duration = 0;
if (timer_duration) { // negatives are perma buffs
timer_duration = GetActSpellDuration(forcedSpellID, timer_duration);
if (!isDisc) {
timer_duration = CalcBuffDuration(tar, this, spell_id);
if (timer_duration) {
timer_duration = GetActSpellDuration(spell_id, timer_duration);
}
if (timer_duration < 0) {
timer_duration = 0;
}
}
else {
if (spell.recast_time > 0) {
timer_duration = spell.recast_time / 1000;
auto focus = GetFocusEffect(focusReduceRecastTime, spell_id);
if (focus > timer_duration) {
timer_duration = 0;
}
else {
timer_duration -= focus;
}
}
if (timer_duration > 0) {
timer_duration = timer_duration * 1000;
}
}
if (timer_duration < 0) {
timer_duration = 0;
if (!isDisc) {
SetSpellRecastTimer(spell_id, timer_duration);
}
else {
SetDisciplineReuseTimer(spell_id, timer_duration);
}
SetSpellRecastTimer(forcedSpellID, timer_duration);
return true;
}
@@ -11804,7 +11841,7 @@ uint16 Bot::GetSpellByAA(int id, AA::Rank*& rank) {
}
uint32 points = GetAA(ability->first_rank_id);
//if (points) { LogTestDebug("{}: {} says, '{} points for {} [#{} - {}] rank {}'", __LINE__, GetCleanName(), points, zone->GetAAName(aa_ability.first->id), aa_ability.first->id, aa_ability.second->id, points); } //deleteme
if (points > 0) {
aa_ability = zone->GetAlternateAdvancementAbilityAndRank(ability->id, points);
}
@@ -11812,14 +11849,11 @@ uint16 Bot::GetSpellByAA(int id, AA::Rank*& rank) {
rank = aa_ability.second;
if (!points || !rank) {
LogTestDebug("{}: {} says, 'No {} found'", __LINE__, GetCleanName(), (!points ? "points" : "rank")); //deleteme
return spell_id;
}
spell_id = rank->spell;
LogTestDebug("{}: {} says, 'Found {} [#{}]'", __LINE__, GetCleanName(), spells[spell_id].name, spell_id); //deleteme
return spell_id;
}
+1 -1
View File
@@ -401,7 +401,7 @@ public:
bool AICastSpell(Mob* tar, uint8 iChance, uint16 spellType, uint16 subTargetType = UINT16_MAX, uint16 subType = UINT16_MAX);
bool AttemptAICastSpell(uint16 spellType, Mob* tar = nullptr);
bool AttemptAACastSpell(Mob* tar, uint16 spell_id, AA::Rank* rank);
bool AttemptForcedCastSpell(Mob* tar, uint16 spell_id);
bool AttemptForcedCastSpell(Mob* tar, uint16 spell_id, bool isDisc = false);
bool AttemptCloseBeneficialSpells(uint16 spellType);
bool AI_EngagedCastCheck() override;
bool AI_PursueCastCheck() override;
+2
View File
@@ -1286,6 +1286,7 @@ int bot_command_init(void)
bot_command_add("botupdate", "Updates a bot to reflect any level changes that you have experienced", AccountStatus::Player, bot_command_update) ||
bot_command_add("botwoad", "Changes the Barbarian woad of a bot", AccountStatus::Player, bot_command_woad) ||
bot_command_add("cast", "Tells the first found specified bot to cast the given spell type", AccountStatus::Player, bot_command_cast) ||
bot_command_add("discipline", "Uses aggressive/defensive disciplines or can specify spell ID", AccountStatus::Player, bot_command_discipline) ||
bot_command_add("distanceranged", "Controls the range casters and ranged will try to stay away from a mob", AccountStatus::Player, bot_command_distance_ranged) ||
bot_command_add("classracelist", "Lists the classes and races and their appropriate IDs", AccountStatus::Player, bot_command_class_race_list) ||
bot_command_add("clickitem", "Orders your targeted bot to click the item in the provided inventory slot.", AccountStatus::Player, bot_command_click_item) ||
@@ -2222,6 +2223,7 @@ void SendSpellTypeWindow(Client* c, const Seperator* sep) {
#include "bot_commands/default_settings.cpp"
#include "bot_commands/defensive.cpp"
#include "bot_commands/depart.cpp"
#include "bot_commands/discipline.cpp"
#include "bot_commands/distance_ranged.cpp"
#include "bot_commands/find_aliases.cpp"
#include "bot_commands/follow.cpp"
+1
View File
@@ -1673,6 +1673,7 @@ void bot_command_blocked_pet_buffs(Client* c, const Seperator* sep);
void bot_command_bot(Client *c, const Seperator *sep);
void bot_command_bot_settings(Client* c, const Seperator* sep);
void bot_command_cast(Client* c, const Seperator* sep);
void bot_command_discipline(Client* c, const Seperator* sep);
void bot_command_distance_ranged(Client* c, const Seperator* sep);
void bot_command_class_race_list(Client* c, const Seperator* sep);
void bot_command_click_item(Client* c, const Seperator* sep);
+3 -5
View File
@@ -184,7 +184,7 @@ void bot_command_cast(Client* c, const Seperator* sep)
uint16 chosenSpellID = UINT16_MAX;
if (!arg1.compare("aa") || !arg1.compare("harmtouch") || !arg1.compare("layonhands")) {
if (!RuleB(Bots, AllowForcedCastsBySpellID)) {
if (!RuleB(Bots, AllowCastAAs)) {
c->Message(Chat::Yellow, "This commanded type is currently disabled.");
return;
}
@@ -208,7 +208,7 @@ void bot_command_cast(Client* c, const Seperator* sep)
}
if (!arg1.compare("spellid")) {
if (!RuleB(Bots, AllowCastAAs)) {
if (!RuleB(Bots, AllowForcedCastsBySpellID)) {
c->Message(Chat::Yellow, "This commanded type is currently disabled.");
return;
}
@@ -561,13 +561,11 @@ void bot_command_cast(Client* c, const Seperator* sep)
continue;
}
else if (bySpellID) {
SPDat_Spell_Struct spell = spells[chosenSpellID];
if (!bot_iter->CanUseBotSpell(chosenSpellID)) {
continue;
}
if (!tar || (spell.target_type == ST_Self && tar != bot_iter)) {
if (!tar || (spells[chosenSpellID].target_type == ST_Self && tar != bot_iter)) {
tar = bot_iter;
}
+296
View File
@@ -0,0 +1,296 @@
#include "../bot_command.h"
void bot_command_discipline(Client* c, const Seperator* sep)
{
if (helper_command_alias_fail(c, "bot_command_discipline", sep->arg[0], "discipline")) {
return;
}
if (helper_is_help_or_usage(sep->arg[1])) {
std::vector<std::string> description =
{
"Tells applicable bots to use the specified disciplines"
};
std::vector<std::string> notes = { };
std::vector<std::string> example_format =
{
fmt::format(
"{} [aggressive | defensive | spell ID] [actionable, default: spawned]"
, sep->arg[0]
)
};
std::vector<std::string> examples_one =
{
"To tell all bots to use an aggressive discipline:",
fmt::format(
"{} aggressive spawned",
sep->arg[0]
)
};
std::vector<std::string> examples_two =
{
"To tell Warrior bots to use a defensive discipline:",
fmt::format(
"{} defensive byclass {}",
sep->arg[0],
Class::Warrior
)
};
std::vector<std::string> examples_three =
{
"To tell all bots to use their Fearless discipline:",
fmt::format(
"{} 4587 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];
std::string arg2 = sep->arg[2];
int ab_arg = 2;
bool aggressive = false;
bool defensive = false;
Mob* tar = c->GetTarget();
uint16 spell_id = UINT16_MAX;
if (!arg1.compare("aggressive")) {
aggressive = true;
}
else if (!arg1.compare("defensive")) {
defensive = true;
}
else if (sep->IsNumber(1)) {
if (!IsValidSpell(atoi(sep->arg[1]))) {
c->Message(Chat::Yellow, "You must enter a valid spell ID.");
return;
}
spell_id = atoi(sep->arg[1]);
}
else {
c->Message(
Chat::Yellow,
fmt::format(
"Incorrect argument, 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 = "spawned";
}
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::vector<Bot*> sbl;
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;
}
sbl.erase(std::remove(sbl.begin(), sbl.end(), nullptr), sbl.end());
bool isSuccess = false;
uint16 successCount = 0;
Bot* firstFound = nullptr;
for (auto bot_iter : sbl) {
if (!bot_iter->IsInGroupOrRaid(c)) {
continue;
}
if (bot_iter->GetBotStance() == Stance::Passive || bot_iter->GetHoldFlag() || bot_iter->GetAppearance() == eaDead || bot_iter->IsFeared() || bot_iter->IsSilenced() || bot_iter->IsAmnesiad() || bot_iter->GetHP() < 0) {
continue;
}
if (spell_id == UINT16_MAX) { // Aggressive/Defensive type
std::vector<BotSpells_Struct_wIndex> botSpellList;
if (aggressive) {
botSpellList = bot_iter->BotGetSpellsByType(BotSpellTypes::DiscAggressive);
}
else if (defensive) {
botSpellList = bot_iter->BotGetSpellsByType(BotSpellTypes::DiscDefensive);
}
for (int i = botSpellList.size() - 1; i >= 0; i--) {
if (!IsValidSpell(botSpellList[i].spellid)) {
continue;
}
if (!bot_iter->CheckDisciplineReuseTimer(botSpellList[i].spellid)) {
uint32 remaining_time = (bot_iter->GetDisciplineReuseRemainingTime(botSpellList[i].spellid) / 1000);
bot_iter->OwnerMessage(
fmt::format(
"I can use this discipline in {}.",
Strings::SecondsToTime(remaining_time)
)
);
continue;
}
if (bot_iter->GetEndurance() < spells[botSpellList[i].spellid].endurance_cost) {
continue;
}
if (bot_iter->DivineAura() && !IsCastNotStandingSpell(botSpellList[i].spellid)) {
continue;
}
if (spells[botSpellList[i].spellid].buff_duration_formula != 0 && spells[botSpellList[i].spellid].target_type == ST_Self && bot_iter->HasDiscBuff()) {
continue;
}
if (!tar || (spells[botSpellList[i].spellid].target_type == ST_Self && tar != bot_iter)) {
tar = bot_iter;
}
if (bot_iter->AttemptForcedCastSpell(tar, botSpellList[i].spellid, true)) {
if (!firstFound) {
firstFound = bot_iter;
}
isSuccess = true;
++successCount;
spell_id = botSpellList[i].spellid;
}
}
}
else { // Direct spell ID
if (!IsValidSpell(spell_id)) {
continue;
}
SPDat_Spell_Struct spell = spells[spell_id];
if (!bot_iter->CanUseBotSpell(spell_id)) {
continue;
}
if (!bot_iter->CheckDisciplineReuseTimer(spell_id)) {
uint32 remaining_time = (bot_iter->GetDisciplineReuseRemainingTime(spell_id) / 1000);
bot_iter->OwnerMessage(
fmt::format(
"I can use this item in {}.",
Strings::SecondsToTime(remaining_time)
)
);
continue;
}
if (bot_iter->GetEndurance() < spell.endurance_cost) {
continue;
}
if (bot_iter->DivineAura() && !IsCastNotStandingSpell(spell_id)) {
continue;
}
if (spell.buff_duration_formula != 0 && spell.target_type == ST_Self && bot_iter->HasDiscBuff()) {
continue;
}
if (!tar || (spell.target_type == ST_Self && tar != bot_iter)) {
tar = bot_iter;
}
if (bot_iter->AttemptForcedCastSpell(tar, spell_id, true)) {
if (!firstFound) {
firstFound = bot_iter;
}
isSuccess = true;
++successCount;
}
}
continue;
}
if (!isSuccess) {
c->Message(Chat::Yellow, "No bots were selected.");
}
else {
if (aggressive || defensive) {
c->Message(
Chat::Yellow,
fmt::format(
"{} {} {} {} discipline.",
((successCount == 1 && firstFound) ? firstFound->GetCleanName() : (fmt::format("{}", successCount).c_str())),
((successCount == 1 && firstFound) ? "used" : "of your bots used"),
(aggressive ? "an" : "a"),
(aggressive ? "aggressive" : "defensive")
).c_str()
);
}
else {
c->Message(
Chat::Yellow,
fmt::format(
"{} {} their {} [#{}] discipline.",
((successCount == 1 && firstFound) ? firstFound->GetCleanName() : (fmt::format("{}", successCount).c_str())),
((successCount == 1 && firstFound) ? "used" : "of your bots used"),
spells[spell_id].name,
spell_id
).c_str()
);
}
}
}
+21 -5
View File
@@ -649,6 +649,10 @@ bool Bot::AI_PursueCastCheck() {
continue;
}
if (AIBot_spells_by_type[currentCast.spellType].empty()) {
continue;
}
result = AttemptAICastSpell(currentCast.spellType, nullptr);
if (!result && IsBotSpellTypeBeneficial(currentCast.spellType)) {
@@ -721,6 +725,10 @@ bool Bot::AI_IdleCastCheck() {
continue;
}
if (AIBot_spells_by_type[currentCast.spellType].empty()) {
continue;
}
result = AttemptAICastSpell(currentCast.spellType, nullptr);
if (result) {
@@ -778,6 +786,10 @@ bool Bot::AI_EngagedCastCheck() {
continue;
}
if (AIBot_spells_by_type[currentCast.spellType].empty()) {
continue;
}
result = AttemptAICastSpell(currentCast.spellType, nullptr);
if (!result && IsBotSpellTypeBeneficial(currentCast.spellType)) {
@@ -1041,11 +1053,15 @@ std::vector<BotSpell_wPriority> Bot::GetPrioritizedBotSpellsBySpellType(Bot* bot
}
if (
!RuleB(Bots, EnableBotTGB) &&
IsGroupSpell(botSpellList[i].spellid) &&
!IsTGBCompatibleSpell(botSpellList[i].spellid) &&
!botCaster->IsInGroupOrRaid(tar, true)
) {
!botCaster->IsInGroupOrRaid(tar, true) &&
(
!RuleB(Bots, EnableBotTGB) ||
(
IsGroupSpell(botSpellList[i].spellid) &&
!IsTGBCompatibleSpell(botSpellList[i].spellid)
)
)
) {
continue;
}