forked from Fryheit/Kombatant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kombatant.cs
209 lines (175 loc) · 6.58 KB
/
Kombatant.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
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ff14bot;
using ff14bot.AClasses;
using ff14bot.Behavior;
using ff14bot.Helpers;
using ff14bot.Navigation;
using ff14bot.Pathing.Service_Navigation;
using Kombatant.Forms;
using Kombatant.Forms.Models;
using Kombatant.Logic;
using Kombatant.Helpers;
using TreeSharp;
namespace Kombatant
{
/// <summary>
/// <para>Kombatant - An Advanced Open-Source Combat Assist Botbase</para>
/// <para>For credits and stuff, see README.md</para>
/// </summary>
// ReSharper disable once UnusedMember.Global
public class Kombatant : AsyncBotBase
{
#region Botbase Metadata
public override string Name => Resources.Localization.Name_Kombatant;
public override bool IsAutonomous => Settings.BotBase.Instance.IsAutonomous;
public override bool RequiresProfile => false;
public override bool WantButton => true;
public override PulseFlags PulseFlags => Settings.Fleeting.Instance.BotBasePulseFlags;
/// <summary>
/// Required dummy composite. Why, though?
/// </summary>
public override Composite Root => new ActionAlwaysFail();
#endregion
#region Xaml Dummies
private Window _window;
private static readonly object ContentLock = new object();
private UserControl _windowContent;
#endregion
#region Windows Forms Dummies
private ClassicSettingsForm _classicSettings;
#endregion
/// <summary>
/// Called when someone presses "Botbase Settings" in the main window.
/// </summary>
public override void OnButtonPress()
{
if (Settings.BotBase.Instance.UseWinFormsSettings)
{
if (_classicSettings == null || _classicSettings.IsDisposed)
_classicSettings = new ClassicSettingsForm();
_classicSettings.Show();
}
else
{
if (_window == null)
{
_window = new SettingsForm
{
DataContext = SettingsFormModel.Instance,
Content = LoadWindowContent(),
Title = $@"{Resources.Localization.UI_SettingsWindowTitle}",
};
_window.Loaded += (e, a) =>
{
};
_window.Closed += (e, a) =>
{
_window = null;
_windowContent = null;
Settings.BotBase.Reload();
Settings.Hotkeys.Reload();
Logging.Write(Resources.Localization.Msg_ReloadedSettings);
};
}
_window.Show();
}
}
/// <summary>
/// Load up the xaml window.
/// </summary>
/// <returns></returns>
private UserControl LoadWindowContent()
{
try
{
lock (ContentLock)
{
_windowContent = WpfHelper.Instance.LoadWindowContent(Resources.Controls.SettingsControl);
return _windowContent;
}
}
catch (Exception ex)
{
LogHelper.Instance.Log(@"Exception loading window content! {0}", ex);
}
return null;
}
/// <summary>
/// Called when the botbase gets started.
/// </summary>
public override void Start()
{
// Always start paused
Settings.BotBase.Instance.IsPaused = true;
// Set up navigation
Navigator.PlayerMover = new SlideMover();
Navigator.NavigationProvider = new ServiceNavigationProvider();
// Register the hotkeys
HotkeyHelper.Instance.ReloadHotkeys();
// Less than 30 TPS are a no-no due to the design of this botbase. At least warn the user of this!
if (TreeRoot.TicksPerSecond < 30)
{
LogHelper.Instance.Log(Resources.Localization.Msg_Not30Tps_Log);
OverlayHelper.Instance.AddToast(Resources.Localization.Msg_Not30Tps, Colors.Red, Colors.DarkRed, TimeSpan.FromSeconds(10));
}
}
/// <summary>
/// Called when the botbase gets stopped.
/// </summary>
public override void Stop()
{
// Destroy the navigator
Navigator.PlayerMover = new NullMover();
Navigator.NavigationProvider = new NullProvider();
// Unregister the hotkeys
HotkeyHelper.Instance.UnregisterHotkeys();
}
/// <summary>
/// Task wrapper for the main botbase logic.
/// </summary>
/// <returns></returns>
public override Task AsyncRoot()
{
return KombatantLogic();
}
/// <summary>
/// Main botbase logic task.
/// </summary>
/// <returns></returns>
private async Task<bool> KombatantLogic()
{
// Execute duty commence logic
if (await CommenceDuty.Instance.ExecuteLogic())
return await Task.FromResult(true);
// Execute mechanics logic (gaze attacks et al)
if (await Mechanics.Instance.ExecuteLogic())
return await Task.FromResult(true);
// Execute convenience logic (auto sprint etc.)
if (await Convenience.Instance.ExecuteLogic())
return await Task.FromResult(true);
// Execute target logic
if (await Target.Instance.ExecuteLogic())
return await Task.FromResult(true);
// Execute avoidance logic
if (await Avoidance.Instance.ExecuteLogic())
return await Task.FromResult(true);
// Execute auto movement
if (await Movement.Instance.ExecuteLogic())
return await Task.FromResult(true);
// Execute tank specific logic
if (await Tank.Instance.ExecuteLogic())
return await Task.FromResult(true);
// Execute healer specific logic
if (await Healer.Instance.ExecuteLogic())
return await Task.FromResult(true);
// Execute DPS specific logic
if (await DPS.Instance.ExecuteLogic())
return await Task.FromResult(true);
return await Task.FromResult(false);
}
}
}