-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResourceManager.cs
313 lines (272 loc) · 11.3 KB
/
ResourceManager.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace TheInfiniteBlack2CraftingCalculator
{
public enum ResourceCategory
{
Basic,
Relics,
OblivionFragments,
ShipMods // Added new category
}
public class ResourceManager
{
private Dictionary<string, decimal> baseResourcePrices;
private Dictionary<string, decimal> currentResourcePrices;
private Dictionary<string, decimal> shipModPrices;
private decimal skullPrice = 700m;
public ResourceManager()
{
InitializeBaseResources();
InitializeShipMods();
currentResourcePrices = new Dictionary<string, decimal>(baseResourcePrices);
}
private void InitializeBaseResources()
{
baseResourcePrices = new Dictionary<string, decimal>
{
// Basic Resources
{ "darkmatter", 20m },
{ "radioactive", 16m },
{ "radioactives", 16m },
{ "metal", 12m },
{ "metals", 12m },
{ "gas", 6m },
{ "organic", 4m },
{ "organics", 4m },
{ "crew", 1m },
{ "skull", 700m },
// Relics
{ "human relic", 5000m },
{ "het relic", 2000m },
{ "wyrd relic", 2000m },
{ "precursor relic", 10000m },
// Oblivion Fragments
{ "human oblivion fragment", 10000m },
{ "het oblivion fragment", 10000m },
{ "wyrd oblivion fragment", 10000m },
{ "precursor oblivion fragment", 10000m }
};
}
private void InitializeShipMods()
{
shipModPrices = new Dictionary<string, decimal>
{
{ "N/A", 0m },
{ "Medic", 150000m },
{ "Freighter", 350000m },
{ "Raider", 20000m },
{ "Paladin", 300000m },
{ "Interdictor", 1000000m },
{ "Ultimate", 100000m },
{ "Phoenix", 25000m },
{ "Gladiator", 50000m }
};
}
public decimal GetResourcePrice(string resource)
{
string key = resource.ToLower();
return currentResourcePrices.ContainsKey(key) ? currentResourcePrices[key] : 0m;
}
public decimal GetShipModPrice(string modName)
{
return shipModPrices.ContainsKey(modName) ? shipModPrices[modName] : 0m;
}
public List<string> GetAvailableShipMods(string shipName)
{
var mods = new List<string> { "N/A", "Medic", "Freighter", "Raider", "Paladin", "Ultimate", "Phoenix", "Gladiator" };
// Add Interdictor only for Carrier-class ships
if (shipName.Contains("Carrier"))
{
mods.Add("Interdictor");
}
return mods;
}
public void SetResourcePrice(string resource, decimal price)
{
string key = resource.ToLower();
if (currentResourcePrices.ContainsKey(key))
{
decimal minPrice = baseResourcePrices[key];
currentResourcePrices[key] = Math.Max(price, minPrice);
}
}
public void SetShipModPrice(string modName, decimal price)
{
if (shipModPrices.ContainsKey(modName))
{
shipModPrices[modName] = Math.Max(price, 0m);
}
}
public decimal GetSkullPrice() => skullPrice;
public void SetSkullPrice(decimal price) => skullPrice = Math.Max(price, baseResourcePrices["skull"]);
public Dictionary<string, decimal> GetAllResourcePrices() => new Dictionary<string, decimal>(currentResourcePrices);
public Dictionary<string, decimal> GetBaseResourcePrices() => new Dictionary<string, decimal>(baseResourcePrices);
public Dictionary<string, decimal> GetShipModPrices() => new Dictionary<string, decimal>(shipModPrices);
public Dictionary<string, decimal> GetResourcesByCategory(ResourceCategory category)
{
var resources = new Dictionary<string, decimal>();
switch (category)
{
case ResourceCategory.Basic:
var basicResources = new[] { "darkmatter", "radioactive", "radioactives", "metal", "metals", "gas", "organic", "organics", "crew" };
foreach (var resource in basicResources)
{
resources.Add(resource, currentResourcePrices[resource]);
}
break;
case ResourceCategory.Relics:
var relics = new[] { "human relic", "het relic", "wyrd relic", "precursor relic" };
foreach (var relic in relics)
{
resources.Add(relic, currentResourcePrices[relic]);
}
break;
case ResourceCategory.OblivionFragments:
var fragments = new[] { "human oblivion fragment", "het oblivion fragment", "wyrd oblivion fragment", "precursor oblivion fragment" };
foreach (var fragment in fragments)
{
resources.Add(fragment, currentResourcePrices[fragment]);
}
break;
case ResourceCategory.ShipMods:
foreach (var mod in shipModPrices)
{
resources.Add(mod.Key, mod.Value);
}
break;
}
return resources;
}
}
public class ResourceConfigForm : Form
{
private ResourceManager resourceManager;
private TabControl tabControl;
private Dictionary<string, NumericUpDown> priceInputs;
public ResourceConfigForm(ResourceManager manager)
{
resourceManager = manager;
priceInputs = new Dictionary<string, NumericUpDown>();
InitializeComponent();
LoadResourcePrices();
this.StartPosition = FormStartPosition.CenterParent;
this.Size = new Size(300, 400);
}
private void InitializeComponent()
{
this.Text = "Resource Price Configuration";
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
tabControl = new TabControl
{
Dock = DockStyle.Fill,
Location = new Point(0, 0)
};
CreateResourceTab("Basic Resources", ResourceCategory.Basic);
CreateResourceTab("Relics", ResourceCategory.Relics);
CreateResourceTab("Oblivion Fragments", ResourceCategory.OblivionFragments);
CreateResourceTab("Ship Mods", ResourceCategory.ShipMods); // Added new tab
Button resetButton = new Button
{
Text = "Reset to Default",
Dock = DockStyle.Bottom
};
resetButton.Click += ResetButton_Click;
this.Controls.Add(tabControl);
this.Controls.Add(resetButton);
}
private void CreateResourceTab(string title, ResourceCategory category)
{
TabPage tab = new TabPage(title);
TableLayoutPanel layout = new TableLayoutPanel
{
Dock = DockStyle.Fill,
ColumnCount = 2,
AutoScroll = true,
Padding = new Padding(10)
};
tab.Controls.Add(layout);
tabControl.TabPages.Add(tab);
}
private void LoadResourcePrices()
{
LoadCategoryResources(ResourceCategory.Basic, 0);
LoadCategoryResources(ResourceCategory.Relics, 1);
LoadCategoryResources(ResourceCategory.OblivionFragments, 2);
LoadCategoryResources(ResourceCategory.ShipMods, 3); // Load ship mod prices
AddResourceRow("skull", resourceManager.GetSkullPrice(), tabControl.TabPages[0].Controls[0] as TableLayoutPanel);
}
private void LoadCategoryResources(ResourceCategory category, int tabIndex)
{
var resources = resourceManager.GetResourcesByCategory(category);
var layout = tabControl.TabPages[tabIndex].Controls[0] as TableLayoutPanel;
foreach (var resource in resources)
{
AddResourceRow(resource.Key, resource.Value, layout);
}
}
private void AddResourceRow(string resource, decimal price, TableLayoutPanel layout)
{
Label label = new Label
{
Text = char.ToUpper(resource[0]) + resource.Substring(1),
AutoSize = true
};
NumericUpDown priceInput = new NumericUpDown
{
Minimum = 0,
Maximum = 10000000,
DecimalPlaces = 2,
Value = price,
Width = 100
};
if (resourceManager.GetBaseResourcePrices().ContainsKey(resource))
{
priceInput.Minimum = resourceManager.GetBaseResourcePrices()[resource];
}
priceInput.ValueChanged += (s, e) =>
{
if (resource.ToLower() == "skull")
{
resourceManager.SetSkullPrice(priceInput.Value);
}
else if (resourceManager.GetShipModPrices().ContainsKey(resource))
{
resourceManager.SetShipModPrice(resource, priceInput.Value);
}
else
{
resourceManager.SetResourcePrice(resource, priceInput.Value);
}
};
priceInputs[resource] = priceInput;
layout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
layout.Controls.Add(label, 0, layout.RowCount - 1);
layout.Controls.Add(priceInput, 1, layout.RowCount - 1);
}
private void ResetButton_Click(object sender, EventArgs e)
{
var baseResources = resourceManager.GetBaseResourcePrices();
foreach (var resource in baseResources)
{
if (priceInputs.ContainsKey(resource.Key))
{
priceInputs[resource.Key].Value = resource.Value;
}
}
// Reset ship mod prices
var shipMods = resourceManager.GetShipModPrices();
foreach (var mod in shipMods)
{
if (priceInputs.ContainsKey(mod.Key))
{
priceInputs[mod.Key].Value = mod.Value;
}
}
}
}
}