TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ConfusedMovementGenerator< T > Class Template Reference

#include <ConfusedMovementGenerator.h>

Public Member Functions

 ConfusedMovementGenerator ()
 
void DoInitialize (T *)
 
void DoFinalize (T *)
 
void DoReset (T *)
 
bool DoUpdate (T *, uint32)
 
MovementGeneratorType GetMovementGeneratorType () const override
 
template<>
void DoFinalize (Player *unit)
 
template<>
void DoFinalize (Creature *unit)
 
- Public Member Functions inherited from MovementGeneratorMedium< T, ConfusedMovementGenerator< T > >
void Initialize (Unit *u) override
 
void Finalize (Unit *u) override
 
void Reset (Unit *u) override
 
bool Update (Unit *u, uint32 time_diff) override
 
- Public Member Functions inherited from MovementGenerator
virtual ~MovementGenerator ()
 
virtual void unitSpeedChanged ()
 
virtual bool GetResetPosition (Unit *, float &, float &, float &)
 

Private Attributes

TimeTracker i_nextMoveTime
 
float i_x
 
float i_y
 
float i_z
 

Constructor & Destructor Documentation

template<class T >
ConfusedMovementGenerator< T >::ConfusedMovementGenerator ( )
inlineexplicit
29 : i_nextMoveTime(0), i_x(0), i_y(0), i_z(0) { }
float i_x
Definition: ConfusedMovementGenerator.h:39
float i_z
Definition: ConfusedMovementGenerator.h:39
TimeTracker i_nextMoveTime
Definition: ConfusedMovementGenerator.h:38
float i_y
Definition: ConfusedMovementGenerator.h:39

Member Function Documentation

template<class T >
void ConfusedMovementGenerator< T >::DoFinalize ( T *  )
template<>
void ConfusedMovementGenerator< Player >::DoFinalize ( Player unit)
107 {
108  unit->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
109  unit->ClearUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
110  unit->StopMoving();
111 }
Definition: Unit.h:561
Definition: Unit.h:573
Definition: UpdateFields.h:109
Definition: Unit.h:695
template<>
void ConfusedMovementGenerator< Creature >::DoFinalize ( Creature unit)
115 {
118  if (unit->GetVictim())
119  unit->SetTarget(unit->EnsureVictim()->GetGUID());
120 }
Unit * EnsureVictim() const
Definition: Unit.h:1381
Definition: Unit.h:561
void ClearUnitState(uint32 f)
Definition: Unit.h:1396
Definition: Unit.h:573
Unit * GetVictim() const
Definition: Unit.h:1379
void RemoveFlag(uint16 index, uint32 oldFlag)
Definition: Object.cpp:1214
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Definition: UpdateFields.h:109
void SetTarget(ObjectGuid const &guid) override
Definition: Creature.cpp:2675
Definition: Unit.h:695

+ Here is the call graph for this function:

template<class T >
template void ConfusedMovementGenerator< T >::DoInitialize ( T *  )
33 {
34  unit->AddUnitState(UNIT_STATE_CONFUSED);
35  unit->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
36  unit->GetPosition(i_x, i_y, i_z);
37 
38  if (!unit->IsAlive() || unit->IsStopped())
39  return;
40 
41  unit->StopMoving();
42  unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE);
43 }
Definition: Unit.h:561
float i_x
Definition: ConfusedMovementGenerator.h:39
Definition: Unit.h:573
Definition: UpdateFields.h:109
float i_z
Definition: ConfusedMovementGenerator.h:39
Definition: Unit.h:695
float i_y
Definition: ConfusedMovementGenerator.h:39
template<class T >
template void ConfusedMovementGenerator< T >::DoReset ( T *  )
47 {
49 
50  if (!unit->IsAlive() || unit->IsStopped())
51  return;
52 
53  unit->StopMoving();
54  unit->AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
55 }
Definition: Unit.h:561
void Reset(time_t interval)
Definition: Timer.h:119
Definition: Unit.h:573
TimeTracker i_nextMoveTime
Definition: ConfusedMovementGenerator.h:38
template<class T >
template bool ConfusedMovementGenerator< T >::DoUpdate ( T *  ,
uint32   
)
59 {
60  if (unit->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED | UNIT_STATE_DISTRACTED))
61  return true;
62 
63  if (i_nextMoveTime.Passed())
64  {
65  // currently moving, update location
66  unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE);
67 
68  if (unit->movespline->Finalized())
69  i_nextMoveTime.Reset(urand(800, 1500));
70  }
71  else
72  {
73  // waiting for next move
74  i_nextMoveTime.Update(diff);
75  if (i_nextMoveTime.Passed())
76  {
77  // start moving
78  unit->AddUnitState(UNIT_STATE_CONFUSED_MOVE);
79 
80  float dest = 4.0f * (float)rand_norm() - 2.0f;
81 
82  Position pos;
83  pos.Relocate(i_x, i_y, i_z);
84  unit->MovePositionToFirstCollision(pos, dest, 0.0f);
85 
86  PathGenerator path(unit);
87  path.SetPathLengthLimit(30.0f);
88  bool result = path.CalculatePath(pos.m_positionX, pos.m_positionY, pos.m_positionZ);
89  if (!result || (path.GetPathType() & PATHFIND_NOPATH))
90  {
91  i_nextMoveTime.Reset(100);
92  return true;
93  }
94 
95  Movement::MoveSplineInit init(unit);
96  init.MovebyPath(path.GetPath());
97  init.SetWalk(true);
98  init.Launch();
99  }
100  }
101 
102  return true;
103 }
Definition: Unit.h:562
Definition: PathGenerator.h:47
float m_positionY
Definition: Position.h:53
float m_positionX
Definition: Position.h:52
float i_x
Definition: ConfusedMovementGenerator.h:39
void Reset(time_t interval)
Definition: Timer.h:119
Definition: Unit.h:573
void Relocate(float x, float y)
Definition: Position.h:67
Definition: Unit.h:553
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
void Update(time_t diff)
Definition: Timer.h:109
Definition: PathGenerator.h:52
float m_positionZ
Definition: Position.h:54
double rand_norm()
Definition: Random.cpp:69
Definition: Unit.h:560
Definition: Position.h:27
bool Passed() const
Definition: Timer.h:114
float i_z
Definition: ConfusedMovementGenerator.h:39
TimeTracker i_nextMoveTime
Definition: ConfusedMovementGenerator.h:38
Definition: MoveSplineInit.h:52
float i_y
Definition: ConfusedMovementGenerator.h:39

+ Here is the call graph for this function:

template<class T >
MovementGeneratorType ConfusedMovementGenerator< T >::GetMovementGeneratorType ( ) const
inlineoverridevirtual

Implements MovementGenerator.

36 { return CONFUSED_MOTION_TYPE; }
Definition: MotionMaster.h:42

Member Data Documentation

template<class T >
TimeTracker ConfusedMovementGenerator< T >::i_nextMoveTime
private
template<class T >
float ConfusedMovementGenerator< T >::i_x
private
template<class T >
float ConfusedMovementGenerator< T >::i_y
private
template<class T >
float ConfusedMovementGenerator< T >::i_z
private

The documentation for this class was generated from the following files: