2010-10-07 15:35:36 +02:00
|
|
|
/*
|
2014-01-01 00:07:53 +01:00
|
|
|
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
|
2010-10-07 15:35:36 +02:00
|
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "Common.h"
|
2010-06-08 15:50:23 -06:00
|
|
|
#include "UpdateMask.h"
|
|
|
|
|
#include "Opcodes.h"
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "World.h"
|
|
|
|
|
#include "ObjectAccessor.h"
|
2010-06-08 15:50:23 -06:00
|
|
|
#include "DatabaseEnv.h"
|
|
|
|
|
#include "GridNotifiers.h"
|
|
|
|
|
#include "CellImpl.h"
|
|
|
|
|
#include "GridNotifiersImpl.h"
|
2010-08-06 19:23:43 +02:00
|
|
|
#include "ScriptMgr.h"
|
2014-03-16 20:00:09 +01:00
|
|
|
#include "Transport.h"
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2011-12-20 17:05:08 -05:00
|
|
|
DynamicObject::DynamicObject(bool isWorldObject) : WorldObject(isWorldObject),
|
2011-06-16 00:55:27 +02:00
|
|
|
_aura(NULL), _removedAura(NULL), _caster(NULL), _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
|
|
|
|
2012-07-12 21:20:34 +02:00
|
|
|
m_updateFlag = UPDATEFLAG_STATIONARY_POSITION;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
m_valuesCount = DYNAMICOBJECT_END;
|
2014-10-26 22:06:48 +01:00
|
|
|
_dynamicValuesCount = DYNAMICOBJECT_DYNAMIC_END;
|
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
|
|
|
{
|
2010-12-23 23:25:44 +01:00
|
|
|
sObjectAccessor->AddObject(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();
|
2010-12-23 23:25:44 +01:00
|
|
|
sObjectAccessor->RemoveObject(this);
|
2009-03-25 15:54:23 -06:00
|
|
|
}
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-10-26 02:57:28 +02:00
|
|
|
bool DynamicObject::CreateDynamicObject(ObjectGuid::LowType guidlow, Unit* caster, SpellInfo const* spell, Position const& pos, float radius, DynamicObjectType type)
|
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
|
|
|
|
2009-08-01 00:20:32 +02:00
|
|
|
WorldObject::_Create(guidlow, HIGHGUID_DYNAMICOBJECT, caster->GetPhaseMask());
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2012-10-20 00:02:32 +02:00
|
|
|
SetEntry(spell->Id);
|
2012-05-30 08:01:02 +02:00
|
|
|
SetObjectScale(1);
|
2014-09-14 16:14:12 +02:00
|
|
|
SetGuidValue(DYNAMICOBJECT_CASTER, caster->GetGUID());
|
2012-10-20 00:02:32 +02:00
|
|
|
SetUInt32Value(DYNAMICOBJECT_BYTES, spell->SpellVisual[0] | (type << 28));
|
|
|
|
|
SetUInt32Value(DYNAMICOBJECT_SPELLID, spell->Id);
|
2010-04-07 22:59:46 +02:00
|
|
|
SetFloatValue(DYNAMICOBJECT_RADIUS, radius);
|
|
|
|
|
SetUInt32Value(DYNAMICOBJECT_CASTTIME, getMSTime());
|
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())
|
2010-01-10 01:23:15 +01:00
|
|
|
{
|
2011-02-04 00:27:43 +01:00
|
|
|
SendObjectDeSpawnAnim(GetGUID());
|
|
|
|
|
RemoveFromWorld();
|
|
|
|
|
AddObjectToRemoveList();
|
2010-01-10 01:23:15 +01:00
|
|
|
}
|
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;
|
2011-04-19 15:14:50 +02:00
|
|
|
_aura = NULL;
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
_caster = NULL;
|
2011-02-04 00:27:43 +01:00
|
|
|
}
|