diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-11-01 12:43:26 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-11-01 12:43:26 +0300 |
commit | 2c1e16bd1e47dcaf33ad16367bc44b47a4ffa0b8 (patch) | |
tree | a2290db5f76d961a18b47e4884c2eb742c932926 | |
parent | be6e852a52610e5715a6cb87d606647e39a6b487 (diff) | |
download | evol-tools-2c1e16bd1e47dcaf33ad16367bc44b47a4ffa0b8.tar.gz evol-tools-2c1e16bd1e47dcaf33ad16367bc44b47a4ffa0b8.tar.bz2 evol-tools-2c1e16bd1e47dcaf33ad16367bc44b47a4ffa0b8.tar.xz evol-tools-2c1e16bd1e47dcaf33ad16367bc44b47a4ffa0b8.zip |
hercules: add conversion for npc shops.
Also create initial script file.
-rw-r--r-- | hercules/code/server/npcs.py | 55 | ||||
-rw-r--r-- | hercules/code/server/utils.py | 1 | ||||
-rwxr-xr-x | hercules/convert_server.py | 1 |
3 files changed, 47 insertions, 10 deletions
diff --git a/hercules/code/server/npcs.py b/hercules/code/server/npcs.py index 7157c31..a60ce81 100644 --- a/hercules/code/server/npcs.py +++ b/hercules/code/server/npcs.py @@ -10,14 +10,23 @@ 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<gender>[\d]+))" + "[\t](?P<tag>script)[\t](?P<name>[\w#' ]+)[\t]" "(?P<class>[\d]+)((,((?P<xs>[\d]+),(?P<ys>[\d]+)))|)(|;(?P<size>[\d]+))(|,|;){$") +shopRe = re.compile("^(?P<map>[^/](.+))[.]gat,([ ]*)(?P<x>[\d]+),([ ]*)(?P<y>[\d]+),([ ]*)(?P<dir>[\d]+)(|,(?P<gender>[\d]+))" + + "[\t](?P<tag>shop)[\t](?P<name>[\w#' ]+)[\t]" + "(?P<class>[\d]+),(?P<items>(.+))$") + class ScriptTracker: pass +def createMainScript(): + with open(npcMainScript, "w") as w: + w.write("import: npc/scripts.conf\n") + def convertNpcs(): processNpcDir("oldserverdata/npc/", "newserverdata/npc/") @@ -53,10 +62,15 @@ def convertTextLine(tracker): if line[:5] == "map: ": processScriptMapLine(line) return False + idx = line.find("\tscript\t") if idx >= 0: processScript(tracker) return False + idx = line.find("\tshop\t") + if idx >= 0: + processShop(tracker) + return False return True def processScriptMapLine(line): @@ -68,9 +82,19 @@ def processScriptMapLine(line): w.write(line + "\n") with open(mapsIndexFile, "a") as w: - w.write("{0} {1}\n".format(line, mapsIndex)) + w.write("{0} {1}\n".format(line[5:], mapsIndex)) mapsIndex = mapsIndex + 1 +def writeScript(w, m): + if m.group("gender") != None: + w.write("// Gender = {0}\n".format(m.group("gender"))); + + if m.group("x") == 0 and m.group("y") == 0 and m.group("class") == 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"))) + w.write("\t{0}\t{1}\t{2}".format(m.group("tag"), m.group("name"), m.group("class"))); + def processScript(tracker): line = tracker.line w = tracker.w @@ -89,17 +113,28 @@ def processScript(tracker): # m.group("map"), m.group("x"), m.group("y"), m.group("dir"), m.group("gender"), # m.group("tag"), m.group("name"), m.group("class"), m.group("xs"), m.group("ys"), m.group("size")) - if m.group("gender") != None: - w.write("// Gender = {0}\n".format(m.group("gender"))); if m.group("size") != None: w.write("// Size = {0}\n".format(m.group("size"))); - - if m.group("x") == 0 and m.group("y") == 0 and m.group("class") == 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"))) - w.write("\tscript\t{0}\t{1}".format(m.group("name"), m.group("class"))); - + writeScript(w, m) if m.group("xs") != None: w.write(",{0},{1}".format(m.group("xs"), m.group("ys"))); w.write(",{\n"); + + +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} gender={4} tag={5} name={6} class={7} items={8}".format( + m.group("map"), m.group("x"), m.group("y"), m.group("dir"), m.group("gender"), + m.group("tag"), m.group("name"), m.group("class"), m.group("items")) + + writeScript(w, m) + w.write("," + m.group("items") + "\n") diff --git a/hercules/code/server/utils.py b/hercules/code/server/utils.py index 922cf5b..c39aeeb 100644 --- a/hercules/code/server/utils.py +++ b/hercules/code/server/utils.py @@ -9,3 +9,4 @@ def cleanServerData(): removeAllFiles("newserverdata") makeDir("newserverdata/conf") makeDir("newserverdata/db") + makeDir("newserverdata/npc/re/") diff --git a/hercules/convert_server.py b/hercules/convert_server.py index 2902015..3965d37 100755 --- a/hercules/convert_server.py +++ b/hercules/convert_server.py @@ -8,4 +8,5 @@ from code.server.npcs import * from code.server.utils import * cleanServerData() +createMainScript() convertNpcs(); |