Skip to content

Commit

Permalink
Parse Shop Furnishing (#34)
Browse files Browse the repository at this point in the history
* Parse Shop Furnishing

* Update Maple2.File.Parser.csproj
  • Loading branch information
AngeloTadeucci authored Sep 16, 2024
1 parent d7ccf56 commit 7c54f1b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Maple2.File.Parser/TableParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class TableParser {
private readonly XmlSerializer individualItemDropSerializer;
private readonly XmlSerializer gachaInfoSerializer;
private readonly XmlSerializer shopBeautyCouponSerializer;
private readonly XmlSerializer shopFurnishingSerializer;
private readonly XmlSerializer meretmarketCategorySerializer;
private readonly XmlSerializer expBaseSerializer;
private readonly XmlSerializer nextExpSerializer;
Expand Down Expand Up @@ -141,6 +142,7 @@ public TableParser(M2dReader xmlReader) {
individualItemDropSerializer = new XmlSerializer(typeof(IndividualItemDropRoot));
gachaInfoSerializer = new XmlSerializer(typeof(GachaInfoRoot));
shopBeautyCouponSerializer = new XmlSerializer(typeof(ShopBeautyCouponRoot));
shopFurnishingSerializer = new XmlSerializer(typeof(ShopFurnishingRoot));
meretmarketCategorySerializer = new XmlSerializer(typeof(MeretMarketCategoryRoot));
expBaseSerializer = new XmlSerializer(typeof(ExpBaseRoot));
nextExpSerializer = new XmlSerializer(typeof(NextExpRoot));
Expand Down Expand Up @@ -885,6 +887,28 @@ public IEnumerable<JobTable> ParseJobTable() {
}
}

public IEnumerable<(int ItemId, ShopFurnishing UgcItem)> ParseFurnishingShopUgcAll() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/na/shop_ugcall.xml")));
var reader = XmlReader.Create(new StringReader(xml));
var data = shopFurnishingSerializer.Deserialize(reader) as ShopFurnishingRoot;
Debug.Assert(data != null);

foreach (ShopFurnishing shop in data.key) {
yield return (shop.id, shop);
}
}

public IEnumerable<(int ItemId, ShopFurnishing UgcItem)> ParseFurnishingShopMaid() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/na/shop_maid.xml")));
var reader = XmlReader.Create(new StringReader(xml));
var data = shopFurnishingSerializer.Deserialize(reader) as ShopFurnishingRoot;
Debug.Assert(data != null);

foreach (ShopFurnishing shop in data.key) {
yield return (shop.id, shop);
}
}

public IEnumerable<(int CategoryId, MeretMarketCategory Category)> ParseMeretMarketCategory() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/na/meratmarketcategory.xml")));
var reader = XmlReader.Create(new StringReader(xml));
Expand Down
23 changes: 23 additions & 0 deletions Maple2.File.Parser/Xml/Table/ShopFurnishing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Xml.Serialization;
using M2dXmlGenerator;

namespace Maple2.File.Parser.Xml.Table;

// ./data/xml/table/na/shop_ugcall.xml
// ./data/xml/table/na/shop_maid.xml
[XmlRoot("ms2")]
public partial class ShopFurnishingRoot {
[M2dFeatureLocale(Selector = "id")] private IList<ShopFurnishing> _key;
}

public partial class ShopFurnishing : IFeatureLocale {
[XmlAttribute] public int id;
[XmlAttribute] public bool ugcHousingBuy;
[M2dEnum] public HousingMoneyType ugcHousingMoneyType = HousingMoneyType.Meso;
[XmlAttribute] public int ugcHousingDefaultPrice;
}

public enum HousingMoneyType {
Meso = 1,
Meret = 3,
}
18 changes: 18 additions & 0 deletions Maple2.File.Tests/TableParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,24 @@ public void TestShopBeautyCoupon() {
}
}

[TestMethod]
public void TestShopFurnishingUgcAll() {
var parser = new TableParser(TestUtils.XmlReader);

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

[TestMethod]
public void TestShopFurnishingMaid() {
var parser = new TableParser(TestUtils.XmlReader);

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

[TestMethod]
public void TestMeretMarketCategory() {
var parser = new TableParser(TestUtils.XmlReader);
Expand Down

0 comments on commit 7c54f1b

Please sign in to comment.