forked from ike3/mangosbot-bots
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ServerFacade.cpp
177 lines (152 loc) · 4.15 KB
/
ServerFacade.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "../botpch.h"
#include "playerbot.h"
#include "PlayerbotAIConfig.h"
#include "ServerFacade.h"
#include "../../modules/Bots/ahbot/AhBot.h"
#include "DatabaseEnv.h"
#include "PlayerbotAI.h"
#include "../../modules/Bots/ahbot/AhBotConfig.h"
#include "MotionGenerators/TargetedMovementGenerator.h"
ServerFacade::ServerFacade() {}
ServerFacade::~ServerFacade() {}
float ServerFacade::GetDistance2d(Unit *unit, WorldObject* wo)
{
if (!unit || !wo)
return false;
float dist =
#ifdef MANGOS
unit->GetDistance2d(wo);
#endif
#ifdef CMANGOS
sqrt(unit->GetDistance2d(wo->GetPositionX(), wo->GetPositionY(), DIST_CALC_NONE));
#endif
return round(dist * 10.0f) / 10.0f;
}
float ServerFacade::GetDistance2d(Unit *unit, float x, float y)
{
float dist =
#ifdef MANGOS
unit->GetDistance2d(x, y);
#endif
#ifdef CMANGOS
sqrt(unit->GetDistance2d(x, y, DIST_CALC_NONE));
#endif
return round(dist * 10.0f) / 10.0f;
}
bool ServerFacade::IsDistanceLessThan(float dist1, float dist2)
{
return dist1 - dist2 < sPlayerbotAIConfig.targetPosRecalcDistance;
}
bool ServerFacade::IsDistanceGreaterThan(float dist1, float dist2)
{
return dist1 - dist2 > sPlayerbotAIConfig.targetPosRecalcDistance;
}
bool ServerFacade::IsDistanceGreaterOrEqualThan(float dist1, float dist2)
{
return !IsDistanceLessThan(dist1, dist2);
}
bool ServerFacade::IsDistanceLessOrEqualThan(float dist1, float dist2)
{
return !IsDistanceGreaterThan(dist1, dist2);
}
void ServerFacade::SetFacingTo(Unit* unit, float angle, bool force)
{
MotionMaster &mm = *unit->GetMotionMaster();
if (!force && !unit->IsStopped()) unit->SetFacingTo(angle);
else
{
unit->SetOrientation(angle);
unit->SendHeartBeat();
}
//unit->m_movementInfo.RemoveMovementFlag(MovementFlags(MOVEFLAG_SPLINE_ENABLED | MOVEFLAG_FORWARD));
}
bool ServerFacade::IsFriendlyTo(Unit* bot, Unit* to)
{
#ifdef MANGOS
return bot->IsFriendlyTo(to);
#endif
#ifdef CMANGOS
return bot->IsFriend(to);
#endif
}
bool ServerFacade::IsHostileTo(Unit* bot, Unit* to)
{
#ifdef MANGOS
return bot->IsHostileTo(to);
#endif
#ifdef CMANGOS
return bot->IsEnemy(to);
#endif
}
bool ServerFacade::IsFriendlyTo(WorldObject* bot, Unit* to)
{
#ifdef MANGOS
return bot->IsFriendlyTo(to);
#endif
#ifdef CMANGOS
return bot->IsFriend(to);
#endif
}
bool ServerFacade::IsHostileTo(WorldObject* bot, Unit* to)
{
#ifdef MANGOS
return bot->IsHostileTo(to);
#endif
#ifdef CMANGOS
return bot->IsEnemy(to);
#endif
}
bool ServerFacade::IsSpellReady(Player* bot, uint32 spell, uint32 itemId)
{
#ifdef MANGOS
return !bot->HasSpellCooldown(spell);
#endif
#ifdef CMANGOS
if (itemId)
{
const ItemPrototype* proto = sObjectMgr.GetItemPrototype(itemId);
return bot->IsSpellReady(spell, proto);
}
else
return bot->IsSpellReady(spell);
#endif
}
bool ServerFacade::IsUnderwater(Unit *unit)
{
#ifdef MANGOS
return unit->IsUnderWater();
#endif
#ifdef CMANGOS
return unit->IsUnderwater();
#endif
}
FactionTemplateEntry const* ServerFacade::GetFactionTemplateEntry(Unit *unit)
{
#ifdef MANGOS
return unit->getFactionTemplateEntry();
#endif
#ifdef CMANGOS
return unit->GetFactionTemplateEntry();
#endif
}
Unit* ServerFacade::GetChaseTarget(Unit* target)
{
return static_cast<ChaseMovementGenerator const*>(target->GetMotionMaster()->GetCurrent())->GetCurrentTarget();
}
float ServerFacade::GetChaseAngle(Unit* target)
{
return static_cast<ChaseMovementGenerator const*>(target->GetMotionMaster()->GetCurrent())->GetAngle();
}
float ServerFacade::GetChaseOffset(Unit* target)
{
return static_cast<ChaseMovementGenerator const*>(target->GetMotionMaster()->GetCurrent())->GetOffset();
}
bool ServerFacade::isMoving(Unit *unit)
{
#ifdef MANGOS
return unit->m_movementInfo.HasMovementFlag(movementFlagsMask);
#endif
#ifdef CMANGOS
return !unit->IsStopped() || (!unit->GetMotionMaster()->empty() && unit->GetMotionMaster()->GetCurrentMovementGeneratorType() != IDLE_MOTION_TYPE);
#endif
}