Skip to content

Commit 5fcfb76

Browse files
Feat: handling npc script gotos (#432)
* Feat: handling npc script gotos * formatting + config file
1 parent 62cfcae commit 5fcfb76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+189
-148
lines changed

.luaFormatConfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#vscode-lua-format extension
2+
3+
keep_simple_function_one_line: false
4+
keep_simple_control_block_one_line: false
5+
column_limit: 100
6+
double_quote_to_single_quote: true
7+
extra_sep_at_table_end: true
8+
spaces_inside_table_braces: true
9+
indent_width: 4
10+
chop_down_kv_table: true
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
694e5f3ddd8327f00a842e208f419244
1+
d80c4948421a906557fb08ba15f2a729

GameDataParser/Parsers/ScriptParser.cs

+46-59
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,17 @@ private static List<ScriptMetadata> ParseNpc(MetadataResources resources)
5050
{
5151
type = ScriptType.Select;
5252
}
53+
5354
int id = int.Parse(node.Attributes["id"].Value);
5455
string buttonSet = node.Attributes["buttonSet"]?.Value;
56+
5557
List<Content> contents = new List<Content>();
58+
5659
if (type == ScriptType.Script)
5760
{
58-
foreach (XmlNode content in node.ChildNodes)
59-
{
60-
if (content.Name != "content")
61-
{
62-
continue;
63-
}
64-
65-
List<int> gotoList = new List<int>();
66-
List<int> gotoFailList = new List<int>();
67-
foreach (XmlNode distractor in content.ChildNodes)
68-
{
69-
if (distractor.Name != "distractor")
70-
{
71-
continue;
72-
}
73-
74-
if (!string.IsNullOrEmpty(distractor.Attributes["goto"]?.Value))
75-
{
76-
gotoList.AddRange(distractor.Attributes["goto"].Value.Split(",").Select(int.Parse).ToList());
77-
}
78-
if (!string.IsNullOrEmpty(distractor.Attributes["gotoFail"]?.Value))
79-
{
80-
gotoFailList.AddRange(distractor.Attributes["gotoFail"].Value.Split(",").Select(int.Parse).ToList());
81-
}
82-
}
83-
84-
string functionId = content.Attributes["functionID"]?.Value;
85-
DialogType dialogType = string.IsNullOrEmpty(content.Attributes["buttonSet"]?.Value) ? DialogType.None : (DialogType) int.Parse(content.Attributes["buttonSet"].Value);
86-
contents.Add(new Content(gotoList, gotoFailList, functionId, dialogType));
87-
}
61+
ParseScript(node, contents);
8862
}
63+
8964
metadata.Options.Add(new Option(type, id, contents, buttonSet));
9065
}
9166

@@ -126,47 +101,59 @@ private static List<ScriptMetadata> ParseQuest(MetadataResources resources)
126101
ScriptMetadata metadata = new ScriptMetadata();
127102
int questId = int.Parse(questNode.Attributes["id"].Value);
128103
string buttonSet = questNode.Attributes["buttonSet"]?.Value;
104+
129105
foreach (XmlNode script in questNode.ChildNodes)
130106
{
131107
int id = int.Parse(script.Attributes["id"].Value);
132108
List<Content> contents = new List<Content>();
133-
foreach (XmlNode content in script.ChildNodes)
134-
{
135-
if (content.Name != "content")
136-
{
137-
continue;
138-
}
139-
140-
List<int> gotoList = new List<int>();
141-
List<int> gotoFailList = new List<int>();
142-
foreach (XmlNode distractor in content.ChildNodes)
143-
{
144-
if (distractor.Name != "distractor")
145-
{
146-
continue;
147-
}
148-
if (!string.IsNullOrEmpty(distractor.Attributes["goto"]?.Value))
149-
{
150-
gotoList.AddRange(distractor.Attributes["goto"].Value.Split(",").Select(int.Parse).ToList());
151-
}
152-
if (!string.IsNullOrEmpty(distractor.Attributes["gotoFail"]?.Value))
153-
{
154-
gotoFailList.AddRange(distractor.Attributes["gotoFail"].Value.Split(",").Select(int.Parse).ToList());
155-
}
156-
}
157-
158-
string functionId = content.Attributes["functionID"]?.Value;
159-
DialogType dialogType = string.IsNullOrEmpty(content.Attributes["buttonSet"]?.Value) ? DialogType.None : (DialogType) int.Parse(content.Attributes["buttonSet"].Value);
160-
contents.Add(new Content(gotoList, gotoFailList, functionId, dialogType));
161-
}
109+
110+
ParseScript(script, contents);
111+
162112
metadata.Options.Add(new Option(ScriptType.Script, id, contents, buttonSet));
163113
}
114+
164115
metadata.Id = questId;
165116
metadata.IsQuestScript = true;
117+
166118
scripts.Add(metadata);
167119
}
168120
}
169121
return scripts;
170122
}
123+
124+
private static void ParseScript(XmlNode node, List<Content> contents)
125+
{
126+
foreach (XmlNode content in node.ChildNodes)
127+
{
128+
if (content.Name != "content")
129+
{
130+
continue;
131+
}
132+
string functionId = content.Attributes["functionID"]?.Value;
133+
DialogType dialogType = string.IsNullOrEmpty(content.Attributes["buttonSet"]?.Value) ? DialogType.None : (DialogType) int.Parse(content.Attributes["buttonSet"].Value);
134+
135+
List<Distractor> distractors = new List<Distractor>();
136+
foreach (XmlNode distractorNode in content.ChildNodes)
137+
{
138+
List<int> gotoList = new List<int>();
139+
List<int> gotoFailList = new List<int>();
140+
if (distractorNode.Name != "distractor")
141+
{
142+
continue;
143+
}
144+
145+
if (!string.IsNullOrEmpty(distractorNode.Attributes["goto"]?.Value))
146+
{
147+
gotoList.AddRange(distractorNode.Attributes["goto"].Value.Split(",").Select(int.Parse).ToList());
148+
}
149+
if (!string.IsNullOrEmpty(distractorNode.Attributes["gotoFail"]?.Value))
150+
{
151+
gotoFailList.AddRange(distractorNode.Attributes["gotoFail"].Value.Split(",").Select(int.Parse).ToList());
152+
}
153+
distractors.Add(new Distractor(gotoList, gotoFailList));
154+
}
155+
contents.Add(new Content(functionId, dialogType, distractors));
156+
}
157+
}
171158
}
172159
}

Maple2Storage/Scripts/Npcs/11000003.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ function getFirstScriptId()
33
return 60
44
end
55
return 50
6-
end
6+
end

Maple2Storage/Scripts/Npcs/11000005.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ function getFirstScriptId()
33
return 80
44
end
55
return 90
6-
end
6+
end

Maple2Storage/Scripts/Npcs/11000007.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ function getFirstScriptId()
33
return 30
44
end
55
return 40
6-
end
6+
end

Maple2Storage/Scripts/Npcs/11000024.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ function getFirstScriptId()
33
return 40
44
end
55
return -1
6-
end
6+
end

Maple2Storage/Scripts/Npcs/11000025.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ function getFirstScriptId()
33
return 60
44
end
55
return -1
6-
end
6+
end
+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
function getFirstScriptId()
2-
--funni long line haha. not as long as it used to be tho
3-
if Helper.HasQuestStarted({50001573,50001580,50001581,50001582,50001583,50001584,50001603,50001604,50001665,50001669}) and Helper.GetCurrentMapId() == 02000023 then
2+
if Helper.HasQuestStarted({
3+
50001573, 50001580, 50001581, 50001582, 50001583, 50001584, 50001603, 50001604, 50001665,
4+
50001669,
5+
}) and Helper.GetCurrentMapId() == 02000023 then
46
return 40
57
end
68
return 50
7-
end
9+
end

Maple2Storage/Scripts/Npcs/11000037.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ function getFirstScriptId()
33
return 40
44
end
55
return -1
6-
end
6+
end

Maple2Storage/Scripts/Npcs/11000040.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ function getFirstScriptId()
33
if jobId == 1 then
44
return 10
55
end
6-
return jobId + 10;
7-
end
6+
return jobId + 10
7+
end

Maple2Storage/Scripts/Npcs/11000041.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ function getFirstScriptId()
77
elseif jobId == 20 then
88
return 20
99
end
10-
return jobId + 10;
11-
end
10+
return jobId + 10
11+
end

Maple2Storage/Scripts/Npcs/11000042.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ function getFirstScriptId()
88
return 40
99
elseif jobId == 30 then
1010
return 20
11-
elseif jobId >= 40 then
12-
return Helper.GetPlayerJobId() + 10;
11+
else
12+
return Helper.GetPlayerJobId() + 10
1313
end
1414
return -1
1515
end
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function getFirstScriptId()
22
local jobId = Helper.GetPlayerJobId()
3-
if jobId == 1 then
4-
return 10
5-
elseif jobId == 40 then
6-
return 20
7-
elseif jobId < 50 then
8-
return jobId + 20
3+
if jobId == 1 then
4+
return 10
5+
elseif jobId == 40 then
6+
return 20
7+
elseif jobId < 50 then
8+
return jobId + 20
99
end
1010
return jobId + 10
11-
end
11+
end
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function getFirstScriptId()
22
local jobId = Helper.GetPlayerJobId()
33
if jobId == 1 then
4-
return 10
4+
return 10
55
elseif jobId == 50 then
6-
return 20
6+
return 20
77
elseif jobId < 50 then
8-
return jobId + 20
8+
return jobId + 20
99
end
1010
return jobId + 10
11-
end
11+
end
1212

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function getFirstScriptId()
22
local jobId = Helper.GetPlayerJobId()
33
if jobId == 1 then
4-
return 10
4+
return 10
55
elseif jobId == 60 then
6-
return 20
6+
return 20
77
elseif jobId < 60 then
8-
return jobId + 20
8+
return jobId + 20
99
end
1010
return jobId + 10
11-
end
11+
end
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function getFirstScriptId()
22
local jobId = Helper.GetPlayerJobId()
33
if jobId == 1 then
4-
return 10
4+
return 10
55
elseif jobId == 70 then
6-
return 20
7-
elseif jobId < 70 then
8-
return jobId + 20
6+
return 20
7+
elseif jobId < 70 then
8+
return jobId + 20
99
end
1010
return jobId + 10
11-
end
11+
end
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function getFirstScriptId()
22
local jobId = Helper.GetPlayerJobId()
3-
if jobId == 1 then
4-
return 10
5-
elseif jobId == 80 then
6-
return 20
7-
elseif jobId < 80 then
8-
return jobId + 20
3+
if jobId == 1 then
4+
return 10
5+
elseif jobId == 80 then
6+
return 20
7+
elseif jobId < 80 then
8+
return jobId + 20
99
end
1010
return jobId + 10
11-
end
11+
end

Maple2Storage/Scripts/Npcs/11000064.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ function getFirstScriptId()
33
local x = math.random()
44
if x > 0.66 then
55
return 50
6-
elseif x > 0.33 and x < 0.66 then
7-
return 40
6+
elseif x > 0.33 and x < 0.66 then
7+
return 40
88
end
99
return 30
1010
end

Maple2Storage/Scripts/Npcs/11000074.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ function getFirstScriptId()
22
if Helper.HasQuestStarted(91000022) then
33
return 40
44
end
5-
return -1 --TO DO: GET KMS2 FOOTAGE THAT CONFIRMS WHETHER SCRIPT ID 20 IS USED ALONGSIDE ID 10
6-
end
5+
return -1 -- TO DO: GET KMS2 FOOTAGE THAT CONFIRMS WHETHER SCRIPT ID 20 IS USED ALONGSIDE ID 10
6+
end

Maple2Storage/Scripts/Npcs/11000106.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ function getFirstScriptId()
33
return 50
44
end
55
return -1
6-
end
6+
end

Maple2Storage/Scripts/Npcs/11000119.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ function getFirstScriptId()
44
end
55
math.randomseed(os.time())
66
return (math.random() > 0.7 and 40 or 120)
7-
end
7+
end

Maple2Storage/Scripts/Npcs/11000157.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ function getFirstScriptId()
33
return 30
44
end
55
return -1
6-
end
6+
end

Maple2Storage/Scripts/Npcs/11000158.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ function getFirstScriptId()
44
end
55
math.randomseed(os.time())
66
return (math.random() > 0.5 and 20 or 30)
7-
end
7+
end
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function getFirstScriptId()
22
if Helper.HasQuestStarted(91000022) then
33
return 70
4-
elseif Helper.HasQuestStarted(80000614) then
4+
elseif Helper.HasQuestStarted(80000614) then
55
return 80
66
end
77
return 60
8-
end
8+
end

0 commit comments

Comments
 (0)