-
Notifications
You must be signed in to change notification settings - Fork 1
/
Extensions.cs
220 lines (207 loc) · 7.76 KB
/
Extensions.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
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Windows.Media;
using AutoMelder.MeldingLogic;
using ff14bot.Enums;
using ff14bot.Helpers;
using LlamaLibrary.JsonObjects;
using LlamaLibrary.Logging;
namespace AutoMelder
{
public static class Extensions
{
public static IEnumerable<Control> GetAllControls(this Control root)
{
var stack = new Stack<Control>();
stack.Push(root);
while (stack.Count > 0)
{
Control next = stack.Pop();
foreach (Control child in next.Controls)
{
stack.Push(child);
}
yield return next;
}
}
public static string AriyalaKey(this EquipmentSlot equipmentSlot)
{
switch (equipmentSlot)
{
case EquipmentSlot.MainHand:
return "mainhand";
case EquipmentSlot.OffHand:
return "offhand";
case EquipmentSlot.Head:
return "head";
case EquipmentSlot.Body:
return "chest";
case EquipmentSlot.Hands:
return "hands";
case EquipmentSlot.Legs:
return "legs";
case EquipmentSlot.Feet:
return "feet";
case EquipmentSlot.Earring:
return "ears";
case EquipmentSlot.Necklace:
return "neck";
case EquipmentSlot.Bracelet:
return "wrist";
case EquipmentSlot.Ring1:
return "ringLeft";
case EquipmentSlot.Ring2:
return "ringRight";
default:
throw new ArgumentOutOfRangeException(nameof(equipmentSlot), equipmentSlot, $"Unknown EquipmentSlot Type: {equipmentSlot}");
}
}
public static string AriyalaKey(this MeldInfo info) => AriyalaKey(info.EquipType);
public static string EtroKey(this EquipmentSlot equipmentSlot)
{
switch (equipmentSlot)
{
case EquipmentSlot.MainHand:
return "weapon";
case EquipmentSlot.OffHand:
return "offHand";
case EquipmentSlot.Head:
return "head";
case EquipmentSlot.Body:
return "body";
case EquipmentSlot.Hands:
return "hands";
case EquipmentSlot.Legs:
return "legs";
case EquipmentSlot.Feet:
return "feet";
case EquipmentSlot.Earring:
return "ears";
case EquipmentSlot.Necklace:
return "neck";
case EquipmentSlot.Bracelet:
return "wrists";
case EquipmentSlot.Ring1:
return "fingerL";
case EquipmentSlot.Ring2:
return "fingerR";
default:
throw new ArgumentOutOfRangeException(nameof(equipmentSlot), equipmentSlot, $"Unknown EquipmentSlot Type: {equipmentSlot}");
}
}
public static string EtroKey(this MeldInfo info) => EtroKey(info.EquipType);
private static readonly Regex CondensedNameRegex = new Regex(@"^(?:(?:Craftsman's|Gatherer's) )?(?<name>(?:[A-Za-z']+ ?){1,2}) Materia (?<rNumTier>[IVXLCDM]+)$");
public static string ToFullString(this MateriaItem materiaItem)
{
string itemName = materiaItem.ItemName;
Match match = CondensedNameRegex.Match(itemName);
if (match.Success)
{
return $"{match.Groups["name"].Value} {match.Groups["rNumTier"].Value} {materiaItem.Stat} +{materiaItem.Value}";
}
return $"{materiaItem.ItemName} {materiaItem.Stat} +{materiaItem.Value}";
}
public static string ToShortJobString(this string jobString)
{
switch (jobString.ToLower())
{
case "carpenter":
return "CRP";
case "blacksmith":
return "BLM";
case "armorer":
return "ARM";
case "goldsmith":
return "GSM";
case "leatherworker":
return "LTW";
case "weaver":
return "WVR";
case "alchemist":
return "ALC";
case "culinarian":
return "CUL";
case "miner":
return "MIN";
case "botanist":
return "BTN";
case "fisher":
return "FSH";
case "paladin":
return "PLD";
case "warrior":
return "WAR";
case "darkknight":
case "dark knight":
return "DRK";
case "gunbreaker":
return "GNB";
case "monk":
return "MNK";
case "dragoon":
return "DRG";
case "ninja":
return "NIN";
case "samurai":
return "SAM";
case "reaper":
return "RPR";
case "whitemage":
case "white mage":
return "WHM";
case "astrologian":
return "AST";
case "scholar":
return "SCH";
case "sage":
return "SGE";
case "bard":
return "BRD";
case "machinist":
return "MCH";
case "dancer":
return "DNC";
case "blackmage":
case "black mage":
return "BLM";
case "summoner":
return "SMN";
case "redmage":
case "red mage":
return "RDM";
case "bluemage":
case "blue mage":
return "BLU";
default:
return jobString;
}
}
public static float GetOvermeldChance(this MateriaItem item, MeldInfo info)
{
int meldSlot = info.GetIndexBySlot(item);
byte guaranteedSlots = info.EquipSlot.Item.MateriaSlots;
int overmeldSlot = meldSlot + 1 - guaranteedSlots;
if (overmeldSlot <= 0) return 100f;
return ResourceManager.OvermeldChances.Value[overmeldSlot][item.Tier];
}
public static float GetOvermeldChance(this MeldInfo info, int materiaSlot)
{
byte guaranteedSlots = info.EquipSlot.Item.MateriaSlots;
var chanceDic = ResourceManager.OvermeldChances.Value;
int materiaTier = info.GetSlotByIndex(materiaSlot).Tier;
int overmeldIndex = materiaSlot - guaranteedSlots;
try
{
return chanceDic[materiaTier][overmeldIndex];
}
catch (KeyNotFoundException e)
{
Log.Error($"MateriaTier {materiaTier} or OvermeldIndex {overmeldIndex} not found in dictionary. GuaranteedSlots: {guaranteedSlots}, Item: {info.EquipSlot.Item.EnglishName}{Environment.NewLine}{e}");
throw;
}
}
private static readonly LLogger Log = new LLogger("AutoMelder", Colors.Brown);
}
}