def WriteDatabase(mode, serverpath): MobDB = Tools.LoadDBConsts('mob_db', mode, serverpath) for k, v in old_databases.items(): print(f'{MOBG_NAME[k]}: (') for i in v: print(f'\t("{MobDB[i]}", {v[i]}),') print(')')
def ConvertDB(mode, serverpath): db = LoadOldDB(mode, serverpath) MobDB = Tools.LoadDBConsts('mob_db', mode, serverpath) SkillDB = Tools.LoadDBConsts('skill_db', mode, serverpath) printHeader() for mobid in sorted(db.iterkeys()): print('\t{}: {{'.format(MobDB[int(mobid)])) for skillidx in sorted(db[mobid].iterkeys()): valid = True if int(db[mobid][skillidx]['SkillId']) not in SkillDB: valid = False print('/*') print('// Can\'t find skill with id {} in skill_db'.format( db[mobid][skillidx]['SkillId'])) print('\t\t{}: {{'.format(db[mobid][skillidx]['SkillId'])) else: print('\t\t{}: {{'.format(SkillDB[int( db[mobid][skillidx]['SkillId'])])) printClearSkills('ClearSkills', db[mobid][skillidx]) printSkillState('SkillState', db[mobid][skillidx]) printStrToInt('SkillLevel', db[mobid][skillidx]) printStrToInt('Rate', db[mobid][skillidx]) printStrToInt('CastTime', db[mobid][skillidx]) printStrToInt('Delay', db[mobid][skillidx]) printBool('Cancelable', db[mobid][skillidx]) printSkillTarget('SkillTarget', db[mobid][skillidx]) printCastCondition('CastCondition', db[mobid][skillidx]) printConditionData('ConditionData', db[mobid][skillidx]) for i in range(5): printInt('val{}'.format(i), db[mobid][skillidx]) printEmotion('Emotion', db[mobid][skillidx]) printStrToInt('ChatMsgID', db[mobid][skillidx]) print('\t\t}') if valid is False: print('*/') print('\t}') printFooter()
def ConvertDB(luaName, mode, serverpath): ItemDB = Tools.LoadDBConsts('item_db', mode, serverpath) f = open(luaName) content = f.read() f.close() recipeDB = re.findall(r'InsertEvolutionRecipeLGU\((\d+),\s*(\d+),\s*(\d+),\s*(\d+)\)', content) autoFeedDB = re.findall(r'InsertPetAutoFeeding\((\d+)\)', content) current = 0 entry = dict() EvolveDB = dict() printHeader() for recipe in recipeDB: fromEgg = getItemConstant(entry, ItemDB, int(recipe[0])) petEgg = getItemConstant(entry, ItemDB, int(recipe[1])) if (current == 0): entry = { 'Id': petEgg, 'from': fromEgg, 'items': list() } current = petEgg if (current != petEgg): EvolveDB = saveEntry(EvolveDB, entry) entry = { 'Id': petEgg, 'from': fromEgg, 'items': list() } entry['id'] = petEgg entry['items'] = list() current = petEgg itemConst = getItemConstant(entry, ItemDB, int(recipe[2])) quantity = int(recipe[3]) entry['items'].append((itemConst, quantity)) saveEntry(EvolveDB, entry) printEntry(ItemDB, EvolveDB, autoFeedDB, entry, mode, serverpath) print(')')
def ConvertFile(args): print( r'''//================= Hercules Database ===================================== //= _ _ _ //= | | | | | | //= | |_| | ___ _ __ ___ _ _| | ___ ___ //= | _ |/ _ \ '__/ __| | | | |/ _ \/ __| //= | | | | __/ | | (__| |_| | | __/\__ \ //= \_| |_/\___|_| \___|\__,_|_|\___||___/ //================= License =============================================== //= This file is part of Hercules. //= http://herc.ws - http://github.com/HerculesWS/Hercules //= //= Copyright (C) 2019-2022 Hercules Dev Team //= //= Hercules is free software: you can redistribute it and/or modify //= it under the terms of the GNU General Public License as published by //= the Free Software Foundation, either version 3 of the License, or //= (at your option) any later version. //= //= This program is distributed in the hope that it will be useful, //= but WITHOUT ANY WARRANTY; without even the implied warranty of //= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //= GNU General Public License for more details. //= //= You should have received a copy of the GNU General Public License //= along with this program. If not, see <http://www.gnu.org/licenses/>. //================= Description =========================================== // Configurations file for status effects //========================================================================= combo_db: ( /************************************************************************** ************* Entry structure ******************************************** ************************************************************************** { // ================ Mandatory fields =============================== Items: ["item_list"] (string, array) list of items Script: <" Script (it can be multi-line) "> } **************************************************************************/''') ItemDB = Tools.LoadDBConsts('item_db', f'{args.mode}', '../') with open(f'../db/{args.mode}/item_combo_db.txt') as dbfile: line = 0 for entry in dbfile: line = line + 1 if not entry.strip() or entry.startswith('//'): continue m = re.search(r'(^[0-9:]+),\{(.*)\}$', entry) if not m: print( f'Error: Invalid pattern in entry {entry}, line {line}, aborting..' ) exit() items_list = m.group(1).split(':') script = m.group(2) for item in range(len(items_list)): if int(items_list[item]) not in ItemDB: print( f'Error: invalid item {item} found in line {line}, aborting..' ) exit() items_list[item] = ItemDB[int(items_list[item])] if args.enable_jsbeautifier: import jsbeautifier opts = jsbeautifier.default_options() opts.indent_with_tabs = True opts.indent_level = 2 script = jsbeautifier.beautify(script, opts) print(f'''{{ Items: {json.dumps(items_list)} Script: <"\n{script}\n\t"> }},''') print(')')