forked from Lbniese/PureRotation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdvancedAI.Context.cs
382 lines (317 loc) · 13.8 KB
/
AdvancedAI.Context.cs
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
using System;
using System.Linq;
using AdvancedAI.Helpers;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.Plugins;
using Styx.WoWInternals;
using Styx.WoWInternals.DBC;
using Styx.WoWInternals.WoWObjects;
namespace AdvancedAI
{
#region Nested type: LocationContextEventArg
public class WoWContextEventArg : EventArgs
{
public readonly WoWContext CurrentWoWContext;
public readonly WoWContext PreviousWoWContext;
public WoWContextEventArg(WoWContext currentWoWContext, WoWContext prevWoWContext)
{
CurrentWoWContext = currentWoWContext;
PreviousWoWContext = prevWoWContext;
}
}
#endregion Nested type: LocationContextEventArg
partial class AdvancedAI
{
public static event EventHandler<WoWContextEventArg> OnWoWContextChanged;
private static WoWContext _lastContext = WoWContext.None;
internal static bool IsQuestBotActive { get; set; }
internal static bool IsBgBotActive { get; set; }
internal static bool IsDungeonBuddyActive { get; set; }
internal static bool IsPokeBuddyActive { get; set; }
internal static bool IsManualMovementBotActive { get; set; }
internal static WoWContext CurrentWoWContext
{
get
{
return DetermineCurrentWoWContext;
}
}
internal static HealingContext CurrentHealContext
{
get
{
WoWContext ctx = CurrentWoWContext;
if (ctx == WoWContext.Instances && Me.GroupInfo.IsInRaid)
return HealingContext.Raids;
return (HealingContext)ctx;
}
}
private static WoWContext DetermineCurrentWoWContext
{
get
{
if (!StyxWoW.IsInGame)
return WoWContext.None;
if (PvPRot)
return WoWContext.Battlegrounds;
if (PvERot)
return WoWContext.Instances;
Map map = StyxWoW.Me.CurrentMap;
if (map.IsBattleground || IsArena())
{
return WoWContext.Battlegrounds;
}
if (Me.IsInGroup())
{
if (Me.IsInInstance)
{
return WoWContext.Instances;
}
if (Group.Tanks.Any())
{
return WoWContext.Instances;
}
}
//if (SingularRoutine.ForceInstanceBehaviors)
// return WoWContext.Instances;
return WoWContext.Normal;
}
}
private bool _contextEventSubscribed;
private void UpdateContext()
{
// Subscribe to the map change event, so we can automatically update the context.
if (!_contextEventSubscribed)
{
// Subscribe to OnBattlegroundEntered. Just 'cause.
BotEvents.Battleground.OnBattlegroundEntered += e => UpdateContext();
_contextEventSubscribed = true;
}
var current = DetermineCurrentWoWContext;
// Can't update the context when it doesn't exist.
if (current == WoWContext.None)
return;
if (current != _lastContext && OnWoWContextChanged != null)
{
// store values that require scanning lists
UpdateContextStateValues();
DescribeContext();
try
{
OnWoWContextChanged(this, new WoWContextEventArg(current, _lastContext));
}
catch
{
// Eat any exceptions thrown.
}
_lastContext = current;
}
}
private static bool UpdateContextStateValues()
{
bool questBot = IsBotInUse("Quest");
bool bgBot = IsBotInUse("BGBuddy") || IsBotInUse("BG Bot");
bool dungeonBot = IsBotInUse("DungeonBuddy");
bool petHack = IsPluginActive("Pokébuddy") || IsPluginActive("Pokehbuddy");
bool manualBot = IsBotInUse("LazyRaider", "Raid Bot", "Tyrael");
bool changed = false;
if (questBot != IsQuestBotActive)
{
changed = true;
IsQuestBotActive = questBot;
}
if (bgBot != IsBgBotActive)
{
changed = true;
IsBgBotActive = bgBot;
}
if (dungeonBot != IsDungeonBuddyActive)
{
changed = true;
IsDungeonBuddyActive = dungeonBot;
}
if (petHack != IsPokeBuddyActive)
{
changed = true;
IsPokeBuddyActive = petHack;
}
if (manualBot != IsManualMovementBotActive)
{
changed = true;
IsManualMovementBotActive = manualBot;
}
return changed;
}
private static WoWContext LastWoWContext { get; set; }
private static GroupType GroupType
{
get
{
if (Me.GroupInfo.IsInRaid)
{
return GroupType.Raid;
}
return Me.GroupInfo.IsInParty ? GroupType.Party : GroupType.Solo;
}
}
private static bool IsArena()
{
return Me.MapId == 3698 || Me.MapId == 3702 || Me.MapId == 3968 || Me.MapId == 4378 || Me.MapId == 4406 || Me.MapId == 6296 || Me.MapId == 6732;
}
public static bool IsBotInUse(params string[] nameSubstrings)
{
string botName = GetBotName().ToLowerInvariant();
return nameSubstrings.Any(s => botName.Contains(s.ToLowerInvariant()));
}
public static bool IsPluginActive(params string[] nameSubstrings)
{
var lowerNames = nameSubstrings.Select(s => s.ToLowerInvariant()).ToList();
return PluginManager.Plugins.Any(p => p.Enabled && lowerNames.Contains(p.Name.ToLowerInvariant()));
}
private static int GetInstanceDifficulty()
{
int diffidx = Lua.GetReturnVal<int>("return GetInstanceDifficulty()", 0);
return diffidx;
}
private static string[] _InstDiff = new string[]
{
/* 0*/ "Unknown Difficulty",
/* 1*/ "None; not in an Instance",
/* 2*/ "5-player Normal",
/* 3*/ "5-player Heroic",
/* 4*/ "10-player Raid",
/* 5*/ "25-player Raid",
/* 6*/ "10-player Heroic Raid",
/* 7*/ "25-player Heroic Raid",
/* 8*/ "LFR Raid Instance",
/* 9*/ "Challenge Mode Raid",
/* 10*/ "40-player Raid"
};
private static string GetInstanceDifficultyName()
{
int diff = GetInstanceDifficulty();
if (diff < _InstDiff.GetLowerBound(0) || diff > _InstDiff.GetUpperBound(0))
return string.Format("Difficulty {0} Undefined", diff);
return _InstDiff[diff];
}
public static string GetBotName()
{
BotBase bot = null;
if (TreeRoot.Current != null)
{
if (!(TreeRoot.Current is NewMixedMode.MixedModeEx))
bot = TreeRoot.Current;
else
{
NewMixedMode.MixedModeEx mmb = (NewMixedMode.MixedModeEx)TreeRoot.Current;
if (mmb != null)
{
if (mmb.SecondaryBot != null && mmb.SecondaryBot.RequirementsMet)
return "Mixed:" + mmb.SecondaryBot.Name;
return mmb.PrimaryBot != null ? "Mixed:" + mmb.PrimaryBot.Name : "Mixed:[primary null]";
}
}
}
return bot.Name;
}
static void DescribeContext()
{
string sRace = Me.Race.ToString().CamelToSpaced();
if (Me.Race == WoWRace.Pandaren)
sRace = " " + Me.FactionGroup.ToString() + sRace;
Logging.Write(" "); // spacer before prior log text
Logging.Write("Your Level {0}{1} {2} {3} Build is", Me.Level, sRace, SpecializationName(), Me.Class.ToString());
Logging.Write("... running the {0} bot in {1} {2}",
GetBotName(),
Me.RealZoneText,
!Me.IsInInstance || Battlegrounds.IsInsideBattleground ? "" : "[" + GetInstanceDifficultyName() + "]"
);
Logging.Write(" MapId = {0}", Me.MapId);
Logging.Write(" ZoneId = {0}", Me.ZoneId);
/*
if (Me.CurrentMap != null && Me.CurrentMap.IsValid)
{
Logger.WriteFile(" AreaTableId = {0}", Me.CurrentMap.AreaTableId);
Logger.WriteFile(" InternalName = {0}", Me.CurrentMap.InternalName);
Logger.WriteFile(" IsArena = {0}", Me.CurrentMap.IsArena.ToYN());
Logger.WriteFile(" IsBattleground = {0}", Me.CurrentMap.IsBattleground.ToYN());
Logger.WriteFile(" IsContinent = {0}", Me.CurrentMap.IsContinent.ToYN());
Logger.WriteFile(" IsDungeon = {0}", Me.CurrentMap.IsDungeon.ToYN());
Logger.WriteFile(" IsInstance = {0}", Me.CurrentMap.IsInstance.ToYN());
Logger.WriteFile(" IsRaid = {0}", Me.CurrentMap.IsRaid.ToYN());
Logger.WriteFile(" IsScenario = {0}", Me.CurrentMap.IsScenario.ToYN());
Logger.WriteFile(" MapDescription = {0}", Me.CurrentMap.MapDescription);
Logger.WriteFile(" MapDescription2 = {0}", Me.CurrentMap.MapDescription2);
Logger.WriteFile(" MapType = {0}", Me.CurrentMap.MapType);
Logger.WriteFile(" MaxPlayers = {0}", Me.CurrentMap.MaxPlayers);
Logger.WriteFile(" Name = {0}", Me.CurrentMap.Name);
}
*/
string sRunningAs = "";
if (Me.CurrentMap == null)
sRunningAs = "Unknown";
else if (Me.CurrentMap.IsArena)
sRunningAs = "Arena";
else if (Me.CurrentMap.IsBattleground)
sRunningAs = "Battleground";
else if (Me.CurrentMap.IsScenario)
sRunningAs = "Scenario";
else if (Me.CurrentMap.IsRaid)
sRunningAs = "Raid";
else if (Me.CurrentMap.IsDungeon)
sRunningAs = "Dungeon";
else if (Me.CurrentMap.IsInstance)
sRunningAs = "Instance";
else
sRunningAs = "Zone: " + Me.CurrentMap.Name;
Logging.Write("... {0} using my {1} Behaviors",
sRunningAs,
CurrentWoWContext == WoWContext.Normal ? "SOLO" : CurrentWoWContext.ToString().ToUpper());
if (CurrentWoWContext != WoWContext.Battlegrounds && Me.IsInGroup())
{
Logging.Write("... in a group as {0} role with {1} of {2} players",
(Me.Role & (WoWPartyMember.GroupRole.Tank | WoWPartyMember.GroupRole.Healer | WoWPartyMember.GroupRole.Damage)).ToString().ToUpper(),
Me.GroupInfo.NumRaidMembers,
(int)Math.Max(Me.CurrentMap.MaxPlayers, Me.GroupInfo.GroupSize)
);
}
//Item.WriteCharacterGearAndSetupInfo();
#if LOG_GROUP_COMPOSITION
if (CurrentWoWContext == WoWContext.Instances)
{
int idx = 1;
Logger.WriteFile(" ");
Logger.WriteFile("Group Comprised of {0} members as follows:", Me.GroupInfo.NumRaidMembers);
foreach (var pm in Me.GroupInfo.RaidMembers )
{
string role = (pm.Role & ~WoWPartyMember.GroupRole.None).ToString().ToUpper() + " ";
role = role.Substring( 0, 6);
Logger.WriteFile( "{0} {1} {2} {3} {4} {5}",
idx++,
role,
pm.IsOnline ? "online " : "offline",
pm.Level,
pm.HealthMax,
pm.Specialization
);
}
Logger.WriteFile(" ");
}
#endif
if (Styx.CommonBot.Targeting.PullDistance < 25)
Logging.Write("your Pull Distance is {0:F0} yds which is low for any class!!!", Styx.CommonBot.Targeting.PullDistance);
}
private static string SpecializationName()
{
if (Me.Specialization == WoWSpec.None)
return "Lowbie";
string spec = Me.Specialization.ToString().CamelToSpaced();
int idxLastSpace = spec.LastIndexOf(' ');
if (idxLastSpace >= 0 && ++idxLastSpace < spec.Length)
spec = spec.Substring(idxLastSpace);
return spec;
}
}
}