This repository has been archived by the owner on Mar 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OsirisPlugin.cs
454 lines (396 loc) · 17.4 KB
/
OsirisPlugin.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Media;
using Buddy.Coroutines;
using ff14bot;
using ff14bot.AClasses;
using ff14bot.Behavior;
using ff14bot.Enums;
using ff14bot.Helpers;
using ff14bot.Managers;
using ff14bot.Navigation;
using ff14bot.NeoProfiles;
using ff14bot.Objects;
using ff14bot.RemoteWindows;
using TreeSharp;
namespace OsirisPlugin
{
public class OsirisPlugin : BotPlugin
{
private static readonly string name = "Osiris";
private static string[] Shouts = new string[]
{
"/shout Raise please at <pos>.",
"/shout Could I please get a raise at <pos>.",
"/shout Ugh, dead again, anyone available at <pos>.",
"/shout Dead body at <pos>, can anyone help.",
"/shout Code 187 found in crater at <pos> suspect fled the scene described as red feathered and yelling 'Wark'",
"/shout Sprout asks me what happened when HP hits zero. Well, I demonstrated it and need assistance at <pos>",
"/shout Anyone have a Mettle Detector? I seem to have lost some of mine at <pos> and need help",
"/shout Nike and Martha Stewart worked me too hard at the sweatshop today and I finally fell over. Can someone give me a boost at <pos>",
"/shout Well this is embarrassing , raise please <pos>."
};
private static readonly Random _random = new Random();
private Composite deathCoroutine;
private Composite RaisePeople;
private Composite FakeDeath;
private OsirisSettingsForm _form;
public override string Author { get; } = "Kayla, DomesticWarlord86";
private static Dictionary<ClassJobType, uint> RezSpells = new Dictionary<ClassJobType, uint>()
{
{ClassJobType.WhiteMage, 125},
{ClassJobType.Astrologian, 3603},
{ClassJobType.Scholar, 173},
{ClassJobType.Summoner, 173},
{ClassJobType.RedMage, 7523},
{ClassJobType.Sage, 24287}
};
public override Version Version => new Version(0, 1);
public override string Name { get; } = name;
public override bool WantButton => true;
public override void OnButtonPress()
{
if (_form == null)
{
_form = new OsirisSettingsForm()
{
Text = "Osiris Settings v" + Version,
};
_form.Closed += (o, e) => { _form = null; };
}
try
{
_form.Show();
}
catch (Exception e)
{
// ignored
}
}
public override void OnInitialize()
{
deathCoroutine = new ActionRunCoroutine(ctx => HandleDeath());
RaisePeople = new ActionRunCoroutine(ctx => RaisePeopleTask());
FakeDeath = new ActionRunCoroutine(ctx => HandleFakeDeath());
}
public override void OnEnabled()
{
TreeRoot.OnStart += setHooks;
}
private void setHooks(BotBase bot)
{
Log("Setting Hooks");
TreeHooks.Instance.AddHook("DeathReviveLogic", deathCoroutine);
TreeHooks.Instance.AddHook("TreeStart", RaisePeople);
TreeHooks.Instance.AddHook("TreeStart", FakeDeath);
}
public override void OnDisabled()
{
TreeRoot.OnStart -= setHooks;
}
private bool IsInBozjaOrEureka()
{
return WorldManager.ZoneId == 975 || WorldManager.ZoneId == 920 || WorldManager.ZoneId == 732 ||
WorldManager.ZoneId == 763 || WorldManager.ZoneId == 795 || WorldManager.ZoneId == 827;
}
private bool HasRezzerInParty()
{
return PartyManager.AllMembers.Any(i => i.BattleCharacter.CurrentJob is ClassJobType.WhiteMage or
ClassJobType.Scholar or ClassJobType.Summoner or
ClassJobType.RedMage or ClassJobType.Astrologian or
ClassJobType.Sage or ClassJobType.Arcanist or ClassJobType.Conjurer
&& !i.IsMe && i.BattleCharacter.IsAlive);
}
private bool AnyPartyMemberAlive()
{
return PartyManager.AllMembers.Any(i => i.BattleCharacter.IsAlive);
}
internal async Task<bool> HandleFakeDeath()
{
if (Core.Me.CurrentHealth >= 1 || !(DutyManager.InInstance && !PartyManager.IsInParty) || !(DutyManager.InInstance && PartyManager.AllMembers.Any(i=> i.GetType() == typeof(TrustPartyMember)))) return false;
if (Core.Me.CurrentHealth == 0)
{
Log($"Catching fake death. Waiting to be alive.");
await Coroutine.Wait(-1, () => (Core.Me.IsAlive));
Log($"We are alive, loading profile...");
NeoProfileManager.Load(NeoProfileManager.CurrentProfile.Path);
NeoProfileManager.UpdateCurrentProfileBehavior();
await Coroutine.Sleep(5000);
}
return false;
}
internal async Task<bool> RaisePeopleTask()
{
if (Core.Me.InCombat || !Core.Me.IsAlive || DutyManager.InInstance || FateManager.WithinFate) return false;
// Cast Raise on nearby people.
if (!DutyManager.InInstance && RezSpells.ContainsKey(Core.Me.CurrentJob) && OsirisSettings.Instance.Raise)
{
var deadPeople = GameObjectManager.GetObjectsOfType<BattleCharacter>().Where(p =>
!p.IsNpc && !p.HasAura(148) && !p.IsAlive && Core.Me.Distance(p) < 50 && !p.IsMe).ToList();
if (deadPeople.Any())
{
foreach (var partyMember in deadPeople.Where(partyMember => Core.Me.Distance(partyMember) < 30))
{
if (partyMember.Distance2D(Core.Me.Location) >= 30)
{
Log($"Moving to person to raise.");
var _target = partyMember.Location;
Navigator.PlayerMover.MoveTowards(_target);
while (_target.Distance2D(Core.Me.Location) >= 30)
{
Navigator.PlayerMover.MoveTowards(_target);
await Coroutine.Sleep(100);
}
Navigator.PlayerMover.MoveStop();
}
await Resurrect(partyMember);
}
}
}
return false;
}
private async Task<bool> HandleDeath()
{
var currentZone = WorldManager.CurrentZoneName;
// Check if loading in the case of instant release like Squadron dungeons
if (CommonBehaviors.IsLoading)
{
Log($"Waiting to be alive.");
await Coroutine.Wait(-1, () => (Core.Me.IsAlive));
}
//Logic for Bozja and Eureka
if (IsInBozjaOrEureka())
{
Log($"Handling Death For {currentZone}");
await HandleDeathInBozjaAndEureka();
}
// Logic for NPC parties
if (PartyManager.AllMembers.Any(i=> i.GetType() == typeof(TrustPartyMember)))
{
Log($"In a NPC party. Waiting for zone.");
await Coroutine.Wait(-1, () => (Core.Me.IsAlive));
}
//Logic for In Duty
if (DutyManager.InInstance && !IsInBozjaOrEureka() && !PartyManager.AllMembers.Any(i=> i.GetType() == typeof(TrustPartyMember)))
{
await HandleDeathInInstance();
}
//Logic for not in a party
if (PartyManager.IsInParty && !IsInBozjaOrEureka() && !DutyManager.InInstance)
{
if (HasRezzerInParty())
{
Log($"We died in {currentZone}. We have a Raiser.");
await WaitForLife();
}
else
{
if (OsirisSettings.Instance.ReleaseWait)
{
Log($"We died in {currentZone}. Wait for release checked.");
await WaitForLife();
}
else
{
Log($"We died in {currentZone} with no Raiser in party.");
await Release();
}
}
}
//Logic for everything else
if (!PartyManager.IsInParty && !IsInBozjaOrEureka() && !DutyManager.InInstance)
{
if (OsirisSettings.Instance.ReleaseWait)
{
await WaitForLife();
}
else
{
await Release();
}
}
Log($"We are alive, loading profile...");
NeoProfileManager.Load(NeoProfileManager.CurrentProfile.Path);
NeoProfileManager.UpdateCurrentProfileBehavior();
await Coroutine.Sleep(5000);
return true;
}
private async Task HandleDeathInBozjaAndEureka()
{
await Coroutine.Wait(3000, () => ClientGameUiRevive.ReviveState == ReviveState.Dead);
if (!PartyManager.IsInParty)
{
if (OsirisSettings.Instance.RaiseShout)
{
while (!Core.Me.HasAura(148) && Core.Me.CurrentHealth < 1)
{
Log("Shout for raise selected, shouting...");
ChatManager.SendChat(Shouts[_random.Next(0, Shouts.Length)]);
await Coroutine.Wait(OsirisSettings.Instance.ShoutTime * 60 * 1000, () => Core.Me.HasAura(148) || Core.Me.CurrentHealth > 1);
if (Core.Me.HasAura(148))
{
await AcceptRaise();
break;
}
if (Core.Me.CurrentHealth > 1)
{
break;
}
}
}
else
{
if (OsirisSettings.Instance.ReleaseWait)
{
await WaitForLife();
}
else
{
Log("Releasing in Bozja, gonna loose some mettle here.");
await Release();
}
}
}
// If is in party
else
{
if (OsirisSettings.Instance.ReleaseWait)
{
if (HasRezzerInParty())
{
Log("In a party with a rezzer, waiting for party member to raise us.");
await WaitForLife();
}
else
{
if (OsirisSettings.Instance.RaiseShout)
{
while (!Core.Me.HasAura(148) && Core.Me.CurrentHealth < 1)
{
Log("In a party with no rezzer. Shout for raise selected, shouting...");
ChatManager.SendChat(Shouts[_random.Next(0, Shouts.Length)]);
await Coroutine.Wait(OsirisSettings.Instance.ShoutTime * 60 * 1000, () => Core.Me.HasAura(148) || Core.Me.CurrentHealth > 1);
if (Core.Me.HasAura(148))
{
await AcceptRaise();
break;
}
if (Core.Me.CurrentHealth > 1)
{
break;
}
}
}
else
{
if (OsirisSettings.Instance.ReleaseWait)
{
Log("In party, with no rezzer but ReleaseWait is checked. Waiting for rez.");
await WaitForLife();
}
else
{
Log("In a party without a Rezzer. Releasing in Bozja, gonna loose some mettle here.");
await Release();
}
}
}
}
}
if (NotificationRevive.IsOpen)
{
await AcceptRaise();
}
}
private async Task HandleDeathInInstance()
{
if (PartyManager.AllMembers.Any(i => i.BattleCharacter.InCombat) && AnyPartyMemberAlive())
{
Log("Party memebers in combat, waiting for Raise.");
await Coroutine.Wait(3000, () => ClientGameUiRevive.ReviveState == ReviveState.Dead);
await Coroutine.Wait(-1, () => Core.Me.HasAura(148) || !PartyManager.AllMembers.Any(i => i.BattleCharacter.InCombat) && AnyPartyMemberAlive());
await Coroutine.Sleep(500);
if (Core.Me.HasAura(148))
{
await AcceptRaise();
return;
}
}
await Release();
}
private async Task Release()
{
Log($"Releasing.");
await Coroutine.Wait(-1, () => (SelectYesno.IsOpen));
SelectYesno.ClickYes();
await Coroutine.Wait(-1, () => (CommonBehaviors.IsLoading));
while (CommonBehaviors.IsLoading)
{
Log($"Waiting for zoning to finish...");
await Coroutine.Wait(-1, () => (!CommonBehaviors.IsLoading));
}
while (!Core.Me.IsAlive)
{
Log($"Zoning finsihed, waiting to become alive...");
await Coroutine.Wait(-1, () => (Core.Me.IsAlive));
}
}
private async Task AcceptRaise()
{
Log($"We have Raise Aura.");
Log($"Clicking Accept");
await Coroutine.Sleep(500);
ClientGameUiRevive.Revive();
await Coroutine.Wait(-1, () => (CommonBehaviors.IsLoading));
Log($"Waiting for loading to finish...");
await Coroutine.Wait(-1, () => (Core.Me.IsAlive));
if (OsirisSettings.Instance.ThankYouSir)
{
ChatManager.SendChat("/say Thanks for the raise.");
}
await Coroutine.Wait(15000, () => ClientGameUiRevive.ReviveState == ReviveState.None);
Poi.Clear("We live!");
}
private async Task WaitForLife()
{
Log("Waiting for raise or auto Starting Point.");
await Coroutine.Wait(-1, () => Core.Me.HasAura(148) || Core.Me.CurrentHealth > 1);
if (Core.Me.HasAura(148))
{
await AcceptRaise();
}
}
internal async Task Resurrect(BattleCharacter partyMember)
{
if (!RezSpells.ContainsKey(Core.Me.CurrentJob)) return;
var spell = ActionManager.CurrentActions[RezSpells[Core.Me.CurrentJob]];
if (!ActionManager.ActionReady(ActionType.Spell, spell.Id)) return;
if (Core.Me.IsMounted)
{
ActionManager.Dismount();
await Coroutine.Wait(10000, () => !Core.Me.IsMounted);
}
Log(($"Casting {spell.LocalizedName} on {partyMember.Name}"));
if (ActionManager.ActionReady(ActionType.Spell, 7561))
{
ActionManager.DoAction(7561, Core.Me);
await Coroutine.Sleep(500);
ActionManager.DoAction(spell, partyMember);
await Coroutine.Sleep(1000);
}
else
{
ActionManager.DoAction(spell, partyMember);
await Coroutine.Wait(10000, () => Core.Me.IsCasting);
await Coroutine.Wait(10000, () => !Core.Me.IsCasting);
}
}
private static void Log(string text)
{
var msg = string.Format($"[{name}] " + text);
Logging.Write(Colors.Bisque, msg);
}
}
}