Skip to content

Commit

Permalink
[Spell] Interruption healing spell if target with full health
Browse files Browse the repository at this point in the history
  • Loading branch information
liyunfan1223 committed Oct 3, 2024
1 parent 54a8445 commit 6886a5b
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "SharedDefines.h"
#include "SocialMgr.h"
#include "SpellAuraEffects.h"
#include "SpellInfo.h"
#include "Transport.h"
#include "Unit.h"
#include "UpdateTime.h"
Expand Down Expand Up @@ -318,12 +319,43 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal)
currentSpell = bot->GetCurrentSpell(CURRENT_CHANNELED_SPELL);
if (currentSpell && currentSpell->getState() == SPELL_STATE_PREPARING)
{
const SpellInfo* spellInfo = currentSpell->GetSpellInfo();

// interrupt if target is dead
if (currentSpell->m_targets.GetUnitTarget() && !currentSpell->m_targets.GetUnitTarget()->IsAlive() &&
currentSpell->GetSpellInfo() && !currentSpell->GetSpellInfo()->IsAllowingDeadTarget())
spellInfo && !spellInfo->IsAllowingDeadTarget())
{
bot->InterruptSpell(CURRENT_GENERIC_SPELL);
InterruptSpell();
SetNextCheckDelay(sPlayerbotAIConfig->reactDelay);
}

bool isHeal = false;
bool isSingleTarget = true;

for (uint8 i = 0; i < 3; ++i)
{
if (!spellInfo->Effects[i].Effect)
continue;

if (spellInfo->Effects[i].Effect == SPELL_EFFECT_HEAL ||
spellInfo->Effects[i].Effect == SPELL_EFFECT_HEAL_MAX_HEALTH ||
spellInfo->Effects[i].Effect == SPELL_EFFECT_HEAL_MECHANICAL)
isHeal = true;

if ((spellInfo->Effects[i].TargetA.GetTarget() && spellInfo->Effects[i].TargetA.GetTarget() != TARGET_UNIT_TARGET_ALLY) ||
(spellInfo->Effects[i].TargetB.GetTarget() && spellInfo->Effects[i].TargetB.GetTarget() != TARGET_UNIT_TARGET_ALLY))
{
isSingleTarget = false;
}
}
// interrupt if target ally has full health (heal by other member)
if (isHeal && isSingleTarget && currentSpell->m_targets.GetUnitTarget() && currentSpell->m_targets.GetUnitTarget()->IsFullHealth())
{
InterruptSpell();
SetNextCheckDelay(sPlayerbotAIConfig->reactDelay);
}

// wait for spell cast
return;
}

Expand Down Expand Up @@ -3733,15 +3765,12 @@ void PlayerbotAI::WaitForSpellCast(Spell* spell)

void PlayerbotAI::InterruptSpell()
{
for (uint8 type = CURRENT_MELEE_SPELL; type < CURRENT_CHANNELED_SPELL; type++)
for (uint8 type = CURRENT_MELEE_SPELL; type <= CURRENT_CHANNELED_SPELL; type++)
{
Spell* spell = bot->GetCurrentSpell((CurrentSpellTypes)type);
if (!spell)
continue;

if (spell->m_spellInfo->IsPositive())
continue;

bot->InterruptSpell((CurrentSpellTypes)type);

WorldPacket data(SMSG_SPELL_FAILURE, 8 + 1 + 4 + 1);
Expand Down

0 comments on commit 6886a5b

Please sign in to comment.