forked from MS2Community/Maple2.File
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemOptionParser.cs
More file actions
271 lines (242 loc) · 9.67 KB
/
ItemOptionParser.cs
File metadata and controls
271 lines (242 loc) · 9.67 KB
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
using System.Diagnostics;
using System.Xml;
using System.Xml.Serialization;
using Maple2.File.IO;
using Maple2.File.Parser.Tools;
using Maple2.File.Parser.Xml;
using Maple2.File.Parser.Xml.Table;
namespace Maple2.File.Parser;
public class ItemOptionParser {
private readonly string[] constantSuffix = [
"equip",
"equip_fighter",
"equip_pet",
"equip_s2",
"equipmanual",
"etc",
"gemstone",
"mergematerial",
"skin",
];
private readonly string[] randomSuffix = [
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"30",
"31",
"32",
"33",
"34",
"40",
"41",
"50",
"51",
"52",
"53",
"54",
"54_pvp",
"55",
"56",
"accmanual",
"armormanual",
"pet_60",
"weaponmanual",
];
private readonly string[] staticSuffix = [
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"30",
"31",
"32",
"33",
"34",
"40",
"41",
"50",
"51",
"52",
"53",
"54",
"armormanual",
"mergematerial",
"petequipment",
];
private readonly string[] variationSuffix = [
"acc",
"armor",
"pet",
"weapon",
];
private readonly M2dReader xmlReader;
private readonly XmlSerializer itemOptionConstantSerializer;
private readonly XmlSerializer itemOptionConstantNewSerializer;
private readonly XmlSerializer itemOptionSerializer;
private readonly XmlSerializer itemOptionNewSerializer;
private readonly XmlSerializer itemMergeOptionNewSerializer;
private readonly XmlSerializer itemMergeOptionSerializer;
private readonly XmlSerializer itemOptionPickSerializer;
private readonly XmlSerializer itemVariationSerializer;
private readonly XmlSerializer itemVariationNewSerializer;
private readonly XmlSerializer itemVariationIndexSerializer;
public ItemOptionParser(M2dReader xmlReader) {
this.xmlReader = xmlReader;
itemOptionConstantSerializer = new XmlSerializer(typeof(ItemOptionConstantRoot));
itemOptionConstantNewSerializer = new XmlSerializer(typeof(ItemOptionConstantRootNew));
itemOptionSerializer = new XmlSerializer(typeof(ItemOptionRoot));
itemOptionNewSerializer = new XmlSerializer(typeof(ItemOptionRandomRootNew));
itemMergeOptionNewSerializer = new XmlSerializer(typeof(ItemMergeOptionRootNew));
itemMergeOptionSerializer = new XmlSerializer(typeof(ItemMergeOptionRoot));
itemOptionPickSerializer = new XmlSerializer(typeof(ItemOptionPickRoot));
itemVariationSerializer = new XmlSerializer(typeof(ItemOptionVariation));
itemVariationNewSerializer = new XmlSerializer(typeof(ItemOptionVariationNewRoot));
itemVariationIndexSerializer = new XmlSerializer(typeof(ItemOptionVariationEquip));
}
public IEnumerable<ItemOptionConstantData> ParseConstant() {
foreach (string suffix in constantSuffix) {
string filename = $"itemoption/constant/itemoptionconstant_{suffix}.xml";
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry(filename)));
var reader = XmlReader.Create(new StringReader(xml));
var root = itemOptionConstantSerializer.Deserialize(reader) as ItemOptionConstantRoot;
Debug.Assert(root != null);
foreach (ItemOptionConstantData option in root.option) {
if (option.code > 0) {
yield return option;
}
}
}
}
public IEnumerable<ItemOptionConstant> ParseConstantNew() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/itemoptionconstant.xml")));
xml = Sanitizer.RemoveUtf8Bom(xml);
var reader = XmlReader.Create(new StringReader(xml));
var root = itemOptionConstantNewSerializer.Deserialize(reader) as ItemOptionConstantRootNew;
Debug.Assert(root != null);
foreach (ItemOptionConstant option in root.options) {
if (option.code > 0) {
yield return option;
}
}
}
public IEnumerable<ItemOptionData> ParseRandom() {
foreach (string suffix in randomSuffix) {
string filename = $"itemoption/option/random/itemoptionrandom_{suffix}.xml";
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry(filename)));
var reader = XmlReader.Create(new StringReader(xml));
var root = itemOptionSerializer.Deserialize(reader) as ItemOptionRoot;
Debug.Assert(root != null);
foreach (ItemOptionData option in root.option) {
if (option.code > 0) {
yield return option;
}
}
}
}
public IEnumerable<ItemOptionRandomNew> ParseRandomNew() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/itemoptionrandom.xml")));
xml = Sanitizer.RemoveUtf8Bom(xml);
var reader = XmlReader.Create(new StringReader(xml));
var root = itemOptionNewSerializer.Deserialize(reader) as ItemOptionRandomRootNew;
Debug.Assert(root != null);
foreach (ItemOptionRandomNew option in root.options) {
if (option.code > 0) {
yield return option;
}
}
}
public IEnumerable<ItemOptionData> ParseStatic() {
foreach (string suffix in staticSuffix) {
string filename = $"itemoption/option/static/itemoptionstatic_{suffix}.xml";
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry(filename)));
var reader = XmlReader.Create(new StringReader(xml));
var root = itemOptionSerializer.Deserialize(reader) as ItemOptionRoot;
Debug.Assert(root != null);
foreach (ItemOptionData option in root.option) {
if (option.code > 0) {
yield return option;
}
}
}
}
public IEnumerable<MergeOptionNew> ParseMergeOptionBaseNew() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/itemmergeoptionbase.xml")));
xml = Sanitizer.RemoveUtf8Bom(xml);
var reader = XmlReader.Create(new StringReader(xml));
var root = itemMergeOptionNewSerializer.Deserialize(reader) as ItemMergeOptionRootNew;
Debug.Assert(root != null);
foreach (MergeOptionNew option in root.mergeOption) {
yield return option;
}
}
public IEnumerable<MergeOption> ParseMergeOptionBase() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/itemmergeoptionbase.xml")));
var reader = XmlReader.Create(new StringReader(xml));
var root = itemMergeOptionSerializer.Deserialize(reader) as ItemMergeOptionRoot;
Debug.Assert(root != null);
foreach (MergeOption option in root.mergeOption) {
yield return option;
}
}
public IEnumerable<MergeOption> ParseMergeOptionMaterial() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/itemmergeoptionmaterial.xml")));
var reader = XmlReader.Create(new StringReader(xml));
var root = itemMergeOptionSerializer.Deserialize(reader) as ItemMergeOptionRoot;
Debug.Assert(root != null);
foreach (MergeOption option in root.mergeOption) {
yield return option;
}
}
public IEnumerable<ItemOptionPick> ParsePick() {
XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("table/itemoptionpick.xml"));
var root = itemOptionPickSerializer.Deserialize(reader) as ItemOptionPickRoot;
Debug.Assert(root != null);
foreach (ItemOptionPick pick in root.itemOptionPick) {
yield return pick;
}
}
public IEnumerable<ItemOptionVariation.Option> ParseVariation() {
XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("table/itemoptionvariation.xml"));
var data = itemVariationSerializer.Deserialize(reader) as ItemOptionVariation;
Debug.Assert(data != null);
foreach (ItemOptionVariation.Option option in data.option) {
yield return option;
}
}
public IEnumerable<ItemOptionVariationNewRoot.Option> ParseVariationNew() {
XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("table/itemoptionvariation.xml"));
var data = itemVariationNewSerializer.Deserialize(reader) as ItemOptionVariationNewRoot;
Debug.Assert(data != null);
foreach (ItemOptionVariationNewRoot.Option option in data.option) {
yield return option;
}
}
public IEnumerable<(string Type, List<ItemOptionVariationEquip.Option> Option)> ParseVariationEquip() {
foreach (string suffix in variationSuffix) {
string filename = $"table/itemoptionvariation_{suffix}.xml";
XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry(filename));
var data = itemVariationIndexSerializer.Deserialize(reader) as ItemOptionVariationEquip;
Debug.Assert(data != null);
var options = new List<ItemOptionVariationEquip.Option>();
foreach (ItemOptionVariationEquip.Option option in data.option) {
options.Add(option);
}
yield return (suffix, options);
}
}
}