Files
moonwell-core-vanilla/src/game/Objects/DynamicObject.cpp
T
Prithu 094f55e879 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?
2017-06-29 08:25:15 +01:00

266 lines
8.2 KiB
C++

/*
* Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
* Copyright (C) 2009-2011 MaNGOSZero <https://github.com/mangos/zero>
* Copyright (C) 2011-2016 Nostalrius <https://nostalrius.org>
* Copyright (C) 2016-2017 Elysium Project <https://github.com/elysium-project>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Common.h"
#include "UpdateMask.h"
#include "Opcodes.h"
#include "World.h"
#include "ObjectAccessor.h"
#include "Database/DatabaseEnv.h"
#include "GridNotifiers.h"
#include "CellImpl.h"
#include "GridNotifiersImpl.h"
#include "SpellMgr.h"
DynamicObject::DynamicObject() : WorldObject(), m_effIndex(EFFECT_INDEX_0), m_spellId(0), m_aliveDuration(0), m_positive(false), m_radius(0)
{
m_objectType |= TYPEMASK_DYNAMICOBJECT;
m_objectTypeId = TYPEID_DYNAMICOBJECT;
m_updateFlag = (UPDATEFLAG_ALL | UPDATEFLAG_HAS_POSITION);
m_valuesCount = DYNAMICOBJECT_END;
}
void DynamicObject::AddToWorld()
{
///- Register the dynamicObject for guid lookup
if (!IsInWorld())
GetMap()->InsertObject<DynamicObject>(GetObjectGuid(), this);
Object::AddToWorld();
}
void DynamicObject::RemoveFromWorld()
{
///- Remove the dynamicObject from the accessor
if (IsInWorld())
{
GetMap()->EraseObject<DynamicObject>(GetObjectGuid());
GetViewPoint().Event_RemovedFromWorld();
}
Object::RemoveFromWorld();
}
bool DynamicObject::Create(uint32 guidlow, Unit *caster, uint32 spellId, SpellEffectIndex effIndex, float x, float y, float z, int32 duration, float radius, DynamicObjectType type)
{
WorldObject::_Create(guidlow, HIGHGUID_DYNAMICOBJECT);
SetMap(caster->GetMap());
Relocate(x, y, z, 0);
if (!IsPositionValid())
{
sLog.outError("DynamicObject (spell %u eff %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)", spellId, effIndex, GetPositionX(), GetPositionY());
return false;
}
SetEntry(spellId);
SetObjectScale(DEFAULT_OBJECT_SCALE);
SetGuidValue(DYNAMICOBJECT_CASTER, caster->GetObjectGuid());
/* Bytes field, so it's really 4 bit fields. These flags are unknown, but we do know that 0x00000001 is set for most.
Farsight for example, does not have this flag, instead it has 0x80000002.
Flags are set dynamically with some conditions, so one spell may have different flags set, depending on those conditions.
The size of the visual may be controlled to some degree with these flags.
uint32 bytes = 0x00000000;
bytes |= 0x01;
bytes |= 0x00 << 8;
bytes |= 0x00 << 16;
bytes |= 0x00 << 24;
*/
uint32 bytes = type;
// Nostalrius: fusee eclairante. Fix diametre visuel.
if (spellId == 1543)
bytes = 0x10; // Aucune idee de ce que ca represente ...
SetUInt32Value(DYNAMICOBJECT_BYTES, bytes);
SetUInt32Value(DYNAMICOBJECT_SPELLID, spellId);
if (bytes == 0x10)
SetFloatValue(DYNAMICOBJECT_RADIUS, radius * 2.0f); // Serait-ce enfait le diametre dans ce cas ?
else
SetFloatValue(DYNAMICOBJECT_RADIUS, radius);
SetFloatValue(DYNAMICOBJECT_POS_X, x);
SetFloatValue(DYNAMICOBJECT_POS_Y, y);
SetFloatValue(DYNAMICOBJECT_POS_Z, z);
SpellEntry const* spellProto = sSpellMgr.GetSpellEntry(spellId);
if (!spellProto)
{
sLog.outError("DynamicObject (spell %u) not created. Spell not exist!", spellId, GetPositionX(), GetPositionY());
return false;
}
m_aliveDuration = duration;
m_radius = radius;
m_effIndex = effIndex;
m_spellId = spellId;
m_positive = IsPositiveEffect(spellProto, m_effIndex);
m_channeled = IsChanneledSpell(spellProto);
return true;
}
Unit* DynamicObject::GetCaster() const
{
// can be not found in some cases
return ObjectAccessor::GetUnit(*this, GetCasterGuid());
}
void DynamicObject::Update(uint32 update_diff, uint32 p_time)
{
WorldObject::Update(update_diff, p_time);
// caster can be not in world at time dynamic object update, but dynamic object not yet deleted in Unit destructor
Unit* caster = GetCaster();
if (!caster)
{
Delete();
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;
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)
iter->second += update_diff;
// have radius and work as persistent effect
if (m_radius)
{
// TODO: make a timer and update this in larger intervals
MaNGOS::DynamicObjectUpdater notifier(*this, caster, m_positive);
Cell::VisitAllObjects(this, notifier, m_radius);
// Nostalrius
// Hackfix pour Piege explosif. Ne doit s'activer qu'une fois.
switch (m_spellId)
{
case 13812: // rang 1
case 14314: // rang 2
case 14315: // rang 3
m_radius = 0.0f;
break;
}
}
if (deleteThis)
{
caster->RemoveDynObjectWithGUID(GetObjectGuid());
Delete();
}
}
void DynamicObject::Delete()
{
SendObjectDeSpawnAnim(GetObjectGuid());
AddObjectToRemoveList();
}
void DynamicObject::Delay(int32 delaytime)
{
m_aliveDuration -= delaytime;
for (AffectedMap::iterator iter = m_affected.begin(); iter != m_affected.end();)
{
Unit *target = GetMap()->GetUnit(iter->first);
if (target)
{
SpellAuraHolder *holder = target->GetSpellAuraHolder(m_spellId, GetCasterGuid());
if (!holder)
{
++iter;
continue;
}
bool foundAura = false;
for (int32 i = m_effIndex + 1; i < MAX_EFFECT_INDEX; ++i)
{
if ((holder->GetSpellProto()->Effect[i] == SPELL_EFFECT_PERSISTENT_AREA_AURA || holder->GetSpellProto()->Effect[i] == SPELL_EFFECT_ADD_FARSIGHT) && holder->m_auras[i])
{
foundAura = true;
break;
}
}
if (foundAura)
{
++iter;
continue;
}
target->DelaySpellAuraHolder(m_spellId, delaytime, GetCasterGuid());
++iter;
}
else
m_affected.erase(iter++);
}
}
bool DynamicObject::isVisibleForInState(Player const* u, WorldObject const* viewPoint, bool inVisibleList) const
{
if (!IsInWorld() || !u->IsInWorld())
return false;
// always seen by owner
if (GetCasterGuid() == u->GetObjectGuid())
return true;
// normal case
return IsWithinDistInMap(viewPoint, GetMap()->GetVisibilityDistance() + (inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f), false);
}
bool DynamicObject::IsHostileTo(Unit const* unit) const
{
if (Unit* owner = GetCaster())
return owner->IsHostileTo(unit);
else
return false;
}
bool DynamicObject::IsFriendlyTo(Unit const* unit) const
{
if (Unit* owner = GetCaster())
return owner->IsFriendlyTo(unit);
else
return true;
}
bool DynamicObject::NeedsRefresh(Unit* unit) const
{
AffectedMap::const_iterator it = m_affected.find(unit->GetObjectGuid());
return it == m_affected.end() || it->second > 2000;
}