def special(text, region): path = files.get_path(region, 'special.sc') if region == 'ropru': codirovka = 'Windows-1251' else: codirovka = 'utf-8' pattern = r'^\s*item\s+(\S+)\s*' new_items = list() for line in text.splitlines(): if re.search(pattern, line): new_items.append(re.search(pattern, line).group(1)) old_lines = files.open_lines(path, codirovka) skip = False old_lines_fixed = list() for line in old_lines: if re.search(pattern, line): skip = False if re.search(pattern, line) is not None and re.search(pattern, line).group(1) in new_items: skip = True if skip == True: pass else: old_lines_fixed.append(line) old_text_fixed = '\n'.join(old_lines_fixed) begin = old_text_fixed.rsplit('return', 1)[0] + '\n\n' end = old_text_fixed.rsplit('return', 1)[1] new_text = begin + text.strip() + end files.write_text(new_text, path, codirovka, errors='ignore')
def PackageItem(text, region): path = files.get_path(region, 'PackageItem.lua') pattern = r'^\s*\[(.*)\]\s*=' new_items = list() for line in text.splitlines(): if re.search(pattern, line): name = re.search(pattern, line).group(1).replace('[[', '\"').replace(']]', '\"').strip().replace('\"', '') new_items.append(name) old_lines = files.open_lines(path) skip = False lines = list() for line in old_lines: if re.search(pattern, line): name = re.search(pattern, line).group(1).replace('[[', '\"').replace(']]', '\"').strip().replace('\"', '') skip = False if re.search(pattern, line) is not None and name in new_items: skip = True if 'function' in line: break elif skip == True: pass else: lines.append(line) old_text = '\n'.join(lines).rsplit('};', 1)[0] function_block = list() block_write = False for line in old_lines: if 'function' in line: block_write = True if block_write == True: function_block.append(line) function_block = '\n'.join(function_block).rsplit('};', 1)[0] new_text = old_text + text + '};\n\n\n' + function_block files.write_text(new_text, path)
def script_sql(text, region, date): path = files.get_path(region, 'script.sql') if region == 'ropru': path = path.replace('script.sql', date+'_script_prime.sql') elif region == 'ropeu': path = path.replace('script.sql', date+'_script_euprime.sql') elif region == 'roeu': path = path.replace('script.sql', date+'_script_chaos.sql') try: old_text = files.open_text(path) new_text = old_text.rstrip() + '\n\n' + text files.write_text(new_text, path) except FileNotFoundError: files.write_text(text, path) print('Прогнать SQL скрипт в базе данных? (да/нет)') choice = input('Выбор: ') if 'да' in choice.lower(): db.execute(text)
def ItemMoveInfoV(text, region, version=5): path = files.get_path(region, 'ItemMoveInfoV{}.txt'.format(version)) pattern = r'^\s*(\S+)\s*' new_items = list() for line in text.splitlines(): if re.search(pattern, line): new_items.append(re.search(pattern, line).group(1)) old_lines = files.open_lines(path) old_lines_fixed = list() for line in old_lines: if re.search(pattern, line) is not None and re.search(pattern, line).group(1) in new_items: pass else: old_lines_fixed.append(line) old_text_fixed = '\n'.join(old_lines_fixed) new_text = old_text_fixed + '\n' + text files.write_text(new_text, path)
def CashItemList(text, region): path = files.get_path(region, 'CashItemList.txt') pattern = r'^\s*("\S+")\s*' new_items = list() for line in text.splitlines(): if re.search(pattern, line): new_items.append(re.search(pattern, line).group(1)) old_lines = files.open_lines(path) old_lines_fixed = list() for line in old_lines: if re.search(pattern, line) is not None and re.search(pattern, line).group(1) in new_items: pass else: old_lines_fixed.append(line) old_text_fixed = '\n'.join(old_lines_fixed) new_text = old_text_fixed + '\n' + text files.write_text(new_text, path)
def combiItem(text, region): path = files.get_path(region, 'combiItem.sc') pattern = r'^\s*COMBIITEM(\S+)\s*' new_combiitems = list() for line in text.splitlines(): if re.search(pattern, line): new_combiitems.append(re.search(pattern, line).group(1)) old_lines = files.open_lines(path) skip = False old_lines_fixed = list() for line in old_lines: if re.search(pattern, line): skip = False if re.search(pattern, line) is not None and re.search(pattern, line).group(1) in new_combiitems: skip = True if skip == True: pass else: old_lines_fixed.append(line) old_text_fixed = '\n'.join(old_lines_fixed) new_text = old_text_fixed + '\n' + text files.write_text(new_text, path)
def main(sql=True, server=True, client=True): filenames = os.listdir() for filename in filenames: if '.xlsx' in filename: if sql == True: sql_script = create_sql(filename) files.write_text(sql_script, 'script.sql') if server == True: server_dict = create_server(filename) for key in server_dict.keys(): if key == 'special.sc': codirovka = 'Windows-1251' else: codirovka = 'UTF-8' files.write_text(server_dict[key], 'NEW_' + key, codirovka=codirovka) if client == True: client_dict = create_client(filename) for key in client_dict.keys(): if key == 'idnum2itemresnametable.txt' or key == 'num2itemresnametable.txt': codirovka = 'EUC-KR' else: codirovka = 'UTF-8' files.write_text(client_dict[key], 'NEW_' + key, codirovka=codirovka) break
def BuffSpecial(text, region): path = files.get_path(region, 'BuffSpecial.sc') pattern = r'^\s*Buff\s+(\S+)\s*' new_buffs = list() for line in text.splitlines(): if re.search(pattern, line): new_buffs.append(re.search(pattern, line).group(1)) old_lines = files.open_lines(path, codirovka='EUC-KR') skip = False old_lines_fixed = list() for line in old_lines: if re.search(pattern, line): skip = False if re.search(pattern, line) is not None and re.search(pattern, line).group(1) in new_buffs: skip = True if skip == True: pass else: old_lines_fixed.append(line) old_text_fixed = '\n'.join(old_lines_fixed) begin = old_text_fixed.rsplit('return', 1)[0] + '\n\n' end = old_text_fixed.rsplit('return', 1)[1] new_text = begin + text.strip() + end files.write_text(new_text, path, codirovka='EUC-KR')
print('1 - Шоп') print('2 - Лакибокс') choice = input('Выбор: ') print("\033[31mВыберите регион\033[0m:") print('1 - ropru') print('2 - ropeu') print('3 - roeu') region = input('Выбор: ') if region.strip() == '1': region = 'ropru' elif region.strip() == '2': region = 'ropeu' elif region.strip() == '3': region = 'roeu' if '1' in choice.strip(): shop = create_shop(region) files.write_text(shop, 'SimpleCashShopScript.lua') if '2' in choice.strip(): filenames = os.listdir() for filename in filenames: if '.xlsx' in filename: xlsx_filename = filename break luckybox_dict = create_luckybox(region, xlsx_filename) for file, text in luckybox_dict.items(): files.write_text(text, 'NEW_files/NEW_' + file) files.open_with_notepad('NEW_files/NEW_' + file) print('Хотите обновить файлы сервера/клиента/бд? (да/нет)') want_to_update = input('Выбор: ') if 'да' in want_to_update.strip().lower(): update_files.all(luckybox_dict, region)