From 665d7e3641717abce65374acad59b8019e54141a Mon Sep 17 00:00:00 2001 From: nytmyr <53322305+nytmyr@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:50:07 -0600 Subject: [PATCH] Combine GatherGroupSpellTargets and GatherSpellTargets --- zone/bot.cpp | 107 ++++++++----------------------------------- zone/bot.h | 3 +- zone/botspellsai.cpp | 27 +++-------- 3 files changed, 26 insertions(+), 111 deletions(-) diff --git a/zone/bot.cpp b/zone/bot.cpp index d2c928673..a9f455a30 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -6007,12 +6007,7 @@ bool Bot::DoFinishedSpellSingleTarget(uint16 spell_id, Mob* spellTarget, EQ::spe if (!noGroupSpell) { std::vector v; - if (RuleB(Bots, RaidBuffing)) { - v = GatherSpellTargets(true); - } - else { - v = GatherGroupSpellTargets(); - } + v = GatherSpellTargets(RuleB(Bots, RaidBuffing)); for (Mob* m : v) { if (IsEffectInSpell(thespell, SE_AbsorbMagicAtt) || IsEffectInSpell(thespell, SE_Rune)) { @@ -6072,7 +6067,7 @@ bool Bot::DoFinishedSpellGroupTarget(uint16 spell_id, Mob* spellTarget, EQ::spel v = GatherSpellTargets(true); } else { - v = GatherGroupSpellTargets(spellTarget); + v = GatherSpellTargets(false, spellTarget); } for (Mob* m : v) { @@ -9287,74 +9282,11 @@ void Bot::DoItemClick(const EQ::ItemData *item, uint16 slot_id) uint8 Bot::spell_casting_chances[SPELL_TYPE_COUNT][Class::PLAYER_CLASS_COUNT][Stance::AEBurn][cntHSND] = { 0 }; -std::vector Bot::GatherGroupSpellTargets(Mob* target, bool noClients, bool noBots) { +std::vector Bot::GatherSpellTargets(bool entireRaid, Mob* target, bool noClients, bool noBots, bool noPets) { std::vector valid_spell_targets; if (IsRaidGrouped()) { - if (auto raid = entity_list.GetRaidByBotName(GetName())) { - std::vector raidGroupMembers; - if (target) { - auto raidGroup = raid->GetGroup(target->GetName()); - - if (raidGroup != RAID_GROUPLESS) { - raidGroupMembers = raid->GetRaidGroupMembers(raidGroup); - } - else { - return valid_spell_targets; - } - } - else { - auto raidGroup = raid->GetGroup(GetName()); - - if (raidGroup != RAID_GROUPLESS) { - raidGroupMembers = raid->GetRaidGroupMembers(raidGroup); - } - else { - return valid_spell_targets; - } - } - - for (const auto& m : raidGroupMembers) { - if ( - m.member && m.group_number != RAID_GROUPLESS && - ( - (m.member->IsClient() && !noClients) || - (m.member->IsBot() && !noBots) - ) - ) { - valid_spell_targets.emplace_back(m.member); - } - } - } - } - else if (IsGrouped()) { - Group* group = GetGroup(); - if (group) { - for (const auto& m : group->members) { - if ( - m && - ( - (m->IsClient() && !noClients) || - (m->IsBot() && !noBots) - ) - ) { - valid_spell_targets.emplace_back(m); - } - } - } - } - else { - valid_spell_targets.emplace_back(this); - } - - return valid_spell_targets; -} - -std::vector Bot::GatherSpellTargets(bool entireRaid, bool noClients, bool noBots, bool noPets) { - std::vector valid_spell_targets; - - if (IsRaidGrouped()) { - if (auto raid = entity_list.GetRaidByBotName(GetName())) { + if (auto raid = GetRaid()) { if (entireRaid) { for (const auto& m : raid->members) { if (m.member && m.group_number != RAID_GROUPLESS && ((m.member->IsClient() && !noClients) || (m.member->IsBot() && !noBots))) { @@ -9363,8 +9295,15 @@ std::vector Bot::GatherSpellTargets(bool entireRaid, bool noClients, bool } } else { - std::vector raidGroup = raid->GetRaidGroupMembers(raid->GetGroup(GetName())); + std::vector raidGroup; + if (target) { + raidGroup = raid->GetRaidGroupMembers(raid->GetGroup(target->GetName())); + } + else { + raidGroup = raid->GetRaidGroupMembers(raid->GetGroup(GetName())); + } + for (const auto& m : raidGroup) { if (m.member && m.group_number != RAID_GROUPLESS && ((m.member->IsClient() && !noClients) || (m.member->IsBot() && !noBots))) { valid_spell_targets.emplace_back(m.member); @@ -9375,6 +9314,7 @@ std::vector Bot::GatherSpellTargets(bool entireRaid, bool noClients, bool } else if (IsGrouped()) { Group* group = GetGroup(); + if (group) { for (const auto& m : group->members) { if (m && ((m->IsClient() && !noClients) || (m->IsBot() && !noBots))) { @@ -9384,9 +9324,9 @@ std::vector Bot::GatherSpellTargets(bool entireRaid, bool noClients, bool } } else { - valid_spell_targets.emplace_back(this); + valid_spell_targets.emplace_back(this); } - + return valid_spell_targets; } @@ -9832,24 +9772,15 @@ bool Bot::BotHasEnoughMana(uint16 spell_id) { } bool Bot::IsTargetAlreadyReceivingSpell(Mob* tar, uint16 spell_id) { - if (!tar || !spell_id) { return true; } - if (IsNPC() && CastToNPC()->GetSwarmOwner()) { - return true; - } - std::vector v; - - if (RuleB(Bots, CrossRaidBuffingAndHealing)) { - v = GatherSpellTargets(true); - } - else { - v = GatherGroupSpellTargets(); - } - + uint16 targetID = tar->GetID(); + + v = GatherSpellTargets(RuleB(Bots, CrossRaidBuffingAndHealing)); + for (Mob* m : v) { if ( m->IsBot() && diff --git a/zone/bot.h b/zone/bot.h index d365d2431..d9340e8a1 100644 --- a/zone/bot.h +++ b/zone/bot.h @@ -455,8 +455,7 @@ public: { return Mob::Attack(other, Hand, FromRiposte, IsStrikethrough, IsFromSpell, opts); } void DoAttackRounds(Mob* target, int hand); - std::vector GatherGroupSpellTargets(Mob* target = nullptr, bool noClients = false, bool noBots = false); - std::vector GatherSpellTargets(bool entireRaid = false, bool noClients = false, bool noBots = false, bool noPets = false); + std::vector GatherSpellTargets(bool entireRaid = false, Mob* target = nullptr, bool noClients = false, bool noBots = false, bool noPets = false); bool PrecastChecks(Mob* tar, uint16 spellType); bool CastChecks(uint16 spell_id, Mob* tar, uint16 spellType, bool doPrechecks = false, bool AECheck = false); diff --git a/zone/botspellsai.cpp b/zone/botspellsai.cpp index b2705023e..b5ea1766d 100644 --- a/zone/botspellsai.cpp +++ b/zone/botspellsai.cpp @@ -350,7 +350,7 @@ bool Bot::BotCastCure(Mob* tar, uint8 botClass, BotSpell& botSpell, uint16 spell ).c_str() ); - const std::vector v = GatherGroupSpellTargets(tar); + const std::vector v = GatherSpellTargets(false, tar); if (!IsCommandedSpell()) { @@ -533,7 +533,7 @@ bool Bot::BotCastHeal(Mob* tar, uint8 botClass, BotSpell& botSpell, uint16 spell ); if (botClass != Class::Bard) { - const std::vector v = GatherGroupSpellTargets(tar); + const std::vector v = GatherSpellTargets(false, tar); if (!IsCommandedSpell()) { for (Mob* m : v) { @@ -1264,12 +1264,7 @@ BotSpell Bot::GetBestBotSpellForGroupHeal(Bot* botCaster, Mob* tar, uint16 spell std::list botSpellList = GetBotSpellsForSpellEffect(botCaster, spellType, SE_CurrentHP); std::vector v; - if (RuleB(Bots, CrossRaidBuffingAndHealing)) { - v = botCaster->GatherSpellTargets(true); - } - else { - v = botCaster->GatherGroupSpellTargets(); - } + v = botCaster->GatherSpellTargets(RuleB(Bots, CrossRaidBuffingAndHealing)); int targetCount = 0; @@ -1313,12 +1308,7 @@ BotSpell Bot::GetBestBotSpellForGroupHealOverTime(Bot* botCaster, Mob* tar, uint std::list botSpellList = GetBotSpellsForSpellEffect(botCaster, spellType, SE_HealOverTime); std::vector v; - if (RuleB(Bots, CrossRaidBuffingAndHealing)) { - v = botCaster->GatherSpellTargets(true); - } - else { - v = botCaster->GatherGroupSpellTargets(); - } + v = botCaster->GatherSpellTargets(RuleB(Bots, CrossRaidBuffingAndHealing)); int targetCount = 0; @@ -1362,12 +1352,7 @@ BotSpell Bot::GetBestBotSpellForGroupCompleteHeal(Bot* botCaster, Mob* tar, uint std::list botSpellList = GetBotSpellsForSpellEffect(botCaster, spellType, SE_CompleteHeal); std::vector v; - if (RuleB(Bots, CrossRaidBuffingAndHealing)) { - v = botCaster->GatherSpellTargets(true); - } - else { - v = botCaster->GatherGroupSpellTargets(); - } + v = botCaster->GatherSpellTargets(RuleB(Bots, CrossRaidBuffingAndHealing)); int targetCount = 0; @@ -1970,7 +1955,7 @@ BotSpell Bot::GetBestBotSpellForCure(Bot* botCaster, Mob* tar, uint16 spellType) std::list botSpellListItr = GetPrioritizedBotSpellsBySpellType(botCaster, spellType, tar); if (IsGroupBotSpellType(spellType)) { - const std::vector v = botCaster->GatherGroupSpellTargets(tar); + const std::vector v = botCaster->GatherSpellTargets(false, tar); int countNeedsCured = 0; uint16 countPoisoned = 0; uint16 countDiseased = 0;