-
Notifications
You must be signed in to change notification settings - Fork 0
/
FateAutoLeveler.cs
221 lines (182 loc) · 6.37 KB
/
FateAutoLeveler.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
using System;
using System.Threading.Tasks;
using ff14bot;
using ff14bot.Behavior;
using ff14bot.Helpers;
using ff14bot.Interfaces;
using ff14bot.Managers;
using ff14bot.RemoteWindows;
using Buddy.Coroutines;
using System.Windows.Media;
using TreeSharp;
namespace FateAutoLeveler
{
public class FateAutoLeveler : IBotPlugin
{
#region Basics
public string Author { get { return "Sidgurdan"; } }
public Version Version { get { return new Version(1, 5); } }
public string Name { get { return "Fate Auto Leveler"; } }
public string EnglishName { get { return "Fate Auto Leveler"; } }
public string Description { get { return "Moves your character to appropriate level range."; } }
public bool WantButton
{
get { return false; }
}
public string ButtonText
{
get { return "FateAutoLeveler"; }
}
public void OnButtonPress() {}
public bool Equals(IBotPlugin other)
{
throw new NotImplementedException();
}
#endregion
#region Prerequirements and Hooks
private Composite _coroutine;
private bool _enabled;
private uint? _disabledForLevel;
public void OnPulse()
{
if (!CheckBotBase())
{
_enabled = false;
return;
}
if (_disabledForLevel.HasValue && (uint) Core.Player.ClassLevel == _disabledForLevel)
{
_enabled = false;
return;
}
_enabled = true;
}
public void OnInitialize()
{
_coroutine = new ActionRunCoroutine(r => ChangeZone());
_enabled = true;
_disabledForLevel = null;
}
public void OnShutdown()
{
}
public void OnEnabled()
{
Log("Enabled");
TreeHooks.Instance.AddHook("TreeStart", _coroutine);
TreeHooks.Instance.OnHooksCleared += OnHooksCleared;
}
public void OnDisabled()
{
TreeHooks.Instance.OnHooksCleared -= OnHooksCleared;
TreeHooks.Instance.RemoveHook("TreeStart", _coroutine);
}
private void DisablePluginUntilLevelChange()
{
_enabled = false;
_disabledForLevel = (uint) Core.Player.ClassLevel;
}
private void OnHooksCleared(object sender, EventArgs args)
{
TreeHooks.Instance.AddHook("TreeStart", _coroutine);
}
private bool CheckBotBase()
{
return (BotManager.Current.Name == "Fate Bot" || BotManager.Current.Name == "ExFateBot" || BotManager.Current.Name == "LizExFateBot");
}
#endregion
#region Change Zone Logic
internal async Task<bool> ChangeZone()
{
// Skip if OnPulse disabled the plugin functionality
if(_enabled == false)
{
return false;
}
var nextAetherite = FindNextAetherite();
if (nextAetherite == null)
{
Log("There is no recommended zone for your level registered.");
DisablePluginUntilLevelChange();
return false;
}
bool playerIsOnCorrectMap = WorldManager.ZoneId == nextAetherite.ZoneId;
if (playerIsOnCorrectMap)
{
return false;
}
try
{
WorldManager.TeleportLocation aetherite = FindAetheriteInAvailableLocations(nextAetherite.Name);
await PrepareForTeleport();
Log("Teleporting to " + aetherite.Name);
await CommonTasks.Teleport(aetherite.AetheryteId);
}
catch (Exception exception)
{
Logging.WriteVerbose(exception.ToString());
LogZone();
Log("The required aetherite is not yet known by your character. You need: " + nextAetherite.Name);
Log("Please disable/enable the plugin once you have the aetherite acquired.");
// TODO Manually MoveTo if aetherite is not known
DisablePluginUntilLevelChange();
return false;
}
return true;
}
private async Task<bool> PrepareForTeleport()
{
if (Core.Player.IsMounted)
{
await CommonTasks.StopAndDismount();
}
while (NowLoading.IsVisible)
{
Log("Loading Screen detected. Waiting for 3s!");
await Coroutine.Sleep(3000);
}
return true;
}
private Aetherite FindNextAetherite()
{
int level = (int) Core.Player.ClassLevel;
foreach (var entry in AetheriteName.GetTargetAetherites())
{
var aetherite = entry.Value;
if (level >= aetherite.MinLevel && level <= aetherite.MaxLevel)
{
return aetherite;
}
}
return null;
}
private WorldManager.TeleportLocation FindAetheriteInAvailableLocations(string teleportName)
{
foreach (var location in WorldManager.AvailableLocations)
{
if (location.Name == teleportName)
{
return location;
}
}
throw new Exception("Requested Aetherite not found in known locations.");
}
#endregion
#region Debugging
static void Log(string message)
{
Logging.Write(Colors.SkyBlue, "[FateAutoLeveler] " + message);
}
static void LogZone()
{
Logging.Write(
Colors.SkyBlue,
"[FateAutoLeveler] Unknown Zone Id: {0} | Raw Zone Id: {1} | Subzone Id: {2}",
WorldManager.ZoneId,
WorldManager.RawZoneId,
WorldManager.SubZoneId
);
}
#endregion
}
}