Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
ConfusedMovementGenerator.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#include "
ConfusedMovementGenerator.h
"
7
#include "
Creature.h
"
8
#include "
MapManager.h
"
9
#include "
MoveSpline.h
"
10
#include "
MoveSplineInit.h
"
11
#include "
PathGenerator.h
"
12
#include "
Player.h
"
13
#include "
VMapFactory.h
"
14
15
#ifdef MAP_BASED_RAND_GEN
16
#define rand_norm() unit.rand_norm()
17
#define urand(a, b) unit.urand(a, b)
18
#endif
19
20
template
<
class
T>
21
void
ConfusedMovementGenerator<T>::DoInitialize
(T* unit)
22
{
23
unit->AddUnitState(
UNIT_STATE_CONFUSED
);
24
unit->SetFlag(
UNIT_FIELD_FLAGS
,
UNIT_FLAG_CONFUSED
);
25
unit->GetPosition(
i_x
,
i_y
,
i_z
);
26
27
if
(!unit->IsAlive() || unit->IsStopped())
28
return
;
29
30
unit->StopMoving();
31
unit->AddUnitState(
UNIT_STATE_CONFUSED_MOVE
);
32
}
33
34
template
<
class
T>
35
void
ConfusedMovementGenerator<T>::DoReset
(T* unit)
36
{
37
i_nextMoveTime
.Reset(0);
38
39
if
(!unit->IsAlive() || unit->IsStopped())
40
return
;
41
42
unit->StopMoving();
43
unit->AddUnitState(
UNIT_STATE_CONFUSED
|
UNIT_STATE_CONFUSED_MOVE
);
44
}
45
46
template
<
class
T>
47
bool
ConfusedMovementGenerator<T>::DoUpdate
(T* unit,
uint32
diff)
48
{
49
if
(unit->HasUnitState(
UNIT_STATE_ROOT
|
UNIT_STATE_STUNNED
|
UNIT_STATE_DISTRACTED
))
50
return
true
;
51
52
if
(
i_nextMoveTime
.Passed())
53
{
54
// currently moving, update location
55
unit->AddUnitState(
UNIT_STATE_CONFUSED_MOVE
);
56
57
if
(unit->movespline->Finalized())
58
i_nextMoveTime
.Reset(std::rand() % 1500 + 800);
59
}
60
else
61
{
62
// waiting for next move
63
i_nextMoveTime
.Update(diff);
64
if
(
i_nextMoveTime
.Passed())
65
{
66
// start moving
67
unit->AddUnitState(
UNIT_STATE_CONFUSED_MOVE
);
68
69
float
dest = 4.0f * (float)
rand_norm
() - 2.0f;
70
71
Position
pos;
72
pos.
Relocate
(
i_x
,
i_y
,
i_z
);
73
unit->MovePositionToFirstCollision(pos, dest, 0.0f);
74
75
PathGenerator
path(unit);
76
path.
SetPathLengthLimit
(30.0f);
77
bool
result = path.
CalculatePath
(pos.
m_positionX
, pos.
m_positionY
, pos.
m_positionZ
);
78
if
(!result || (path.
GetPathType
() &
PATHFIND_NOPATH
))
79
{
80
i_nextMoveTime
.Reset(100);
81
return
true
;
82
}
83
84
Movement::MoveSplineInit
init(unit);
85
init.
MovebyPath
(path.
GetPath
());
86
init.
SetWalk
(
true
);
87
init.
Launch
();
88
}
89
}
90
91
return
true
;
92
}
93
94
template
<>
95
void
ConfusedMovementGenerator<Player>::DoFinalize
(
Player
* unit)
96
{
97
unit->
RemoveFlag
(
UNIT_FIELD_FLAGS
,
UNIT_FLAG_CONFUSED
);
98
unit->
ClearUnitState
(
UNIT_STATE_CONFUSED
|
UNIT_STATE_CONFUSED_MOVE
);
99
unit->
StopMoving
();
100
}
101
102
template
<>
103
void
ConfusedMovementGenerator<Creature>::DoFinalize
(
Creature
* unit)
104
{
105
unit->
RemoveFlag
(
UNIT_FIELD_FLAGS
,
UNIT_FLAG_CONFUSED
);
106
unit->
ClearUnitState
(
UNIT_STATE_CONFUSED
|
UNIT_STATE_CONFUSED_MOVE
);
107
if
(unit->
GetVictim
())
108
unit->
SetTarget
(unit->
GetVictim
()->
GetGUID
());
109
}
110
111
template
void
ConfusedMovementGenerator<Player>::DoInitialize
(
Player
*);
112
template
void
ConfusedMovementGenerator<Creature>::DoInitialize
(
Creature
*);
113
template
void
ConfusedMovementGenerator<Player>::DoReset
(
Player
*);
114
template
void
ConfusedMovementGenerator<Creature>::DoReset
(
Creature
*);
115
template
bool
ConfusedMovementGenerator<Player>::DoUpdate
(
Player
*,
uint32
diff);
116
template
bool
ConfusedMovementGenerator<Creature>::DoUpdate
(
Creature
*,
uint32
diff);
ConfusedMovementGenerator.h
Creature.h
uint32
std::uint32_t uint32
Definition
Define.h:77
MapManager.h
MoveSpline.h
MoveSplineInit.h
PathGenerator.h
PATHFIND_NOPATH
@ PATHFIND_NOPATH
Definition
PathGenerator.h:34
Player.h
UNIT_STATE_DISTRACTED
@ UNIT_STATE_DISTRACTED
Definition
Unit.h:524
UNIT_STATE_CONFUSED
@ UNIT_STATE_CONFUSED
Definition
Unit.h:523
UNIT_STATE_ROOT
@ UNIT_STATE_ROOT
Definition
Unit.h:522
UNIT_STATE_CONFUSED_MOVE
@ UNIT_STATE_CONFUSED_MOVE
Definition
Unit.h:535
UNIT_STATE_STUNNED
@ UNIT_STATE_STUNNED
Definition
Unit.h:515
UNIT_FLAG_CONFUSED
@ UNIT_FLAG_CONFUSED
Definition
Unit.h:647
UNIT_FIELD_FLAGS
@ UNIT_FIELD_FLAGS
Definition
UpdateFields.h:82
rand_norm
double rand_norm(void)
Definition
Util.cpp:50
VMapFactory.h
ConfusedMovementGenerator::i_x
float i_x
Definition
ConfusedMovementGenerator.h:26
ConfusedMovementGenerator::DoReset
void DoReset(T *)
Definition
ConfusedMovementGenerator.cpp:35
ConfusedMovementGenerator::DoUpdate
bool DoUpdate(T *, uint32)
Definition
ConfusedMovementGenerator.cpp:47
ConfusedMovementGenerator::DoInitialize
void DoInitialize(T *)
Definition
ConfusedMovementGenerator.cpp:21
ConfusedMovementGenerator::DoFinalize
void DoFinalize(T *)
ConfusedMovementGenerator::i_nextMoveTime
TimeTracker i_nextMoveTime
Definition
ConfusedMovementGenerator.h:25
ConfusedMovementGenerator::i_y
float i_y
Definition
ConfusedMovementGenerator.h:26
ConfusedMovementGenerator::i_z
float i_z
Definition
ConfusedMovementGenerator.h:26
Creature
Definition
Creature.h:427
Creature::SetTarget
void SetTarget(uint64 guid) OVERRIDE
Definition
Creature.cpp:2626
Movement::MoveSplineInit
Definition
MoveSplineInit.h:40
Movement::MoveSplineInit::SetWalk
void SetWalk(bool enable)
Definition
MoveSplineInit.h:147
Movement::MoveSplineInit::Launch
int32 Launch()
Definition
MoveSplineInit.cpp:46
Movement::MoveSplineInit::MovebyPath
void MovebyPath(const PointsArray &path, int32 pointId=0)
Definition
MoveSplineInit.h:157
Object::GetGUID
uint64 GetGUID() const
Definition
Object.h:119
Object::RemoveFlag
void RemoveFlag(uint16 index, uint32 oldFlag)
Definition
Object.cpp:1280
PathGenerator
Definition
PathGenerator.h:40
PathGenerator::GetPath
Movement::PointsArray const & GetPath() const
Definition
PathGenerator.h:58
PathGenerator::GetPathType
PathType GetPathType() const
Definition
PathGenerator.h:60
PathGenerator::SetPathLengthLimit
void SetPathLengthLimit(float distance)
Definition
PathGenerator.h:51
PathGenerator::CalculatePath
bool CalculatePath(float destX, float destY, float destZ, bool forceDest=false)
Definition
PathGenerator.cpp:42
Player
Definition
Player.h:1289
Unit::ClearUnitState
void ClearUnitState(uint32 f)
Definition
Unit.h:1489
Unit::StopMoving
void StopMoving()
-------—End of Pet responses methods-------—
Definition
Unit.cpp:5877
Unit::GetVictim
Unit * GetVictim() const
Definition
Unit.h:1468
Position
Definition
Object.h:274
Position::m_positionZ
float m_positionZ
Definition
Object.h:289
Position::m_positionX
float m_positionX
Definition
Object.h:287
Position::m_positionY
float m_positionY
Definition
Object.h:288
Position::Relocate
void Relocate(float x, float y)
Definition
Object.h:302
src
server
game
Movement
MovementGenerators
ConfusedMovementGenerator.cpp
Generated on
for Project SkyFire Core by
1.17.0