-
Notifications
You must be signed in to change notification settings - Fork 372
Expand file tree
/
Copy pathAiFactory.cpp
More file actions
318 lines (285 loc) · 8.96 KB
/
AiFactory.cpp
File metadata and controls
318 lines (285 loc) · 8.96 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#include "../botpch.h"
#include "playerbot.h"
#include "AiFactory.h"
#include "strategy/Engine.h"
#include "strategy/priest/PriestAiObjectContext.h"
#include "strategy/mage/MageAiObjectContext.h"
#include "strategy/warlock/WarlockAiObjectContext.h"
#include "strategy/warrior/WarriorAiObjectContext.h"
#include "strategy/shaman/ShamanAiObjectContext.h"
#include "strategy/paladin/PaladinAiObjectContext.h"
#include "strategy/druid/DruidAiObjectContext.h"
#include "strategy/hunter/HunterAiObjectContext.h"
#include "strategy/rogue/RogueAiObjectContext.h"
#include "Player.h"
#include "PlayerbotAIConfig.h"
#include "RandomPlayerbotMgr.h"
AiObjectContext* AiFactory::createAiObjectContext(Player* player, PlayerbotAI* ai)
{
switch (player->getClass())
{
case CLASS_PRIEST:
return new PriestAiObjectContext(ai);
break;
case CLASS_MAGE:
return new MageAiObjectContext(ai);
break;
case CLASS_WARLOCK:
return new WarlockAiObjectContext(ai);
break;
case CLASS_WARRIOR:
return new WarriorAiObjectContext(ai);
break;
case CLASS_SHAMAN:
return new ShamanAiObjectContext(ai);
break;
case CLASS_PALADIN:
return new PaladinAiObjectContext(ai);
break;
case CLASS_DRUID:
return new DruidAiObjectContext(ai);
break;
case CLASS_HUNTER:
return new HunterAiObjectContext(ai);
break;
case CLASS_ROGUE:
return new RogueAiObjectContext(ai);
break;
}
return new AiObjectContext(ai);
}
int AiFactory::GetPlayerSpecTab(Player* bot)
{
map<uint32, int32> tabs = GetPlayerSpecTabs(bot);
int tab = -1, max = 0;
for (uint32 i = 0; i < uint32(3); i++)
{
if (tab == -1 || max < tabs[i])
{
tab = i;
max = tabs[i];
}
}
return tab;
}
map<uint32, int32> AiFactory::GetPlayerSpecTabs(Player* bot)
{
map<uint32, int32> tabs;
for (uint32 i = 0; i < uint32(3); i++)
{
tabs[i] = 0;
}
uint32 classMask = bot->getClassMask();
uint32 spentPoints = bot->getLevel() >= 10 ? (bot->getLevel() - 9) - bot->GetFreeTalentPoints() : 0;
uint32 found = 0;
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{
if (found >= spentPoints)
break;
TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
if (!talentInfo)
{
continue;
}
TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab);
if (!talentTabInfo)
{
continue;
}
if ((classMask & talentTabInfo->ClassMask) == 0)
{
continue;
}
for (int rank = MAX_TALENT_RANK - 1; rank >= 0; --rank)
{
if (!talentInfo->RankID[rank])
{
continue;
}
uint32 spellid = talentInfo->RankID[rank];
if (spellid && bot->HasSpell(spellid))
{
tabs[talentTabInfo->tabpage]++;
found++;
}
}
}
return tabs;
}
void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const facade, Engine* engine)
{
int tab = GetPlayerSpecTab(player);
engine->addStrategies("attack weak", "racials", "chat", "default", "aoe", "potions", "cast time", "conserve mana", "duel", "pvp", NULL);
if (sPlayerbotAIConfig.cautiousDefault)
{
engine->addStrategy("cautious");
}
switch (player->getClass())
{
case CLASS_PRIEST:
if (tab == 2)
{
engine->addStrategies("dps", "threat", NULL);
if (player->getLevel() > 19)
{
engine->addStrategy("dps debuff");
}
}
else
{
engine->addStrategy("heal");
}
engine->addStrategy("flee");
break;
case CLASS_MAGE:
if (tab == 0)
{
engine->addStrategies("arcane", "threat", NULL);
}
else if (tab == 1)
{
engine->addStrategies("fire", "fire aoe", "threat", NULL);
}
else
{
engine->addStrategies("frost", "frost aoe", "threat", NULL);
}
engine->addStrategy("flee");
break;
case CLASS_WARRIOR:
if (tab == 2)
{
engine->addStrategies("tank", "tank aoe", NULL);
}
else
{
engine->addStrategies("dps", "threat", NULL);
}
break;
case CLASS_SHAMAN:
if (tab == 0)
{
engine->addStrategies("caster", "caster aoe", "bmana", "threat", "flee", NULL);
}
else if (tab == 2)
{
engine->addStrategies("heal", "bmana", "flee", NULL);
}
else
{
engine->addStrategies("dps", "melee aoe", "bdps", "threat", NULL);
}
break;
case CLASS_PALADIN:
if (tab == 1)
{
engine->addStrategies("tank", "tank aoe", "barmor", NULL);
}
else
{
engine->addStrategies("dps", "bdps", "threat", NULL);
}
break;
case CLASS_DRUID:
if (tab == 0)
{
engine->addStrategies("caster", "caster aoe", "threat", "flee", NULL);
if (player->getLevel() > 19)
{
engine->addStrategy("caster debuff");
}
}
else if (tab == 2)
{
engine->addStrategies("heal", "flee", NULL);
}
else
{
engine->addStrategies("bear", "tank aoe", "threat", "flee", NULL);
}
break;
case CLASS_HUNTER:
engine->addStrategies("dps", "bdps", "threat", NULL);
if (player->getLevel() > 19)
{
engine->addStrategy("dps debuff");
}
break;
case CLASS_ROGUE:
engine->addStrategies("dps", "threat", NULL);
break;
case CLASS_WARLOCK:
if (tab == 1)
{
engine->addStrategies("tank", "threat", NULL);
}
else
{
engine->addStrategies("dps", "threat", NULL);
}
if (player->getLevel() > 19)
{
engine->addStrategy("dps debuff");
}
engine->addStrategy("flee");
break;
}
if (sRandomPlayerbotMgr.IsRandomBot(player) && !player->GetGroup())
{
engine->ChangeStrategy(sPlayerbotAIConfig.randomBotCombatStrategies);
}
}
Engine* AiFactory::createCombatEngine(Player* player, PlayerbotAI* const facade, AiObjectContext* AiObjectContext) {
Engine* engine = new Engine(facade, AiObjectContext);
AddDefaultCombatStrategies(player, facade, engine);
return engine;
}
void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const facade, Engine* nonCombatEngine)
{
int tab = GetPlayerSpecTab(player);
if (sPlayerbotAIConfig.cautiousDefault)
{
nonCombatEngine->addStrategy("cautious");
}
switch (player->getClass()){
case CLASS_PALADIN:
case CLASS_HUNTER:
case CLASS_SHAMAN:
nonCombatEngine->addStrategy("bmana");
break;
case CLASS_MAGE:
if (tab == 1)
{
nonCombatEngine->addStrategy("bdps");
}
else
{
nonCombatEngine->addStrategy("bmana");
}
break;
}
nonCombatEngine->addStrategies("nc", "attack weak", "food", "stay", "chat",
"default", "quest", "loot", "gather", "duel", "emote", NULL);
if (sRandomPlayerbotMgr.IsRandomBot(player) && !player->GetGroup())
{
nonCombatEngine->ChangeStrategy(sPlayerbotAIConfig.randomBotNonCombatStrategies);
}
}
Engine* AiFactory::createNonCombatEngine(Player* player, PlayerbotAI* const facade, AiObjectContext* AiObjectContext) {
Engine* nonCombatEngine = new Engine(facade, AiObjectContext);
AddDefaultNonCombatStrategies(player, facade, nonCombatEngine);
return nonCombatEngine;
}
void AiFactory::AddDefaultDeadStrategies(Player* player, PlayerbotAI* const facade, Engine* deadEngine)
{
deadEngine->addStrategies("dead", "stay", "chat", "default", "follow master", NULL);
if (sRandomPlayerbotMgr.IsRandomBot(player) && !player->GetGroup())
{
deadEngine->removeStrategy("follow master");
}
}
Engine* AiFactory::createDeadEngine(Player* player, PlayerbotAI* const facade, AiObjectContext* AiObjectContext) {
Engine* deadEngine = new Engine(facade, AiObjectContext);
AddDefaultDeadStrategies(player, facade, deadEngine);
return deadEngine;
}