From 8c0b57568736abfe5c1d4410ffa64e845881fe71 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 3 Sep 2014 16:15:51 +0300 Subject: hercules: add ability to convert quests db into quests.xml --- hercules/maptool.py | 41 +++++++++++++++++++++++++++++++++++++++++ hercules/queststoxml.py | 1 + hercules/templates/quest.tpl | 5 +++++ hercules/templates/quests.xml | 6 ++++++ 4 files changed, 53 insertions(+) create mode 120000 hercules/queststoxml.py create mode 100644 hercules/templates/quest.tpl create mode 100644 hercules/templates/quests.xml diff --git a/hercules/maptool.py b/hercules/maptool.py index 51ff750..ef7fec3 100755 --- a/hercules/maptool.py +++ b/hercules/maptool.py @@ -26,6 +26,8 @@ def detectCommand(): return "extractmaps" elif sys.argv[0][-13:] == "/mapstotmx.py": return "mapstotmx" + elif sys.argv[0][-15:] == "/queststoxml.py": + return "queststoxml" return "help" def makeDir(path): @@ -79,6 +81,13 @@ def saveFile(fileName, data): with open(fileName, "w") as w: w.write(data) +def stripQuotes(data): + if data[-1] == "\"": + data = data[:-1] + if data[0] == "\"": + data = data[1:] + return data + def printHelp(): print "Unknown options selected." print "" @@ -150,9 +159,41 @@ def covertToTmx(f, mapsCount): collision = collision + "\n" saveFile(mapsDir + name + ".tmx", tmx.format(sx, sy, ground, collision, fringe)) +def covertQuests(): + destDir = "clientdata/" + templatesDir = "templates/" + questsDbFile = "serverdata/db/quest_db.txt" + fieldsSplit = re.compile(",") + makeDir(destDir) + tpl = readFile(templatesDir + "quest.tpl") + quests = readFile(templatesDir + "quests.xml") + data = "" + with open(questsDbFile, "r") as f: + for line in f: + if line == "" or line[0:2] == "//": + continue + rows = fieldsSplit.split(line) + if len(rows) < 9: + continue + questId = rows[0] + text = rows[8] + if text[-1] == "\n": + text = text[:-1] + text = stripQuotes(text) + name = text + if len(name) > 20: + name = name[:19] + + data = data + tpl.format(questId, name, text + ": " + str(questId)) + saveFile(destDir + "quests.xml", quests.format(data)) + def readMapCache(path, cmd): if cmd == "help": printHelp() + if cmd == "queststoxml": + covertQuests() + return + with open(path, "rb") as f: size = readInt32(f) if os.path.getsize(path) != size: diff --git a/hercules/queststoxml.py b/hercules/queststoxml.py new file mode 120000 index 0000000..df2b3e6 --- /dev/null +++ b/hercules/queststoxml.py @@ -0,0 +1 @@ +maptool.py \ No newline at end of file diff --git a/hercules/templates/quest.tpl b/hercules/templates/quest.tpl new file mode 100644 index 0000000..25615f9 --- /dev/null +++ b/hercules/templates/quest.tpl @@ -0,0 +1,5 @@ + + + {2} + + diff --git a/hercules/templates/quests.xml b/hercules/templates/quests.xml new file mode 100644 index 0000000..c2828f9 --- /dev/null +++ b/hercules/templates/quests.xml @@ -0,0 +1,6 @@ + + + +{0} + -- cgit v1.2.3-60-g2f50