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 ItemMoveInfo(region, id): if region == 'roeu': path = files.get_path(region, 'ItemMoveInfoV4.txt') else: path = files.get_path(region, 'ItemMoveInfoV5.txt') lines = files.open_lines(path) for line in lines: if line.strip().startswith(str(id)): if region == 'roeu': return ''.join(re.split(r'\s+', line)[1:8]) else: return ''.join(re.split(r'\s+', line)[1:9])
def special(region, dbname): path = files.get_path(region, 'special.sc') if region == 'ropru': codirovka = 'Windows-1251' else: codirovka = 'EUC-KR' lines = files.open_lines(path, codirovka) result = list() writing = False for line in lines: if re.search(r'^\s*item\s+(\S+)', line): if dbname == re.search(r'\s*item\s+(\S+)', line).group(1): writing = True else: writing = False if writing == True: result.append(line) result = '\n'.join(result) return result.strip()
def PackageItem(region, dbname): path = files.get_path(region, 'PackageItem.lua') lines = files.open_lines(path) pattern = r'^\s*\[(.*)\]\s*=' # боксы result = '' writing = False for line in lines: if re.search(pattern, line): fixed_line = line.replace(']]', '\"').replace('[[', '\"') if re.search(pattern, fixed_line).group(1).replace('\"', '').strip() == dbname: writing = True elif writing == True: break if writing == True: result += line + '\n' return result.strip()
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 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')
def Importantitem(region, id): path = files.get_path(region, 'Importantitem.txt') lines = files.open_lines(path) for line in lines: if line.strip().startswith(str(id)): return True return False
def CashItemList(region, dbname): path = files.get_path(region, 'CashItemList.txt') lines = files.open_lines(path) for line in lines: if "\"" + dbname + "\"" in line: return True return False