#!/usr/bin/python3
# This consolidates server databases
import os, traceback
MYSELF="serverdata/"
EVOLVED="../pre-renewal/server-data/"
MOUBOO="../server-data/"
REVOLT="../evol/server-data/"
# Rewrite db/re/item_db.conf
# Pets? Can't be carried over :< Homunculus? Same :<
# Skills? Eugh.
os.chdir("..")
item_db=[]
def parse(l, offset, prefix):
# Disabled commands
l=l.replace('statusup2', '//statusup2')
# Parsing block
if "\tId:" in l:
tmp=l.split("Id:")
try:
tmp[1]=str(int(tmp[1]) + offset)
except ValueError:
print("%s invalid ID" % repr(tmp[1]))
except:
traceback.print_exc()
tmp[1]=str(offset*2-1)
l="Id: ".join(tmp).replace(" ", " ")
l+="\n"
elif "\tAegisName:" in l:
tmp=l.split("\"")
tmp[1]="%s_%s" % (prefix, tmp[1])
l="\"".join(tmp)
elif "\tName:" in l:
tmp=l.split("\"")
tmp[1]="%s %s" % (prefix, tmp[1])
l="\"".join(tmp)
elif "Sprite:" in l:
tmp=l.split("Sprite:")
try:
assert int(tmp[1]) > 1
tmp[1]=str(int(tmp[1]) + offset)
except ValueError:
print("%s invalid Sprite" % repr(tmp[1]))
except AssertionError:
pass
except:
traceback.print_exc()
tmp[1]=str(offset*2-1)
l="Sprite: ".join(tmp).replace(" ", " ")
l+="\n"
return l
#################################################################################
## Moubootaur Legends is a raw copy (prefix = 0)
with open("%s/db/re/item_db.conf" % MOUBOO, "r") as f:
skip = False
for l in f:
#l=l.replace(" ", "\t")
## Disabled commands (statusup2, AllowCards)
l=l.replace('statusup2', '//statusup2')
if skip and not "}" in l:
continue
elif skip and "}" in l:
skip=False
continue
elif not skip and "AllowCards" in l:
skip=True
continue
## Add headers
if "== License ==" in l:
item_db.append("//=========================================================================\n")
item_db.append("// This file is generated automatically.\n")
item_db.append("// Please do not edit it directly.\n")
## Save the line
item_db.append(l)
while not ")" in item_db[-1]:
item_db=item_db[:-1]
item_db=item_db[:-1]
print("\033[32;1mMoubootaur Legends OK\033[0m")
## Legacy/Evolved has an offset of 10k
with open("%s/db/pre-re/item_db.conf" % EVOLVED, "r") as f:
for l in f:
l=l.replace(" ", "\t")
if "item_db:" in l:
continue
l=parse(l, 10000, "L")
##############################
## Recalc Stats
if "\tAtk:" in l:
tmp=l.split(":")
try:
tmp[1]=str(min(int(int(tmp[1]) * 1.1), 999))
except ValueError:
print("%s invalid ATK" % repr(tmp[1]))
except:
traceback.print_exc()
l=": ".join(tmp)
l+="\n"
if "\tDef:" in l:
tmp=l.split(":")
try:
tmp[1]=str(min(int(int(tmp[1]) * 1.1), 100))
except ValueError:
print("%s invalid DEF" % repr(tmp[1]))
except:
traceback.print_exc()
l=": ".join(tmp)
l+="\n"
## TODO: ATKSpd
##############################
item_db.append(l)
while not ")" in item_db[-1]:
item_db=item_db[:-1]
item_db=item_db[:-1]
print("\033[32;1mLegacy/Evolved OK\033[0m")
## rEvolt has an offset of 20k
with open("%s/db/re/item_db.conf" % REVOLT, "r") as f:
for l in f:
l=l.replace(" ", "\t")
if "item_db:" in l:
continue
l=parse(l, 20000, "R")
item_db.append(l)
while not ")" in item_db[-1]:
item_db=item_db[:-1]
#item_db=item_db[:-1]
print("\033[32;1mrEvolt OK\033[0m")
## Save the final item database
with open(MYSELF+"db/re/item_db.conf", "w") as f:
for l in item_db:
f.write(l)
print("\033[33;1mSaved! Databases merged!\033[0m")