Skip to content

Commit

Permalink
GameEvent (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zintixx authored Jun 28, 2024
1 parent c843966 commit 50a96cd
Show file tree
Hide file tree
Showing 4 changed files with 47 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.21</PackageVersion>
<PackageVersion>2.1.22</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 @@ -39,6 +39,7 @@ public class ServerTableParser {
private readonly XmlSerializer adventureExpTableSerializer;
private readonly XmlSerializer timeEventDataSerializer;
private readonly XmlSerializer oxQuizSerializer;
private readonly XmlSerializer gameEventSerializer;

public ServerTableParser(M2dReader xmlReader) {
this.xmlReader = xmlReader;
Expand Down Expand Up @@ -71,6 +72,7 @@ public ServerTableParser(M2dReader xmlReader) {
adventureExpTableSerializer = new XmlSerializer(typeof(AdventureExpTableRoot));
timeEventDataSerializer = new XmlSerializer(typeof(TimeEventDataRoot));
oxQuizSerializer = new XmlSerializer(typeof(OxQuizRoot));
gameEventSerializer = new XmlSerializer(typeof(GameEventRoot));

// var seen = new HashSet<string>();
// this.bankTypeSerializer.UnknownAttribute += (sender, args) => {
Expand Down Expand Up @@ -553,4 +555,14 @@ public ServerTableParser(M2dReader xmlReader) {
yield return (entry.quizID, entry);
}
}

public IEnumerable<(int Id, GameEvent GameEvent)> ParseGameEvent() {
XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("table/Server/NA/GameEvent.xml"));
var data = gameEventSerializer.Deserialize(reader) as GameEventRoot;
Debug.Assert(data != null);

foreach (GameEvent entry in data.gameEvent) {
yield return (entry.gameEventID, entry);
}
}
}
25 changes: 25 additions & 0 deletions Maple2.File.Parser/Xml/Table/Server/GameEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Xml.Serialization;
using M2dXmlGenerator;
using DayOfWeek = Maple2.File.Parser.Enum.DayOfWeek;

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

// ./data/server/table/Server/NA/GameEvent.xml
[XmlRoot("ms2")]
public partial class GameEventRoot {
[M2dFeatureLocale(Selector = "gameEventID")] private IList<GameEvent> _gameEvent;
}

public partial class GameEvent : IFeatureLocale {
[XmlAttribute] public int gameEventID;
[XmlAttribute] public string eventType = string.Empty;
[XmlAttribute] public string eventStart = string.Empty;
[XmlAttribute] public string eventEnd = string.Empty;
[XmlAttribute] public string partTime = string.Empty;
[M2dArray] public DayOfWeek[] dayOfWeek = Array.Empty<DayOfWeek>();
[XmlAttribute] public string value1 = string.Empty;
[XmlAttribute] public string value2 = string.Empty;
[XmlAttribute] public string value3 = string.Empty;
[XmlAttribute] public string value4 = string.Empty;
[XmlAttribute] public string reference = string.Empty;
}
9 changes: 9 additions & 0 deletions Maple2.File.Tests/ServerTableParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,13 @@ public void TestOxQuiz() {
continue;
}
}

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

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

0 comments on commit 50a96cd

Please sign in to comment.