Skip to content

Commit

Permalink
custom meret market (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zintixx authored Sep 18, 2024
1 parent 4d743ad commit 9a98964
Show file tree
Hide file tree
Showing 4 changed files with 64 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.29</PackageVersion>
<PackageVersion>2.1.30</PackageVersion>
<TargetFramework>net8.0</TargetFramework>
<PackageReadmeFile>README.md</PackageReadmeFile>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
13 changes: 13 additions & 0 deletions Maple2.File.Parser/ServerTableParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ServerTableParser {
private readonly XmlSerializer itemMergeOptionSerializer;
private readonly XmlSerializer enchantOptionSerializer;
private readonly XmlSerializer shopMeretSerializer;
private readonly XmlSerializer shopMeretCustomSerializer;

public ServerTableParser(M2dReader xmlReader) {
this.xmlReader = xmlReader;
Expand Down Expand Up @@ -81,6 +82,7 @@ public ServerTableParser(M2dReader xmlReader) {
itemMergeOptionSerializer = new XmlSerializer(typeof(ItemMergeOptionRoot));
enchantOptionSerializer = new XmlSerializer(typeof(EnchantOptionRoot));
shopMeretSerializer = new XmlSerializer(typeof(ShopMeretRoot));
shopMeretCustomSerializer = new XmlSerializer(typeof(ShopMeretCustomRoot));

// var seen = new HashSet<string>();
// this.bankTypeSerializer.UnknownAttribute += (sender, args) => {
Expand Down Expand Up @@ -627,4 +629,15 @@ public ServerTableParser(M2dReader xmlReader) {
yield return (shopMeret.sn, shopMeret);
}
}

public IEnumerable<(int Id, ShopMeretCustom ShopMeret)> ParseShopMeretCustom() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/Server/shop_merat_custom.xml")));
var reader = XmlReader.Create(new StringReader(xml));
var data = shopMeretCustomSerializer.Deserialize(reader) as ShopMeretCustomRoot;
Debug.Assert(data != null);

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

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

// ./data/server/table/Server/shop_merat_custom.xml
[XmlRoot("ms2")]
public class ShopMeretCustomRoot {
[XmlElement] public List<ShopMeretCustom> item;
}

public partial class ShopMeretCustom {
[XmlAttribute] public int id;
[XmlAttribute] public int tabID;
[XmlAttribute] public string banner = string.Empty;
[XmlAttribute] public int bannerTag;
[XmlAttribute] public int itemID;
[XmlAttribute] public int grade;
[XmlAttribute] public int quantity;
[XmlAttribute] public int bonusQuantity;
[XmlAttribute] public int durationDay;
[XmlAttribute] public byte saleTag;
[XmlAttribute] public int paymentType;
[XmlAttribute] public long price;
[XmlAttribute] public long salePrice;
[XmlAttribute] public string saleStartTime = string.Empty;
[XmlAttribute] public string saleEndTime = string.Empty;
[M2dArray] public int[] jobRequire = Array.Empty<int>();
[XmlAttribute] public bool noRestock;
[XmlAttribute] public short minLevel;
[XmlAttribute] public short maxLevel;
[XmlAttribute] public int achieveID;
[XmlAttribute] public byte achieveGrade;
[XmlAttribute] public bool pcCafe;
[XmlAttribute] public bool giftable;
[XmlAttribute] public bool showSaleTime;
[XmlAttribute] public string promoName = string.Empty;
[XmlAttribute] public string promoSaleStartTime = string.Empty;
[XmlAttribute] public string promoSaleEndTime = string.Empty;
[XmlElement] public List<ShopMeretCustom> additionalQuantity;
}
9 changes: 9 additions & 0 deletions Maple2.File.Tests/ServerTableParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,13 @@ public void TestMeretShop() {
continue;
}
}

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

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

0 comments on commit 9a98964

Please sign in to comment.