1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
# -*- coding: utf8 -*-
#
# Copyright (C) 2014 Evol Online
# Author: Andrei Karas (4144)
import re
from code.fileutils import *
from code.stringutils import *
mapsConfFile = "newserverdata/conf/maps.conf"
mapsIndexFile = "newserverdata/db/map_index.txt"
npcMainScript = "newserverdata/npc/re/scripts_main.conf"
mapsIndex = 1
scriptRe = re.compile("^(((?P<map>[^/](.+))([.]gat|),([ ]*)(?P<x>[\d]+),([ ]*)(?P<y>[\d]+),([ ]*)(?P<dir>[\d]+))|(?P<function>function)|-)" +
"[|](?P<tag>script)[|](?P<name>[^|]+)([|]"
"(?P<class>[\d-]+)((,((?P<xs>[\d]+),(?P<ys>[\d]+)))|)|)$")
shopRe = re.compile("^(?P<map>[^/](.+))[.]gat,([ ]*)(?P<x>[\d]+),([ ]*)(?P<y>[\d]+),([ ]*)(?P<dir>[\d]+)(|,(?P<gender>[\d]+))" +
"[|](?P<tag>shop)[|](?P<name>[\w#' ]+)[|]"
"(?P<class>[\d]+),(?P<items>(.+))$")
mapFlagRe = re.compile("^(?P<map>[^/](.+))[.]gat" +
"[|](?P<tag>mapflag)[|](?P<name>[\w#']+)(|[|](?P<flag>.*))$")
warpRe = re.compile("^(?P<map>[^/](.+))[.]gat,([ ]*)(?P<x>[\d]+),([ ]*)(?P<y>[\d]+)[|]"
"(?P<tag>warp)[|](?P<name>[^|]+)[|](?P<xs>[\d-]+),(?P<ys>[\d-]+),(?P<targetmap>[^/](.+))[.]gat,([ ]*)(?P<targetx>[\d]+),([ ]*)(?P<targety>[\d]+)$")
monsterRe = re.compile("^(?P<map>[^/](.+))[.]gat,([ ]*)(?P<x>[\d]+),([ ]*)(?P<y>[\d]+),([ ]*)(?P<xs>[\d-]+),(?P<ys>[\d-]+)[|]"
"(?P<tag>monster)[|](?P<name>[\w#' ]+)[|]"
"(?P<class>[\d]+),(?P<num>[\d]+),(?P<delay1>[\d]+)ms,(?P<delay2>[\d]+)ms(|,(?P<label>[\w+-:#]+))$")
setRe = re.compile("^(?P<space>[ ]+)set[ ](?P<var>[^,]+),([ ]*)(?P<val>[^;]+);$");
class ScriptTracker:
pass
def createMainScript():
with open(npcMainScript, "w") as w:
w.write("npc: npc/functions/main.txt\n")
w.write("import: npc/scripts.conf\n")
def convertNpcs(items):
processNpcDir("oldserverdata/npc/", "newserverdata/npc/", items)
def processNpcDir(srcDir, dstDir, items):
makeDir(dstDir)
files = os.listdir(srcDir)
for file1 in files:
if file1[0] == '.':
continue
srcPath = os.path.abspath(srcDir + os.path.sep + file1)
dstPath = os.path.abspath(dstDir + os.path.sep + file1)
if not os.path.isfile(srcPath):
processNpcDir(srcPath, dstPath, items)
else:
if file1[-5:] == ".conf" or file1[-4:] == ".txt":
processNpcFile(srcPath, dstPath, items)
def processNpcFile(srcFile, dstFile, items):
# print "file: " + srcFile
tracker = ScriptTracker()
tracker.insideScript = False
tracker.items = items
with open(srcFile, "r") as r:
with open(dstFile, "w") as w:
tracker.w = w
for line in r:
tracker.line = line
res = convertTextLine(tracker)
if res:
w.write(tracker.line)
def convertTextLine(tracker):
line = tracker.line
if line[:5] == "map: ":
processScriptMapLine(line)
return False
if len(line) >= 2 and line[0:2] == "//":
return False
idx = line.find("|script|")
if idx >= 0:
processScript(tracker)
return False
idx = line.find("|shop|")
if idx >= 0:
processShop(tracker)
return False
idx = line.find("|monster|")
if idx >= 0:
processMonster(tracker)
return False
idx = line.find("|warp|")
if idx >= 0:
processWarp(tracker)
return False
idx = line.find("|mapflag|")
if idx >= 0:
processMapFlag(tracker)
return False
processStrReplace(tracker)
return False
def processScriptMapLine(line):
global mapsIndex
line = stripNewLine(line)
if line[-4:] == ".gat":
line = line[:-4]
with open(mapsConfFile, "a") as w:
w.write(line + "\n")
with open(mapsIndexFile, "a") as w:
w.write("{0} {1}\n".format(line[5:], mapsIndex))
mapsIndex = mapsIndex + 1
def writeScript(w, m):
try:
if m.group("function") != None:
isFunction = True
else:
isFunction = False
except:
isFunction = False
if isFunction:
w.write("function");
elif m.group("x") == None or (m.group("x") == 0 and m.group("y") == 0): # float npc
w.write("-")
else:
w.write("{0},{1},{2},{3}".format(m.group("map"), m.group("x"), m.group("y"), m.group("dir")))
if isFunction:
funcName = m.group("name")
if funcName == "DailyQuestPoints":
funcName = "DailyQuestPointsFunc"
w.write("\t{0}\t{1}\t".format(m.group("tag"), funcName));
else:
class_ = m.group("class")
if class_ == "0": # hidden npc
class_ = "32767"
else:
class_ = int(class_)
# if class_ > 125 and class_ <= 400:
# class_ = class_ + 100
w.write("\t{0}\t{1}\t{2}".format(m.group("tag"), m.group("name"), class_));
def processScript(tracker):
line = tracker.line[:-1]
w = tracker.w
m = scriptRe.search(line)
if m == None:
print "error in parsing: " + line
w.write("!!!error parsing line")
w.write(line)
return
# print "source=" + line
# print "map={0} x={1} y={2} dir={3} tag={4} name={5} class={6}, xs={7}, ys={8}".format(
# m.group("map"), m.group("x"), m.group("y"), m.group("dir"),
# m.group("tag"), m.group("name"), m.group("class"), m.group("xs"), m.group("ys"))
try:
if m.group("function") != None:
isFunction = True
else:
isFunction = False
except:
isFunction = False
writeScript(w, m)
if m.group("xs") != None:
w.write(",{0},{1}".format(m.group("xs"), m.group("ys")));
if isFunction == False:
w.write(",{\n");
else:
w.write("{\n");
def itemsToShop(tracker, itemsStr):
itemsSplit = re.compile(",")
itemsSplit2 = re.compile(":")
itemsDict = tracker.items
outStr = ""
items = itemsSplit.split(itemsStr)
for str2 in items:
parts = itemsSplit2.split(str2)
if parts[1][0] == "*":
parts[1] = parts[1][1:]
if outStr != "":
outStr = outStr + ","
outStr = outStr + itemsDict[parts[0].strip()] + ":" + parts[1]
return outStr
def processShop(tracker):
line = tracker.line
w = tracker.w
m = shopRe.search(line)
if m == None:
print "error in parsing: " + line
w.write("!!!error parsing line")
w.write(line)
return
# print "source=" + line[:-1]
# print "map={0} x={1} y={2} dir={3} tag={4} name={5} class={6} items={7}".format(
# m.group("map"), m.group("x"), m.group("y"), m.group("dir"),
# m.group("tag"), m.group("name"), m.group("class"), m.group("items"))
writeScript(w, m)
w.write("," + itemsToShop(tracker, m.group("items")) + "\n")
def processMapFlag(tracker):
line = tracker.line
w = tracker.w
m = mapFlagRe.search(line)
if m == None:
print "error in parsing: " + line
w.write("!!!error parsing line")
w.write(line)
return
# print "source=" + line[:-1]
# print "map={0} tag={1} name={2} flag={3}".format(
# m.group("map"), m.group("tag"), m.group("name"), m.group("flag"))
if m.group("name") == "town" or m.group("name") == "resave":
w.write("//")
w.write("{0}\t{1}\t{2}".format(m.group("map"), m.group("tag"), m.group("name")))
if m.group("flag") == None:
w.write("\n")
else:
w.write("\t{0}\n".format(m.group("flag")))
def processWarp(tracker):
line = tracker.line
w = tracker.w
m = warpRe.search(line)
if m == None:
print "error in parsing: " + line
w.write("!!!error parsing line")
w.write(line)
return
# print "source=" + line[:-1]
# print "map={0} xy={1},{2} tag={3} name={4} xs={5} ys={6} target: map={7} xy={8},{9}".format(
# m.group("map"), m.group("x"), m.group("y"), m.group("tag"), m.group("name"), m.group("xs"), m.group("ys"), m.group("targetmap"), m.group("targetx"), m.group("targety"))
xs = int(m.group("xs"))
ys = int(m.group("ys"))
if xs < 0:
xs = 0
if ys < 0:
ys = 0
w.write("{0},{1},{2},{3}\t{4}\t{5}\t{6},{7},{8},{9},{10}\n".format(
m.group("map"), m.group("x"), m.group("y"), "0", m.group("tag"), m.group("name"),
xs, ys, m.group("targetmap"), m.group("targetx"), m.group("targety")))
def processMonster(tracker):
line = tracker.line
w = tracker.w
m = monsterRe.search(line)
if m == None:
print "error in parsing: " + line
w.write("!!!error parsing line")
w.write(line)
return
# print "source=" + line[:-1]
# print ("map={0} xy={1},{2} xs={3} ys={4} tag={5} name={6} class={7} " +
# "num={8} delays={9},{10}, label={11}").format(
# m.group("map"), m.group("x"), m.group("y"), m.group("xs"), m.group("ys"),
# m.group("tag"), m.group("name"), m.group("class"),
# m.group("num"), m.group("delay1"), m.group("delay2"), m.group("label"))
if m.group("label") != None:
label = "," + m.group("label")
else:
label = ""
w.write("{0},{1},{2},{3},{4}\t{5}\t{6}\t{7},{8},{9},{10}{11}\n".format(m.group("map"),
m.group("x"), m.group("y"), m.group("xs"), m.group("ys"),
m.group("tag"), m.group("name"),
m.group("class"), m.group("num"), m.group("delay1"), m.group("delay2"), label))
def processStrReplace(tracker):
line = tracker.line
w = tracker.w
if line == "{\n":
return
line = line.replace("setskill ", "addtoskill ")
line = line.replace("zeny", "Zeny")
line = line.replace("sc_poison", "SC_POISON")
line = line.replace("sc_slowpoison", "SC_SLOWPOISON")
line = line.replace("countitem(", "countitemcolor(")
line = line.replace(".gat", "")
line = line.replace("Bugleg", "BugLeg")
line = line.replace("set BugLeg, 0;", "//set BugLeg, 0;")
line = line.replace("set CaveSnakeLamp, 0;", "//set CaveSnakeLamp, 0;")
line = line.replace("set Class, @BaseClass;", "//set Class, @BaseClass;")
line = line.replace("getmap()", "getmapname()")
line = line.replace("L_end", "L_End")
line = line.replace("gmcommand", "atcommand")
line = line.replace("MF_NOSAVE", "mf_nosave")
line = line.replace("S_update_var", "S_Update_Var")
line = line.replace("L_teach", "L_Teach")
line = line.replace("L_focus", "L_Focus")
line = line.replace("L_unfocus", "L_Unfocus")
line = line.replace("L_main", "L_Main")
line = line.replace("L_next", "L_Next")
line = line.replace("L_close", "L_Close")
# fix at same time usage with same name function and variable
line = line.replace("\"DailyQuestPoints\"", "\"DailyQuestPointsFunc\"")
idx = line.find("getmapmobs(")
if idx >= 0:
idx2 = line.find("\"", idx + len("getmapmobs(") + 1)
idx3 = line.find(")", idx + len("getmapmobs(") + 1)
if idx2 + 1 == idx3:
line = line[:idx2 + 1] + ",\"all\"" + line[idx2 + 1:]
line = line.replace("getmapmobs(", "mobcount(")
m = setRe.search(line);
if m != None:
line = "{0}{1} = {2};\n".format(m.group("space"), m.group("var"), m.group("val"))
w.write(line)
|