TrinityCore
Loading...
Searching...
No Matches
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 : 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 IsServerSide() const { return _areaTriggerTemplate->Id.IsServerSide; }
77
78 bool IsNeverVisibleFor(WorldObject const* seer, bool allowServersideObjects = false) const override;
79
80 private:
81 bool Create(uint32 areaTriggerCreatePropertiesId, Unit* caster, Unit* target, SpellInfo const* spellInfo, Position const& pos, int32 duration, SpellCastVisual spellVisual, Spell const* spell, AuraEffect const* aurEff);
82 bool CreateServer(Map* map, AreaTriggerTemplate const* areaTriggerTemplate, AreaTriggerSpawn const& position);
83
84 public:
85 static AreaTrigger* CreateAreaTrigger(uint32 areaTriggerCreatePropertiesId, Unit* caster, Unit* target, SpellInfo const* spellInfo, Position const& pos, int32 duration, SpellCastVisual spellVisual, Spell const* spell = nullptr, AuraEffect const* aurEff = nullptr);
86 static ObjectGuid CreateNewMovementForceId(Map* map, uint32 areaTriggerId);
87 bool LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap, bool allowDuplicate);
88
89 void Update(uint32 diff) override;
90 void Remove();
91 bool IsRemoved() const { return _isRemoved; }
92 uint32 GetSpellId() const { return m_areaTriggerData->SpellID; }
93 AuraEffect const* GetAuraEffect() const { return _aurEff; }
94 uint32 GetTimeSinceCreated() const { return _timeSinceCreated; }
95 uint32 GetTimeToTarget() const { return m_areaTriggerData->TimeToTarget; }
96 uint32 GetTimeToTargetScale() const { return m_areaTriggerData->TimeToTargetScale; }
97 int32 GetDuration() const { return _duration; }
98 int32 GetTotalDuration() const { return _totalDuration; }
99 void SetDuration(int32 newDuration);
100 void Delay(int32 delaytime) { SetDuration(GetDuration() - delaytime); }
101
102 GuidUnorderedSet const& GetInsideUnits() const { return _insideUnits; }
103
104 AreaTriggerCreateProperties const* GetCreateProperties() const { return _areaTriggerCreateProperties; }
105 AreaTriggerTemplate const* GetTemplate() const;
106 uint32 GetScriptId() const;
107
108 ObjectGuid GetOwnerGUID() const override { return GetCasterGuid(); }
109 ObjectGuid const& GetCasterGuid() const { return m_areaTriggerData->Caster; }
110 Unit* GetCaster() const;
111 Unit* GetTarget() const;
112
113 uint32 GetFaction() const override;
114
115 AreaTriggerShapeInfo const& GetShape() const { return _shape; }
116 float GetMaxSearchRadius() const { return _maxSearchRadius; }
117 Position const& GetRollPitchYaw() const { return _rollPitchYaw; }
118 Position const& GetTargetRollPitchYaw() const { return _targetRollPitchYaw; }
119 void InitSplineOffsets(std::vector<Position> const& offsets, uint32 timeToTarget);
120 void InitSplines(std::vector<G3D::Vector3> splinePoints, uint32 timeToTarget);
121 bool HasSplines() const;
122 ::Movement::Spline<int32> const& GetSpline() const { return *_spline; }
123 uint32 GetElapsedTimeForMovement() const { return GetTimeSinceCreated(); }
124
125 void InitOrbit(AreaTriggerOrbitInfo const& orbit, uint32 timeToTarget);
126 bool HasOrbit() const;
127 Optional<AreaTriggerOrbitInfo> const& GetCircularMovementInfo() const { return _orbitInfo; }
128
129 void UpdateShape();
130
132
133 protected:
134 void _UpdateDuration(int32 newDuration);
135 float GetProgress() const;
136
137 float GetScaleCurveValue(UF::ScaleCurve const& scaleCurve, float x) const;
138 void SetScaleCurve(UF::MutableFieldReference<UF::ScaleCurve, false>&& scaleCurveMutator, Optional<AreaTriggerScaleCurveTemplate> const& curve);
139
140 void UpdateTargetList();
141 void SearchUnits(std::vector<Unit*>& targetList, float radius, bool check3D);
142 void SearchUnitInSphere(std::vector<Unit*>& targetList);
143 void SearchUnitInBox(std::vector<Unit*>& targetList);
144 void SearchUnitInPolygon(std::vector<Unit*>& targetList);
145 void SearchUnitInCylinder(std::vector<Unit*>& targetList);
146 void SearchUnitInDisk(std::vector<Unit*>& targetList);
147 void SearchUnitInBoundedPlane(std::vector<Unit*>& targetList);
148 bool CheckIsInPolygon2D(Position const* pos) const;
149 void HandleUnitEnterExit(std::vector<Unit*> const& targetList);
150
151 void DoActions(Unit* unit);
152 void UndoActions(Unit* unit);
153
154 void UpdatePolygonOrientation();
155 void UpdateOrbitPosition(uint32 diff);
156 void UpdateSplinePosition(uint32 diff);
157
158 Position const* GetOrbitCenterPosition() const;
159 Position CalculateOrbitPosition() const;
160
161 void DebugVisualizePosition(); // Debug purpose only
162
164
166
168
176
179 std::vector<Position> _polygonVertices;
180 std::unique_ptr<::Movement::Spline<int32>> _spline;
181
185
187
191
192 std::unique_ptr<AreaTriggerAI> _ai;
193};
194
195#endif
#define TC_GAME_API
Definition: Define.h:124
int32_t int32
Definition: Define.h:139
uint32_t uint32
Definition: Define.h:143
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition: ObjectGuid.h:394
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
float _maxSearchRadius
Definition: AreaTrigger.h:170
GuidUnorderedSet const & GetInsideUnits() const
Definition: AreaTrigger.h:102
AreaTriggerCreateProperties const * _areaTriggerCreateProperties
Definition: AreaTrigger.h:188
bool _isRemoved
Definition: AreaTrigger.h:175
std::vector< Position > _polygonVertices
Definition: AreaTrigger.h:179
ObjectGuid::LowType _spawnId
Definition: AreaTrigger.h:163
int32 _duration
Definition: AreaTrigger.h:171
AreaTriggerAI * AI()
Definition: AreaTrigger.h:74
Position _rollPitchYaw
Definition: AreaTrigger.h:177
ObjectGuid GetOwnerGUID() const override
Definition: AreaTrigger.h:108
uint32 GetTimeSinceCreated() const
Definition: AreaTrigger.h:94
uint32 _timeSinceCreated
Definition: AreaTrigger.h:173
AreaTriggerShapeInfo const & GetShape() const
Definition: AreaTrigger.h:115
ObjectGuid const & GetCasterGuid() const
Definition: AreaTrigger.h:109
bool _reachedDestination
Definition: AreaTrigger.h:182
int32 GetTotalDuration() const
Definition: AreaTrigger.h:98
float GetMaxSearchRadius() const
Definition: AreaTrigger.h:116
UF::UpdateField< UF::AreaTriggerData, 0, TYPEID_AREATRIGGER > m_areaTriggerData
Definition: AreaTrigger.h:131
std::unique_ptr< AreaTriggerAI > _ai
Definition: AreaTrigger.h:192
uint32 _movementTime
Definition: AreaTrigger.h:184
ObjectGuid _targetGuid
Definition: AreaTrigger.h:165
bool IsServerSide() const
Definition: AreaTrigger.h:76
uint32 GetSpellId() const
Definition: AreaTrigger.h:92
float _previousCheckOrientation
Definition: AreaTrigger.h:174
bool IsRemoved() const
Definition: AreaTrigger.h:91
Optional< AreaTriggerOrbitInfo > const & GetCircularMovementInfo() const
Definition: AreaTrigger.h:127
uint32 GetTimeToTarget() const
Definition: AreaTrigger.h:95
int32 _lastSplineIndex
Definition: AreaTrigger.h:183
GuidUnorderedSet _insideUnits
Definition: AreaTrigger.h:190
uint32 GetTimeToTargetScale() const
Definition: AreaTrigger.h:96
std::unique_ptr<::Movement::Spline< int32 > > _spline
Definition: AreaTrigger.h:180
uint32 GetElapsedTimeForMovement() const
Definition: AreaTrigger.h:123
AreaTriggerTemplate const * _areaTriggerTemplate
Definition: AreaTrigger.h:189
Position _targetRollPitchYaw
Definition: AreaTrigger.h:178
Optional< AreaTriggerOrbitInfo > _orbitInfo
Definition: AreaTrigger.h:186
AuraEffect const * _aurEff
Definition: AreaTrigger.h:167
AuraEffect const * GetAuraEffect() const
Definition: AreaTrigger.h:93
::Movement::Spline< int32 > const & GetSpline() const
Definition: AreaTrigger.h:122
Position const & GetTargetRollPitchYaw() const
Definition: AreaTrigger.h:118
Position const & GetRollPitchYaw() const
Definition: AreaTrigger.h:117
int32 GetDuration() const
Definition: AreaTrigger.h:97
AreaTriggerCreateProperties const * GetCreateProperties() const
Definition: AreaTrigger.h:104
int32 _totalDuration
Definition: AreaTrigger.h:172
void Delay(int32 delaytime)
Definition: AreaTrigger.h:100
AreaTriggerShapeInfo _shape
Definition: AreaTrigger.h:169
Definition: Map.h:187
uint64 LowType
Definition: ObjectGuid.h:276
virtual void BuildValuesCreate(ByteBuffer *data, Player const *target) const =0
virtual void ClearUpdateMask(bool remove)
Definition: Object.cpp:782
virtual void BuildValuesUpdate(ByteBuffer *data, Player const *target) const =0
Definition: Spell.h:243
Definition: Unit.h:747
void AddToWorld() override
Definition: Object.cpp:1002
void RemoveFromWorld() override
Definition: Object.cpp:1008
virtual uint32 GetFaction() const =0
virtual bool IsNeverVisibleFor(WorldObject const *seer, bool allowServersideObjects=false) const
Definition: Object.h:798
virtual void Update(uint32 diff)
Definition: Object.cpp:890
Definition: wmo.h:163
ValuesUpdateForPlayerWithMaskSender(AreaTrigger const *owner)
Definition: AreaTrigger.h:59