-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathChanko.cs
168 lines (138 loc) · 4.41 KB
/
Chanko.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
using Buddy.Coroutines;
using ff14bot;
using ff14bot.AClasses;
using ff14bot.Behavior;
using ff14bot.Helpers;
using ff14bot.Managers;
using Newtonsoft.Json;
using System;
using System.Configuration;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Media;
using TreeSharp;
namespace ChankoPlugin
{
public class Chanko : BotPlugin
{
private Composite _coroutine;
private ChankoSettings _settingsForm;
private static int _buff = 48;
public override string Author
{
get { return "evo89"; }
}
public override string Name
{
get { return "Chanko"; }
}
public override Version Version
{
get { return new Version(1, 0, 0, 1); }
}
private static async Task<bool> EatFood()
{
if (Settings.Instance.Id == 0 || !InventoryManager.FilledSlots.ContainsFooditem(Settings.Instance.Id))
{
Logging.Write(Colors.Aquamarine, "[Chanko] No food selected, check your settings");
return false;
}
if (GatheringManager.WindowOpen)
{
Logging.Write(Colors.Aquamarine, "[Chanko] Waiting for gathering window to close");
return false;
}
var item = InventoryManager.FilledSlots.GetFoodItem(Settings.Instance.Id);
if (item == null) return false;
if (FishingManager.State != FishingState.None)
{
Logging.Write(Colors.Aquamarine, "[Chanko] Stop fishing");
Actionmanager.DoAction("Quit", Core.Me);
await Coroutine.Wait(5000, () => FishingManager.State == FishingState.None);
}
if (Core.Me.IsMounted)
{
Logging.Write(Colors.Aquamarine, "[Chanko] Dismounting to eat");
await CommonTasks.StopAndDismount();
}
Logging.Write(Colors.Aquamarine, "[Chanko] Eating " + item.EnglishName);
item.UseItem();
await Coroutine.Wait(5000, () => Core.Me.HasAura(_buff));
return true;
}
public override void OnInitialize()
{
_coroutine = new Decorator(c => !Core.Me.HasAura(_buff), new ActionRunCoroutine(r => EatFood()));
}
public override void OnEnabled()
{
TreeRoot.OnStart += OnBotStart;
TreeRoot.OnStop += OnBotStop;
TreeHooks.Instance.OnHooksCleared += OnHooksCleared;
if (TreeRoot.IsRunning)
{
AddHooks();
}
}
public override void OnDisabled()
{
TreeRoot.OnStart -= OnBotStart;
TreeRoot.OnStop -= OnBotStop;
RemoveHooks();
}
public override void OnShutdown()
{
TreeRoot.OnStart -= OnBotStart;
TreeRoot.OnStop -= OnBotStop;
RemoveHooks();
}
public override bool WantButton
{
get { return true; }
}
public override void OnButtonPress()
{
if (_settingsForm == null || _settingsForm.IsDisposed || _settingsForm.Disposing)
{
_settingsForm = new ChankoSettings();
}
_settingsForm.ShowDialog();
}
private void AddHooks()
{
Logging.Write(Colors.Aquamarine, "Adding Chanko Hook");
TreeHooks.Instance.AddHook("TreeStart", _coroutine);
}
private void RemoveHooks()
{
Logging.Write(Colors.Aquamarine, "Removing Chanko Hook");
TreeHooks.Instance.RemoveHook("TreeStart", _coroutine);
}
private void OnBotStop(BotBase bot)
{
RemoveHooks();
}
private void OnBotStart(BotBase bot)
{
AddHooks();
}
private void OnHooksCleared(object sender, EventArgs e)
{
RemoveHooks();
}
}
public class Settings : JsonSettings
{
private static Settings _instance;
public static Settings Instance
{
get { return _instance ?? (_instance = new Settings()); ; }
}
public Settings()
: base(Path.Combine(CharacterSettingsDirectory, "Chanko.json"))
{
}
[Setting]
public uint Id { get; set; }
}
}