This repository was archived by the owner on Jan 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathGatherTest.cs
More file actions
538 lines (447 loc) · 19.7 KB
/
GatherTest.cs
File metadata and controls
538 lines (447 loc) · 19.7 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Media;
using Buddy.Coroutines;
using Clio.Utilities;
using Clio.Utilities.Helpers;
using ff14bot;
using ff14bot.AClasses;
using ff14bot.Behavior;
using ff14bot.Enums;
using ff14bot.Helpers;
using ff14bot.Managers;
using ff14bot.Navigation;
using ff14bot.Objects;
using ff14bot.Pathing;
using ff14bot.Pathing.Service_Navigation;
using ff14bot.RemoteWindows;
using LlamaLibrary.Extensions;
using LlamaLibrary.Helpers;
using LlamaLibrary.Memory;
using TreeSharp;
namespace LlamaLibrary
{
public class GatherTest : BotBase
{
// public static InstanceContentDirector Director => DirectorManager.ActiveDirector as InstanceContentDirector;
public int TimerOffset;
public TimeSpan TimeLeftInDiadem => TimeSpan.FromSeconds(Core.Memory.Read<float>(DirectorManager.ActiveDirector.Pointer + TimerOffset)); //640
//Wind new Vector3(greenf), BTN
private static readonly Vector3[] umbralTempest =
{
new Vector3(-580.9533f, 330.8294f, 458.0585f),
new Vector3(-608.1638f, 329.7346f, 456.2433f),
new Vector3(-606.6253f, 331.0921f, 427.3463f),
new Vector3(-579.6904f, 329.4015f, 424.7657f)
};
//Red Flare Mining
private static readonly Vector3[] umbralFlare =
{
new Vector3(-430.0615f, 320.2874f, -572.0226f),
new Vector3(-453.1085f, 320.7165f, -594.9066f),
new Vector3(-431.1396f, 320.0077f, -609.3666f),
new Vector3(-408.5051f, 319.256f, -594.2559f)
};
//Purple Mining Levin
private static readonly Vector3[] umbralLevin =
{
new Vector3(619.6818f, 251.9896f, -423.0514f),
new Vector3(613.7454f, 251.9896f, -396.2267f),
new Vector3(644.903f, 251.9896f, -403.8661f),
new Vector3(635.2657f, 252.35f, -420.4232f)
};
//ORange btn
private static readonly Vector3[] umbralDuststorm =
{
new Vector3(408.5911f, 293.0109f, 604.5204f),
new Vector3(409.6448f, 293.4354f, 568.1148f),
new Vector3(379.7924f, 292.971f, 569.1271f)
};
private static readonly Vector3[] afkSpots2 =
{
new Vector3(60.57302f, 246.5133f, -290.3074f),
new Vector3(168.4951f, 170.8651f, 72.97058f),
new Vector3(-9.105042f, 158.3274f, 129.1192f)
};
private static readonly Vector3[] afkSpots =
{
//-182.1712, 0.8445628, -298.0846
new Vector3(-182.1712f, 0.8445628f, -298.0846f),
new Vector3(214.7894f, -144.3608f, -267.1053f),
new Vector3(318.1068f, -4.934579f, 408.4625f)
};
//Above orange
private static readonly Vector3 umbralDuststormAbove = new Vector3(409.9393f, 314.985f, 560.1671f);
//above green
private static readonly Vector3 umbralTempestAbove = new Vector3(-578.7819f, 349.9304f, 462.1082f);
//above purple
private static readonly Vector3 umbralLevinAbove = new Vector3(602.6203f, 276.4863f, -394.3397f);
//above red
private static readonly Vector3 umbralFlareAbove = new Vector3(-396.0904f, 340.3934f, -557.02f);
//above start
private static readonly Vector3 startAbove = new Vector3(-645.4365f, 300.4301f, -151.262f);
private static Vector3 standBy = new Vector3(-164.3966f, -1.072426f, -302.2528f);
private static int[] weatherNodes = new[] {33229, 33230, 33231, 33232,33584, 33585, 33586, 33587, 33836, 33837,33838,33839};
private static int lastWeather = 0;
private static WaitTimer lastChange;
private Composite _root;
public GatherTest()
{
if (Translator.Language == Language.Chn)
{
TimerOffset = 0x6F0;//0x650
}
else
{
TimerOffset = 0x6F0;
}
}
public override string Name => "DiademGather";
public override PulseFlags PulseFlags => PulseFlags.All;
public override bool IsAutonomous => true;
public override bool RequiresProfile => false;
public override Composite Root => _root;
public override bool WantButton { get; } = false;
public override void Start()
{
lastWeather = 0;
_root = new ActionRunCoroutine(r => Run());
}
public override void Stop()
{
lastWeather = 0;
_root = null;
}
private async Task<bool> Run()
{
//await LeveWindow(1018997);
//await HousingWards();
Navigator.PlayerMover = new SlideMover();
Navigator.NavigationProvider = new ServiceNavigationProvider();
await GatherWeatherNodes();
//Navigator.PlayerMover = new SlideMover();
//Navigator.NavigationProvider = new ServiceNavigationProvider();
//TreeRoot.Stop("Stop Requested");
return true;
}
public async Task GatherWeatherNodes()
{
if (WorldManager.RawZoneId != 901)
{
await EnterDiadem();
Log($"Waiting for instance time");
await Coroutine.Wait(5000, () => TimeLeftInDiadem.TotalMinutes > 1);
Log($"Time left {TimeLeftInDiadem:hh\\:mm\\:ss}");
}
lastChange = new WaitTimer(new TimeSpan(0,7,0));
Log($"Current Weather: {WorldManager.CurrentWeather} {WorldManager.CurrentWeatherId}");
Random time = new Random();
int minutes = time.Next(10, 20);
int sec = time.Next(0, 59);
standBy = afkSpots[time.Next(0, afkSpots.Length)];
while (TimeLeftInDiadem > new TimeSpan(0,minutes,sec))
{
switch (WorldManager.CurrentWeatherId)
{
case 133:
if (lastWeather == 133) break;
//await FlyTo(new Vector3(-295.9257f, 268.4518f, -370.327f));
await MineWeather(ClassJobType.Miner, umbralFlareAbove, umbralFlare);
standBy = afkSpots[time.Next(0, afkSpots.Length)];
await StandBy();
break;
case 135: if (lastWeather == 135) break; await MineWeather(ClassJobType.Miner, umbralLevinAbove, umbralLevin);
standBy = afkSpots[time.Next(0, afkSpots.Length)];
await StandBy();
break;
case 134: if (lastWeather == 134) break; await MineWeather(ClassJobType.Botanist, umbralDuststormAbove, umbralDuststorm);
standBy = afkSpots[time.Next(0, afkSpots.Length)];
await StandBy();
break;
case 136: if (lastWeather == 136) break; await MineWeather(ClassJobType.Botanist, umbralTempestAbove, umbralTempest);
standBy = afkSpots[time.Next(0, afkSpots.Length)];
await StandBy();
break;
default: await Coroutine.Sleep(3000);
if (lastChange.IsFinished)
{
lastChange.Reset();
lastWeather = 0;
}
/*Log($"New instance: {TimeLeftInDiadem:hh\\:mm\\:ss} Left");
DutyManager.LeaveActiveDuty();
if (await Coroutine.Wait(30000, () => CommonBehaviors.IsLoading))
{
await Coroutine.Yield();
await Coroutine.Wait(Timeout.Infinite, () => !CommonBehaviors.IsLoading);
await Coroutine.Sleep(30000);
return;
} break;
//*/
await StandBy(); break;
}
await Coroutine.Sleep(1000);
}
if (DutyManager.InInstance)
{
Log($"Out of time: {TimeLeftInDiadem:hh\\:mm\\:ss} Left");
DutyManager.LeaveActiveDuty();
if (await Coroutine.Wait(30000, () => CommonBehaviors.IsLoading))
{
await Coroutine.Yield();
await Coroutine.Wait(Timeout.Infinite, () => !CommonBehaviors.IsLoading);
await Coroutine.Sleep(10000);
}
}
}
public async Task UseCordial()
{
if (Core.Me.CurrentGP < 500)
{
await Coroutine.Sleep(2000);
var cordial = InventoryManager.FilledSlots.FirstOrDefault(i => i.RawItemId == 12669);
if (cordial != default(BagSlot))
{
cordial.UseItem();
await Coroutine.Sleep(2000);
}
}
}
public void GetNodes()
{
foreach (var node in NodeList)
{
if (weatherNodes.Contains(node.Base()))
Log($"Weather Node Found: {node.Name} ({node.EnglishName}) Base: {node.Base()} Visible: {node.CanGather}");
else
{
Log($"Node Found: {node.Name} ({node.EnglishName}) Base: {node.Base()} Visible {node.CanGather}");
}
}
}
public async Task StandBy()
{
if (Core.Me.DistanceSqr(standBy) > 10f)
await FlyTo(standBy);
}
public async Task MineWeather(ClassJobType jobType, Vector3 above, Vector3[] safeSpots)
{
lastWeather = WorldManager.CurrentWeatherId;
lastChange.Reset();
await SwitchToJob(jobType);
//await FlyTo(above);
var safeSpot = safeSpots.ToList().OrderBy(i => i.DistanceSqr(Core.Me.Location)).First();
await FlyTo(safeSpot);
Log("Near Node Location");
Log($"Current Weather: {WorldManager.CurrentWeather} {WorldManager.CurrentWeatherId}");
GetNodes();
var node = WeatherNodeList.FirstOrDefault();
if (node != null)
{
//safeSpot = safeSpots.ToList().OrderBy(i => i.DistanceSqr(node.Location)).First();
//Log("Node Found");
await FlyTo(node.Location);
/*if (MovementManager.IsFlying)
{
MovementManager.StartDescending();
await Coroutine.Wait(2000, () => !MovementManager.IsFlying);
MovementManager.StopDescending();
}*/
var _target = node.Location;
Navigator.PlayerMover.MoveTowards(_target);
while (_target.Distance2DSqr(Core.Me.Location) >= 3)
{
Navigator.PlayerMover.MoveTowards(_target);
await Coroutine.Sleep(100);
}
Navigator.PlayerMover.MoveStop();
if (Core.Player.IsMounted)
{
ActionManager.Dismount();
await Coroutine.Sleep(2000);
}
//await UseCordial();
node = WeatherNodeList.FirstOrDefault();
node.Interact();
await Coroutine.Sleep(200);
await Coroutine.Wait(2000, () => GatheringManager.WindowOpen);
await Coroutine.Sleep(500);
if (Core.Me.CurrentJob == ClassJobType.Miner)
await testMine();
else if (Core.Me.CurrentJob == ClassJobType.Botanist)
await testBtn();
//await UseCordial();
Log("Done Test Gather");
/*DutyManager.LeaveActiveDuty();
if (await Coroutine.Wait(30000, () => CommonBehaviors.IsLoading))
{
await Coroutine.Yield();
await Coroutine.Wait(Timeout.Infinite, () => !CommonBehaviors.IsLoading);
await Coroutine.Sleep(10000);
}*/
}
}
public static async Task SwitchToJob(ClassJobType job)
{
if (Core.Me.CurrentJob == job) return;
var gearSets = GearsetManager.GearSets.Where(i => i.InUse);
if (gearSets.Any(gs => gs.Class == job))
{
Logging.Write(Colors.Fuchsia, $"[ChangeJob] Found GearSet");
gearSets.First(gs => gs.Class == job).Activate();
await Coroutine.Sleep(1000);
}
}
public static List<GatheringPointObject> NodeList => GameObjectManager.GetObjectsOfType<GatheringPointObject>().OrderBy(r=>r.Distance()).ToList();
public static List<GatheringPointObject> WeatherNodeList => GameObjectManager.GetObjectsOfType<GatheringPointObject>().Where(i => weatherNodes.Contains(i.Base()) && i.IsVisible).OrderBy(r=>r.Distance()).ToList();
public async Task testGather()
{
var GatherLock = Core.Memory.Read<uint>(Offsets.Conditions + 0x2A);
Log("in Test Gather");
if (GatheringManager.WindowOpen)
{
GatheringItem items = GatheringManager.GatheringWindowItems.FirstOrDefault(i => i.IsFilled && i.CanGather);
Log($"Gathering: {items}");
while (GatheringManager.SwingsRemaining > 0)
{
items.GatherItem();
await Coroutine.Wait(20000, () => Core.Memory.Read<uint>(Offsets.Conditions + 0x2A) != 0);
await Coroutine.Wait(20000, () => Core.Memory.Read<uint>(Offsets.Conditions + 0x2A) == 0);
}
}
}
public async Task testMine()
{
//Log("in Test Gather");
if (GatheringManager.WindowOpen)
{
GatheringItem items = GatheringManager.GatheringWindowItems.Where(i => i.IsFilled && i.CanGather).OrderByDescending(s => s.Stars).FirstOrDefault();
if (Core.Me.CurrentGP >= 500)
{
await Coroutine.Wait(5000, () => ActionManager.CanCast(241, Core.Me));
ActionManager.DoAction(241, Core.Me);
await Coroutine.Sleep(2500);
}
/*
if (Core.Me.CurrentGP >= 250)
{
await Coroutine.Wait(5000, () => ActionManager.CanCast(4587, Core.Me));
ActionManager.DoAction(4587, Core.Me);
await Coroutine.Sleep(2500);
}
*/
Log($"Gathering: {items}");
while (GatheringManager.SwingsRemaining > 0 && GatheringManager.WindowOpen)
{
if (Core.Me.CurrentGP >= 100)
{
await Coroutine.Wait(5000, () => ActionManager.CanCast(272, Core.Me));
ActionManager.DoAction(272, Core.Me);
await Coroutine.Sleep(2500);
}
await Coroutine.Wait(20000, () => Core.Memory.Read<uint>(Offsets.Conditions + 0x2A) == 0);
items?.GatherItem();
await Coroutine.Wait(20000, () => Core.Memory.Read<uint>(Offsets.Conditions + 0x2A) != 0);
await Coroutine.Wait(20000, () => Core.Memory.Read<uint>(Offsets.Conditions + 0x2A) == 0);
}
}
}
public async Task testBtn()
{
//Log("in Test Gather");
if (GatheringManager.WindowOpen)
{
GatheringItem items = GatheringManager.GatheringWindowItems.Where(i => i.IsFilled && i.CanGather).OrderByDescending(s => s.Stars).FirstOrDefault();
if (Core.Me.CurrentGP >= 500)
{
await Coroutine.Wait(5000, () => ActionManager.CanCast(224, Core.Me));
ActionManager.DoAction(224, Core.Me);
await Coroutine.Sleep(2500);
}
/*
if (Core.Me.CurrentGP >= 250)
{
await Coroutine.Wait(5000, () => ActionManager.CanCast(4588, Core.Me));
ActionManager.DoAction(4588, Core.Me);
await Coroutine.Sleep(2500);
}
*/
Log($"Gathering: {items}");
while (GatheringManager.SwingsRemaining > 0)
{
if (Core.Me.CurrentGP >= 100)
{
await Coroutine.Wait(5000, () => ActionManager.CanCast(273, Core.Me));
ActionManager.DoAction(273, Core.Me);
await Coroutine.Sleep(2500);
}
await Coroutine.Wait(20000, () => Core.Memory.Read<uint>(Offsets.Conditions + 0x2A) == 0);
items?.GatherItem();
await Coroutine.Wait(20000, () => Core.Memory.Read<uint>(Offsets.Conditions + 0x2A) != 0);
await Coroutine.Wait(20000, () => Core.Memory.Read<uint>(Offsets.Conditions + 0x2A) == 0);
}
}
}
private void Log(string text, params object[] args)
{
var msg = string.Format("[" + Name + "] " + text, args);
Logging.Write(Colors.Pink, msg);
}
private static async Task EnterDiadem()
{
await Navigation.GetTo(886, new Vector3(-17.82406f, -16f, 141.3146f));
var Aurvael = GameObjectManager.GetObjectByNPCId(1031694);
if (Aurvael != null)
{
Aurvael.Interact();
if (await Coroutine.Wait(3000, () => Talk.DialogOpen))
{
Talk.Next();
}
await Coroutine.Wait(3000, () => SelectString.IsOpen);
if (SelectString.IsOpen)
{
SelectString.ClickSlot(0);
await Coroutine.Wait(3000, () => SelectYesno.IsOpen);
SelectYesno.Yes();
await Coroutine.Wait(30000, () => ContentsFinderConfirm.IsOpen);
await Coroutine.Yield();
while (ContentsFinderConfirm.IsOpen)
{
DutyManager.Commence();
await Coroutine.Yield();
if (await Coroutine.Wait(30000, () => CommonBehaviors.IsLoading))
{
await Coroutine.Yield();
await Coroutine.Wait(Timeout.Infinite, () => !CommonBehaviors.IsLoading);
}
}
await Coroutine.Sleep(2500);
}
}
}
internal static async Task<bool> FlyTo2(Vector3 loc)
{
var moving = MoveResult.GeneratingPath;
while (!(moving == MoveResult.Done ||
moving == MoveResult.ReachedDestination ||
moving == MoveResult.Failed ||
moving == MoveResult.Failure ||
moving == MoveResult.PathGenerationFailed))
{
moving = Flightor.MoveTo(loc, 100f,false);
await Coroutine.Yield();
}
Flightor.Clear();
MovementManager.MoveStop();
return true;
}
internal static async Task<bool> FlyTo(Vector3 loc)
{
return await Lisbeth.TravelTo("The Diadem", loc);
}
}
}