TrinityCore
AreaTrigger.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITYCORE_AREATRIGGER_H
19#define TRINITYCORE_AREATRIGGER_H
20
21#include "Object.h"
22#include "GridObject.h"
23#include "MapObject.h"
24#include "AreaTriggerTemplate.h"
25
26class AuraEffect;
27class AreaTriggerAI;
28class SpellInfo;
29class Unit;
30
31namespace G3D
32{
33 class Vector2;
34 class Vector3;
35}
36namespace Movement
37{
38 template<typename length_type>
39 class Spline;
40}
41
42class TC_GAME_API AreaTrigger final : public WorldObject, public GridObject<AreaTrigger>, public MapObject
43{
44 public:
47
48 protected:
49 void BuildValuesCreate(ByteBuffer* data, Player const* target) const override;
50 void BuildValuesUpdate(ByteBuffer* data, Player const* target) const override;
51 void ClearUpdateMask(bool remove) override;
52
53 public:
54 void BuildValuesUpdateForPlayerWithMask(UpdateData* data, UF::ObjectData::Mask const& requestedObjectMask,
55 UF::AreaTriggerData::Mask const& requestedAreaTriggerMask, Player const* target) const;
56
57 struct ValuesUpdateForPlayerWithMaskSender // sender compatible with MessageDistDeliverer
58 {
59 explicit ValuesUpdateForPlayerWithMaskSender(AreaTrigger const* owner) : Owner(owner) { }
60
64
65 void operator()(Player const* player) const;
66 };
67
68 void AddToWorld() override;
69 void RemoveFromWorld() override;
70
71 void AI_Initialize();
72 void AI_Destroy();
73
74 AreaTriggerAI* AI() { return _ai.get(); }
75
76 bool IsCustom() const { return _areaTriggerTemplate->Id.IsCustom; }
77 bool IsServerSide() const { return _areaTriggerTemplate->Flags.HasFlag(AreaTriggerFlag::IsServerSide); }
78 bool IsStaticSpawn() const { return _spawnId != 0; }
79 bool HasActionSetFlag(AreaTriggerActionSetFlag flag) const { return _areaTriggerTemplate->ActionSetFlags.HasFlag(flag); }
80
81 bool IsNeverVisibleFor(WorldObject const* seer, bool allowServersideObjects = false) const override;
82
83 float GetStationaryX() const override { return _stationaryPosition.GetPositionX(); }
84 float GetStationaryY() const override { return _stationaryPosition.GetPositionY(); }
85 float GetStationaryZ() const override { return _stationaryPosition.GetPositionZ(); }
86 float GetStationaryO() const override { return _stationaryPosition.GetOrientation(); }
87 void RelocateStationaryPosition(Position const& pos) { _stationaryPosition.Relocate(pos); }
88 void PlaySpellVisual(uint32 spellVisualId) const;
89
90 private:
91 bool Create(AreaTriggerCreatePropertiesId areaTriggerCreatePropertiesId, Map* map, Position const& pos, int32 duration, AreaTriggerSpawn const* spawnData = nullptr, Unit* caster = nullptr, Unit* target = nullptr, SpellCastVisual spellVisual = { 0, 0 }, SpellInfo const* spellInfo = nullptr, Spell* spell = nullptr, AuraEffect const* aurEff = nullptr);
92
93 public:
94 static AreaTrigger* CreateAreaTrigger(AreaTriggerCreatePropertiesId areaTriggerCreatePropertiesId, Position const& pos, int32 duration, Unit* caster, Unit* target, SpellCastVisual spellVisual = { 0, 0 }, SpellInfo const* spellInfo = nullptr, Spell* spell = nullptr, AuraEffect const* aurEff = nullptr);
95 static ObjectGuid CreateNewMovementForceId(Map* map, uint32 areaTriggerId);
96 bool LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap, bool allowDuplicate);
97
98 void Update(uint32 diff) override;
99 void Remove();
100 bool IsRemoved() const { return _isRemoved; }
101 uint32 GetSpellId() const { return m_areaTriggerData->SpellID; }
102 AuraEffect const* GetAuraEffect() const { return _aurEff; }
103 uint32 GetTimeSinceCreated() const { return _timeSinceCreated; }
104
105 void SetHeightIgnoresScale(bool heightIgnoresScale) { SetUpdateFieldValue(m_values.ModifyValue(&AreaTrigger::m_areaTriggerData).ModifyValue(&UF::AreaTriggerData::HeightIgnoresScale), heightIgnoresScale); }
106
107 void SetOverrideScaleCurve(float overrideScale);
108 void SetOverrideScaleCurve(std::array<DBCPosition2D, 2> const& points, Optional<uint32> startTimeOffset = {}, CurveInterpolationMode interpolation = CurveInterpolationMode::Linear);
109 void ClearOverrideScaleCurve();
110
111 void SetExtraScaleCurve(float extraScale);
112 void SetExtraScaleCurve(std::array<DBCPosition2D, 2> const& points, Optional<uint32> startTimeOffset = {}, CurveInterpolationMode interpolation = CurveInterpolationMode::Linear);
113 void ClearExtraScaleCurve();
114
115 void SetOverrideMoveCurve(float x, float y, float z);
116 void SetOverrideMoveCurve(std::array<DBCPosition2D, 2> const& xCurvePoints, std::array<DBCPosition2D, 2> const& yCurvePoints, std::array<DBCPosition2D, 2> const& zCurvePoints,
117 Optional<uint32> startTimeOffset = {}, CurveInterpolationMode interpolation = CurveInterpolationMode::Linear);
118 void ClearOverrideMoveCurve();
119
120 uint32 GetTimeToTarget() const { return m_areaTriggerData->TimeToTarget; }
121 void SetTimeToTarget(uint32 timeToTarget) { SetUpdateFieldValue(m_values.ModifyValue(&AreaTrigger::m_areaTriggerData).ModifyValue(&UF::AreaTriggerData::TimeToTarget), timeToTarget); }
122
123 uint32 GetTimeToTargetScale() const { return m_areaTriggerData->TimeToTargetScale; }
124 void SetTimeToTargetScale(uint32 timeToTargetScale) { SetUpdateFieldValue(m_values.ModifyValue(&AreaTrigger::m_areaTriggerData).ModifyValue(&UF::AreaTriggerData::TimeToTargetScale), timeToTargetScale); }
125
126 uint32 GetTimeToTargetExtraScale() const { return m_areaTriggerData->TimeToTargetExtraScale; }
127 void SetTimeToTargetExtraScale(uint32 timeToTargetExtraScale) { SetUpdateFieldValue(m_values.ModifyValue(&AreaTrigger::m_areaTriggerData).ModifyValue(&UF::AreaTriggerData::TimeToTargetExtraScale), timeToTargetExtraScale); }
128
129 uint32 GetTimeToTargetPos() const { return m_areaTriggerData->TimeToTargetPos; }
130 void SetTimeToTargetPos(uint32 timeToTargetPos) { SetUpdateFieldValue(m_values.ModifyValue(&AreaTrigger::m_areaTriggerData).ModifyValue(&UF::AreaTriggerData::TimeToTargetPos), timeToTargetPos); }
131
132 int32 GetDuration() const { return _duration; }
133 int32 GetTotalDuration() const { return _totalDuration; }
134 void SetDuration(int32 newDuration);
135 void Delay(int32 delaytime) { SetDuration(GetDuration() - delaytime); }
136
137 GuidUnorderedSet const& GetInsideUnits() const { return _insideUnits; }
138
139 AreaTriggerCreateProperties const* GetCreateProperties() const { return _areaTriggerCreateProperties; }
140 AreaTriggerTemplate const* GetTemplate() const;
141 uint32 GetScriptId() const;
142
143 ObjectGuid GetCreatorGUID() const override { return GetCasterGuid(); }
144 ObjectGuid GetOwnerGUID() const override { return GetCasterGuid(); }
145 ObjectGuid const& GetCasterGuid() const { return m_areaTriggerData->Caster; }
146 Unit* GetCaster() const;
147 Unit* GetTarget() const;
148
149 uint32 GetFaction() const override;
150
151 AreaTriggerShapeInfo const& GetShape() const { return _shape; }
152 float GetMaxSearchRadius() const;
153 Position const& GetRollPitchYaw() const { return _rollPitchYaw; }
154 Position const& GetTargetRollPitchYaw() const { return _targetRollPitchYaw; }
155 void InitSplineOffsets(std::vector<Position> const& offsets, uint32 timeToTarget);
156 void InitSplines(std::vector<G3D::Vector3> splinePoints, uint32 timeToTarget);
157 bool HasSplines() const;
158 ::Movement::Spline<int32> const& GetSpline() const { return *_spline; }
159 uint32 GetElapsedTimeForMovement() const { return GetTimeSinceCreated(); }
160
161 void InitOrbit(AreaTriggerOrbitInfo const& orbit, uint32 timeToTarget);
162 bool HasOrbit() const;
163 Optional<AreaTriggerOrbitInfo> const& GetOrbit() const { return _orbitInfo; }
164
165 bool HasOverridePosition() const;
166
167 void UpdateShape();
168
170
171 protected:
172 void _UpdateDuration(int32 newDuration);
173
174 float CalcCurrentScale() const;
175
176 float GetProgress() const;
177
178 float GetScaleCurveProgress(UF::ScaleCurve const& scaleCurve, uint32 timeTo) const;
179 float GetScaleCurveValueAtProgress(UF::ScaleCurve const& scaleCurve, float x) const;
180 float GetScaleCurveValue(UF::ScaleCurve const& scaleCurve, uint32 timeTo) const;
181 void SetScaleCurve(UF::MutableFieldReference<UF::ScaleCurve, false> scaleCurveMutator, float constantValue);
182 void SetScaleCurve(UF::MutableFieldReference<UF::ScaleCurve, false> scaleCurveMutator, std::array<DBCPosition2D, 2> const& points, Optional<uint32> startTimeOffset, CurveInterpolationMode interpolation);
183 void ClearScaleCurve(UF::MutableFieldReference<UF::ScaleCurve, false> scaleCurveMutator);
184 void SetScaleCurve(UF::MutableFieldReference<UF::ScaleCurve, false> scaleCurveMutator, Optional<AreaTriggerScaleCurveTemplate> const& curve);
185
186 void UpdateTargetList();
187 void SearchUnits(std::vector<Unit*>& targetList, float radius, bool check3D);
188 void SearchUnitInSphere(std::vector<Unit*>& targetList);
189 void SearchUnitInBox(std::vector<Unit*>& targetList);
190 void SearchUnitInPolygon(std::vector<Unit*>& targetList);
191 void SearchUnitInCylinder(std::vector<Unit*>& targetList);
192 void SearchUnitInDisk(std::vector<Unit*>& targetList);
193 void SearchUnitInBoundedPlane(std::vector<Unit*>& targetList);
194 void HandleUnitEnterExit(std::vector<Unit*> const& targetList);
195
196 void DoActions(Unit* unit);
197 void UndoActions(Unit* unit);
198
199 void UpdatePolygonVertices();
200 void UpdateOrbitPosition(uint32 diff);
201 void UpdateSplinePosition(uint32 diff);
202 void UpdateOverridePosition();
203
204 Position const* GetOrbitCenterPosition() const;
205 Position CalculateOrbitPosition() const;
206
207 void DebugVisualizePosition(); // Debug purpose only
208
210
212
214
222
225 std::vector<Position> _polygonVertices;
226 std::unique_ptr<::Movement::Spline<int32>> _spline;
227
231
233
237
238 std::unique_ptr<AreaTriggerAI> _ai;
239};
240
241#endif
CurveInterpolationMode
Definition: DBCEnums.h:907
AreaTriggerActionSetFlag
Definition: DBCEnums.h:181
#define TC_GAME_API
Definition: Define.h:123
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition: ObjectGuid.h:396
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
float GetStationaryY() const override
Definition: AreaTrigger.h:84
GuidUnorderedSet const & GetInsideUnits() const
Definition: AreaTrigger.h:137
AreaTriggerCreateProperties const * _areaTriggerCreateProperties
Definition: AreaTrigger.h:234
uint32 GetTimeToTargetExtraScale() const
Definition: AreaTrigger.h:126
bool _isRemoved
Definition: AreaTrigger.h:221
std::vector< Position > _polygonVertices
Definition: AreaTrigger.h:225
ObjectGuid::LowType _spawnId
Definition: AreaTrigger.h:209
bool HasActionSetFlag(AreaTriggerActionSetFlag flag) const
Definition: AreaTrigger.h:79
int32 _duration
Definition: AreaTrigger.h:217
AreaTriggerAI * AI()
Definition: AreaTrigger.h:74
void SetHeightIgnoresScale(bool heightIgnoresScale)
Definition: AreaTrigger.h:105
Position _rollPitchYaw
Definition: AreaTrigger.h:223
ObjectGuid GetOwnerGUID() const override
Definition: AreaTrigger.h:144
uint32 GetTimeSinceCreated() const
Definition: AreaTrigger.h:103
void SetTimeToTargetPos(uint32 timeToTargetPos)
Definition: AreaTrigger.h:130
uint32 _timeSinceCreated
Definition: AreaTrigger.h:219
float GetStationaryZ() const override
Definition: AreaTrigger.h:85
float GetStationaryO() const override
Definition: AreaTrigger.h:86
AreaTriggerShapeInfo const & GetShape() const
Definition: AreaTrigger.h:151
ObjectGuid const & GetCasterGuid() const
Definition: AreaTrigger.h:145
void RelocateStationaryPosition(Position const &pos)
Definition: AreaTrigger.h:87
bool _reachedDestination
Definition: AreaTrigger.h:228
int32 GetTotalDuration() const
Definition: AreaTrigger.h:133
Position _stationaryPosition
Definition: AreaTrigger.h:215
UF::UpdateField< UF::AreaTriggerData, 0, TYPEID_AREATRIGGER > m_areaTriggerData
Definition: AreaTrigger.h:169
std::unique_ptr< AreaTriggerAI > _ai
Definition: AreaTrigger.h:238
uint32 _movementTime
Definition: AreaTrigger.h:230
uint32 GetTimeToTargetPos() const
Definition: AreaTrigger.h:129
ObjectGuid _targetGuid
Definition: AreaTrigger.h:211
bool IsServerSide() const
Definition: AreaTrigger.h:77
uint32 GetSpellId() const
Definition: AreaTrigger.h:101
bool IsRemoved() const
Definition: AreaTrigger.h:100
void SetTimeToTarget(uint32 timeToTarget)
Definition: AreaTrigger.h:121
uint32 GetTimeToTarget() const
Definition: AreaTrigger.h:120
int32 _lastSplineIndex
Definition: AreaTrigger.h:229
GuidUnorderedSet _insideUnits
Definition: AreaTrigger.h:236
uint32 GetTimeToTargetScale() const
Definition: AreaTrigger.h:123
bool IsStaticSpawn() const
Definition: AreaTrigger.h:78
Optional< AreaTriggerOrbitInfo > const & GetOrbit() const
Definition: AreaTrigger.h:163
std::unique_ptr<::Movement::Spline< int32 > > _spline
Definition: AreaTrigger.h:226
uint32 GetElapsedTimeForMovement() const
Definition: AreaTrigger.h:159
AreaTriggerTemplate const * _areaTriggerTemplate
Definition: AreaTrigger.h:235
void SetTimeToTargetScale(uint32 timeToTargetScale)
Definition: AreaTrigger.h:124
Position _targetRollPitchYaw
Definition: AreaTrigger.h:224
Optional< AreaTriggerOrbitInfo > _orbitInfo
Definition: AreaTrigger.h:232
bool IsCustom() const
Definition: AreaTrigger.h:76
AuraEffect const * _aurEff
Definition: AreaTrigger.h:213
AuraEffect const * GetAuraEffect() const
Definition: AreaTrigger.h:102
::Movement::Spline< int32 > const & GetSpline() const
Definition: AreaTrigger.h:158
ObjectGuid GetCreatorGUID() const override
Definition: AreaTrigger.h:143
Position const & GetTargetRollPitchYaw() const
Definition: AreaTrigger.h:154
Position const & GetRollPitchYaw() const
Definition: AreaTrigger.h:153
void SetTimeToTargetExtraScale(uint32 timeToTargetExtraScale)
Definition: AreaTrigger.h:127
int32 GetDuration() const
Definition: AreaTrigger.h:132
AreaTriggerCreateProperties const * GetCreateProperties() const
Definition: AreaTrigger.h:139
int32 _totalDuration
Definition: AreaTrigger.h:218
void Delay(int32 delaytime)
Definition: AreaTrigger.h:135
float _verticesUpdatePreviousOrientation
Definition: AreaTrigger.h:220
float GetStationaryX() const override
Definition: AreaTrigger.h:83
AreaTriggerShapeInfo _shape
Definition: AreaTrigger.h:216
Definition: Map.h:190
uint64 LowType
Definition: ObjectGuid.h:280
virtual void BuildValuesCreate(ByteBuffer *data, Player const *target) const =0
virtual void ClearUpdateMask(bool remove)
Definition: Object.cpp:796
void SetUpdateFieldValue(UF::UpdateFieldSetter< T > setter, typename UF::UpdateFieldSetter< T >::value_type value)
Definition: Object.h:288
virtual void BuildValuesUpdate(ByteBuffer *data, Player const *target) const =0
Definition: Spell.h:262
Definition: Unit.h:628
void AddToWorld() override
Definition: Object.cpp:1025
void RemoveFromWorld() override
Definition: Object.cpp:1031
virtual uint32 GetFaction() const =0
virtual bool IsNeverVisibleFor(WorldObject const *seer, bool allowServersideObjects=false) const
Definition: Object.h:824
virtual void Update(uint32 diff)
Definition: Object.cpp:905
Definition: wmo.h:168
std::unique_ptr< VignetteData > Create(VignetteEntry const *vignetteData, WorldObject const *owner)
Definition: Vignette.cpp:75
void Remove(VignetteData &vignette, WorldObject const *owner)
Definition: Vignette.cpp:103
ValuesUpdateForPlayerWithMaskSender(AreaTrigger const *owner)
Definition: AreaTrigger.h:59
UpdateField< uint32, 0, 12 > TimeToTargetExtraScale
UpdateField< bool, 0, 1 > HeightIgnoresScale
UpdateField< uint32, 0, 13 > TimeToTargetPos
UpdateField< uint32, 0, 11 > TimeToTargetScale
UpdateField< uint32, 0, 10 > TimeToTarget