From 7ee8060460c63f0f4aaae338c99686f38edff2a0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 29 Dec 2014 12:02:21 +0300 Subject: hercules: start adding support for conversion from tmwa data. --- hercules/code/server/evol/__init__.py | 0 hercules/code/server/evol/itemdb.py | 105 ++++++++++++++++++++++++++++++++++ hercules/code/server/evol/main.py | 24 ++++++++ hercules/code/server/itemdb.py | 105 ---------------------------------- hercules/code/server/tmw/__init__.py | 0 hercules/code/server/tmw/itemdb.py | 93 ++++++++++++++++++++++++++++++ hercules/code/server/tmw/main.py | 24 ++++++++ hercules/code/serverutils.py | 12 ++++ hercules/convert_server.py | 23 +++----- 9 files changed, 266 insertions(+), 120 deletions(-) create mode 100644 hercules/code/server/evol/__init__.py create mode 100644 hercules/code/server/evol/itemdb.py create mode 100644 hercules/code/server/evol/main.py delete mode 100644 hercules/code/server/itemdb.py create mode 100644 hercules/code/server/tmw/__init__.py create mode 100644 hercules/code/server/tmw/itemdb.py create mode 100644 hercules/code/server/tmw/main.py create mode 100644 hercules/code/serverutils.py diff --git a/hercules/code/server/evol/__init__.py b/hercules/code/server/evol/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hercules/code/server/evol/itemdb.py b/hercules/code/server/evol/itemdb.py new file mode 100644 index 0000000..b86b848 --- /dev/null +++ b/hercules/code/server/evol/itemdb.py @@ -0,0 +1,105 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.configutils import * +from code.fileutils import * +from code.stringutils import * + +def convertItemDb(): + srcFile = "oldserverdata/db/item_db.txt" + dstFile = "newserverdata/db/re/item_db.conf" + constsFile = "newserverdata/db/const.txt" + fieldsSplit = re.compile(",") + scriptsSplit = re.compile("{") + items = dict() + with open(srcFile, "r") as r: + with open(dstFile, "w") as w: + with open(constsFile, "a") as c: + c.write("// items\n"); + tpl = readFile("templates/item_db.tpl") + w.write(tpl) + for line in r: + if len(line) < 2 or line[0] == "#" or line[0:2] == "//": + continue + rows = fieldsSplit.split(line) + if len(rows) < 5 or rows[0] == "0": + continue + + sz = len(rows) + if sz > 19: + sz = 19 + for f in xrange(0, sz): + rows[f] = rows[f].strip() + if rows[4] == "2": + rows[4] = "0" + rows[3] = str(int(rows[3]) | 4) + + items[rows[1]] = rows[0] + w.write("{\n") + c.write("{0}\t{1}\n".format(rows[1], rows[0])) + writeIntField(w, "Id", rows[0]) + writeStrField(w, "AegisName", rows[1]) + writeStrField(w, "Name", rows[2]) + writeIntField(w, "Type", rows[4]) + writeIntField(w, "Buy", rows[5]) + writeIntField(w, "Sell", rows[6]) + writeIntField(w, "Weight", rows[7]) + writeIntField(w, "Atk", rows[8]) + writeIntField(w, "Matk", "0") + writeIntField(w, "Def", rows[9]) + writeIntField(w, "Range", rows[10]) + writeIntField(w, "Slots", "0") + writeIntField(w, "Job", "0xFFFFFFFF") + writeIntField(w, "Upper", "0x3F") + writeIntField(w, "Gender", rows[13]) + writeIntField(w, "Loc", rows[14]) + writeIntField(w, "WeaponLv", rows[15]) + writeIntField(w, "EquipLv", rows[16]) + writeIntField(w, "Refine", "false") + if rows[14] == "2": + writeIntField(w, "View", "1") + else: + writeIntField(w, "View", rows[0]) + writeIntField(w, "BindOnEquip", "false") + writeIntField(w, "BuyingStore", "false") + writeIntField(w, "Delay", "0") + trade = int(rows[3]) + if trade != 0: + writeStartBlock(w, "Trade") + if trade & 1 == 1: + writeSubField(w, "nodrop", "true") + if trade & 2 == 2: + writeSubField(w, "notrade", "true") + if trade & 4 == 4: + writeSubField(w, "nodelonuse", "true") + if trade & 8 == 8: + writeSubField(w, "nostorage", "true") + if trade & 256 == 256: + writeSubField(w, "nogstorage", "true") + if trade & 512 == 512: + writeSubField(w, "noselltonpc", "true") + if trade != 0: + writeEndBlock(w) + writeIntField(w, "Sprite", "0") + + scripts = "" + for f in xrange(sz, len(rows)): + scripts = scripts + ", " + rows[f] + rows = scriptsSplit.split(scripts) + cnt = len(rows) + if cnt > 1: + text = rows[1].strip() + if len(text) > 1: + text = text[:-2] + if text != "": + writeStartScript(w, "Script") + w.write(" {0}\n".format(text)) + writeEndScript(w) + + w.write("},\n") + w.write(")\n") + return items diff --git a/hercules/code/server/evol/main.py b/hercules/code/server/evol/main.py new file mode 100644 index 0000000..8919c76 --- /dev/null +++ b/hercules/code/server/evol/main.py @@ -0,0 +1,24 @@ +#! /usr/bin/env python +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +from code.server.consts import * +from code.server.evol.itemdb import * +from code.server.mobdb import * +from code.server.mobskilldb import * +from code.server.npcs import * +from code.server.utils import * +from code.server.questsdb import * +from code.serverutils import * + +def serverEvolMain(): + cleanServerData() + createMainScript() + items = convertItemDb() + convertNpcs(items) + convertMobDb() + quests = convertQuestsDb() + convertConsts(quests) + convertMobSkillDb() diff --git a/hercules/code/server/itemdb.py b/hercules/code/server/itemdb.py deleted file mode 100644 index b86b848..0000000 --- a/hercules/code/server/itemdb.py +++ /dev/null @@ -1,105 +0,0 @@ -# -*- coding: utf8 -*- -# -# Copyright (C) 2014 Evol Online -# Author: Andrei Karas (4144) - -import re - -from code.configutils import * -from code.fileutils import * -from code.stringutils import * - -def convertItemDb(): - srcFile = "oldserverdata/db/item_db.txt" - dstFile = "newserverdata/db/re/item_db.conf" - constsFile = "newserverdata/db/const.txt" - fieldsSplit = re.compile(",") - scriptsSplit = re.compile("{") - items = dict() - with open(srcFile, "r") as r: - with open(dstFile, "w") as w: - with open(constsFile, "a") as c: - c.write("// items\n"); - tpl = readFile("templates/item_db.tpl") - w.write(tpl) - for line in r: - if len(line) < 2 or line[0] == "#" or line[0:2] == "//": - continue - rows = fieldsSplit.split(line) - if len(rows) < 5 or rows[0] == "0": - continue - - sz = len(rows) - if sz > 19: - sz = 19 - for f in xrange(0, sz): - rows[f] = rows[f].strip() - if rows[4] == "2": - rows[4] = "0" - rows[3] = str(int(rows[3]) | 4) - - items[rows[1]] = rows[0] - w.write("{\n") - c.write("{0}\t{1}\n".format(rows[1], rows[0])) - writeIntField(w, "Id", rows[0]) - writeStrField(w, "AegisName", rows[1]) - writeStrField(w, "Name", rows[2]) - writeIntField(w, "Type", rows[4]) - writeIntField(w, "Buy", rows[5]) - writeIntField(w, "Sell", rows[6]) - writeIntField(w, "Weight", rows[7]) - writeIntField(w, "Atk", rows[8]) - writeIntField(w, "Matk", "0") - writeIntField(w, "Def", rows[9]) - writeIntField(w, "Range", rows[10]) - writeIntField(w, "Slots", "0") - writeIntField(w, "Job", "0xFFFFFFFF") - writeIntField(w, "Upper", "0x3F") - writeIntField(w, "Gender", rows[13]) - writeIntField(w, "Loc", rows[14]) - writeIntField(w, "WeaponLv", rows[15]) - writeIntField(w, "EquipLv", rows[16]) - writeIntField(w, "Refine", "false") - if rows[14] == "2": - writeIntField(w, "View", "1") - else: - writeIntField(w, "View", rows[0]) - writeIntField(w, "BindOnEquip", "false") - writeIntField(w, "BuyingStore", "false") - writeIntField(w, "Delay", "0") - trade = int(rows[3]) - if trade != 0: - writeStartBlock(w, "Trade") - if trade & 1 == 1: - writeSubField(w, "nodrop", "true") - if trade & 2 == 2: - writeSubField(w, "notrade", "true") - if trade & 4 == 4: - writeSubField(w, "nodelonuse", "true") - if trade & 8 == 8: - writeSubField(w, "nostorage", "true") - if trade & 256 == 256: - writeSubField(w, "nogstorage", "true") - if trade & 512 == 512: - writeSubField(w, "noselltonpc", "true") - if trade != 0: - writeEndBlock(w) - writeIntField(w, "Sprite", "0") - - scripts = "" - for f in xrange(sz, len(rows)): - scripts = scripts + ", " + rows[f] - rows = scriptsSplit.split(scripts) - cnt = len(rows) - if cnt > 1: - text = rows[1].strip() - if len(text) > 1: - text = text[:-2] - if text != "": - writeStartScript(w, "Script") - w.write(" {0}\n".format(text)) - writeEndScript(w) - - w.write("},\n") - w.write(")\n") - return items diff --git a/hercules/code/server/tmw/__init__.py b/hercules/code/server/tmw/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hercules/code/server/tmw/itemdb.py b/hercules/code/server/tmw/itemdb.py new file mode 100644 index 0000000..58e8d97 --- /dev/null +++ b/hercules/code/server/tmw/itemdb.py @@ -0,0 +1,93 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import re + +from code.configutils import * +from code.fileutils import * +from code.stringutils import * + +def getItemDbFile(srcDir): + files = os.listdir(srcDir) + for srcFile in files: + if srcFile.find("item_db.txt") >= 0: + yield srcFile + +def convertItemDb(): + srcDir = "oldserverdata/db/" + dstFile = "newserverdata/db/re/item_db.conf" + constsFile = "newserverdata/db/const.txt" + fieldsSplit = re.compile(",") + scriptsSplit = re.compile("{") + items = dict() + + tpl = readFile("templates/item_db.tpl") + with open(dstFile, "w") as w: + with open(constsFile, "a") as c: + for srcFile in getItemDbFile(srcDir): + with open(srcDir + srcFile, "r") as r: + c.write("// items\n"); + w.write(tpl) + for line in r: + if len(line) < 2 or line[0] == "#" or line[0:2] == "//": + continue + rows = fieldsSplit.split(line) + if len(rows) < 5 or rows[0] == "0": + continue + + sz = len(rows) + if sz > 19: + sz = 19 + for f in xrange(0, sz): + rows[f] = rows[f].strip() + + items[rows[1]] = rows[0] + w.write("{\n") + c.write("{0}\t{1}\n".format(rows[1], rows[0])) + writeIntField(w, "Id", rows[0]) + writeStrField(w, "AegisName", rows[1]) + writeStrField(w, "Name", rows[2]) + writeIntField(w, "Type", rows[3]) + writeIntField(w, "Buy", rows[4]) + writeIntField(w, "Sell", rows[5]) + writeIntField(w, "Weight", rows[6]) + writeIntField(w, "Atk", rows[7]) + writeIntField(w, "Matk", "0") + writeIntField(w, "Def", rows[8]) + writeIntField(w, "Range", rows[9]) + writeIntField(w, "Slots", "0") + writeIntField(w, "Job", "0xFFFFFFFF") + writeIntField(w, "Upper", "0x3F") + writeIntField(w, "Gender", rows[12]) + writeIntField(w, "Loc", rows[13]) + writeIntField(w, "WeaponLv", rows[14]) + writeIntField(w, "EquipLv", rows[15]) + writeIntField(w, "Refine", "false") + if rows[14] == "2": + writeIntField(w, "View", "1") + else: + writeIntField(w, "View", rows[0]) + writeIntField(w, "BindOnEquip", "false") + writeIntField(w, "BuyingStore", "false") + writeIntField(w, "Delay", "0") + writeIntField(w, "Sprite", "0") + + scripts = "" + for f in xrange(sz, len(rows)): + scripts = scripts + ", " + rows[f] + rows = scriptsSplit.split(scripts) + cnt = len(rows) + if cnt > 1: + text = rows[1].strip() + if len(text) > 1: + text = text[:-2] + if text != "": + writeStartScript(w, "Script") + w.write(" {0}\n".format(text)) + writeEndScript(w) + + w.write("},\n") + w.write(")\n") + return items diff --git a/hercules/code/server/tmw/main.py b/hercules/code/server/tmw/main.py new file mode 100644 index 0000000..bd4f5eb --- /dev/null +++ b/hercules/code/server/tmw/main.py @@ -0,0 +1,24 @@ +#! /usr/bin/env python +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +from code.server.consts import * +from code.server.tmw.itemdb import * +from code.server.mobdb import * +from code.server.mobskilldb import * +from code.server.npcs import * +from code.server.utils import * +from code.server.questsdb import * +from code.serverutils import * + +def serverTmwMain(): + cleanServerData() + createMainScript() + items = convertItemDb() + #convertNpcs(items) + #convertMobDb() + #quests = convertQuestsDb() + #convertConsts(quests) + #convertMobSkillDb() diff --git a/hercules/code/serverutils.py b/hercules/code/serverutils.py new file mode 100644 index 0000000..c377bd7 --- /dev/null +++ b/hercules/code/serverutils.py @@ -0,0 +1,12 @@ +# -*- coding: utf8 -*- +# +# Copyright (C) 2014 Evol Online +# Author: Andrei Karas (4144) + +import os + +def detectServerType(): + if os.path.exists("oldserverdata/news.d"): + return "tmw" + else: + return "evol" diff --git a/hercules/convert_server.py b/hercules/convert_server.py index 4cbaa89..f323b4e 100755 --- a/hercules/convert_server.py +++ b/hercules/convert_server.py @@ -4,19 +4,12 @@ # Copyright (C) 2014 Evol Online # Author: Andrei Karas (4144) -from code.server.consts import * -from code.server.itemdb import * -from code.server.mobdb import * -from code.server.mobskilldb import * -from code.server.npcs import * -from code.server.utils import * -from code.server.questsdb import * +from code.serverutils import * +from code.server.evol.main import * +from code.server.tmw.main import * -cleanServerData() -createMainScript() -items = convertItemDb() -convertNpcs(items) -convertMobDb() -quests = convertQuestsDb() -convertConsts(quests) -convertMobSkillDb() +serverType = detectServerType() +if serverType == "evol": + serverEvolMain(); +else: + serverTmwMain(); -- cgit v1.2.3-70-g09d2