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

110 lines
3.1 KiB
C++

/*
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
*
* 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 "AreaTrigger.h"
#include "DB2Stores.h"
#include "Log.h"
#include "SpellInfo.h"
#include "Unit.h"
#include "UpdateData.h"
AreaTrigger::AreaTrigger() : WorldObject(false), _duration(0), _spellXSpellVisualId(0)
{
m_objectType |= TYPEMASK_AREATRIGGER;
m_objectTypeId = TYPEID_AREATRIGGER;
m_updateFlag = UPDATEFLAG_STATIONARY_POSITION;
m_valuesCount = AREATRIGGER_END;
_dynamicValuesCount = AREATRIGGER_DYNAMIC_END;
}
AreaTrigger::~AreaTrigger()
{
}
void AreaTrigger::AddToWorld()
{
///- Register the AreaTrigger for guid lookup and for caster
if (!IsInWorld())
{
GetMap()->GetObjectsStore().Insert<AreaTrigger>(GetGUID(), this);
WorldObject::AddToWorld();
}
}
void AreaTrigger::RemoveFromWorld()
{
///- Remove the AreaTrigger from the accessor and from all lists of objects in world
if (IsInWorld())
{
WorldObject::RemoveFromWorld();
GetMap()->GetObjectsStore().Remove<AreaTrigger>(GetGUID());
}
}
bool AreaTrigger::CreateAreaTrigger(ObjectGuid::LowType guidlow, uint32 triggerEntry, Unit* caster, SpellInfo const* spell, Position const& pos, uint32 spellXSpellVisualId)
{
_spellXSpellVisualId = spellXSpellVisualId;
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());
return false;
}
Object::_Create(ObjectGuid::Create<HighGuid::AreaTrigger>(GetMapId(), triggerEntry, guidlow));
SetPhaseMask(caster->GetPhaseMask(), false);
SetEntry(triggerEntry);
SetDuration(spell->GetDuration());
SetObjectScale(1);
SetGuidValue(AREATRIGGER_CASTER, caster->GetGUID());
SetUInt32Value(AREATRIGGER_SPELLID, spell->Id);
SetUInt32Value(AREATRIGGER_SPELL_X_SPELL_VISUAL_ID, spellXSpellVisualId);
SetUInt32Value(AREATRIGGER_DURATION, spell->GetDuration());
CopyPhaseFrom(caster);
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
WorldObject::Update(p_time);
}
void AreaTrigger::Remove()
{
if (IsInWorld())
{
SendObjectDeSpawnAnim(GetGUID());
RemoveFromWorld();
AddObjectToRemoveList();
}
}