Skip to content

Instantly share code, notes, and snippets.

@Langerz82
Last active January 21, 2019 10:21
Show Gist options
  • Select an option

  • Save Langerz82/bce7c59a4069cba26d6f5fa512feafd0 to your computer and use it in GitHub Desktop.

Select an option

Save Langerz82/bce7c59a4069cba26d6f5fa512feafd0 to your computer and use it in GitHub Desktop.
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 6150dbb422..54bba5007e 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -2262,6 +2262,16 @@ void Spell::AddDestTarget(SpellDestination const& dest, uint32 effIndex)
m_destTargets[effIndex] = dest;
}
+bool Spell::TargetInfo::MissedTarget(Spell *spell)
+{
+ Unit* unit = spell->m_caster->GetGUID() == TargetGUID ? spell->m_caster->ToUnit() : ObjectAccessor::GetUnit(*spell->m_caster, TargetGUID);
+ if (!unit)
+ return true;
+ if (unit->HasStealthAura() && unit->IsHostileTo(spell->m_caster))
+ return true;
+ return false;
+}
+
void Spell::TargetInfo::PreprocessTarget(Spell* spell)
{
Unit* unit = spell->m_caster->GetGUID() == TargetGUID ? spell->m_caster->ToUnit() : ObjectAccessor::GetUnit(*spell->m_caster, TargetGUID);
@@ -2818,6 +2828,7 @@ void Spell::DoSpellEffectHit(Unit* unit, uint8 effIndex, TargetInfo& hitInfo)
}
}
+
HandleEffects(unit, nullptr, nullptr, effIndex, SPELL_EFFECT_HANDLE_HIT_TARGET);
}
@@ -3449,6 +3460,12 @@ void Spell::_cast(bool skipCheck)
template <class Container>
void Spell::DoProcessTargetContainer(Container& targetContainer)
{
+ for (TargetInfoBase& target : targetContainer)
+ {
+ if (target.MissedTarget(this))
+ return;
+ }
+
for (TargetInfoBase& target : targetContainer)
target.PreprocessTarget(this);
@@ -3562,6 +3579,8 @@ uint64 Spell::handle_delayed(uint64 t_offset)
return false;
}), m_UniqueTargetInfo.end());
+
+
DoProcessTargetContainer(delayedTargets);
}
@@ -3725,14 +3744,53 @@ void Spell::update(uint32 difftime)
}
if (m_timer == 0 && !m_spellInfo->IsNextMeleeSwingSpell() && !IsAutoRepeat())
+ {
// don't CheckCast for instant spells - done in spell::prepare, skip duplicate checks, needed for range checks for example
cast(!m_casttime);
+
+ // If the spell is an Instant Spell clear state casting.
+ if (!m_spellInfo->IsChanneled())
+ {
+ Unit* unitCaster = m_caster->ToUnit();
+ if (!unitCaster)
+ return;
+
+ unitCaster->ClearUnitState(UNIT_STATE_CASTING);
+ }
+ break;
+ }
break;
}
case SPELL_STATE_CASTING:
{
if (m_timer)
{
+ // If the spell is channelled, and any stealthed then remove the aura,
+ // If there are no auras left then stop the channeled spell cast.
+ if (m_spellInfo->IsChanneled())
+ {
+ bool stopChannel = true;
+ for (TargetInfo const& target : m_UniqueTargetInfo)
+ {
+ if (Unit* unit = m_caster->GetGUID() == target.TargetGUID ? m_caster->ToUnit() : ObjectAccessor::GetUnit(*m_caster, target.TargetGUID))
+ {
+ if (unit->HasStealthAura())
+ unit->RemoveOwnedAura(m_spellInfo->Id, m_originalCasterGUID, 0, AURA_REMOVE_BY_CANCEL);
+ else
+ stopChannel = false;
+ }
+ }
+ if (stopChannel)
+ {
+ m_timer = 0;
+
+ Unit* unitCaster = m_caster->ToUnit();
+ if (!unitCaster)
+ return;
+ unitCaster->ClearUnitState(UNIT_STATE_CASTING);
+ }
+ }
+
// check if there are alive targets left
if (!UpdateChanneledTargetList())
{
diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h
index 8b94b176ef..c2de023cf5 100644
--- a/src/server/game/Spells/Spell.h
+++ b/src/server/game/Spells/Spell.h
@@ -643,6 +643,7 @@ class TC_GAME_API Spell
// Targets store structures and data
struct TargetInfoBase
{
+ virtual bool MissedTarget(Spell * spell) { return false; }
virtual void PreprocessTarget(Spell* /*spell*/) { }
virtual void DoTargetSpellHit(Spell* spell, uint8 effIndex) = 0;
virtual void DoDamageAndTriggers(Spell* /*spell*/) { }
@@ -656,6 +657,7 @@ class TC_GAME_API Spell
struct TargetInfo : public TargetInfoBase
{
+ bool MissedTarget(Spell * spell) override;
void PreprocessTarget(Spell* spell) override;
void DoTargetSpellHit(Spell* spell, uint8 effIndex) override;
void DoDamageAndTriggers(Spell* spell) override;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment