Consolidate AttemptForcedCastSpell

This commit is contained in:
nytmyr
2025-01-20 19:30:26 -06:00
parent 5de72999fe
commit 46a45679b2
+19 -68
View File
@@ -10954,7 +10954,7 @@ bool Bot::AttemptForcedCastSpell(Mob* tar, uint16 spell_id, bool is_disc) {
tar = this; tar = this;
} }
if ((IsCharmSpell(spell_id) || IsPetSpell(spell_id) && HasPet())) { if ((IsCharmSpell(spell_id) || (IsPetSpell(spell_id) && HasPet()))) {
return false; return false;
} }
@@ -10963,19 +10963,16 @@ bool Bot::AttemptForcedCastSpell(Mob* tar, uint16 spell_id, bool is_disc) {
} }
if (IsBeneficialSpell(spell_id)) { if (IsBeneficialSpell(spell_id)) {
if ( bool invalid_beneficial_target =
(tar->IsNPC() && !tar->GetOwner()) || (tar->IsNPC() && !tar->GetOwner()) ||
(tar->GetOwner() && tar->GetOwner()->IsOfClientBot() && !GetBotOwner()->IsInGroupOrRaid(tar->GetOwner())) || (tar->GetOwner() && tar->GetOwner()->IsOfClientBot() && !GetBotOwner()->IsInGroupOrRaid(tar->GetOwner())) ||
(tar->IsOfClientBot() && !GetBotOwner()->IsInGroupOrRaid(tar)) (tar->IsOfClientBot() && !GetBotOwner()->IsInGroupOrRaid(tar));
) {
if (invalid_beneficial_target) {
GetBotOwner()->Message( GetBotOwner()->Message(
Chat::Yellow, Chat::Yellow,
fmt::format( fmt::format("[{}] is an invalid target. Only players or their pet in your group or raid are eligible targets.", tar->GetCleanName()).c_str()
"[{}] is an invalid target. Only players or their pet in your group or raid are eligible targets."
, tar->GetCleanName()
).c_str()
); );
return false; return false;
} }
} }
@@ -10983,32 +10980,17 @@ bool Bot::AttemptForcedCastSpell(Mob* tar, uint16 spell_id, bool is_disc) {
if (IsDetrimentalSpell(spell_id) && (!GetBotOwner()->IsAttackAllowed(tar) || !IsAttackAllowed(tar))) { if (IsDetrimentalSpell(spell_id) && (!GetBotOwner()->IsAttackAllowed(tar) || !IsAttackAllowed(tar))) {
GetBotOwner()->Message( GetBotOwner()->Message(
Chat::Yellow, Chat::Yellow,
fmt::format( fmt::format("{} says, 'I cannot attack [{}]'.", GetCleanName(), tar->GetCleanName()).c_str()
"{} says, 'I cannot attack [{}]'.",
GetCleanName(),
tar->GetCleanName()
).c_str()
); );
return false; return false;
} }
if (!is_disc) { if (!is_disc && !CheckSpellRecastTimer(spell_id)) {
if (!CheckSpellRecastTimer(spell_id)) {
return false; return false;
} }
}
if ( if (!IsInGroupOrRaid(tar, true) &&
!IsInGroupOrRaid(tar, true) && (!RuleB(Bots, EnableBotTGB) || (IsGroupSpell(spell_id) && !IsTGBCompatibleSpell(spell_id)))) {
(
!RuleB(Bots, EnableBotTGB) ||
(
IsGroupSpell(spell_id) &&
!IsTGBCompatibleSpell(spell_id)
)
)
) {
return false; return false;
} }
@@ -11019,12 +11001,8 @@ bool Bot::AttemptForcedCastSpell(Mob* tar, uint16 spell_id, bool is_disc) {
if (!CastChecks(spell_id, tar, UINT16_MAX)) { if (!CastChecks(spell_id, tar, UINT16_MAX)) {
GetBotOwner()->Message( GetBotOwner()->Message(
Chat::Red, Chat::Red,
fmt::format( fmt::format("{} says, 'Ability failed to cast. This could be due to range, mana, immune, target type, etc.'", GetBotOwner()->GetCleanName()).c_str()
"{} 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()
); );
return false; return false;
} }
@@ -11038,11 +11016,13 @@ bool Bot::AttemptForcedCastSpell(Mob* tar, uint16 spell_id, bool is_disc) {
tar->GetCleanName() tar->GetCleanName()
).c_str() ).c_str()
); );
InterruptSpell(); InterruptSpell();
} }
if (CastSpell(spell_id, tar->GetID())) { if (!CastSpell(spell_id, tar->GetID())) {
return false;
}
BotGroupSay( BotGroupSay(
this, this,
fmt::format( fmt::format(
@@ -11056,44 +11036,15 @@ bool Bot::AttemptForcedCastSpell(Mob* tar, uint16 spell_id, bool is_disc) {
if (!is_disc) { if (!is_disc) {
timer_duration = CalcBuffDuration(tar, this, spell_id); timer_duration = CalcBuffDuration(tar, this, spell_id);
timer_duration = std::max(0, GetActSpellDuration(spell_id, timer_duration));
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 (!is_disc) {
SetSpellRecastTimer(spell_id, timer_duration); SetSpellRecastTimer(spell_id, timer_duration);
} }
else { else if (spell.recast_time > 0) {
SetDisciplineReuseTimer(spell_id, timer_duration); timer_duration = std::max(0, int(spell.recast_time / 1000 - GetFocusEffect(focusReduceRecastTime, spell_id)));
SetDisciplineReuseTimer(spell_id, timer_duration * 1000);
} }
return true; return true;
}
return false;
} }
uint16 Bot::GetParentSpellType(uint16 spell_type) { uint16 Bot::GetParentSpellType(uint16 spell_type) {