forked from LlamaMagic/RBtrust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrustPlugin.cs
164 lines (133 loc) · 3.64 KB
/
TrustPlugin.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
using Buddy.Coroutines;
using ff14bot;
using ff14bot.AClasses;
using ff14bot.Behavior;
using ff14bot.Managers;
using ff14bot.NeoProfiles;
using ff14bot.Settings;
using System;
using System.Linq;
using System.Threading.Tasks;
using TreeSharp;
using Trust.Helpers;
using Trust.Localization;
using Trust.Logging;
using Trust.Managers;
namespace Trust;
/// <summary>
/// Main RebornBuddy plugin class for RB Trust.
/// </summary>
public class TrustPlugin : BotPlugin
{
private Composite root;
private DungeonManager dungeonManager;
/// <inheritdoc/>
public override string Author => "athlon";
/// <inheritdoc/>
public override string Name => Translations.PROJECT_NAME;
/// <inheritdoc/>
public override Version Version => new(1, 2, 0);
/// <inheritdoc/>
public override bool WantButton => false;
/// <inheritdoc/>
public override void OnInitialize()
{
PluginContainer plugin = PluginHelpers.GetSideStepPlugin();
if (plugin != null)
{
plugin.Enabled = true;
}
root = new Decorator(c => CanTrust(), new ActionRunCoroutine(r => RunTrust()));
}
/// <inheritdoc/>
public override void OnEnabled()
{
TreeRoot.OnStart += OnBotStart;
TreeRoot.OnStop += OnBotStop;
TreeHooks.Instance.OnHooksCleared += OnHooksCleared;
if (TreeRoot.IsRunning)
{
AddHooks();
}
dungeonManager = new DungeonManager();
}
/// <inheritdoc/>
public override void OnDisabled()
{
TreeRoot.OnStart -= OnBotStart;
TreeRoot.OnStop -= OnBotStop;
RemoveHooks();
}
/// <inheritdoc/>
public override void OnShutdown()
{
OnDisabled();
}
/// <inheritdoc/>
public override void OnButtonPress()
{
base.OnButtonPress();
}
private void AddHooks()
{
Logger.Information("Adding Trust Hook");
TreeHooks.Instance.AddHook("TreeStart", root);
}
private void RemoveHooks()
{
Logger.Information("Removing Trust Hook");
TreeHooks.Instance.RemoveHook("TreeStart", root);
}
private void OnBotStop(BotBase bot)
{
RemoveHooks();
}
private void OnBotStart(BotBase bot)
{
AddHooks();
}
private void OnHooksCleared(object sender, EventArgs e)
{
RemoveHooks();
}
private bool CanTrust()
{
return LoadingHelpers.IsInInstance;
}
private async Task<bool> RunTrust()
{
if (await TryRespawnPlayerAsync())
{
return true;
}
await MovementHelpers.TryIncreaseMovementSpeedAsync();
// LoggingHelpers.LogAllSpellCasts();
LoggingHelpers.LogZoneChanges();
return await dungeonManager.RunAsync();
}
private async Task<bool> TryRespawnPlayerAsync()
{
if (Core.Player.IsAlive)
{
return false;
}
if (!PartyManager.AllMembers.Any(pm => pm is TrustPartyMember))
{
return false;
}
Logger.Information(Translations.PLAYER_DIED_RELOADING_PROFILE);
const int maxRespawnTime = 60_000;
bool respawnedInReasonableTime = await Coroutine.Wait(maxRespawnTime, () => Core.Player.IsAlive);
await LoadingHelpers.WaitForLoadingAsync();
if (respawnedInReasonableTime)
{
NeoProfileManager.Load(CharacterSettings.Instance.LastNeoProfile, true);
NeoProfileManager.UpdateCurrentProfileBehavior();
}
else
{
Logger.Error(Translations.PLAYER_FAILED_TO_RESPAWN, maxRespawnTime);
}
return true;
}
}