From 094f55e87923c8e16c4a7aa2cc1e9a96792b048c Mon Sep 17 00:00:00 2001 From: Prithu Date: Thu, 29 Jun 2017 17:25:15 +1000 Subject: [PATCH] Fix area aura and channel spell tick loss by syncing updates with the caster (#1099) * Now cache whether the current spell is channeled on DynamicObjects, and prevent deletion of the object if it is from a channeled spell - Fixes premature channel ending when the object despawns before the cast finshes * Now update SpellAuraHolders for channeled spells on Spell::update to ensure the durations remain synced Now cache whether the spell is channeled * Now add aura holder to spell cast for synced updates in channeled area auras Implemented method to sync periodic ticks with remaining aura duration * Add aura holders to channeled spell caster holder list when a unit enters the area of a dynamic object Now sync persistent effect ticks with the remaining aura duration * No longer process channeled spell holders on target unit update, instead they are now updated in the caster's spell update Now buffer unit spell updates (mostly only applicable for players) rather than updating twice per world update if the unit is a player Fixed an issue where channeled AoE spells initiated with CastSpell were having a unique target set, which caused them to cancel if the unit moved out of the area of effect * Replaced const_iterator usage with plain iterators when performing changes * Implemented additional aura remove types * Implemented passive periodic aura tick syncing on application - the aura still currently updates separately, so it can eventually desync Added new aura remove types to area/persistent aura removal calls Fixed an issue with persistent area auras where all holders of the same spell from different casters would be removed if a unit left the range of one Removed redundant arcane missiles cancellation * Updated RemoveSpellAuraHolder channel handling to coincide with new system * Fixed an issue causing double interrupts for channeled spells which are delayed to 0 duration Implemented removal of aura holders from channeled spells, which can occur when other actions remove the holder (eg, Divine Shield) Now remove all remaining holders on units when a channel is ended * Fixed another case where channeled spells were being interrupted more than once * Fixed a bug which was preventing pushback during channeling from having any effect on the aura holder, allowing the full amount of ticks sometimes (depending on spell duration and hit timing) * Fixed aura tick timers not being updated on area aura application * Fixed totems not updating on the final tick before despawn * Area auras now tick in accordance with the caster's update timer to ensure ticks remain synced and none are lost (eg totems) * Fixed order of finish and channel update on FinishSpell * Removed double interrupt call on mod possess end * Now handle removal of holders from the channeled holders list during spell updates more robustly * Now handle some aura remove modes in spell update for efficiency, while allowing others to be handled normally * No longer check through list of channeled holders on AddChanneledHolders, instead we check before calling for better efficiency * Updated some comments, removed some debug logging * Fixed missing parenthesis - merge broke? --- 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 | 126 +++++++++++++++---------- 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, 403 insertions(+), 101 deletions(-) diff --git a/src/game/Maps/GridNotifiersImpl.h b/src/game/Maps/GridNotifiersImpl.h index d14460346..1002c0ba7 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 @@ -176,6 +177,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) { @@ -188,12 +190,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 { @@ -204,6 +209,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 7b8f38768..be5620c63 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 e5a699a9d..8c470d79e 100644 --- a/src/game/Objects/Unit.cpp +++ b/src/game/Objects/Unit.cpp @@ -205,6 +205,8 @@ Unit::Unit() _casterChaseDistance = 0.0f; m_doExtraAttacks = false; + + m_spellUpdateTimeBuffer = 0; } Unit::~Unit() @@ -256,13 +258,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) { @@ -315,7 +328,7 @@ void Unit::Update(uint32 update_diff, uint32 p_time) --m_extraAttacks; } resetAttackTimer(BASE_ATTACK); - + ExtraAttacksLocked(false); } @@ -328,9 +341,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); @@ -735,7 +745,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; } @@ -964,7 +974,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()) @@ -1278,10 +1288,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()); @@ -1544,7 +1558,7 @@ void Unit::CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *da default: break; } - + bool immune = true; bool feral = IsInFeralForm(); @@ -1554,12 +1568,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; @@ -1711,10 +1725,10 @@ void Unit::CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *da int SkillDiff = 0; SkillDiff = pVictim->GetDefenseSkillValue(this) - GetWeaponSkillValue(damageInfo->attackType, pVictim); float reducePercent = 1.0f; - // (Youfie) Formule de calcul de la réduction de dégâts des érafles, influencée en pré-BC par le +skill au delà de [niveau du joueur * 5] - // Formule d'Athan retenue et supposée comme Blizz-like au regard des multiples sources et tests concordants + // (Youfie) Formule de calcul de la réduction de dégâts des érafles, influencée en pré-BC par le +skill au delà de [niveau du joueur * 5] + // Formule d'Athan retenue et supposée comme Blizz-like au regard des multiples sources et tests concordants // float reducePercent = 1 - (5*(pow(2,(victimDefenseSkill/5) - (attackerWeaponSkill/5) - 1))/100); - // Après tentative d'implémentation "propre" de la formule et de nombreux échecs, mise en place de celle-ci après calcul manuel des différentes valeurs + // Après tentative d'implémentation "propre" de la formule et de nombreux échecs, mise en place de celle-ci après calcul manuel des différentes valeurs // cf. http://nostalrius.org/forum/viewtopic.php?p=43964#p43964 pour infos et sources if (SkillDiff >= 15) reducePercent = 0.6500f; @@ -1766,7 +1780,7 @@ void Unit::CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *da break; } - // sLog.outString("SkillDiff = %i, reducePercent = %f", SkillDiff, reducePercent); // Pour tests & débug via la console + // sLog.outString("SkillDiff = %i, reducePercent = %f", SkillDiff, reducePercent); // Pour tests & débug via la console damageInfo->cleanDamage += uint32((1.0f - reducePercent) * damageInfo->totalDamage); damageInfo->totalDamage = uint32(reducePercent * damageInfo->totalDamage); @@ -1781,7 +1795,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; @@ -1943,7 +1957,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; @@ -2092,7 +2106,7 @@ void Unit::CalculateDamageAbsorbAndResist(Unit *pCaster, SpellSchoolMask schoolM // Magic damage, check for resists bool canResist = (schoolMask & SPELL_SCHOOL_MASK_NORMAL) == 0; - // NOSTALRIUS: Sorts binaires ne sont pas résistés. + // NOSTALRIUS: Sorts binaires ne sont pas résistés. if (canResist && spellProto && spellProto->IsBinary()) canResist = false; else if (spellProto && spellProto->AttributesEx4 & SPELL_ATTR_EX4_IGNORE_RESISTANCES) @@ -2526,16 +2540,16 @@ MeleeHitOutcome Unit::RollMeleeOutcomeAgainst(const Unit *pVictim, WeaponAttackT int32 maxskill = attackerMaxSkillValueForLevel; skill = (skill > maxskill) ? maxskill : skill; - // (Youfie) Le +skill avant BC ne permet pas de réduire la fréquence des glancing blows une fois qu'il est égal au niveau du joueur*5 + // (Youfie) Le +skill avant BC ne permet pas de réduire la fréquence des glancing blows une fois qu'il est égal au niveau du joueur*5 if (attackerWeaponSkill > maxskill) attackerWeaponSkill = maxskill; - // (Youfie) Chance de glance en Vanilla (inchangée par le +skill au delà de maxskill, cf. au dessus) : + // (Youfie) Chance de glance en Vanilla (inchangée par le +skill au delà de maxskill, cf. au dessus) : tmp = (10 + ((victimDefenseSkill - attackerWeaponSkill) * 2)) * 100; tmp = tmp > 4000 ? 4000 : tmp; if (tmp < 0) tmp = 0; - // sLog.outString("tmp = %i, Skill = %i, Max Skill = %i", tmp, attackerWeaponSkill, attackerMaxSkillValueForLevel); //Pour tests & débug via la console + // sLog.outString("tmp = %i, Skill = %i, Max Skill = %i", tmp, attackerWeaponSkill, attackerMaxSkillValueForLevel); //Pour tests & débug via la console if (roll < (sum += tmp)) { @@ -3315,6 +3329,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); } @@ -3500,10 +3520,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); } @@ -4307,14 +4327,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; } @@ -4556,7 +4576,7 @@ void Unit::RemoveSpellAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode) SpellEntry const* AurSpellInfo = holder->GetSpellProto(); Totem* statue = nullptr; Unit* caster = holder->GetCaster(); - if (IsChanneledSpell(AurSpellInfo) && caster) + if (holder->IsChanneled() && caster) if (caster->GetTypeId() == TYPEID_UNIT && ((Creature*)caster)->IsTotem() && ((Totem*)caster)->GetTotemType() == TOTEM_STATUE) statue = ((Totem*)caster); @@ -4594,6 +4614,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()) @@ -4606,7 +4627,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) @@ -4618,12 +4639,19 @@ void Unit::RemoveSpellAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode) break; } } - - if (IsChanneledSpell(AurSpellInfo) && caster && (mode != AURA_REMOVE_BY_EXPIRE || caster->IsControlledByPlayer())) + + if (holder->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) @@ -4759,6 +4787,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()); @@ -5220,7 +5250,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 @@ -5591,7 +5621,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()) { @@ -6229,7 +6259,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); @@ -7803,7 +7833,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); @@ -7816,7 +7846,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); @@ -9398,7 +9428,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(); @@ -9475,7 +9505,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; @@ -10543,14 +10573,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; } @@ -11166,14 +11196,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 9e66c56f0..3a23f7275 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 @@ -684,6 +686,7 @@ enum CurrentSpellTypes #define CURRENT_FIRST_NON_MELEE_SPELL 1 #define CURRENT_MAX_SPELL 4 +#define UNIT_SPELL_UPDATE_TIME_BUFFER 60 struct GlobalCooldown { @@ -1446,7 +1449,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); @@ -1832,7 +1835,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); @@ -1959,6 +1962,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 802d2667a..28db50a0c 100644 --- a/src/game/Spells/Spell.cpp +++ b/src/game/Spells/Spell.cpp @@ -260,7 +260,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"); @@ -324,6 +325,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 @@ -1113,7 +1116,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)) @@ -1535,7 +1538,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) @@ -1559,6 +1562,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); + } } } @@ -3062,7 +3073,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) @@ -3105,7 +3116,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) @@ -3339,7 +3350,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 @@ -3439,7 +3450,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); @@ -3725,6 +3736,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 @@ -3862,7 +3909,7 @@ void Spell::finish(bool ok) return; } - if (!IsChanneledSpell(m_spellInfo)) + if (!m_channeled) HandleAddTargetTriggerAuras(); // Heal caster for all health leech from all targets @@ -4172,7 +4219,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); @@ -4278,6 +4325,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) @@ -4308,12 +4358,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) @@ -4722,6 +4803,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 ? @@ -4731,7 +4841,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 @@ -7038,7 +7148,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()); } } @@ -7049,7 +7159,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() @@ -7111,7 +7224,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); @@ -7212,7 +7325,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 1e528a7ad..cc7eb559c 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 77116c06a..5ea81d4ac 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); } } } @@ -756,7 +820,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) @@ -1389,8 +1453,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) @@ -1653,7 +1717,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()) @@ -1663,7 +1727,7 @@ void Aura::HandleAuraDummy(bool apply, bool Real) return; } - } + }*/ } // AT APPLY & REMOVE @@ -2639,7 +2703,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); @@ -5582,6 +5647,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) && @@ -6199,7 +6265,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); @@ -6214,7 +6280,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) @@ -6260,6 +6326,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; @@ -6272,6 +6359,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) @@ -6531,7 +6627,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 34af5f773..980cb96b0 100644 --- a/src/game/Spells/SpellAuras.h +++ b/src/game/Spells/SpellAuras.h @@ -73,6 +73,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; } @@ -135,15 +136,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; } @@ -171,6 +174,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; @@ -224,6 +228,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;