Project SkyFire Core
SkyFire 5.4.8 server core API documentation
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
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
20template<class T>
22{
23 unit->AddUnitState(UNIT_STATE_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
34template<class T>
36{
37 i_nextMoveTime.Reset(0);
38
39 if (!unit->IsAlive() || unit->IsStopped())
40 return;
41
42 unit->StopMoving();
44}
45
46template<class T>
48{
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
94template<>
101
102template<>
110
std::uint32_t uint32
Definition Define.h:77
@ PATHFIND_NOPATH
@ UNIT_STATE_DISTRACTED
Definition Unit.h:524
@ UNIT_STATE_CONFUSED
Definition Unit.h:523
@ UNIT_STATE_ROOT
Definition Unit.h:522
@ UNIT_STATE_CONFUSED_MOVE
Definition Unit.h:535
@ UNIT_STATE_STUNNED
Definition Unit.h:515
@ UNIT_FLAG_CONFUSED
Definition Unit.h:647
@ UNIT_FIELD_FLAGS
double rand_norm(void)
Definition Util.cpp:50
void SetTarget(uint64 guid) OVERRIDE
void SetWalk(bool enable)
void MovebyPath(const PointsArray &path, int32 pointId=0)
uint64 GetGUID() const
Definition Object.h:119
void RemoveFlag(uint16 index, uint32 oldFlag)
Definition Object.cpp:1280
Movement::PointsArray const & GetPath() const
PathType GetPathType() const
void SetPathLengthLimit(float distance)
bool CalculatePath(float destX, float destY, float destZ, bool forceDest=false)
void ClearUnitState(uint32 f)
Definition Unit.h:1489
void StopMoving()
-------—End of Pet responses methods-------—
Definition Unit.cpp:5877
Unit * GetVictim() const
Definition Unit.h:1468
float m_positionZ
Definition Object.h:289
float m_positionX
Definition Object.h:287
float m_positionY
Definition Object.h:288
void Relocate(float x, float y)
Definition Object.h:302