TrinityCore
Loading...
Searching...
No Matches
IdleMovementGenerator.cpp
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
19#include "Creature.h"
20#include "CreatureAI.h"
21#include "G3DPosition.hpp"
22#include "MovementDefines.h"
23#include "MoveSpline.h"
24#include "MoveSplineInit.h"
25#include "Unit.h"
26
33
34/*
35 * TODO: "if (!owner->IsStopped())" is useless, each generator cleans their own STATE_MOVE, the result is that StopMoving is almost never called
36 * Old comment: "StopMoving is needed to make unit stop if its last movement generator expires but it should not be sent otherwise there are many redundent packets"
37 */
39{
40 owner->StopMoving();
41 return true;
42}
43
45{
46 owner->StopMoving();
47 return true;
48}
49
51{
52}
53
54void IdleMovementGenerator::Finalize(Unit* /*owner*/, bool/* active*/, bool/* movementInform*/)
55{
57}
58
63
64//----------------------------------------------------//
65
66RotateMovementGenerator::RotateMovementGenerator(uint32 id, uint32 time, RotateDirection direction) : _id(id), _duration(time), _maxDuration(time), _direction(direction)
67{
71}
72
74{
77
78 return true;
79 /*
80 * TODO: This code should be handled somewhere else, like MovementInform
81 *
82 * if (owner->GetVictim())
83 * owner->SetInFront(owner->GetVictim());
84 *
85 * owner->AttackStop();
86 */
87}
88
95
97{
98 if (!owner)
99 return false;
100
101 float angle = owner->GetOrientation();
102 angle += (float(diff) * static_cast<float>(M_PI * 2) / _maxDuration) * (_direction == ROTATE_DIRECTION_LEFT ? 1.0f : -1.0f);
103
104 Movement::MoveSplineInit init(owner);
105 init.MoveTo(PositionToVector3(*owner), false);
108 init.SetFacing(angle);
109 init.Launch();
110
111 if (_duration > diff)
112 _duration -= diff;
113 else
114 {
116 return false;
117 }
118
119 return true;
120}
121
126
127void RotateMovementGenerator::Finalize(Unit* owner, bool/* active*/, bool movementInform)
128{
130
131 if (movementInform && owner->GetTypeId() == TYPEID_UNIT)
133}
134
139
140//----------------------------------------------------//
141
142DistractMovementGenerator::DistractMovementGenerator(uint32 timer, float orientation) : _timer(timer), _orientation(orientation), _originalOrientation(0.f)
143{
147}
148
150{
153
154 // Distracted creatures stand up if not standing
155 if (!owner->IsStandState())
157
159
160 Movement::MoveSplineInit init(owner);
161 init.MoveTo(PositionToVector3(*owner), false);
165 init.Launch();
166 return true;
167}
168
175
177{
178 if (!owner)
179 return false;
180
181 if (diff > _timer)
182 {
184 return false;
185 }
186
187 _timer -= diff;
188 return true;
189}
190
195
196void DistractMovementGenerator::Finalize(Unit* owner, bool/* active*/, bool movementInform)
197{
199
200 if (movementInform && HasFlag(MOVEMENTGENERATOR_FLAG_INFORM_ENABLED) && owner->GetTypeId() == TYPEID_UNIT)
201 owner->SetFacingTo(_originalOrientation, true);
202}
203
208
209//----------------------------------------------------//
210
215
216void AssistanceDistractMovementGenerator::Finalize(Unit* owner, bool/* active*/, bool movementInform)
217{
219
220 if (movementInform && HasFlag(MOVEMENTGENERATOR_FLAG_INFORM_ENABLED) && owner->GetTypeId() == TYPEID_UNIT)
222}
223
#define M_PI
Definition Common.h:72
uint32_t uint32
Definition Define.h:133
RotateDirection
@ ROTATE_DIRECTION_LEFT
@ MOTION_PRIORITY_HIGHEST
@ MOTION_PRIORITY_NORMAL
MovementGeneratorType
@ DISTRACT_MOTION_TYPE
@ IDLE_MOTION_TYPE
@ ROTATE_MOTION_TYPE
@ ASSISTANCE_DISTRACT_MOTION_TYPE
@ MOVEMENTGENERATOR_FLAG_INITIALIZATION_PENDING
@ MOVEMENTGENERATOR_FLAG_DEACTIVATED
@ MOVEMENTGENERATOR_FLAG_FINALIZED
@ MOVEMENTGENERATOR_FLAG_INFORM_ENABLED
@ MOVEMENTGENERATOR_FLAG_INITIALIZED
@ TYPEID_UNIT
Definition ObjectGuid.h:38
@ REACT_AGGRESSIVE
@ UNIT_STAND_STATE_STAND
Definition UnitDefines.h:34
@ MOVEMENTFLAG_ONTRANSPORT
@ UNIT_STATE_DISTRACTED
Definition Unit.h:232
@ UNIT_STATE_ROTATING
Definition Unit.h:241
MovementGeneratorType GetMovementGeneratorType() const override
void Finalize(Unit *, bool, bool) override
AssistanceDistractMovementGenerator(uint32 timer, float orientation)
virtual void MovementInform(uint32, uint32)
Definition CreatureAI.h:173
void SetReactState(ReactStates st)
Definition Creature.h:119
CreatureAI * AI() const
Definition Creature.h:154
void Finalize(Unit *, bool, bool) override
MovementGeneratorType GetMovementGeneratorType() const override
bool Update(Unit *, uint32) override
DistractMovementGenerator(uint32 timer, float orientation)
bool Reset(Unit *) override
void Deactivate(Unit *) override
MovementGeneratorType GetMovementGeneratorType() const override
void Finalize(Unit *, bool, bool) override
bool Initialize(Unit *) override
void AddFlag(uint16 const flag)
bool HasFlag(uint16 const flag) const
void RemoveFlag(uint16 const flag)
void MoveTo(Vector3 const &destination, bool generatePath=true, bool forceDestination=false)
void SetFacing(float angle)
bool IsEmpty() const
Definition ObjectGuid.h:172
static Creature * ToCreature(Object *o)
Definition Object.h:186
TypeID GetTypeId() const
Definition Object.h:93
bool Update(Unit *, uint32) override
RotateMovementGenerator(uint32 id, uint32 time, RotateDirection direction)
MovementGeneratorType GetMovementGeneratorType() const override
void Finalize(Unit *, bool, bool) override
void Deactivate(Unit *) override
bool Initialize(Unit *) override
Definition Unit.h:769
void StopMoving(bool force=false)
Definition Unit.cpp:10312
bool IsStandState() const
Definition Unit.cpp:10357
bool HasUnitMovementFlag(uint32 f) const
Definition Unit.h:1678
ObjectGuid GetTransGUID() const override
Definition Unit.cpp:11856
void SetFacingTo(float ori, bool force=true, uint32 movementId=EVENT_FACE)
Definition Unit.cpp:13250
void SetStandState(UnitStandStateType state)
Definition Unit.cpp:10363
float GetOrientation() const
Definition Position.h:82