Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse TimeEventData #23

Merged
merged 6 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Maple2.File.Generator/XmlFeatureLocaleGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ private string ProcessTypeField(GeneratorExecutionContext context, IFieldSymbol
return string.Empty;
}

string keywordName = propertyName;
if (keywordName == "event") {
keywordName = "@" + keywordName;
}

string type = field.Type.ToDisplayString();

return $@"
private List<{type}> {field.Name}_;
public {type} {propertyName} => {field.Name}_.ResolveFeatureLocale();
public {type} {keywordName} => {field.Name}_.ResolveFeatureLocale();

[XmlElement(""{propertyName}"")]
public List<{type}> _{field.Name} {{
Expand All @@ -98,6 +103,11 @@ private string ProcessListField(GeneratorExecutionContext context, IFieldSymbol
return string.Empty;
}

string keywordName = propertyName;
if (keywordName == "event") {
keywordName = "@" + keywordName;
}

string type = field.Type.ToDisplayString();
string concreteList = type.Replace("IList", "List");

Expand All @@ -117,7 +127,7 @@ private string ProcessListField(GeneratorExecutionContext context, IFieldSymbol

return $@"
private {concreteList} {field.Name}_;
public {type} {propertyName} => {field.Name}_.{resolver}({groupBy.ToString()}).ToList();
public {type} {keywordName} => {field.Name}_.{resolver}({groupBy.ToString()}).ToList();

[XmlElement(""{propertyName}"")]
public {concreteList} _{field.Name} {{
Expand Down
11 changes: 11 additions & 0 deletions Maple2.File.Parser/Enum/TimeEventType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Maple2.File.Parser.Enum;

public enum TimeEventType {
Boss = 1,
HiddenRealmPortal = 2,
Unknown3 = 3,
FieldInteractObject = 4, // balloons, chest, etc.
GlobalEvent = 5,
KritiasChestPuzzle = 6,
KritiasInvasion = 7,
}
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.18</PackageVersion>
<PackageVersion>2.1.19</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 @@ -37,6 +37,7 @@ public class ServerTableParser {
private readonly XmlSerializer fishBoxSerializer;
private readonly XmlSerializer adventureIdExpTableSerializer;
private readonly XmlSerializer adventureExpTableSerializer;
private readonly XmlSerializer timeEventDataSerializer;

public ServerTableParser(M2dReader xmlReader) {
this.xmlReader = xmlReader;
Expand Down Expand Up @@ -67,6 +68,7 @@ public ServerTableParser(M2dReader xmlReader) {
fishBoxSerializer = new XmlSerializer(typeof(FishBoxRoot));
adventureIdExpTableSerializer = new XmlSerializer(typeof(AdventureIdExpTableRoot));
adventureExpTableSerializer = new XmlSerializer(typeof(AdventureExpTableRoot));
timeEventDataSerializer = new XmlSerializer(typeof(TimeEventDataRoot));

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

public IEnumerable<(int Id, TimeEventData Data)> ParseTimeEventData() {
string xml = Sanitizer.RemoveEmpty(xmlReader.GetString(xmlReader.GetEntry("table/Server/timeEventData.xml")));
var reader = XmlReader.Create(new StringReader(xml));
var data = timeEventDataSerializer.Deserialize(reader) as TimeEventDataRoot;
Debug.Assert(data != null);

foreach (TimeEventData entry in data.@event) {
yield return (entry.id, entry);
}
}
}
2 changes: 1 addition & 1 deletion Maple2.File.Parser/Xml/Common/Condition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Maple2.File.Parser.Xml.Common;
[XmlType(Namespace = "Common")]
public partial class Condition {
[M2dEnum] public ConditionType type = ConditionType.unknown;
[XmlAttribute] public long value;
[XmlAttribute] public long value = 1;
[M2dArray] public string[] code = Array.Empty<string>(); // split on ',' and '-'
[M2dArray] public string[] target = Array.Empty<string>(); // split on ',' and ':'
[XmlAttribute] public int partyCount;
Expand Down
1 change: 1 addition & 0 deletions Maple2.File.Parser/Xml/Table/Server/SpawnInteractObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public partial class SpawnInteractObject : IFeatureLocale {
[XmlAttribute] public string normal = string.Empty;
[XmlAttribute] public string reactable = string.Empty;
[XmlAttribute] public float scale;
[XmlAttribute] public bool isKeepAnimate;
}
59 changes: 59 additions & 0 deletions Maple2.File.Parser/Xml/Table/Server/TimeEventData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Xml.Serialization;
using M2dXmlGenerator;
using Maple2.File.Parser.Enum;

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

// ./data/server/table/Server/timeEventData.xml
[XmlRoot("ms2")]
public partial class TimeEventDataRoot {
[M2dFeatureLocale(Selector = "id")] private IList<TimeEventData> _event;
}

public partial class TimeEventData : IFeatureLocale {
[XmlAttribute] public int id;
[M2dEnum] public TimeEventType type = TimeEventType.Boss;
[XmlAttribute] public int prob;
[XmlAttribute] public string startTime = "2014-1-1-00-05-00";
[XmlAttribute] public string endTime = "2099-12-31-12-00-00";
[XmlAttribute] public string cycleTime = string.Empty;
[XmlAttribute] public string randomTime = string.Empty;
[XmlAttribute] public string lifeTime = string.Empty;
[XmlAttribute] public bool individualChannelSpawn;
[XmlAttribute] public bool screenNotice;
[XmlAttribute] public bool chatNotice;
[XmlAttribute] public float variableCountByChannelCount;
[M2dArray] public int[] targetFields = Array.Empty<int>();
[XmlAttribute] public bool noticeMap;
[M2dArray] public int[] targetSpawnPointIDs = Array.Empty<int>();
[XmlAttribute] public int tag;
[M2dArray] public string[] targetSpawnTags = Array.Empty<string>();
[M2dArray] public int[] npcIDs = Array.Empty<int>();
[XmlAttribute] public bool lifeTimeText1;
[XmlAttribute] public bool unique;
[XmlAttribute] public int roomID;
[XmlAttribute] public int roomCount;
[XmlAttribute] public int interactCount;
[XmlAttribute] public int interactID;
[XmlAttribute] public bool keepAnimate;
[XmlAttribute] public string interactModel = string.Empty;
[XmlAttribute] public string interactAsset = string.Empty;
[XmlAttribute] public string interactNormal = string.Empty;
[XmlAttribute] public string interactReactable = string.Empty;
[XmlAttribute] public string popupMessage = string.Empty;
[XmlAttribute] public string soundID = string.Empty;
[XmlAttribute] public string eventName1 = string.Empty;
[XmlAttribute] public string eventName2 = string.Empty;
[XmlAttribute] public string eventName3 = string.Empty;
[M2dArray] public int[] eventField1 = Array.Empty<int>();
[M2dArray] public int[] eventField2 = Array.Empty<int>();
[M2dArray] public int[] eventField3 = Array.Empty<int>();
[XmlAttribute] public int triggerID;
[XmlAttribute] public string key = string.Empty;
[XmlAttribute] public int value;
[XmlAttribute] public int fieldWarGroupID;
[XmlAttribute] public int eventDurationStartHour;
[XmlAttribute] public int eventDurationEndHour;
[XmlAttribute] public int eventDurationStartMin;
[XmlAttribute] public int eventDurationEndMin;
}
10 changes: 10 additions & 0 deletions Maple2.File.Tests/ServerTableParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,14 @@ public void TestAdventureExp() {
continue;
}
}

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

var timedEventData = parser.ParseTimeEventData();
foreach ((_, _) in parser.ParseTimeEventData()) {
continue;
}
}
}
Loading