2010-10-07 15:35:36 +02:00
|
|
|
/*
|
2020-01-02 06:44:10 +01:00
|
|
|
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
2010-10-07 15:35:36 +02:00
|
|
|
*
|
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
2008-10-02 16:23:55 -05:00
|
|
|
*/
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2017-06-04 01:00:45 +02:00
|
|
|
#include "DynamicObject.h"
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "Common.h"
|
2017-03-02 02:19:25 +01:00
|
|
|
#include "GameTime.h"
|
2017-05-18 23:52:58 +02:00
|
|
|
#include "Log.h"
|
2017-06-04 01:00:45 +02:00
|
|
|
#include "Map.h"
|
2017-05-18 23:52:58 +02:00
|
|
|
#include "ObjectAccessor.h"
|
2018-04-01 00:28:09 +02:00
|
|
|
#include "PhasingHandler.h"
|
2017-06-04 01:00:45 +02:00
|
|
|
#include "Player.h"
|
2010-08-06 19:23:43 +02:00
|
|
|
#include "ScriptMgr.h"
|
2017-06-04 01:00:45 +02:00
|
|
|
#include "SpellAuras.h"
|
|
|
|
|
#include "SpellInfo.h"
|
|
|
|
|
#include "SpellMgr.h"
|
2014-03-16 20:00:09 +01:00
|
|
|
#include "Transport.h"
|
2017-06-04 01:00:45 +02:00
|
|
|
#include "Unit.h"
|
|
|
|
|
#include "UpdateData.h"
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2011-12-20 17:05:08 -05:00
|
|
|
DynamicObject::DynamicObject(bool isWorldObject) : WorldObject(isWorldObject),
|
2020-08-14 17:06:03 +02:00
|
|
|
_aura(nullptr), _removedAura(nullptr), _caster(nullptr), _duration(0), _isViewpoint(false)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
m_objectType |= TYPEMASK_DYNAMICOBJECT;
|
|
|
|
|
m_objectTypeId = TYPEID_DYNAMICOBJECT;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2018-10-04 18:50:21 +02:00
|
|
|
m_updateFlag.Stationary = true;
|
2011-02-04 00:27:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DynamicObject::~DynamicObject()
|
|
|
|
|
{
|
|
|
|
|
// make sure all references were properly removed
|
2011-04-19 15:14:50 +02:00
|
|
|
ASSERT(!_aura);
|
|
|
|
|
ASSERT(!_caster);
|
|
|
|
|
ASSERT(!_isViewpoint);
|
2011-06-16 00:55:27 +02:00
|
|
|
delete _removedAura;
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
void DynamicObject::AddToWorld()
|
|
|
|
|
{
|
2011-02-04 00:27:43 +01:00
|
|
|
///- Register the dynamicObject for guid lookup and for caster
|
2010-04-07 19:14:10 +02:00
|
|
|
if (!IsInWorld())
|
2009-03-25 15:54:23 -06:00
|
|
|
{
|
2015-02-25 00:13:14 +01:00
|
|
|
GetMap()->GetObjectsStore().Insert<DynamicObject>(GetGUID(), this);
|
2009-03-25 15:54:23 -06:00
|
|
|
WorldObject::AddToWorld();
|
2011-02-04 00:27:43 +01:00
|
|
|
BindToCaster();
|
2009-03-25 15:54:23 -06:00
|
|
|
}
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
void DynamicObject::RemoveFromWorld()
|
|
|
|
|
{
|
2011-02-04 00:27:43 +01:00
|
|
|
///- Remove the dynamicObject from the accessor and from all lists of objects in world
|
2010-04-07 19:14:10 +02:00
|
|
|
if (IsInWorld())
|
2009-03-25 15:54:23 -06:00
|
|
|
{
|
2011-04-19 15:14:50 +02:00
|
|
|
if (_isViewpoint)
|
2011-02-04 00:27:43 +01:00
|
|
|
RemoveCasterViewpoint();
|
|
|
|
|
|
2011-04-19 15:14:50 +02:00
|
|
|
if (_aura)
|
2011-02-04 00:27:43 +01:00
|
|
|
RemoveAura();
|
|
|
|
|
|
|
|
|
|
// dynobj could get removed in Aura::RemoveAura
|
|
|
|
|
if (!IsInWorld())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
UnbindFromCaster();
|
2009-03-25 15:54:23 -06:00
|
|
|
WorldObject::RemoveFromWorld();
|
2015-02-25 00:13:14 +01:00
|
|
|
GetMap()->GetObjectsStore().Remove<DynamicObject>(GetGUID());
|
2009-03-25 15:54:23 -06:00
|
|
|
}
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2020-11-15 21:59:18 +01:00
|
|
|
bool DynamicObject::CreateDynamicObject(ObjectGuid::LowType guidlow, Unit* caster, SpellInfo const* spell, Position const& pos, float radius, DynamicObjectType type, SpellCastVisual spellVisual)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2009-07-16 11:49:00 +08:00
|
|
|
SetMap(caster->GetMap());
|
2009-08-29 23:20:16 -05:00
|
|
|
Relocate(pos);
|
2010-04-07 19:14:10 +02:00
|
|
|
if (!IsPositionValid())
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2013-11-08 11:12:17 +01:00
|
|
|
TC_LOG_ERROR("misc", "DynamicObject (spell %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)", spell->Id, GetPositionX(), GetPositionY());
|
2008-10-02 16:23:55 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-10-29 21:13:21 +01:00
|
|
|
WorldObject::_Create(ObjectGuid::Create<HighGuid::DynamicObject>(GetMapId(), spell->Id, guidlow));
|
2018-04-01 00:28:09 +02:00
|
|
|
PhasingHandler::InheritPhaseShift(this, caster);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2022-04-23 23:03:22 +02:00
|
|
|
UpdatePositionData();
|
|
|
|
|
SetZoneScript();
|
|
|
|
|
|
2012-10-20 00:02:32 +02:00
|
|
|
SetEntry(spell->Id);
|
2014-10-29 21:13:21 +01:00
|
|
|
SetObjectScale(1.0f);
|
2019-06-03 20:40:34 +02:00
|
|
|
auto dynamicObjectData = m_values.ModifyValue(&DynamicObject::m_dynamicObjectData);
|
|
|
|
|
SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::Caster), caster->GetGUID());
|
|
|
|
|
SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::Type), type);
|
2020-12-01 21:08:06 +01:00
|
|
|
SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::SpellVisual).ModifyValue(&UF::SpellCastVisual::SpellXSpellVisualID), spellVisual.SpellXSpellVisualID);
|
|
|
|
|
SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::SpellVisual).ModifyValue(&UF::SpellCastVisual::ScriptVisualID), spellVisual.ScriptVisualID);
|
2019-06-03 20:40:34 +02:00
|
|
|
SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::SpellID), spell->Id);
|
|
|
|
|
SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::Radius), radius);
|
2017-03-02 02:19:25 +01:00
|
|
|
SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::CastTime), GameTime::GetGameTimeMS());
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2011-12-20 17:05:08 -05:00
|
|
|
if (IsWorldObject())
|
2011-11-28 14:19:29 -05:00
|
|
|
setActive(true); //must before add to map to be put in world container
|
|
|
|
|
|
2014-03-16 20:00:09 +01:00
|
|
|
Transport* transport = caster->GetTransport();
|
|
|
|
|
if (transport)
|
|
|
|
|
{
|
|
|
|
|
float x, y, z, o;
|
|
|
|
|
pos.GetPosition(x, y, z, o);
|
|
|
|
|
transport->CalculatePassengerOffset(x, y, z, &o);
|
|
|
|
|
m_movementInfo.transport.pos.Relocate(x, y, z, o);
|
|
|
|
|
|
|
|
|
|
// This object must be added to transport before adding to map for the client to properly display it
|
|
|
|
|
transport->AddPassenger(this);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-28 14:19:29 -05:00
|
|
|
if (!GetMap()->AddToMap(this))
|
2014-03-16 20:00:09 +01:00
|
|
|
{
|
|
|
|
|
// Returning false will cause the object to be deleted - remove from transport
|
|
|
|
|
if (transport)
|
|
|
|
|
transport->RemovePassenger(this);
|
2011-11-28 14:19:29 -05:00
|
|
|
return false;
|
2014-03-16 20:00:09 +01:00
|
|
|
}
|
2011-11-28 14:19:29 -05:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
void DynamicObject::Update(uint32 p_time)
|
|
|
|
|
{
|
2012-05-30 08:01:02 +02:00
|
|
|
// caster has to be always available and in the same map
|
2011-04-19 15:14:50 +02:00
|
|
|
ASSERT(_caster);
|
|
|
|
|
ASSERT(_caster->GetMap() == GetMap());
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-01-10 01:23:15 +01:00
|
|
|
bool expired = false;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2011-04-19 15:14:50 +02:00
|
|
|
if (_aura)
|
2009-09-27 02:24:25 -07:00
|
|
|
{
|
2011-04-19 15:14:50 +02:00
|
|
|
if (!_aura->IsRemoved())
|
|
|
|
|
_aura->UpdateOwner(p_time, this);
|
2009-10-17 16:20:24 -07:00
|
|
|
|
2012-05-30 08:01:02 +02:00
|
|
|
// _aura may be set to null in Aura::UpdateOwner call
|
2011-04-19 15:14:50 +02:00
|
|
|
if (_aura && (_aura->IsRemoved() || _aura->IsExpired()))
|
2010-01-10 01:23:15 +01:00
|
|
|
expired = true;
|
2009-09-27 02:24:25 -07:00
|
|
|
}
|
2010-01-10 01:23:15 +01:00
|
|
|
else
|
2008-12-03 18:35:00 -06:00
|
|
|
{
|
2010-04-07 19:14:10 +02:00
|
|
|
if (GetDuration() > int32(p_time))
|
2011-04-19 15:14:50 +02:00
|
|
|
_duration -= p_time;
|
2010-01-10 01:23:15 +01:00
|
|
|
else
|
|
|
|
|
expired = true;
|
2009-03-05 13:08:46 -06:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-01-10 01:23:15 +01:00
|
|
|
if (expired)
|
2011-02-04 00:27:43 +01:00
|
|
|
Remove();
|
2010-08-06 19:23:43 +02:00
|
|
|
else
|
2010-12-22 21:25:23 +01:00
|
|
|
sScriptMgr->OnDynamicObjectUpdate(this, p_time);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2011-02-04 00:27:43 +01:00
|
|
|
void DynamicObject::Remove()
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2011-02-04 00:27:43 +01:00
|
|
|
if (IsInWorld())
|
|
|
|
|
AddObjectToRemoveList();
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-01-10 01:23:15 +01:00
|
|
|
int32 DynamicObject::GetDuration() const
|
|
|
|
|
{
|
2011-04-19 15:14:50 +02:00
|
|
|
if (!_aura)
|
|
|
|
|
return _duration;
|
2010-01-10 01:23:15 +01:00
|
|
|
else
|
2011-04-19 15:14:50 +02:00
|
|
|
return _aura->GetDuration();
|
2010-01-10 01:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DynamicObject::SetDuration(int32 newDuration)
|
|
|
|
|
{
|
2011-04-19 15:14:50 +02:00
|
|
|
if (!_aura)
|
|
|
|
|
_duration = newDuration;
|
2010-01-10 01:23:15 +01:00
|
|
|
else
|
2011-04-19 15:14:50 +02:00
|
|
|
_aura->SetDuration(newDuration);
|
2010-01-10 01:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
void DynamicObject::Delay(int32 delaytime)
|
|
|
|
|
{
|
2010-01-10 01:23:15 +01:00
|
|
|
SetDuration(GetDuration() - delaytime);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2011-02-04 00:27:43 +01:00
|
|
|
|
2011-04-19 15:14:50 +02:00
|
|
|
void DynamicObject::SetAura(Aura* aura)
|
2011-02-04 00:27:43 +01:00
|
|
|
{
|
2011-04-19 15:14:50 +02:00
|
|
|
ASSERT(!_aura && aura);
|
|
|
|
|
_aura = aura;
|
2011-02-04 00:27:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DynamicObject::RemoveAura()
|
|
|
|
|
{
|
2011-06-16 00:55:27 +02:00
|
|
|
ASSERT(_aura && !_removedAura);
|
|
|
|
|
_removedAura = _aura;
|
2020-08-14 17:06:03 +02:00
|
|
|
_aura = nullptr;
|
2011-06-16 00:55:27 +02:00
|
|
|
if (!_removedAura->IsRemoved())
|
|
|
|
|
_removedAura->_Remove(AURA_REMOVE_BY_DEFAULT);
|
2011-02-04 00:27:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DynamicObject::SetCasterViewpoint()
|
|
|
|
|
{
|
2011-04-19 15:14:50 +02:00
|
|
|
if (Player* caster = _caster->ToPlayer())
|
2011-02-04 00:27:43 +01:00
|
|
|
{
|
|
|
|
|
caster->SetViewpoint(this, true);
|
2011-04-19 15:14:50 +02:00
|
|
|
_isViewpoint = true;
|
2011-02-04 00:27:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DynamicObject::RemoveCasterViewpoint()
|
|
|
|
|
{
|
2011-06-11 22:35:29 +02:00
|
|
|
if (Player* caster = _caster->ToPlayer())
|
2011-02-04 00:27:43 +01:00
|
|
|
{
|
|
|
|
|
caster->SetViewpoint(this, false);
|
2011-04-19 15:14:50 +02:00
|
|
|
_isViewpoint = false;
|
2011-02-04 00:27:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-10 16:43:01 -03:00
|
|
|
uint32 DynamicObject::GetFaction() const
|
|
|
|
|
{
|
|
|
|
|
ASSERT(_caster);
|
|
|
|
|
return _caster->GetFaction();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-04 00:27:43 +01:00
|
|
|
void DynamicObject::BindToCaster()
|
|
|
|
|
{
|
2011-04-19 15:14:50 +02:00
|
|
|
ASSERT(!_caster);
|
|
|
|
|
_caster = ObjectAccessor::GetUnit(*this, GetCasterGUID());
|
|
|
|
|
ASSERT(_caster);
|
|
|
|
|
ASSERT(_caster->GetMap() == GetMap());
|
|
|
|
|
_caster->_RegisterDynObject(this);
|
2011-02-04 00:27:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DynamicObject::UnbindFromCaster()
|
|
|
|
|
{
|
2011-04-19 15:14:50 +02:00
|
|
|
ASSERT(_caster);
|
|
|
|
|
_caster->_UnregisterDynObject(this);
|
2020-08-14 17:06:03 +02:00
|
|
|
_caster = nullptr;
|
2011-02-04 00:27:43 +01:00
|
|
|
}
|
2017-06-04 01:00:45 +02:00
|
|
|
|
|
|
|
|
SpellInfo const* DynamicObject::GetSpellInfo() const
|
|
|
|
|
{
|
2020-06-12 01:29:18 +02:00
|
|
|
return sSpellMgr->GetSpellInfo(GetSpellId(), GetMap()->GetDifficultyID());
|
2017-06-04 01:00:45 +02:00
|
|
|
}
|
2019-06-03 20:40:34 +02:00
|
|
|
|
|
|
|
|
void DynamicObject::BuildValuesCreate(ByteBuffer* data, Player const* target) const
|
|
|
|
|
{
|
|
|
|
|
UF::UpdateFieldFlag flags = GetUpdateFieldFlagsFor(target);
|
|
|
|
|
std::size_t sizePos = data->wpos();
|
|
|
|
|
*data << uint32(0);
|
|
|
|
|
*data << uint8(flags);
|
|
|
|
|
m_objectData->WriteCreate(*data, flags, this, target);
|
|
|
|
|
m_dynamicObjectData->WriteCreate(*data, flags, this, target);
|
|
|
|
|
data->put<uint32>(sizePos, data->wpos() - sizePos - 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DynamicObject::BuildValuesUpdate(ByteBuffer* data, Player const* target) const
|
|
|
|
|
{
|
|
|
|
|
UF::UpdateFieldFlag flags = GetUpdateFieldFlagsFor(target);
|
|
|
|
|
std::size_t sizePos = data->wpos();
|
|
|
|
|
*data << uint32(0);
|
|
|
|
|
*data << uint32(m_values.GetChangedObjectTypeMask());
|
|
|
|
|
|
|
|
|
|
if (m_values.HasChanged(TYPEID_OBJECT))
|
|
|
|
|
m_objectData->WriteUpdate(*data, flags, this, target);
|
|
|
|
|
|
|
|
|
|
if (m_values.HasChanged(TYPEID_DYNAMICOBJECT))
|
|
|
|
|
m_dynamicObjectData->WriteUpdate(*data, flags, this, target);
|
|
|
|
|
|
|
|
|
|
data->put<uint32>(sizePos, data->wpos() - sizePos - 4);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 20:22:53 +02:00
|
|
|
void DynamicObject::BuildValuesUpdateForPlayerWithMask(UpdateData* data, UF::ObjectData::Mask const& requestedObjectMask,
|
|
|
|
|
UF::DynamicObjectData::Mask const& requestedDynamicObjectMask, Player const* target) const
|
|
|
|
|
{
|
|
|
|
|
UpdateMask<NUM_CLIENT_OBJECT_TYPES> valuesMask;
|
|
|
|
|
if (requestedObjectMask.IsAnySet())
|
|
|
|
|
valuesMask.Set(TYPEID_OBJECT);
|
|
|
|
|
|
|
|
|
|
if (requestedDynamicObjectMask.IsAnySet())
|
|
|
|
|
valuesMask.Set(TYPEID_DYNAMICOBJECT);
|
|
|
|
|
|
|
|
|
|
ByteBuffer buffer = PrepareValuesUpdateBuffer();
|
|
|
|
|
std::size_t sizePos = buffer.wpos();
|
|
|
|
|
buffer << uint32(0);
|
|
|
|
|
buffer << uint32(valuesMask.GetBlock(0));
|
|
|
|
|
|
|
|
|
|
if (valuesMask[TYPEID_OBJECT])
|
|
|
|
|
m_objectData->WriteUpdate(buffer, requestedObjectMask, true, this, target);
|
|
|
|
|
|
|
|
|
|
if (valuesMask[TYPEID_DYNAMICOBJECT])
|
|
|
|
|
m_dynamicObjectData->WriteUpdate(buffer, requestedDynamicObjectMask, true, this, target);
|
|
|
|
|
|
|
|
|
|
buffer.put<uint32>(sizePos, buffer.wpos() - sizePos - 4);
|
|
|
|
|
|
|
|
|
|
data->AddUpdateBlock(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-26 15:58:23 +01:00
|
|
|
void DynamicObject::ValuesUpdateForPlayerWithMaskSender::operator()(Player const* player) const
|
|
|
|
|
{
|
|
|
|
|
UpdateData udata(Owner->GetMapId());
|
|
|
|
|
WorldPacket packet;
|
|
|
|
|
|
|
|
|
|
Owner->BuildValuesUpdateForPlayerWithMask(&udata, ObjectMask.GetChangesMask(), DynamicObjectMask.GetChangesMask(), player);
|
|
|
|
|
|
|
|
|
|
udata.BuildPacket(&packet);
|
|
|
|
|
player->SendDirectMessage(&packet);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 20:40:34 +02:00
|
|
|
void DynamicObject::ClearUpdateMask(bool remove)
|
|
|
|
|
{
|
|
|
|
|
m_values.ClearChangesMask(&DynamicObject::m_dynamicObjectData);
|
|
|
|
|
Object::ClearUpdateMask(remove);
|
|
|
|
|
}
|