forked from Mattygs6/ExFateBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExFateBot.cs
540 lines (474 loc) · 12.1 KB
/
ExFateBot.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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
namespace ExFateBot
{
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Clio.Utilities;
using ff14bot;
using ff14bot.AClasses;
using ff14bot.Behavior;
using ff14bot.BotBases;
using ff14bot.Enums;
using ff14bot.Helpers;
using ff14bot.Managers;
using ff14bot.Navigation;
using ff14bot.Objects;
using ff14bot.RemoteWindows;
using ff14bot.Settings;
using ff14bot.Pathing.Service_Navigation;
using ff14bot.Windows.FateBotSettingsWindow;
using TreeSharp;
using Action = TreeSharp.Action;
public class ExFateBot : BotBase
{
private FateBotSettingsWindow settingsWindow;
private static readonly DefaultFateScoreProvider FateScoreProvider = new DefaultFateScoreProvider();
public static readonly Stopwatch FateTimer = new Stopwatch();
internal static FateData FateData;
private static bool shouldMoveIntoFate;
private readonly FateIconType[] fateIconType =
{
FateIconType.Battle, FateIconType.Boss, FateIconType.ProtectNPC2,
FateIconType.ProtectNPC
};
private Composite composite;
static ExFateBot()
{
}
public string Description
{
get
{
return "FateBot by ExMatt";
}
}
public override string EnglishName
{
get
{
return "ExFateBot";
}
}
public override bool IsAutonomous
{
get
{
return true;
}
}
public override bool IsPrimaryType
{
get
{
return true;
}
}
public override string Name
{
get
{
return "ExFateBot";
}
}
public override PulseFlags PulseFlags
{
get
{
return PulseFlags.All;
}
}
public override bool RequiresProfile
{
get
{
return false;
}
}
public override Composite Root
{
get
{
return this.composite;
}
}
public override bool WantButton
{
get
{
return true;
}
}
internal bool Withinfate
{
get
{
if (!FateManager.WithinFate)
{
return false;
}
if (FateData == null)
{
return false;
}
var location = Core.Player.Location;
return FateData.Within2D(location);
}
}
private Composite BotLogic
{
get
{
ContextChangeHandler unit = obj => Poi.Current.Unit as BattleCharacter;
Composite[] composite0 = { null, null, null, null, null, null };
composite0[0] = new Decorator(
obj =>
{
if (FateData == null)
{
return false;
}
return !FateData.IsValid;
},
new Action(obj => FateData = null));
composite0[1] = new Decorator(
obj =>
{
if (!this.Withinfate || FateData == null)
{
return false;
}
return Core.Player.ClassLevel > FateData.MaxLevel;
},
new Action(obj => ToDoList.LevelSync()));
composite0[2] = new Decorator(
obj =>
{
if (!shouldMoveIntoFate)
{
return false;
}
if (FateData == null || !FateData.IsValid || FateData.Status == FateStatus.COMPLETE)
{
return true;
}
return FateData.Location.Distance2D(Core.Player.Location) <= FateData.HotSpot.Radius * 0.9;
},
new Action(obj => shouldMoveIntoFate = false));
composite0[3] = new Decorator(
obj => shouldMoveIntoFate,
CommonBehaviors.MoveAndStop(
obj => FateData.Location,
FateData != null ? FateData.HotSpot.Radius * 0.8f : 5f,
true,
"Moving back into fate radius"));
composite0[4] = new Decorator(
obj =>
{
var bc = obj as BattleCharacter;
if (Poi.Current.Type != PoiType.Kill || bc == null || !bc.IsValid
|| !bc.IsFate || !bc.IsAlive || bc.CanAttack
|| this.Withinfate || FateData == null || !FateData.IsValid)
{
return false;
}
return !bc.IsFateGone;
},
new Action(obj => shouldMoveIntoFate = true));
return new PrioritySelector(unit, composite0);
}
}
private Composite CreateSetFatePoi
{
get
{
return new HookExecutor(
"SetFatePoi",
"Handles deciding which fate to move towards.",
new PrioritySelector(new Decorator(
obj =>
{
if (FateData == null)
{
return false;
}
return FateData.IsValid;
},
new Action(obj => Poi.Current = new Poi(FateData, PoiType.Fate))),
new Decorator(
obj =>
{
if (FateData == null)
{
return true;
}
return !FateData.IsValid;
},
new ActionRunCoroutine(obj => ResolveFate()))));
}
}
private Composite CreateSetRestPoi
{
get
{
return new HookExecutor(
"SetRestPoi",
"Handles deciding which fate to move towards.",
new PrioritySelector(new Decorator(
obj =>
{
if (FateData != null)
{
return false;
}
return FatebotSettings.Instance.IdleAction != FateIdleAction.Nothing;
},
new ActionRunCoroutine(obj => HandleFateIdleAction()))));
}
}
public new void Dispose() { }
public override void Initialize() { }
public override void OnButtonPress()
{
if (this.settingsWindow == null || !this.settingsWindow.IsLoaded)
{
this.settingsWindow = new FateBotSettingsWindow();
}
this.settingsWindow.Show();
}
public new void Pulse() { }
public static void SetFate(FateData fate)
{
FateData = fate;
Poi.Current = new Poi(fate, PoiType.Fate);
}
public override void Start()
{
Navigator.PlayerMover = new SlideMover();
Navigator.NavigationProvider = new ServiceNavigationProvider();
GameSettingsManager.FaceTargetOnAction = true;
GameSettingsManager.FlightMode = true;
TreeHooks.Instance.ClearAll();
this.composite = BrainBehavior.CreateBrain();
CharacterSettings.Instance.AutoEquip = FatebotSettings.Instance.UseAutoEquip;
TreeHooks.Instance.ReplaceHook("SelectPoiType", this.SelectPoiType());
TreeHooks.Instance.AddHook("PoiAction", this.SetFatePoi());
TreeHooks.Instance.AddHook("PoiAction2", this.SetRestPoi());
TreeHooks.Instance.AddHook("TreeStart", this.BotLogic);
CombatTargeting.Instance.Provider = new ExFateCombatTargetingProvider(); // TODO Make new targeting
FateData = null;
}
public override void Stop()
{
CharacterSettings.Instance.AutoEquip = false;
CombatTargeting.Instance.Provider = new DefaultCombatTargetingProvider();
var navigationProvider = Navigator.NavigationProvider as ServiceNavigationProvider;
if (navigationProvider != null)
{
navigationProvider.Dispose();
}
Navigator.NavigationProvider = null;
}
public override string ToString()
{
return this.Name;
}
protected async Task<bool> Main()
{
return await Task.FromResult(true);
}
private async Task<bool> HandleFateIdleAction()
{
// TODO: Set idle action location (grind area, aethernet etc)
return await Task.FromResult(true);
}
private Composite SelectPoiType()
{
Composite[] hookExecutor =
{
new HookExecutor("SetDeathPoi"),
new HookExecutor("SetCombatPoi"), this.CreateSetFatePoi, this.CreateSetRestPoi
};
return new PrioritySelector(hookExecutor);
}
private Composite SetFatePoi()
{
return new HookExecutor(
"FatePoi",
"A hook location that executes fate logic.",
new Decorator(obj => Poi.Current.Type == PoiType.Fate, new PrioritySelector(new Decorator(
obj =>
{
if (FateData != null && !FateData.IsValid)
{
return true;
}
return FateData == null;
},
new Action(obj => Poi.Clear("Fate is no longer valid"))),
new Decorator(obj => !Core.Player.IsMounted && !this.Withinfate, CommonBehaviors.CreateMountBehavior()),
new Decorator(
obj =>
{
if (!Core.Player.IsMounted)
{
return true;
}
return this.Withinfate;
},
new HookExecutor("SetCombatPoi")),
CommonBehaviors.MoveAndStop(
obj => FateData.Location,
obj => FateData.Radius / 2f,
true,
"Moving to fate"))));
}
private Composite SetRestPoi()
{
return new HookExecutor(
"RestPoi",
"A hook location that executes downtime logic.",
new Decorator(obj => Poi.Current.Type == PoiType.Wait, new PrioritySelector(new Decorator(
obj =>
{
if (FateData == null)
{
return true;
}
return !FateData.IsValid;
},
new ActionRunCoroutine(obj => ResolveFate())),
new Decorator(
obj => FateData != null,
new Action(obj => Poi.Clear("Time for resting is over!"))),
new Decorator(
obj =>
{
if (!Core.Player.IsMounted)
{
return true;
}
return Poi.Current.Location.Distance(Core.Player.Location) <= 25f;
},
new HookExecutor("SetCombatPoi")),
new Decorator(
obj => Poi.Current.Location.Distance(Core.Player.Location) > 15f,
CommonBehaviors.CreateMountBehavior()),
new Decorator(
obj => Poi.Current.Location != Vector3.Zero,
new Action(obj => Navigator.MoveToPointWithin(Poi.Current.Location, 15f, "Moving to rest location"))))));
}
private async Task<bool> ResolveFate()
{
if (!FateTimer.IsRunning)
{
FateTimer.Restart();
}
if (FateTimer.ElapsedMilliseconds < 3000)
{
return await Task.FromResult(false);
}
FateTimer.Restart();
FateData fate;
var singleFate = FatebotSettings.Instance.ThisFateOnly;
if (!string.IsNullOrWhiteSpace(singleFate))
{
var listThisFateOnly = singleFate.Split(';')
.Select(f => f.Trim()).ToList();
fate =
FateManager.ActiveFates.FirstOrDefault(
f => listThisFateOnly.Any(tfo => tfo.ToLower().Contains(f.Name.ToLower())));
if (fate == null)
{
return await Task.FromResult(false);
}
FateData = fate;
return await Task.FromResult(true);
}
fate = FateScoreProvider.GetObjectsByWeight(FateManager.ActiveFates).FirstOrDefault(ShouldSelectFate);
if (fate == null)
{
return await Task.FromResult(false);
}
FateData = fate;
return await Task.FromResult(true);
}
private bool ShouldSelectFate(FateData fatedata)
{
if (Blacklist.Contains(fatedata.Id, BlacklistFlags.Node))
{
if (FatebotSettings.Instance.VerboseLogging)
{
Logging.WriteVerbose(
"{0} - Blacklist.Contains(fate.Id, BlacklistFlags.Node) - We couldn't find a path most likely",
fatedata.Name);
}
return false;
}
var instance = FatebotSettings.Instance;
if (instance.LevelCheck
&& (fatedata.Level < instance.MinLevel || Core.Player.ClassLevel + instance.MaxLevel < fatedata.Level))
{
if (FatebotSettings.Instance.VerboseLogging)
{
object[] name = { fatedata.Name, null };
name[1] = (fatedata.Level < instance.MinLevel
? "fate.Level < settings.MinLevel"
: "(Core.Player.ClassLevel + settings.MaxLevel) < fate.Level");
Logging.WriteVerbose("{0} {1}", name);
}
return false;
}
var icon = fatedata.Icon;
if (!this.fateIconType.Contains(icon))
{
if (FatebotSettings.Instance.VerboseLogging)
{
object[] objArray = { fatedata.Name, fatedata.Icon };
Logging.WriteVerbose("{0} - {1} - !_goodFates.Contains(fateIconType)", objArray);
}
return false;
}
if (instance.BlackListedFates.Contains(fatedata.Name))
{
if (FatebotSettings.Instance.VerboseLogging)
{
Logging.WriteVerbose("{0} - settings.BlackListedFates.Contains(fate.Name)", fatedata.Name);
}
return false;
}
if (icon == FateIconType.Boss)
{
if (!instance.BossEnabled)
{
return false;
}
if (FatebotSettings.Instance.IgnorePercentageFates.Contains(fatedata.Id))
{
return true;
}
if (fatedata.Progress < instance.BossPercentRequired)
{
if (FatebotSettings.Instance.VerboseLogging)
{
Logging.WriteVerbose("{0} - fate.Progress < settings.BossPercentRequired", fatedata.Name);
}
return false;
}
}
if (icon != FateIconType.Battle || instance.MonsterSlayingEnabled)
{
if (icon == FateIconType.ProtectNPC2 && !instance.EscortEnabled)
{
return false;
}
return true;
}
if (FatebotSettings.Instance.VerboseLogging)
{
Logging.WriteVerbose("{0} - fateIconType == FateIconType.Battle && !settings.MonsterSlayingEnabled", fatedata.Name);
}
return false;
}
}
}