-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInventory.cs
241 lines (224 loc) · 9.01 KB
/
Inventory.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
using ACManager.Settings;
using Decal.Adapter;
using Decal.Adapter.Wrappers;
using Decal.Filters;
using System.Collections.Generic;
using System.Text;
namespace ACManager
{
public static class Inventory
{
public static Dictionary<string, int> GetComponentLevels()
{
Dictionary<string, int> components = new Dictionary<string, int>();
for (int i = 0; i < CoreManager.Current.Filter<FileService>().ComponentTable.Length; i++)
{
string component = CoreManager.Current.Filter<FileService>().ComponentTable[i].Name;
int qty = GetInventoryCount(component);
if (qty > 0)
{
if (components.ContainsKey(component))
{
components[component] = qty;
}
else if (!components.ContainsKey(component))
{
components.Add(component, qty);
}
}
}
return components;
}
public static string ReportOnLowComponents()
{
List<string> lowCompsList = new List<string>();
foreach (KeyValuePair<string, int> component in GetComponentLevels())
{
switch (component.Key)
{
case "Lead Scarab":
if (component.Value <= Utility.BotSettings.LeadScarabThreshold) { lowCompsList.Add(component.Key); }
break;
case "Iron Scarab":
if (component.Value <= Utility.BotSettings.IronScarabThreshold) { lowCompsList.Add(component.Key); }
break;
case "Copper Scarab":
if (component.Value <= Utility.BotSettings.CopperScarabThreshold) { lowCompsList.Add(component.Key); }
break;
case "Silver Scarab":
if (component.Value <= Utility.BotSettings.SilverScarabThreshold) { lowCompsList.Add(component.Key); }
break;
case "Gold Scarab":
if (component.Value <= Utility.BotSettings.GoldScarabThreshold) { lowCompsList.Add(component.Key); }
break;
case "Pyreal Scarab":
if (component.Value <= Utility.BotSettings.PyrealScarabThreshold) { lowCompsList.Add(component.Key); }
break;
case "Platinum Scarab":
if (component.Value <= Utility.BotSettings.PlatinumScarabThreshold) { lowCompsList.Add(component.Key); }
break;
case "Mana Scarab":
if (component.Value <= Utility.BotSettings.ManaScarabThreshold) { lowCompsList.Add(component.Key); }
break;
case "Diamond Scarab":
break;
case "Prismatic Taper":
if (component.Value <= Utility.BotSettings.ComponentThreshold) { lowCompsList.Add(component.Key); }
break;
}
}
if (lowCompsList.Count.Equals(0))
{
return null;
}
StringBuilder sb = new StringBuilder();
sb.Append("I'm low on ");
for (int i = 0; i < lowCompsList.Count; i++)
{
if (!i.Equals(lowCompsList.Count - 1))
{
sb.Append($"{lowCompsList[i]}s");
sb.Append(", ");
}
else
{
if (lowCompsList.Count.Equals(1))
{
sb.Append($"{lowCompsList[i]}s.");
}
else
{
sb.Append($"and {lowCompsList[i]}s.");
}
}
}
return sb.ToString();
}
public static void UpdateInventoryFile()
{
CharacterInventory inventory = new CharacterInventory
{
Name = CoreManager.Current.CharacterFilter.Name
};
foreach (KeyValuePair<string, int> comp in GetComponentLevels())
{
inventory.Components.Add(new AcmComponent { Name = comp.Key, Quantity = comp.Value });
}
foreach (GemSetting gem in Utility.BotSettings.GemSettings)
{
int quantity = GetInventoryCount(gem.Name);
if (quantity > 0)
{
inventory.Gems.Add(new Gem { Name = gem.Name, Quantity = quantity });
}
}
// save inventory to file
Utility.SaveInventory(inventory);
}
/// <summary>
/// Checks for and returns the quantity of items in your inventory.
/// </summary>
/// <param name="item">Name of the item to check for.</param>
/// <returns>The quantity of the requested item in inventory.</returns>
public static int GetInventoryCount(string item)
{
using (WorldObjectCollection inventory = CoreManager.Current.WorldFilter.GetInventory())
{
inventory.SetFilter(new ByNameFilter(item));
return inventory.Quantity;
}
}
public static bool HaveComponents(Spell spell)
{
string scarabType = "";
Dictionary<string, int> requiredComps = new Dictionary<string, int>();
for (int i = 0; i < spell.ComponentIDs.Length; i++)
{
string component = CoreManager.Current.Filter<FileService>().ComponentTable.GetById(spell.ComponentIDs[i]).Name;
if (component.Contains("Scarab"))
{
scarabType = component;
}
if (!requiredComps.ContainsKey(component))
{
requiredComps.Add(component, 1);
}
else
{
requiredComps[component] += 1;
}
}
if (HaveFociOrAugmentation(spell))
{
if (!(GetInventoryCount(scarabType) > requiredComps[scarabType]))
{
return false;
}
int tapers = GetInventoryCount("Prismatic Taper");
switch (scarabType)
{
case "Lead Scarab":
return tapers >= 1;
case "Iron Scarab":
return tapers >= 2;
case "Copper Scarab":
return tapers >= 3;
case "Silver Scarab":
return tapers >= 4; // this is erroneously set to 4, for now, since ACEmulator is wrong, should be 3
case "Gold Scarab":
return tapers >= 4;
case "Pyreal Scarab":
return tapers >= 4;
case "Platinum Scarab":
return tapers >= 4;
case "Mana Scarab":
return tapers >= 4;
}
}
else
{
foreach (KeyValuePair<string, int> component in requiredComps)
{
if (GetInventoryCount(component.Key) < component.Value) {
return false;
}
}
}
return true;
}
private static bool HaveFociOrAugmentation(Spell spell)
{
if (spell.School.Name.Equals("Creature Enchantment") &&
(GetInventoryCount("Foci of Enchantment") > 0 || CoreManager.Current.CharacterFilter.GetCharProperty((int)Augmentations.InfusedCreature) > 0))
{
return true;
}
if (spell.School.Name.Equals("Item Enchantment") &&
(GetInventoryCount("Foci of Artifice") > 0 || CoreManager.Current.CharacterFilter.GetCharProperty((int)Augmentations.InfusedItem) > 0))
{
return true;
}
if (spell.School.Name.Equals("Life Magic")
&& (GetInventoryCount("Foci of Verdancy") > 0 || CoreManager.Current.CharacterFilter.GetCharProperty((int)Augmentations.InfusedLife) > 0))
{
return true;
}
return false;
}
public static WorldObject GetItemByName(string name)
{
using (WorldObjectCollection inventory = CoreManager.Current.WorldFilter.GetInventory())
{
inventory.SetFilter(new ByNameFilter(name));
if (inventory.Quantity > 0)
{
return inventory.First;
}
else
{
return null;
}
}
}
}
}