2008-10-02 16:23:55 -05:00
|
|
|
/*
|
2009-02-04 12:42:26 +01:00
|
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
2008-10-14 11:57:03 -05:00
|
|
|
*
|
2010-01-16 20:19:18 +03:00
|
|
|
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
2008-10-02 16:23:55 -05: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
|
2008-11-15 11:56:59 -06:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2008-10-02 16:23:55 -05:00
|
|
|
* 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
|
2008-11-15 11:56:59 -06:00
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
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"
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
DynamicObject::DynamicObject() : WorldObject()
|
|
|
|
|
{
|
|
|
|
|
m_objectType |= TYPEMASK_DYNAMICOBJECT;
|
|
|
|
|
m_objectTypeId = TYPEID_DYNAMICOBJECT;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-12-17 11:06:50 +01:00
|
|
|
m_updateFlag = (UPDATEFLAG_HIGHGUID | UPDATEFLAG_HAS_POSITION | UPDATEFLAG_POSITION);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
m_valuesCount = DYNAMICOBJECT_END;
|
2010-01-10 01:23:15 +01:00
|
|
|
|
|
|
|
|
m_aura = 0;
|
|
|
|
|
m_duration = 0;
|
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()
|
|
|
|
|
{
|
|
|
|
|
///- Register the dynamicObject for guid lookup
|
2010-04-07 19:14:10 +02:00
|
|
|
if (!IsInWorld())
|
2009-03-25 15:54:23 -06:00
|
|
|
{
|
|
|
|
|
ObjectAccessor::Instance().AddObject(this);
|
|
|
|
|
WorldObject::AddToWorld();
|
|
|
|
|
}
|
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()
|
|
|
|
|
{
|
2009-02-22 17:03:01 -06:00
|
|
|
///- Remove the dynamicObject from the accessor
|
2010-04-07 19:14:10 +02:00
|
|
|
if (IsInWorld())
|
2009-03-25 15:54:23 -06:00
|
|
|
{
|
2010-04-07 19:14:10 +02:00
|
|
|
if (m_isWorldObject)
|
2009-03-26 10:53:19 -06:00
|
|
|
{
|
2010-04-07 19:14:10 +02:00
|
|
|
if (Unit *caster = GetCaster())
|
2009-03-26 10:53:19 -06:00
|
|
|
{
|
2010-04-07 19:14:10 +02:00
|
|
|
if (caster->GetTypeId() == TYPEID_PLAYER)
|
2010-03-07 15:20:19 +01:00
|
|
|
caster->ToPlayer()->SetViewpoint(this, false);
|
2009-03-26 10:53:19 -06:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sLog.outCrash("DynamicObject::RemoveFromWorld cannot find viewpoint owner");
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-25 15:54:23 -06:00
|
|
|
WorldObject::RemoveFromWorld();
|
2009-03-28 16:04:37 -06:00
|
|
|
ObjectAccessor::Instance().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
|
|
|
|
2010-01-10 01:23:15 +01:00
|
|
|
bool DynamicObject::Create(uint32 guidlow, Unit *caster, uint32 spellId, const Position &pos, float radius, bool active)
|
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
|
|
|
{
|
2010-01-10 01:23:15 +01:00
|
|
|
sLog.outError("DynamicObject (spell %u) not created. Suggested coordinates isn't valid (X: %f Y: %f)",spellId,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
|
|
|
|
2008-11-15 11:56:59 -06:00
|
|
|
SetEntry(spellId);
|
2010-04-07 22:59:46 +02:00
|
|
|
SetFloatValue(OBJECT_FIELD_SCALE_X, 1);
|
|
|
|
|
SetUInt64Value(DYNAMICOBJECT_CASTER, caster->GetGUID());
|
2010-02-11 21:31:12 +01:00
|
|
|
|
|
|
|
|
// The lower word of DYNAMICOBJECT_BYTES must be 0x0001. This value means that the visual radius will be overriden
|
|
|
|
|
// by client for most of the "ground patch" visual effect spells and a few "skyfall" ones like Hurricane.
|
|
|
|
|
// If any other value is used, the client will _always_ use the radius provided in DYNAMICOBJECT_RADIUS, but
|
2010-04-07 18:09:10 +02:00
|
|
|
// precompensation is necessary (eg radius *= 2) for many spells. Anyway, blizz sends 0x0001 for all the spells
|
2010-02-11 21:31:12 +01:00
|
|
|
// I saw sniffed...
|
2010-04-07 22:59:46 +02:00
|
|
|
SetUInt32Value(DYNAMICOBJECT_BYTES, 0x00000001);
|
|
|
|
|
SetUInt32Value(DYNAMICOBJECT_SPELLID, spellId);
|
|
|
|
|
SetFloatValue(DYNAMICOBJECT_RADIUS, radius);
|
|
|
|
|
SetUInt32Value(DYNAMICOBJECT_CASTTIME, getMSTime());
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-08-27 16:41:10 -05:00
|
|
|
m_isWorldObject = active;
|
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
|
|
|
Unit* DynamicObject::GetCaster() const
|
|
|
|
|
{
|
|
|
|
|
// can be not found in some cases
|
2009-06-06 20:22:14 -05:00
|
|
|
return ObjectAccessor::GetUnit(*this, GetCasterGUID());
|
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::Update(uint32 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();
|
2009-09-26 16:01:30 -07:00
|
|
|
if (!caster)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
Delete();
|
|
|
|
|
return;
|
|
|
|
|
}
|
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
|
|
|
|
2010-01-10 01:23:15 +01:00
|
|
|
if (m_aura)
|
2009-09-27 02:24:25 -07:00
|
|
|
{
|
2010-01-10 01:23:15 +01:00
|
|
|
if (!m_aura->IsRemoved())
|
|
|
|
|
m_aura->UpdateOwner(p_time, this);
|
2009-10-17 16:20:24 -07:00
|
|
|
|
2010-01-16 15:12:21 +01:00
|
|
|
// m_aura may be set to null in Unit::RemoveGameObject call
|
|
|
|
|
if (m_aura && (m_aura->IsRemoved() || m_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))
|
2010-01-10 01:23:15 +01:00
|
|
|
m_duration -= p_time;
|
|
|
|
|
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)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
caster->RemoveDynObjectWithGUID(GetGUID());
|
|
|
|
|
Delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
void DynamicObject::Delete()
|
|
|
|
|
{
|
2010-01-10 01:23:15 +01:00
|
|
|
if (m_aura)
|
|
|
|
|
{
|
|
|
|
|
// dynObj may be removed in Aura::Remove - we cannot delete there
|
|
|
|
|
// so recheck aura here
|
|
|
|
|
if (!m_aura->IsRemoved())
|
|
|
|
|
m_aura->_Remove(AURA_REMOVE_BY_DEFAULT);
|
|
|
|
|
delete m_aura;
|
|
|
|
|
m_aura = NULL;
|
|
|
|
|
}
|
2008-10-02 16:23:55 -05:00
|
|
|
SendObjectDeSpawnAnim(GetGUID());
|
2009-03-26 10:53:19 -06:00
|
|
|
RemoveFromWorld();
|
2008-10-02 16:23:55 -05:00
|
|
|
AddObjectToRemoveList();
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-01-10 01:23:15 +01:00
|
|
|
int32 DynamicObject::GetDuration() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_aura)
|
|
|
|
|
return m_duration;
|
|
|
|
|
else
|
2010-04-07 18:09:10 +02:00
|
|
|
return m_aura->GetDuration();
|
2010-01-10 01:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DynamicObject::SetDuration(int32 newDuration)
|
|
|
|
|
{
|
|
|
|
|
if (!m_aura)
|
|
|
|
|
m_duration = newDuration;
|
|
|
|
|
else
|
|
|
|
|
m_aura->SetDuration(newDuration);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
bool DynamicObject::isVisibleForInState(Player const* u, bool inVisibleList) const
|
|
|
|
|
{
|
2009-02-04 10:33:18 -06:00
|
|
|
return IsInWorld() && u->IsInWorld()
|
2009-03-10 15:26:17 -06:00
|
|
|
&& (IsWithinDistInMap(u->m_seer,World::GetMaxVisibleDistanceForObject()+(inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f), false));
|
2010-01-12 00:14:09 +01:00
|
|
|
}
|