From cad7b13ed378cffcfce0991efd664b25dc3519eb Mon Sep 17 00:00:00 2001 From: Prithu Parker Date: Sat, 14 Oct 2017 12:28:13 +1100 Subject: [PATCH] Revert "Revert "Fix area aura and channel spell tick loss by syncing updates with the caster (#1099)"" This reverts commit 10a58e326b4534525b976d425b13590834f2fe38. --- src/game/Maps/GridNotifiersImpl.h | 29 +++++- src/game/Objects/DynamicObject.cpp | 15 ++- src/game/Objects/DynamicObject.h | 2 + src/game/Objects/Totem.cpp | 11 ++- src/game/Objects/Unit.cpp | 120 +++++++++++++++--------- src/game/Objects/Unit.h | 10 +- src/game/Spells/Spell.cpp | 145 +++++++++++++++++++++++++---- src/game/Spells/Spell.h | 8 ++ src/game/Spells/SpellAuras.cpp | 144 +++++++++++++++++++++++----- src/game/Spells/SpellAuras.h | 14 ++- 10 files changed, 400 insertions(+), 98 deletions(-) diff --git a/src/game/Maps/GridNotifiersImpl.h b/src/game/Maps/GridNotifiersImpl.h index ef9ae10f9..235b73475 100644 --- a/src/game/Maps/GridNotifiersImpl.h +++ b/src/game/Maps/GridNotifiersImpl.h @@ -31,6 +31,7 @@ #include "SpellAuras.h" #include "DBCStores.h" #include "DBCEnums.h" +#include "Spell.h" #include "SpellMgr.h" template @@ -181,6 +182,7 @@ inline void MaNGOS::DynamicObjectUpdater::VisitHelper(Unit* target) // Apply PersistentAreaAura on target // in case 2 dynobject overlap areas for same spell, same holder is selected, so dynobjects share holder SpellAuraHolder *holder = target->GetSpellAuraHolder(spellInfo->Id, i_dynobject.GetCasterGuid()); + bool existing = false; if (holder) { @@ -193,12 +195,15 @@ inline void MaNGOS::DynamicObjectUpdater::VisitHelper(Unit* target) target->AddAuraToModList(Aur); Aur->ApplyModifier(true,true); } - else if (holder->GetAuraDuration() >= 0 && uint32(holder->GetAuraDuration()) < i_dynobject.GetDuration()) + // Don't update aura time for active channeled spells, otherwise it can become out of sync with the cast + else if (!i_dynobject.IsChanneled() && holder->GetAuraDuration() >= 0 && uint32(holder->GetAuraDuration()) < i_dynobject.GetDuration()) { holder->SetAuraDuration(i_dynobject.GetDuration()); holder->UpdateAuraDuration(); } holder->SetInUse(false); + + existing = true; } else { @@ -209,6 +214,28 @@ inline void MaNGOS::DynamicObjectUpdater::VisitHelper(Unit* target) target->AddSpellAuraHolder(holder); } + if (holder && holder->IsChanneled()) + { + if (Unit *caster = i_dynobject.GetCaster()) + { + // Caster is channeling this spell, update current channel spell holders with + // the new holder. Don't check channel object, as it might be a spell with + // multiple dyn objs + if (Spell *spell = caster->GetCurrentSpell(CURRENT_CHANNELED_SPELL)) + { + if (spell->m_spellInfo->Id == spellInfo->Id) + { + if (!existing) + spell->AddChanneledAuraHolder(holder); + + holder->SetAuraDuration(spell->GetCastedTime()); + holder->RefreshAuraPeriodicTimers(); // make sure we are ticking in sync with the spell cast time + holder->UpdateAuraDuration(); + } + } + } + } + i_dynobject.AddAffected(target); } diff --git a/src/game/Objects/DynamicObject.cpp b/src/game/Objects/DynamicObject.cpp index cbacf5b89..954ea63e1 100644 --- a/src/game/Objects/DynamicObject.cpp +++ b/src/game/Objects/DynamicObject.cpp @@ -118,6 +118,7 @@ bool DynamicObject::Create(uint32 guidlow, Unit *caster, uint32 spellId, SpellEf m_effIndex = effIndex; m_spellId = spellId; m_positive = IsPositiveEffect(spellProto, m_effIndex); + m_channeled = IsChanneledSpell(spellProto); return true; } @@ -139,11 +140,19 @@ void DynamicObject::Update(uint32 update_diff, uint32 p_time) return; } + if (_deleted) + return; + + // If this object is from the current channeled spell, do not delete it. Otherwise + // we can lose the last tick of the effect due to differeng updates. The spell + // itself will call for the object to be removed at the end of the cast bool deleteThis = false; - if (m_aliveDuration > int32(p_time)) - m_aliveDuration -= p_time; - else + m_aliveDuration -= p_time; + if (m_aliveDuration <= 0) + m_aliveDuration = 0; + + if (m_aliveDuration == 0 && (!m_channeled || caster->GetChannelObjectGuid() != GetObjectGuid())) deleteThis = true; for (AffectedMap::iterator iter = m_affected.begin(); iter != m_affected.end(); ++iter) diff --git a/src/game/Objects/DynamicObject.h b/src/game/Objects/DynamicObject.h index 661532461..525f09797 100644 --- a/src/game/Objects/DynamicObject.h +++ b/src/game/Objects/DynamicObject.h @@ -55,6 +55,7 @@ class DynamicObject : public WorldObject float GetRadius() const { return m_radius; } DynamicObjectType GetType() const { return (DynamicObjectType)GetByteValue(DYNAMICOBJECT_BYTES,0); } bool NeedsRefresh(Unit *unit) const; + bool IsChanneled() const { return m_channeled; } void AddAffected(Unit *unit) { m_affected[unit->GetObjectGuid()] = 0; } void RemoveAffected(Unit *unit) { m_affected.erase(unit->GetObjectGuid()); } void Delay(int32 delaytime); @@ -77,6 +78,7 @@ class DynamicObject : public WorldObject int32 m_aliveDuration; float m_radius; // radius apply persistent effect, 0 = no persistent effect bool m_positive; + bool m_channeled; AffectedMap m_affected; private: GridReference m_gridRef; diff --git a/src/game/Objects/Totem.cpp b/src/game/Objects/Totem.cpp index 705d0546b..b9f1a9d1e 100644 --- a/src/game/Objects/Totem.cpp +++ b/src/game/Objects/Totem.cpp @@ -74,6 +74,12 @@ void Totem::Update(uint32 update_diff, uint32 time) return; } + if (GetMotionMaster()->GetCurrentMovementGeneratorType() != IDLE_MOTION_TYPE) + GetMotionMaster()->MoveIdle(); + + // Do final update before unsummon, or we lose ticks on the totem's spell + Creature::Update(update_diff, time); + if (m_duration <= update_diff) { UnSummon(); // remove self @@ -81,11 +87,6 @@ void Totem::Update(uint32 update_diff, uint32 time) } else m_duration -= update_diff; - - if (GetMotionMaster()->GetCurrentMovementGeneratorType() != IDLE_MOTION_TYPE) - GetMotionMaster()->MoveIdle(); - - Creature::Update(update_diff, time); } void Totem::Summon(Unit* owner) diff --git a/src/game/Objects/Unit.cpp b/src/game/Objects/Unit.cpp index 933772f5a..98e3995f8 100644 --- a/src/game/Objects/Unit.cpp +++ b/src/game/Objects/Unit.cpp @@ -209,7 +209,9 @@ Unit::Unit() m_doExtraAttacks = false; - m_isCreatureLinkingTrigger = false; + m_spellUpdateTimeBuffer = 0; + + m_isCreatureLinkingTrigger = false; m_isSpawningLinked = false; } @@ -262,13 +264,24 @@ void Unit::Update(uint32 update_diff, uint32 p_time) ++it; } - // WARNING! Order of execution here is important, do not change. - // Spells must be processed with event system BEFORE they go to _UpdateSpells. - // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad. - m_Events.Update(update_diff); - _UpdateSpells(update_diff); + // Buffer spell system update time to save on performance when players are updated twice per + // world update. We do not need to update spells when the interval is only a few ms (~10ms) + m_spellUpdateTimeBuffer += update_diff; + if (m_spellUpdateTimeBuffer >= UNIT_SPELL_UPDATE_TIME_BUFFER) + { + // WARNING! Order of execution here is important, do not change. + // Spells must be processed with event system BEFORE they go to _UpdateSpells. + // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad. + m_Events.Update(m_spellUpdateTimeBuffer); + _UpdateSpells(m_spellUpdateTimeBuffer); - CleanupDeletedAuras(); + CleanupDeletedAuras(); + + // update abilities available only for fraction of time + UpdateReactives(m_spellUpdateTimeBuffer); + + m_spellUpdateTimeBuffer = 0; + } if (m_lastManaUseTimer) { @@ -321,7 +334,7 @@ void Unit::Update(uint32 update_diff, uint32 p_time) --m_extraAttacks; } resetAttackTimer(BASE_ATTACK); - + ExtraAttacksLocked(false); } @@ -334,9 +347,6 @@ void Unit::Update(uint32 update_diff, uint32 p_time) if (uint32 ranged_att = getAttackTimer(RANGED_ATTACK)) setAttackTimer(RANGED_ATTACK, (update_diff >= ranged_att ? 0 : ranged_att - update_diff)); - // update abilities available only for fraction of time - UpdateReactives(update_diff); - if (isAlive()) ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, GetHealth() < GetMaxHealth() * 0.20f); @@ -741,7 +751,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa // Rage from Damage made vs critters (only from direct weapon damage) if (damage && damagetype == DIRECT_DAMAGE && this != pVictim && GetTypeId() == TYPEID_PLAYER && (getPowerType() == POWER_RAGE)) ((Player*)this)->RewardRage(damage, true); - + return damage; } @@ -970,7 +980,7 @@ void Unit::Kill(Unit* pVictim, SpellEntry const *spellProto, bool durabilityLoss if (player_tap && !group_tap) group_tap = player_tap->GetGroup(); } - else if (creature->lootForCreator && creature->GetCreatorGuid()) + else if (creature->lootForCreator && creature->GetCreatorGuid()) { Unit* creator = GetUnit(*this, creature->GetCreatorGuid()); if (creator->IsPlayer()) @@ -1290,10 +1300,14 @@ void Unit::CastSpell(Unit* Victim, SpellEntry const *spellInfo, bool triggered, Spell *spell = new Spell(this, spellInfo, triggered, originalCaster, triggeredBy); SpellCastTargets targets; - targets.setUnitTarget(Victim); + // Don't set unit target on destination target based spells, otherwise the spell will cancel + // as soon as the target dies or leaves the area of the effect if (spellInfo->Targets & TARGET_FLAG_DEST_LOCATION) targets.setDestination(Victim->GetPositionX(), Victim->GetPositionY(), Victim->GetPositionZ()); + else + targets.setUnitTarget(Victim); + if (spellInfo->Targets & TARGET_FLAG_SOURCE_LOCATION) if (WorldObject* caster = spell->GetCastingObject()) targets.setSource(caster->GetPositionX(), caster->GetPositionY(), caster->GetPositionZ()); @@ -1556,7 +1570,7 @@ void Unit::CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *da default: break; } - + bool immune = true; bool feral = IsInFeralForm(); @@ -1566,12 +1580,12 @@ void Unit::CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *da for (uint8 i = 0; i < actualDamageCount; i++) { SubDamageInfo *subDamage = &damageInfo->subDamage[i]; - + // feral only allowed melee school subDamage->damageSchoolMask = GetTypeId() == TYPEID_PLAYER && !feral ? GetSchoolMask(GetWeaponDamageSchool(damageInfo->attackType, i)) : GetMeleeDamageSchoolMask(); - + if (damageInfo->target->IsImmuneToDamage(subDamage->damageSchoolMask)) { subDamage->damage = 0; @@ -1793,7 +1807,7 @@ void Unit::CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *da damageInfo->HitInfo |= HITINFO_CRUSHING; damageInfo->TargetState = VICTIMSTATE_NORMAL; damageInfo->procEx |= PROC_EX_NORMAL_HIT; - + // 150% of normal damage damageInfo->totalDamage += damageInfo->totalDamage / 2; @@ -1969,7 +1983,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo *damageInfo, bool durabilityLoss) // don't allow damage shields to be reduced by Blessing of Sanctuary, etc. if (spellDmgTakenBonus > 0) damage += spellDmgTakenBonus; } - + //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist? //uint32 absorb; //uint32 resist; @@ -3363,6 +3377,12 @@ void Unit::_UpdateSpells(uint32 time) { SpellAuraHolder* i_holder = m_spellAuraHoldersUpdateIterator->second; ++m_spellAuraHoldersUpdateIterator; // need shift to next for allow update if need into aura update + + // If channeled spell, do not update. The spell caster will update the holder on spell + // update to prevent loss of periodic ticks due to out of sync updates + if (i_holder->IsChanneled()) + continue; + i_holder->UpdateHolder(time); } @@ -3547,10 +3567,10 @@ void Unit::FinishSpell(CurrentSpellTypes spellType, bool ok /*= true*/) if (!spell) return; - spell->finish(ok); - if (spellType == CURRENT_CHANNELED_SPELL) spell->SendChannelUpdate(0); + + spell->finish(ok); } @@ -4362,14 +4382,14 @@ void Unit::RemoveAura(uint32 spellId, SpellEffectIndex effindex, Aura* except) ++iter; } } -void Unit::RemoveAurasByCasterSpell(uint32 spellId, ObjectGuid casterGuid) +void Unit::RemoveAurasByCasterSpell(uint32 spellId, ObjectGuid casterGuid, AuraRemoveMode mode) { SpellAuraHolderBounds spair = GetSpellAuraHolderBounds(spellId); for (SpellAuraHolderMap::iterator iter = spair.first; iter != spair.second;) { if (iter->second->GetCasterGuid() == casterGuid) { - RemoveSpellAuraHolder(iter->second); + RemoveSpellAuraHolder(iter->second, mode); spair = GetSpellAuraHolderBounds(spellId); iter = spair.first; } @@ -4611,8 +4631,8 @@ void Unit::RemoveSpellAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode) SpellEntry const* AurSpellInfo = holder->GetSpellProto(); Totem* statue = nullptr; Unit* caster = holder->GetCaster(); - - if (IsChanneledSpell(AurSpellInfo) && caster) + bool isChanneled = holder->IsChanneled(); // cache for after the holder is deleted + if (isChanneled && caster) if (caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->IsTotem() && ((Totem*)caster)->GetTotemType() == TOTEM_STATUE) statue = ((Totem*)caster); @@ -4650,6 +4670,7 @@ void Unit::RemoveSpellAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode) statue->UnSummon(); uint32 auraSpellId = holder->GetId(); + // If holder in use (removed from code that plan access to it data after return) // store it in holder list with delayed deletion if (holder->IsInUse()) @@ -4662,7 +4683,7 @@ void Unit::RemoveSpellAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode) uint32 uiTriggeredSpell = 0; - // Spell that trigger another spell on dispell + // Spell that trigger another spell on dispell if (mode == AURA_REMOVE_BY_DISPEL) { switch (auraSpellId) @@ -4675,11 +4696,18 @@ void Unit::RemoveSpellAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode) } } - if (IsChanneledSpell(AurSpellInfo) && caster && (mode != AURA_REMOVE_BY_EXPIRE || caster->IsControlledByPlayer())) + if (isChanneled && caster) { Spell *channeled = caster->GetCurrentSpell(CURRENT_CHANNELED_SPELL); - if (channeled && channeled->m_spellInfo->Id == auraSpellId && channeled->m_targets.getUnitTarget() == this) - caster->InterruptSpell(CURRENT_CHANNELED_SPELL); + if (channeled && channeled->m_spellInfo->Id == auraSpellId) + { + // If single target, interrupt cast. If not, notify the spell caster so we + // can stop processing this holder + if (channeled->m_targets.getUnitTarget() == this && mode != AURA_REMOVE_BY_CHANNEL && (mode != AURA_REMOVE_BY_EXPIRE || caster->IsControlledByPlayer())) + caster->InterruptSpell(CURRENT_CHANNELED_SPELL); + else + channeled->RemoveChanneledAuraHolder(holder, mode); + } } if (uiTriggeredSpell) @@ -4815,6 +4843,8 @@ void Unit::DelaySpellAuraHolder(uint32 spellId, int32 delaytime, ObjectGuid cast else holder->SetAuraDuration(holder->GetAuraDuration() - delaytime); + // push down the tick timer with the delay, otherwise we can still get max ticks even with pushback + holder->RefreshAuraPeriodicTimers(); holder->UpdateAuraDuration(); DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell %u partially interrupted on %s, new duration: %u ms", spellId, GetObjectGuid().GetString().c_str(), holder->GetAuraDuration()); @@ -5293,7 +5323,7 @@ void Unit::SendAttackStateUpdate(CalcDamageInfo *damageInfo) data << GetPackGUID(); data << damageInfo->target->GetPackGUID(); data << uint32(damageInfo->totalDamage); // Total damage - + data << uint8(m_weaponDamageCount[damageInfo->attackType]); // Sub damage count // Sub damage description @@ -5664,7 +5694,7 @@ bool Unit::Attack(Unit *victim, bool meleeAttack) addUnitState(UNIT_STAT_MELEE_ATTACKING); m_attacking = victim; - m_attacking->_addAttacker(this); + m_attacking->_addAttacker(this); if (GetTypeId() == TYPEID_UNIT) // && !((Creature*)this)->GetLinkGroup()) { @@ -6330,7 +6360,7 @@ uint32 Unit::SpellDamageBonusDone(Unit *pVictim, SpellEntry const *spellProto, u } uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - + // Add pct bonus from spell damage versus DoneTotalMod *= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS, creatureTypeMask); @@ -7313,7 +7343,7 @@ void Unit::SetInCombatState(bool PvP, Unit* enemy) if (spell->m_spellInfo->ChannelInterruptFlags & CHANNEL_FLAG_ENTER_COMBAT) InterruptSpell(CURRENT_CHANNELED_SPELL); - if (m_isCreatureLinkingTrigger) + if (m_isCreatureLinkingTrigger) GetMap()->GetCreatureLinkingHolder()->DoCreatureLinkingEvent(LINKING_EVENT_AGGRO, pCreature, enemy); } } @@ -7913,7 +7943,7 @@ float Unit::GetXZFlagBasedSpeed(const Unit *unit) const if (unit->IsSwimming()) { - if (unit->HasUnitMovementFlag(MOVEFLAG_BACKWARD)) + if (unit->HasUnitMovementFlag(MOVEFLAG_BACKWARD)) return unit->GetSpeed(MOVE_SWIM_BACK); return unit->GetSpeed(MOVE_SWIM); @@ -7926,7 +7956,7 @@ float Unit::GetXZFlagBasedSpeed(const Unit *unit) const } // Presumably only running left when IsMoving is true - if (unit->HasUnitMovementFlag(MOVEFLAG_BACKWARD)) + if (unit->HasUnitMovementFlag(MOVEFLAG_BACKWARD)) return unit->GetSpeed(MOVE_RUN_BACK); return unit->GetSpeed(MOVE_RUN); @@ -8158,7 +8188,7 @@ void Unit::TauntFadeOut(Unit *taunter) if (!GetCharmGuid()) OnLeaveCombat(); - if (m_isCreatureLinkingTrigger) + if (m_isCreatureLinkingTrigger) GetMap()->GetCreatureLinkingHolder()->DoCreatureLinkingEvent(LINKING_EVENT_EVADE, (Creature*)this); return; @@ -8261,8 +8291,8 @@ bool Unit::SelectHostileTarget() // enter in evade mode in other case OnLeaveCombat(); - - if (m_isCreatureLinkingTrigger) + + if (m_isCreatureLinkingTrigger) GetMap()->GetCreatureLinkingHolder()->DoCreatureLinkingEvent(LINKING_EVENT_EVADE, (Creature*)this); return false; @@ -9514,7 +9544,7 @@ void Unit::StopMoving(bool force) if (Transport* t = GetTransport()) { init.SetTransport(t->GetGUIDLow()); } - + if (!movespline->Finalized() || force) { init.SetStop(); // Will trigger CMSG_MOVE_SPLINE_DONE from client. init.Launch(); @@ -9591,7 +9621,7 @@ void Unit::ModConfuseSpell(bool apply, ObjectGuid casterGuid, uint32 spellID, Mo Unit* caster = IsInWorld() ? GetMap()->GetUnit(casterGuid) : nullptr; GetMotionMaster()->MoveFeared(caster, time); break; - } + } case MOV_MOD_CONFUSED: GetMotionMaster()->MoveConfused(); break; @@ -10668,14 +10698,14 @@ float Unit::GetCombatReach(Unit const* pVictim, bool forMeleeRange /*=true*/, fl if (reach < ATTACK_DISTANCE) reach = ATTACK_DISTANCE; } - + // Melee leeway mechanic. // When both player and target has > 70% of normal runspeed, and are moving, // the player gains an additional 2.5yd of melee range. - if (IsPlayer()) + if (IsPlayer()) { static const float leewayMinSpeed = 4.97f; - if (GetXZFlagBasedSpeed(this) > leewayMinSpeed && GetXZFlagBasedSpeed(pVictim) > leewayMinSpeed) + if (GetXZFlagBasedSpeed(this) > leewayMinSpeed && GetXZFlagBasedSpeed(pVictim) > leewayMinSpeed) reach += 2.5f; } @@ -11297,14 +11327,14 @@ void Unit::SetMovement(UnitMovementType pType) { mePlayer->GetCheatData()->OrderSent(&data); mePlayer->GetSession()->SendPacket(&data); - + // We can't send movement info here because it is out-of-date with the client // and causes issues with unit speed updates on death/res /*if (pType == MOVE_ROOT || pType == MOVE_UNROOT) { WorldPacket rootData(pType == MOVE_ROOT ? MSG_MOVE_ROOT : MSG_MOVE_UNROOT, 31); rootData << GetPackGUID(); rootData << m_movementInfo; - + mePlayer->SendMovementMessageToSet(std::move(rootData), false); }*/ } diff --git a/src/game/Objects/Unit.h b/src/game/Objects/Unit.h index 2832810f2..8639bf46d 100644 --- a/src/game/Objects/Unit.h +++ b/src/game/Objects/Unit.h @@ -311,7 +311,9 @@ enum AuraRemoveMode AURA_REMOVE_BY_DELETE, // use for speedup and prevent unexpected effects at player logout/pet unsummon (must be used _only_ after save), delete. AURA_REMOVE_BY_SHIELD_BREAK, // when absorb shield is removed by damage AURA_REMOVE_BY_EXPIRE, // at duration end - + AURA_REMOVE_BY_CHANNEL, // when removing an aura due to channel finish or cancel + AURA_REMOVE_BY_RANGE, // when removing an area aura due to being out of range + AURA_REMOVE_BY_GROUP // when removing an aura due to not being in the same group (includes pet ownership) }; enum UnitMods @@ -676,6 +678,7 @@ enum CurrentSpellTypes #define CURRENT_FIRST_NON_MELEE_SPELL 1 #define CURRENT_MAX_SPELL 4 +#define UNIT_SPELL_UPDATE_TIME_BUFFER 60 struct GlobalCooldown { @@ -1440,7 +1443,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject // removing specific aura stacks by diff reasons and selections void RemoveAurasDueToSpell(uint32 spellId, SpellAuraHolder* except = nullptr, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT); void RemoveAurasDueToItemSpell(Item* castItem,uint32 spellId); - void RemoveAurasByCasterSpell(uint32 spellId, ObjectGuid casterGuid); + void RemoveAurasByCasterSpell(uint32 spellId, ObjectGuid casterGuid, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT); void RemoveAurasDueToSpellBySteal(uint32 spellId, ObjectGuid casterGuid, Unit *stealer); void RemoveAurasDueToSpellByCancel(uint32 spellId); @@ -1831,7 +1834,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject virtual void OnLeaveCombat() {} virtual void OnMoveTo(float, float, float) {} - // Appelé dans SpellEffects::EffectSummonPet et apres un rez en BG. + // Appele dans SpellEffects::EffectSummonPet et apres un rez en BG. void EffectSummonPet(uint32 spellId, uint32 petEntry); void ModPossess(Unit* target, bool apply, AuraRemoveMode m_removeMode = AURA_REMOVE_BY_DEFAULT); @@ -1962,6 +1965,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject ObjectGuid m_reactiveTarget[MAX_REACTIVE]; int32 m_regenTimer; uint32 m_lastManaUseTimer; + uint32 m_spellUpdateTimeBuffer; SpellCooldowns m_spellCooldowns; GlobalCooldownMgr m_GlobalCooldownMgr; diff --git a/src/game/Spells/Spell.cpp b/src/game/Spells/Spell.cpp index b2892b451..9a30de4e5 100644 --- a/src/game/Spells/Spell.cpp +++ b/src/game/Spells/Spell.cpp @@ -261,7 +261,8 @@ void SpellCastTargets::write(ByteBuffer& data) const data << m_strTarget; } -Spell::Spell(Unit* caster, SpellEntry const *info, bool triggered, ObjectGuid originalCasterGUID, SpellEntry const* triggeredBy, Unit* victim): m_immediateHandled(false), m_needSpellLog(false), m_canTrigger(false) +Spell::Spell(Unit* caster, SpellEntry const *info, bool triggered, ObjectGuid originalCasterGUID, SpellEntry const* triggeredBy, Unit* victim): + m_immediateHandled(false), m_needSpellLog(false), m_canTrigger(false) { MANGOS_ASSERT(caster != NULL && info != NULL); MANGOS_ASSERT(info == sSpellMgr.GetSpellEntry(info->Id) && "`info` must be pointer to sSpellStore element"); @@ -326,6 +327,8 @@ Spell::Spell(Unit* caster, SpellEntry const *info, bool triggered, ObjectGuid or m_timer = 0; // will set to cast time in prepare m_duration = 0; + m_channeled = IsChanneledSpell(info); + m_needAliveTargetMask = 0; // determine reflection @@ -1165,7 +1168,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo *target) if (real_caster) { // Restauration d'energie sur miss/dodge des sorts rapportant un CP. - // Source : http://roguecrap.blogspot.co.uk/2006/03/energy-regeneration-oddities.html, + vérifiable en vidéo + // Source : http://roguecrap.blogspot.co.uk/2006/03/energy-regeneration-oddities.html, + verifiable en video // Source for Parry: https://youtu.be/aDXXr3ad3is?t=3m07s if ((missInfo == SPELL_MISS_MISS || missInfo == SPELL_MISS_DODGE || missInfo == SPELL_MISS_PARRY) && m_spellInfo->powerType == POWER_ENERGY && IsSpellHaveEffect(m_spellInfo, SPELL_EFFECT_ADD_COMBO_POINTS)) @@ -1615,7 +1618,7 @@ void Spell::DoSpellHitOnUnit(Unit *unit, uint32 effectMask) m_spellAuraHolder = nullptr; // Need to interrupt pet channeling spells or else they get stuck - if (m_caster && m_caster->IsControlledByPlayer() && IsChanneledSpell(m_spellInfo)) + if (m_caster && m_caster->IsControlledByPlayer() && m_channeled) { Spell *channeled = m_caster->GetCurrentSpell(CURRENT_CHANNELED_SPELL); if (channeled && channeled->m_spellInfo->Id == m_spellInfo->Id && channeled->m_targets.getUnitTarget() == unit) @@ -1639,6 +1642,14 @@ void Spell::DoSpellHitOnUnit(Unit *unit, uint32 effectMask) delete m_spellAuraHolder; m_spellAuraHolder = nullptr; } + + // Aura applied successfully. If it's a channeled spell keep track of the holder so + // we can update it on spell update. Units do not update holders on themselves if + // they are from a channeled spell + if (m_channeled && m_spellAuraHolder) + { + AddChanneledAuraHolder(m_spellAuraHolder); + } } } @@ -3185,7 +3196,7 @@ void Spell::prepare(Aura* triggeredByAura) OnSpellLaunch(); - bool channeled = IsChanneledSpell(m_spellInfo); + bool channeled = m_channeled; // [Nostalrius] Stop pets casting channeled spells ! (succubus seduce ...) if (m_timer && channeled) @@ -3228,7 +3239,7 @@ void Spell::cancel() return; // channeled spells don't display interrupted message even if they are interrupted, possible other cases with no "Interrupted" message - bool sendInterrupt = IsChanneledSpell(m_spellInfo) && m_spellState != SPELL_STATE_PREPARING ? false : true; + bool sendInterrupt = m_channeled && m_spellState != SPELL_STATE_PREPARING ? false : true; m_autoRepeat = false; switch (m_spellState) @@ -3473,7 +3484,7 @@ void Spell::cast(bool skipCheck) m_targets.updateTradeSlotItem(); FillTargetMap(); - if (IsChanneledSpell(m_spellInfo)) + if (m_channeled) HandleAddTargetTriggerAuras(); if (m_spellState == SPELL_STATE_FINISHED) // stop cast if spell marked as finish somewhere in FillTargetMap @@ -3580,7 +3591,7 @@ void Spell::handle_immediate() _handle_immediate_phase(); // start channeling if applicable (after _handle_immediate_phase for get persistent effect dynamic object for channel target - if (IsChanneledSpell(m_spellInfo) && m_duration) + if (m_channeled && m_duration) { m_spellState = SPELL_STATE_CASTING; SendChannelStart(m_duration); @@ -3871,6 +3882,42 @@ void Spell::update(uint32 difftime) finish(); } + // Must update target holder since the target will not update it. Used to keep it in sync + // If the cast is interrupted mid-iteration (i.e. unit dies), break + SpellAuraHolderList::iterator iter = m_channeledHolders.begin(); + SpellAuraHolderList::iterator curr; + while (iter != m_channeledHolders.end()) + { + // increment now, current holder may be removed from the list externally so we need to step + curr = iter; + ++iter; + + SpellAuraHolder *holder = *curr; + holder->UpdateHolder(difftime); + + // Spell cast was interrupted on holder update. Unit likely died, targetted buff was + // dispelled, or unit ran out of range. Return since we cleaned up in + // SendChannelUpdate(0) on cancel. Continuing equals segfault due to deleted + // holders + if (m_spellState == SPELL_STATE_FINISHED) + return; + + // Handle typical removal modes for aura updates here for efficiency, + // RemoveChanneledAuraHolder will ignore these modes. Have to check deleted + // for expired holder as well, because the unit can die on the last tick + // and have a non-checked remove mode. Expired holders will be cleaned up + // on the unit's own update if it's from AoE. Single target cleaned up in + // SendChannelUpdate(0) + AuraRemoveMode remove = holder->GetRemoveMode(); + if ((holder->GetAuraDuration() == 0 && !holder->IsDeleted()) || + (holder->IsDeleted() && (remove == AURA_REMOVE_BY_RANGE || remove == AURA_REMOVE_BY_GROUP))) + { + holder->SetInUse(false); + + m_channeledHolders.erase(curr); + } + } + if (difftime >= m_timer) m_timer = 0; else @@ -4008,7 +4055,7 @@ void Spell::finish(bool ok) return; } - if (!IsChanneledSpell(m_spellInfo)) + if (!m_channeled) HandleAddTargetTriggerAuras(); // Heal caster for all health leech from all targets @@ -4318,7 +4365,7 @@ void Spell::WriteSpellGoTargets(WorldPacket* data) } } // Reset m_needAliveTargetMask for non channeled spell - if (!IsChanneledSpell(m_spellInfo)) + if (!m_channeled) m_needAliveTargetMask = 0; data->put(hitPos, (uint8)hit); @@ -4424,6 +4471,9 @@ void Spell::SendInterrupted(uint8 result) void Spell::SendChannelUpdate(uint32 time) { + if (!m_channeled || m_spellState == SPELL_STATE_FINISHED) + return; + if (!time) { // Reset farsight for some possessing auras of possessed summoned (as they might work with different aura types) @@ -4454,12 +4504,43 @@ void Spell::SendChannelUpdate(uint32 time) } } - m_caster->RemoveAurasByCasterSpell(m_spellInfo->Id, m_caster->GetObjectGuid()); + // Free channeled holders now so they can be safely removed, no handling for + // external removal. Nothing else should be modifying this list during this iteration + SpellAuraHolderList::iterator iter = m_channeledHolders.begin(); + while (iter != m_channeledHolders.end()) + { + SpellAuraHolder *holder = *iter; + holder->SetInUse(false); + // Remove any left over auras on all targets at channel end if they + // have not already been marked as deleted. Cleans up non-expired + // aoe targets + if (!holder->IsDeleted()) + { + if (Unit *unit = holder->GetTarget()) + unit->RemoveSpellAuraHolder(holder, AURA_REMOVE_BY_CHANNEL); + } + + iter = m_channeledHolders.erase(iter); + } + + // Remove single target auras on caster now if they expired + m_caster->RemoveAurasByCasterSpell(m_spellInfo->Id, m_caster->GetObjectGuid(), AURA_REMOVE_BY_CHANNEL); ObjectGuid target_guid = m_caster->GetChannelObjectGuid(); if (target_guid != m_caster->GetObjectGuid() && target_guid.IsUnit()) + { if (Unit* target = ObjectAccessor::GetUnit(*m_caster, target_guid)) - target->RemoveAurasByCasterSpell(m_spellInfo->Id, m_caster->GetObjectGuid()); + { + // Remove single target auras on target now if they expired + target->RemoveAurasByCasterSpell(m_spellInfo->Id, m_caster->GetObjectGuid(), AURA_REMOVE_BY_CHANNEL); + } + } + + // Remove dynamic objects if they are still alive. Persistent channel objects + // live until the cast has finished. Technically don't need to explicitly remove + // but no harm + m_caster->RemoveDynObject(m_spellInfo->Id); + m_caster->RemoveGameObject(m_spellInfo->Id, true); } // Only modify/send values if we are the current channeled spell ! if (m_caster->GetCurrentSpell(CURRENT_CHANNELED_SPELL) && m_caster->GetCurrentSpell(CURRENT_CHANNELED_SPELL) != this) @@ -4868,6 +4949,35 @@ void Spell::CastPreCastSpells(Unit* target) m_caster->CastSpell(target, (*si), true, m_CastItem); } +void Spell::AddChanneledAuraHolder(SpellAuraHolder *holder) +{ + // Set and hold in use until clean up to prevent any delete calls destroying + // the object before we can handle it + holder->SetInUse(true); + m_channeledHolders.push_back(holder); +} + +// Occurs when an aura should be removed from handling due to deletion or expiration +void Spell::RemoveChanneledAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode) +{ + // AURA_REMOVE_BY_CHANNEL comes from here, don't want to double erase. other modes are handled in holder update + if (!holder || mode == AURA_REMOVE_BY_CHANNEL || mode == AURA_REMOVE_BY_GROUP || mode == AURA_REMOVE_BY_RANGE) + return; + + SpellAuraHolderList::iterator iter = m_channeledHolders.begin(); + while (iter != m_channeledHolders.end()) + { + if (*iter == holder) + { + (*iter)->SetInUse(false); + m_channeledHolders.erase(iter); + break; + } + else + ++iter; + } +} + SpellCastResult Spell::CheckCast(bool strict) { // Cheat du joueur ? @@ -4877,7 +4987,7 @@ SpellCastResult Spell::CheckCast(bool strict) //sLog.outString("CheckCast de %u %s%s%s sur %s", // m_spellInfo->Id, strict ? "[strict]" : "", m_IsTriggeredSpell ? "[triggered]" : "", m_triggeredByAuraSpell ? "[triggeredByAura]" : "", m_targets.getUnitTargetGuid().GetString().c_str()); - // Quel sort peut-on faire lancer à un mob que l'on CM ? + // Quel sort peut-on faire lancer a un mob que l'on CM ? if (m_caster->hasUnitState(UNIT_STAT_CONTROLLED)) { if (m_spellInfo->Category == 21) // Enrager @@ -7220,7 +7330,7 @@ void Spell::DelayedChannel() if ((*ihit).missCondition == SPELL_MISS_NONE) { if (Unit* unit = m_caster->GetObjectGuid() == ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID)) - unit->DelaySpellAuraHolder(m_spellInfo->Id, delaytime, unit->GetObjectGuid()); + unit->DelaySpellAuraHolder(m_spellInfo->Id, delaytime, m_caster->GetObjectGuid()); } } @@ -7231,7 +7341,10 @@ void Spell::DelayedChannel() dynObj->Delay(delaytime); } - SendChannelUpdate(m_timer); + if (m_timer == 0) + m_caster->InterruptSpell(CURRENT_CHANNELED_SPELL); + else + SendChannelUpdate(m_timer); } void Spell::UpdateOriginalCasterPointer() @@ -7293,7 +7406,7 @@ CurrentSpellTypes Spell::GetCurrentContainer() const return (CURRENT_MELEE_SPELL); else if (IsAutoRepeat()) return (CURRENT_AUTOREPEAT_SPELL); - else if (IsChanneledSpell(m_spellInfo)) + else if (m_channeled) return (CURRENT_CHANNELED_SPELL); else return (CURRENT_GENERIC_SPELL); @@ -7395,7 +7508,7 @@ bool Spell::CheckTarget(Unit* target, SpellEffectIndex eff) bool Spell::IsNeedSendToClient() const { - return !IsChannelingVisual() && (m_spellInfo->SpellVisual != 0 || IsChanneledSpell(m_spellInfo) || + return !IsChannelingVisual() && (m_spellInfo->SpellVisual != 0 || m_channeled || m_spellInfo->speed > 0.0f || (!m_triggeredByAuraSpell && !m_IsTriggeredSpell)); } diff --git a/src/game/Spells/Spell.h b/src/game/Spells/Spell.h index cf3b6319a..e7eefc4ca 100644 --- a/src/game/Spells/Spell.h +++ b/src/game/Spells/Spell.h @@ -472,6 +472,9 @@ class Spell } void RemoveStealthAuras(); + void AddChanneledAuraHolder(SpellAuraHolder *holder); + void RemoveChanneledAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode); + void Delete() const; bool HasModifierApplied(SpellModifier* mod); @@ -511,6 +514,7 @@ class Spell bool m_autoRepeat; bool m_delayed; bool m_successCast; + bool m_channeled; bool m_isChannelingVisual; // For summoning ritual helpers visual spell // no effect handled, only channel start/update is sent @@ -522,6 +526,10 @@ class Spell uint64 m_delayMoment; // moment of next delay call, used internally bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only) + // Channeled spells system + typedef std::list SpellAuraHolderList; + SpellAuraHolderList m_channeledHolders; // aura holders of spell on targets for channeled spells. process in sync with spell + // These vars are used in both delayed spell system and modified immediate spell system bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers uint32 m_executeStack; // mark as executed to prevent deleted and access by dead pointers diff --git a/src/game/Spells/SpellAuras.cpp b/src/game/Spells/SpellAuras.cpp index 4b632d2f9..0f911c999 100644 --- a/src/game/Spells/SpellAuras.cpp +++ b/src/game/Spells/SpellAuras.cpp @@ -489,11 +489,37 @@ void Aura::SetModifier(AuraType t, int32 a, uint32 pt, int32 miscValue) m_modifier.periodictime = pt; } +void Aura::UpdatePeriodicTimer(int32 duration) +{ + if (m_isPeriodic) + { + // If duration gets changed, also change the periodic timer so that we + // aren't losing out on ticks. Required for channeled spells that utilize + // dynamic objects - don't want periodic timer initialized to the full + // tick timer on entry into the aura + // Avoid using modulo if we don't need to (slight perf increase) + int32 newtick = (duration > m_modifier.periodictime) ? (duration % m_modifier.periodictime) : duration; + // can be a divisible amount, in which case set it to the full period + if (!newtick) + newtick = m_modifier.periodictime; + + m_periodicTimer = newtick; + } +} + +void Aura::UpdateForAffected(uint32 diff) +{ + SetInUse(true); + Aura::Update(diff); + SetInUse(false); +} + void Aura::Update(uint32 diff) { if (m_isPeriodic) { m_periodicTimer -= diff; + if (m_periodicTimer <= 0) // tick also at m_periodicTimer==0 to prevent lost last tick in case max m_duration == (max m_periodicTimer)*N { // update before applying (aura can be removed in TriggerSpell or PeriodicTick calls) @@ -504,6 +530,12 @@ void Aura::Update(uint32 diff) } } +// Called by caster of this area aura to tick auras for affected targets +void AreaAura::UpdateForAffected(uint32 diff) +{ + Aura::UpdateForAffected(diff); +} + void AreaAura::Update(uint32 diff) { // update for the caster of the aura @@ -619,11 +651,12 @@ void AreaAura::Update(uint32 diff) for (Spell::UnitList::iterator tIter = targets.begin(); tIter != targets.end(); tIter++) { - // flag for seelction is need apply aura to current iteration target + // default flag is to apply aura to current iteration target, set to + // false if an area aura of the same spellid exists on the target bool apply = true; - // we need ignore present caster self applied are auras sometime - // in cases if this only auras applied for spell effect + // we need to ignore present caster self applied area auras sometimes + // in cases where this is the only aura applied for this spell effect Unit::SpellAuraHolderBounds spair = (*tIter)->GetSpellAuraHolderBounds(GetId()); for (Unit::SpellAuraHolderMap::const_iterator i = spair.first; i != spair.second; ++i) { @@ -632,12 +665,22 @@ void AreaAura::Update(uint32 diff) Aura *aur = i->second->GetAuraByEffectIndex(m_effIndex); - if (!aur) - continue; + if (aur) + { + // If this unit is the caster, update the tick. Units won't tick their + // own area auras. Make sure we don't double tick if this unit is the caster + // though + if (i->second->GetCasterGuid() == GetCasterGuid() && i->second->GetTarget()->GetObjectGuid() != GetCasterGuid()) + { + aur->UpdateForAffected(diff); + } - // in generic case not allow stacking area auras - apply = false; - break; + // in generic case not allow stacking area auras + apply = false; + break; + } + else + continue; } if (!apply) @@ -663,11 +706,19 @@ void AreaAura::Update(uint32 diff) addedToExisting = false; } - holder->SetAuraDuration(GetAuraDuration()); - AreaAura *aur = new AreaAura(actualSpellInfo, m_effIndex, &actualBasePoints, holder, (*tIter), caster, nullptr); holder->AddAura(aur, m_effIndex); + if (!holder->IsPassive() && !holder->IsPermanent()) + { + // Aura duration has already been decremented in caster holder update, so re-add + // for the target's holder or it will be one diff in the future + holder->SetAuraDuration(GetAuraDuration() + diff); + } + + // Caster's aura will tick at the end of this method, so subtract now to remain synced + holder->RefreshAuraPeriodicTimers(m_periodicTimer - diff); + if (addedToExisting) { (*tIter)->AddAuraToModList(aur); @@ -677,6 +728,17 @@ void AreaAura::Update(uint32 diff) } else (*tIter)->AddSpellAuraHolder(holder); + + DEBUG_LOG("Added aura %u to holder for spell %u on %s", m_effIndex, GetId(), (*tIter)->GetName()); + + // Add holder to spell if it's channeled so the updates are synced + if (IsChanneled() && !addedToExisting) + { + if (Spell *spell = caster->GetCurrentSpell(CURRENT_CHANNELED_SPELL)) + { + spell->AddChanneledAuraHolder(holder); + } + } } } } @@ -687,8 +749,10 @@ void AreaAura::Update(uint32 diff) Unit* caster = GetCaster(); Unit* target = GetTarget(); - Aura::Update(diff); + // Aura updates in caster update, see above + //Aura::Update(diff); + // only do range/removal check, tick is done on caster update to remain in sync // remove aura if out-of-range from caster (after teleport for example) // or caster is isolated or caster no longer has the aura // or caster is (no longer) friendly @@ -698,7 +762,7 @@ void AreaAura::Update(uint32 diff) !caster->HasAura(GetId(), GetEffIndex()) || caster->IsFriendlyTo(target) != needFriendly ) - target->RemoveSingleAuraFromSpellAuraHolder(GetId(), GetEffIndex(), GetCasterGuid()); + target->RemoveSingleAuraFromSpellAuraHolder(GetId(), GetEffIndex(), GetCasterGuid(), AURA_REMOVE_BY_RANGE); else if (m_areaAuraType == AREA_AURA_PARTY) // check if in same sub group { // not check group if target == owner or target == pet @@ -711,16 +775,16 @@ void AreaAura::Update(uint32 diff) { Player* checkTarget = target->GetCharmerOrOwnerPlayerOrPlayerItself(); if (!checkTarget || !pGroup->SameSubGroup(check, checkTarget)) - target->RemoveSingleAuraFromSpellAuraHolder(GetId(), GetEffIndex(), GetCasterGuid()); + target->RemoveSingleAuraFromSpellAuraHolder(GetId(), GetEffIndex(), GetCasterGuid(), AURA_REMOVE_BY_GROUP); } else - target->RemoveSingleAuraFromSpellAuraHolder(GetId(), GetEffIndex(), GetCasterGuid()); + target->RemoveSingleAuraFromSpellAuraHolder(GetId(), GetEffIndex(), GetCasterGuid(), AURA_REMOVE_BY_GROUP); } } else if (m_areaAuraType == AREA_AURA_PET) { if (target->GetObjectGuid() != caster->GetCharmerOrOwnerGuid()) - target->RemoveSingleAuraFromSpellAuraHolder(GetId(), GetEffIndex(), GetCasterGuid()); + target->RemoveSingleAuraFromSpellAuraHolder(GetId(), GetEffIndex(), GetCasterGuid(), AURA_REMOVE_BY_GROUP); } } } @@ -754,7 +818,7 @@ void PersistentAreaAura::Update(uint32 diff) Aura::Update(diff); if (remove) - GetTarget()->RemoveAura(GetId(), GetEffIndex()); + GetTarget()->RemoveSingleAuraFromSpellAuraHolder(GetHolder(), m_effIndex, AURA_REMOVE_BY_RANGE); } void Aura::ApplyModifier(bool apply, bool Real, bool skipCheckExclusive) @@ -1465,8 +1529,8 @@ void Aura::TriggerSpell() WorldObject* triggerTargetObject = nullptr; // for channeled spell cast applied from aura owner to channel target (persistent aura affects already applied to true target) - // come periodic casts applied to targets, so need seelct proper caster (ex. 15790) - if (IsChanneledSpell(GetSpellProto()) && GetSpellProto()->Effect[GetEffIndex()] != SPELL_EFFECT_PERSISTENT_AREA_AURA) + // some periodic casts applied to targets, so need select proper caster (ex. 15790) + if (IsChanneled() && GetSpellProto()->Effect[GetEffIndex()] != SPELL_EFFECT_PERSISTENT_AREA_AURA) { // interesting 2 cases: periodic aura at caster of channeled spell if (target->GetObjectGuid() == casterGUID) @@ -1783,7 +1847,7 @@ void Aura::HandleAuraDummy(bool apply, bool Real) } } - if (m_removeMode == AURA_REMOVE_BY_DEATH) + /*if (m_removeMode == AURA_REMOVE_BY_DEATH) // redundant, AM is cancelled in aura holder removal { // Stop caster Arcane Missle chanelling on death if (GetSpellProto()->IsFitToFamily()) @@ -1793,7 +1857,7 @@ void Aura::HandleAuraDummy(bool apply, bool Real) return; } - } + }*/ } // AT APPLY & REMOVE @@ -2781,7 +2845,8 @@ void Unit::ModPossess(Unit* target, bool apply, AuraRemoveMode m_removeMode) // On transfert la menace vers celui qui a CM target->TransferAttackersThreatTo(caster); - caster->InterruptSpell(CURRENT_CHANNELED_SPELL); // the spell is not automatically canceled when interrupted, do it now + // spell is interrupted on channeled aura removal, don't need to interrupt here + //caster->InterruptSpell(CURRENT_CHANNELED_SPELL); p_caster->SetMover(nullptr); @@ -5819,6 +5884,7 @@ SpellAuraHolder::SpellAuraHolder(SpellEntry const* spellproto, Unit *target, Wor m_isDeathPersist = IsDeathPersistentSpell(spellproto); m_isSingleTarget = IsSingleTargetSpell(spellproto); m_procCharges = spellproto->procCharges; + m_isChanneled = IsChanneledSpell(spellproto); m_isRemovedOnShapeLost = (m_casterGuid == m_target->GetObjectGuid() && (m_spellProto->Stances || m_spellProto->Id == 24864) && @@ -6439,7 +6505,7 @@ void SpellAuraHolder::Update(uint32 diff) { if (target) target->RemoveAurasDueToSpell(m_spellProto->Id, this); - if (IsChanneledSpell(m_spellProto)) + if (m_isChanneled) caster->InterruptSpell(CURRENT_CHANNELED_SPELL); if (Player* plCaster = caster->ToPlayer()) Spell::SendCastResult(plCaster, m_spellProto, SPELL_FAILED_FIZZLE); @@ -6454,7 +6520,7 @@ void SpellAuraHolder::Update(uint32 diff) aura->UpdateAura(diff); // Channeled aura required check distance from caster - if (IsChanneledSpell(m_spellProto) && GetCasterGuid() != m_target->GetObjectGuid()) + if (m_isChanneled && GetCasterGuid() != m_target->GetObjectGuid()) { Unit* caster = GetCaster(); if (!caster) @@ -6500,6 +6566,27 @@ void SpellAuraHolder::RefreshHolder() UpdateAuraDuration(); } +/** + * Updates periodic timers based on the current duration. Used for channeled spells + * which are applied using dynamic objects, when we want the tick to be based on + * the current spell timer rather than a fresh holder. + * @param duration Custom duration to base tick on (typically in the case of passive auras) + * + */ +void SpellAuraHolder::RefreshAuraPeriodicTimers(uint32 duration) +{ + for (int i = 0 ; i < MAX_EFFECT_INDEX; ++i) + { + if (Aura* pAura = GetAuraByEffectIndex(SpellEffectIndex(i))) + { + // If the aura is periodic, update the periodic timer to correspond with the new + // aura timer + if (pAura->IsPeriodic()) + pAura->UpdatePeriodicTimer(duration ? duration : m_duration); + } + } +} + void SpellAuraHolder::SetAuraMaxDuration(int32 duration) { m_maxDuration = duration; @@ -6512,6 +6599,15 @@ void SpellAuraHolder::SetAuraMaxDuration(int32 duration) } } +uint32 SpellAuraHolder::GetAuraPeriodicTickTimer(SpellEffectIndex index) const +{ + Aura *aur = m_auras[index]; + if (!aur) + return -1; + + return aur->GetAuraPeriodicTimer(); +} + bool SpellAuraHolder::HasMechanic(uint32 mechanic) const { if (mechanic == m_spellProto->Mechanic) @@ -6772,7 +6868,7 @@ void SpellAuraHolder::CalculateForDebuffLimit() else m_debuffLimitScore = 0; } - else if (IsChanneledSpell(GetSpellProto()) && m_debuffLimitScore < 1) + else if (m_isChanneled && m_debuffLimitScore < 1) m_debuffLimitScore = 1; } diff --git a/src/game/Spells/SpellAuras.h b/src/game/Spells/SpellAuras.h index eeb6945e7..0b00d0706 100644 --- a/src/game/Spells/SpellAuras.h +++ b/src/game/Spells/SpellAuras.h @@ -74,6 +74,7 @@ class MANGOS_DLL_SPEC SpellAuraHolder bool ModStackAmount(int32 num); // return true if last charge dropped Aura* GetAuraByEffectIndex(SpellEffectIndex index) const { return m_auras[index]; } + uint32 GetAuraPeriodicTickTimer(SpellEffectIndex index) const; uint32 GetId() const { return m_spellProto->Id; } SpellEntry const* GetSpellProto() const { return m_spellProto; } @@ -133,15 +134,17 @@ class MANGOS_DLL_SPEC SpellAuraHolder void UpdateHolder(uint32 diff) { SetInUse(true); Update(diff); SetInUse(false); } void Update(uint32 diff); void RefreshHolder(); + void RefreshAuraPeriodicTimers(uint32 duration = 0); bool IsSingleTarget() const { return m_isSingleTarget; } void SetIsSingleTarget(bool val) { m_isSingleTarget = val; } + bool IsChanneled() { return m_isChanneled; } void UnregisterSingleCastHolder(); int32 GetAuraMaxDuration() const { return m_maxDuration; } void SetAuraMaxDuration(int32 duration); int32 GetAuraDuration() const { return m_duration; } - void SetAuraDuration(int32 duration) { m_duration = duration; } + void SetAuraDuration(int32 duration) { m_duration = duration; }; uint8 GetAuraSlot() const { return m_auraSlot; } void SetAuraSlot(uint8 slot) { m_auraSlot = slot; } @@ -169,6 +172,7 @@ class MANGOS_DLL_SPEC SpellAuraHolder time_t GetAuraApplyTime() const { return m_applyTime; } void SetRemoveMode(AuraRemoveMode mode) { m_removeMode = mode; } + AuraRemoveMode GetRemoveMode() const { return m_removeMode; } void SetLoadedState(ObjectGuid const& casterGUID, ObjectGuid const& itemGUID, uint32 stackAmount, uint32 charges, int32 maxduration, int32 duration) { m_casterGuid = casterGUID; @@ -223,6 +227,7 @@ class MANGOS_DLL_SPEC SpellAuraHolder bool m_isRemovedOnShapeLost:1; bool m_isSingleTarget:1; // true if it's a single target spell and registered at caster - can change at spell steal for example bool m_deleted:1; + bool m_isChanneled:1; bool m_makesTargetSecondaryFocus; bool m_spellTriggered; // applied by a triggered spell (used in debuff priority computation) @@ -406,6 +411,7 @@ class MANGOS_DLL_SPEC Aura int32 GetAuraDuration() const { return GetHolder()->GetAuraDuration(); } time_t GetAuraApplyTime() const { return m_applyTime; } uint32 GetAuraTicks() const { return m_periodicTick; } + uint32 GetAuraPeriodicTimer() const { return m_periodicTimer; } uint32 GetAuraMaxTicks() const { int32 maxDuration = GetAuraMaxDuration(); @@ -428,6 +434,7 @@ class MANGOS_DLL_SPEC Aura bool IsAreaAura() const { return m_isAreaAura; } bool IsPeriodic() const { return m_isPeriodic; } bool IsInUse() const { return m_in_use; } + bool IsChanneled() const { return GetHolder()->IsChanneled(); } // NOSTALRIUS void SetPositive(bool pos) { m_positive = pos; } void SetPersistent(bool on) { m_isPersistent = on; } @@ -459,10 +466,14 @@ class MANGOS_DLL_SPEC Aura // NOSTALRIUS: Ajout de 'skipCheckExclusive' void ApplyModifier(bool apply, bool Real = false, bool skipCheckExclusive = false); + void UpdatePeriodicTimer(int32 duration); void UpdateAura(uint32 diff) { SetInUse(true); Update(diff); SetInUse(false); } + // Called only in Aura::Update, for area aura owners to update affected targets + virtual void UpdateForAffected(uint32 diff); void Refresh(Unit* caster, Unit* target, SpellAuraHolder* pRefreshWithHolder); void SetRemoveMode(AuraRemoveMode mode) { m_removeMode = mode; } + AuraRemoveMode GetRemoveMode() const { return m_removeMode; } virtual Unit* GetTriggerTarget() const { return m_spellAuraHolder->GetTarget(); } @@ -525,6 +536,7 @@ class MANGOS_DLL_SPEC AreaAura : public Aura ~AreaAura(); protected: void Update(uint32 diff); + void UpdateForAffected(uint32 diff); private: float m_radius; AreaAuraType m_areaAuraType;