Files
TCPlayerbotCore/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp
T

108 lines
3.0 KiB
C++
Raw Normal View History

2013-05-26 04:28:19 +03:00
/*
2016-01-01 00:34:25 +01:00
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
2013-05-26 04:28:19 +03: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/>.
*/
#include "Unit.h"
#include "SpellInfo.h"
#include "Log.h"
2015-04-30 19:26:07 +02:00
#include "UpdateData.h"
2013-05-26 04:28:19 +03:00
#include "AreaTrigger.h"
AreaTrigger::AreaTrigger() : WorldObject(false), _duration(0)
{
m_objectType |= TYPEMASK_AREATRIGGER;
m_objectTypeId = TYPEID_AREATRIGGER;
m_updateFlag = UPDATEFLAG_STATIONARY_POSITION;
m_valuesCount = AREATRIGGER_END;
2014-10-26 22:06:48 +01:00
_dynamicValuesCount = AREATRIGGER_DYNAMIC_END;
2013-05-26 04:28:19 +03:00
}
AreaTrigger::~AreaTrigger()
{
}
void AreaTrigger::AddToWorld()
{
///- Register the AreaTrigger for guid lookup and for caster
if (!IsInWorld())
{
2015-02-25 00:13:14 +01:00
GetMap()->GetObjectsStore().Insert<AreaTrigger>(GetGUID(), this);
2013-05-26 04:28:19 +03:00
WorldObject::AddToWorld();
}
}
void AreaTrigger::RemoveFromWorld()
{
///- Remove the AreaTrigger from the accessor and from all lists of objects in world
if (IsInWorld())
{
WorldObject::RemoveFromWorld();
2015-02-25 00:13:14 +01:00
GetMap()->GetObjectsStore().Remove<AreaTrigger>(GetGUID());
2013-05-26 04:28:19 +03:00
}
}
bool AreaTrigger::CreateAreaTrigger(ObjectGuid::LowType guidlow, uint32 triggerEntry, Unit* caster, SpellInfo const* spell, Position const& pos)
2013-05-26 04:28:19 +03:00
{
SetMap(caster->GetMap());
Relocate(pos);
if (!IsPositionValid())
{
TC_LOG_ERROR("misc", "AreaTrigger (spell %u) not created. Invalid coordinates (X: %f Y: %f)", spell->Id, GetPositionX(), GetPositionY());
2013-05-26 04:28:19 +03:00
return false;
}
2014-10-29 21:13:21 +01:00
Object::_Create(ObjectGuid::Create<HighGuid::AreaTrigger>(GetMapId(), triggerEntry, guidlow));
SetPhaseMask(caster->GetPhaseMask(), false);
2013-05-26 04:28:19 +03:00
SetEntry(triggerEntry);
SetDuration(spell->GetDuration());
SetObjectScale(1);
2014-10-26 22:06:48 +01:00
SetGuidValue(AREATRIGGER_CASTER, caster->GetGUID());
2013-05-26 04:28:19 +03:00
SetUInt32Value(AREATRIGGER_SPELLID, spell->Id);
SetUInt32Value(AREATRIGGER_SPELLVISUALID, spell->GetSpellVisual(GetMap()->GetDifficultyID()));
2013-05-26 04:28:19 +03:00
SetUInt32Value(AREATRIGGER_DURATION, spell->GetDuration());
CopyPhaseFrom(caster);
2013-05-26 04:28:19 +03:00
if (!GetMap()->AddToMap(this))
return false;
return true;
}
void AreaTrigger::Update(uint32 p_time)
{
if (GetDuration() > int32(p_time))
_duration -= p_time;
else
Remove(); // expired
2013-05-28 14:20:50 +02:00
WorldObject::Update(p_time);
2013-05-26 04:28:19 +03:00
}
void AreaTrigger::Remove()
{
if (IsInWorld())
{
SendObjectDeSpawnAnim(GetGUID());
RemoveFromWorld();
AddObjectToRemoveList();
}
}