Skip to content

Commit

Permalink
Parse Item Merge Option (#31)
Browse files Browse the repository at this point in the history
* Parse Item Merge Option

* Update ServerTableParserTest.cs
  • Loading branch information
Zintixx authored Aug 9, 2024
1 parent 92b756e commit 128d570
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Maple2.File.Parser/Maple2.File.Parser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageTags>MapleStory2, File, Parser, m2d, xml</PackageTags>
<!-- Use following lines to write the generated files to disk. -->
<EmitCompilerGeneratedFiles Condition=" '$(Configuration)' == 'Debug' ">true</EmitCompilerGeneratedFiles>
<PackageVersion>2.1.24</PackageVersion>
<PackageVersion>2.1.25</PackageVersion>
<TargetFramework>net8.0</TargetFramework>
<PackageReadmeFile>README.md</PackageReadmeFile>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
12 changes: 12 additions & 0 deletions Maple2.File.Parser/ServerTableParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class ServerTableParser {
private readonly XmlSerializer oxQuizSerializer;
private readonly XmlSerializer gameEventSerializer;
private readonly XmlSerializer unlimitedEnchantOptionSerializer;
private readonly XmlSerializer itemMergeOptionSerializer;

public ServerTableParser(M2dReader xmlReader) {
this.xmlReader = xmlReader;
Expand Down Expand Up @@ -75,6 +76,7 @@ public ServerTableParser(M2dReader xmlReader) {
oxQuizSerializer = new XmlSerializer(typeof(OxQuizRoot));
gameEventSerializer = new XmlSerializer(typeof(GameEventRoot));
unlimitedEnchantOptionSerializer = new XmlSerializer(typeof(UnlimitedEnchantOptionRoot));
itemMergeOptionSerializer = new XmlSerializer(typeof(ItemMergeOptionRoot));

// var seen = new HashSet<string>();
// this.bankTypeSerializer.UnknownAttribute += (sender, args) => {
Expand Down Expand Up @@ -578,4 +580,14 @@ public ServerTableParser(M2dReader xmlReader) {
yield return (group.Key, group.ToDictionary(option => option.grade));
}
}

public IEnumerable<(int Id, MergeOption MergeOption)> ParseItemMergeOption() {
XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("table/Server/itemMergeOptionBase.xml"));
var data = itemMergeOptionSerializer.Deserialize(reader) as ItemMergeOptionRoot;
Debug.Assert(data != null);

foreach (MergeOption entry in data.mergeOption) {
yield return (entry.id, entry);
}
}
}
49 changes: 49 additions & 0 deletions Maple2.File.Parser/Xml/Table/Server/ItemMergeOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Xml.Serialization;
using M2dXmlGenerator;

namespace Maple2.File.Parser.Xml.Table.Server;

// ./data/server/table/Server/itemMergeOptionBase.xml
[XmlRoot("ms2")]
public class ItemMergeOptionRoot {
[XmlElement] public List<MergeOption> mergeOption;
}

public partial class MergeOption : IFeatureLocale {
[XmlAttribute] public int id;

[XmlElement] public List<Slot> slot;

public partial class Slot {
[XmlAttribute] public int part = 1;
[XmlAttribute] public long consumeMeso;
[M2dArray] public string[] itemMaterial1 = Array.Empty<string>();
[M2dArray] public string[] itemMaterial2 = Array.Empty<string>();
[XmlElement] public List<Option> option;
}

public partial class Option {
[XmlAttribute] public string optionName = string.Empty;
[XmlAttribute] public int min;
[XmlAttribute] public int idx0_max;
[XmlAttribute] public int idx0_weight;
[XmlAttribute] public int idx1_max;
[XmlAttribute] public int idx1_weight;
[XmlAttribute] public int idx2_max;
[XmlAttribute] public int idx2_weight;
[XmlAttribute] public int idx3_max;
[XmlAttribute] public int idx3_weight;
[XmlAttribute] public int idx4_max;
[XmlAttribute] public int idx4_weight;
[XmlAttribute] public int idx5_max;
[XmlAttribute] public int idx5_weight;
[XmlAttribute] public int idx6_max;
[XmlAttribute] public int idx6_weight;
[XmlAttribute] public int idx7_max;
[XmlAttribute] public int idx7_weight;
[XmlAttribute] public int idx8_max;
[XmlAttribute] public int idx8_weight;
[XmlAttribute] public int idx9_max;
[XmlAttribute] public int idx9_weight;
}
}
9 changes: 9 additions & 0 deletions Maple2.File.Tests/ServerTableParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,13 @@ public void TestUnlimitedEnchantOption() {
continue;
}
}

[TestMethod]
public void TestItemMergeOption() {
var parser = new ServerTableParser(TestUtils.ServerReader);

foreach ((_, _) in parser.ParseItemMergeOption()) {
continue;
}
}
}

0 comments on commit 128d570

Please sign in to comment.