#! /usr/bin/env python3 # -*- coding: utf8 -*- # # Copyright (C) 2010-2011 Evol Online # Author: Andrei Karas (4144) import datetime import os #import xml import sys from xml.dom import minidom wikia=open("Items.md", "w") wikib=open("Monsters.md", "w") # the TYPEs we use to determine where to pack things IT_HEALING=[] IT_ETC=[] IT_USABLE=[] IT_AMMO=[] IT_CARD=[] IT_PETEGG=[] IT_WEAPON={ 'HAND_2': [], # TWO HAND (LR) 'HAND_1':[]} # WEAPONS (R) IT_ARMOR={ 'MISC': [], # FOR FAILURE 'EQP_ACC_L': [], # ? 'EQP_ACC_R': [], # ? 'EQP_HEAD_MID': [], # CHEST 'EQP_SHOES': [], # FEET 'EQP_GARMENT': [], # GLOVES 'EQP_HEAD_LOW':[], # PANTS '1024': [], # NECKLACES (should be EQP_COSTUME_HEAD_TOP instead of number) '2048': [], # RINGS (should be EQP_COSTUME_HEAD_MID instead of number) 'EQP_HEAD_TOP':[], # HATS/HELMETS 'EQP_HAND_L': [], # SHIELDS 'EQP_HAND_R':[]} # WEAPONS def printSeparator(): print("--------------------------------------------------------------------------------") def showHeader(): print("TMW2 Wiki Generator") ##print "Evol client data validator." print("Run at: " + datetime.datetime.now().isoformat()) ##print "https://gitlab.com/evol/evol-tools/blob/master/testxml/testxml.py" printSeparator() def showFooter(): #pass #printSeparator() print("Done.") def writeMob(wikib, tmb): wikib.write("|"+ tmb[0]+"|"+ tmb[1]+"|"+ tmb[2]+"|"+ tmb[3]+"|"+ tmb[4]+"|"+ tmb[5]+"|"+ tmb[6]+"|"+ tmb[7]+"|\n" ) def testMobs(): print("Generating Mob Wiki...") src=open("../../server-data/db/re/mob_db.conf", "r") wikib.write("# Monster Database\n") wikib.write("|ID|Name|hp|xp|def|atk|delay|modes|\n") # 0 1 2 3 4 5 6 7 #tm_entry=False # TODO: Drop list tmb=['--','----','--','--','---','---','-----','-----'] # 0 1 2 3 4 5 6 7 for a in src: if a == "{\n": writeMob(wikib, tmb) tmb=['','','','','','', '', ''] # 0 1 2 3 4 5 6 7 if " Id:" in a: tmb[0]=stp(a) if " Name:" in a: tmb[1]=stp(a) if " Hp:" in a: tmb[2]=stp(a) if " Exp:" in a: tmb[3]=stp(a) if " Def:" in a: tmb[4]=stp(a) if " Attack:" in a: tmb[5]=stp(a) if " AttackDelay:" in a: tmb[6]=stp(a) if " Looter: true" in a: tmb[7]+="Lot," if " Assist: true" in a: tmb[7]+="Ass," if " Aggressive: true" in a: tmb[7]+="Agr," # Write last entry writeMob(wikib, tmb) wikib.write('\n\n|Mode|Desc|\n|----|----|\n') wikib.write('|Lot|Looter|\n') wikib.write('|Ass|Assist|\n') wikib.write('|Agr|Aggressive|\n') src.close() def stp(x): return x.replace('\n', '').replace('|', '').replace('(int, defaults to ', '').replace(')', '').replace('basic experience', '').replace('"','').replace(" ","").replace('(string', '').replace('Name: ','').replace('AttackDelay', 'ms') class It: def __init__(self): # Basic self.id="0" self.aegis="UnknownItem" self.name="Unknown Item Name" self.price="0" # Sell price, of course self.weight="0" self.type="IT_ETC" # default type self.loc="" # Offensive/Defensive self.atk="0" self.matk="0" self.range="0" self.defs="0" # Restrictions (EquipLv) self.lvl="0" self.drop=True self.trade=True self.sell=True self.store=True # Special settings self.rare=False # DropAnnounce self.script=False # Script settings self.minheal="0" self.maxheal="0" self.delheal="0" def ItAlloc(it): a=it.type if "IT_HEALING" in a: IT_HEALING.append(it) elif "IT_ETC" in a: IT_ETC.append(it) elif "IT_USABLE" in a: IT_USABLE.append(it) elif "IT_AMMO" in a: IT_AMMO.append(it) elif "IT_CARD" in a: IT_CARD.append(it) elif "IT_PETEGG" in a: IT_PETEGG.append(it) elif "IT_WEAPON" in a: if "HAND_L" in it.loc or "EQP_ARMS" in it.loc: IT_WEAPON["HAND_2"].append(it) elif "HAND_R" in it.loc: IT_WEAPON["HAND_1"].append(it) else: raise Exception("Invalid location for weapon: %s" % it.loc) elif "IT_ARMOR" in a: if 'EQP_ACC_L' in it.loc: IT_ARMOR['EQP_ACC_L'].append(it) elif 'EQP_ACC_R' in it.loc: IT_ARMOR['EQP_ACC_R'].append(it) elif 'EQP_HEAD_MID' in it.loc: IT_ARMOR['EQP_HEAD_MID'].append(it) elif 'EQP_SHOES' in it.loc: IT_ARMOR['EQP_SHOES'].append(it) elif 'EQP_GARMENT' in it.loc: IT_ARMOR['EQP_GARMENT'].append(it) elif 'EQP_HEAD_LOW' in it.loc: IT_ARMOR['EQP_HEAD_LOW'].append(it) elif 'EQP_HEAD_TOP' in it.loc: IT_ARMOR['EQP_HEAD_TOP'].append(it) elif 'EQP_HAND_L' in it.loc: IT_ARMOR['EQP_HAND_L'].append(it) elif '1024' in it.loc: IT_ARMOR['1024'].append(it) elif '2048' in it.loc: IT_ARMOR['2048'].append(it) else: raise Exception("Invalid Loc for ID %s: %s" % (it.id, it.loc)) def newItemDB(): print("Generating Item Wiki...") src=open("../../server-data/db/re/item_db.conf", "r") x=It() for a in src: if a == "{\n": ItAlloc(x) x=It() # sti() block if " Id:" in a: x.id=sti(a) elif " AegisName:" in a: x.aegis=sti(a) elif " Name:" in a: x.name=sti(a) elif " Sell:" in a: x.price=sti(a) elif " Weight:" in a: x.weight=sti(a) elif " Type:" in a: x.type=sti(a) elif " Loc:" in a: x.loc=sti(a) elif " Atk:" in a: x.atk=sti(a) elif " Matk:" in a: x.matk=sti(a) elif " Range:" in a: x.range=sti(a) elif " Def:" in a: x.defs=sti(a) elif " EquipLv:" in a: x.lvl=sti(a) # Write booleans elif "DropAnnounce: true" in a: x.rare=True elif "nodrop: true" in a: x.drop=False elif "notrade: true" in a: x.trade=False elif "noselltonpc: true" in a: x.sell=False elif "nostorage: true" in a: x.store=False elif "Script" in a: x.script=True # For healing items elif "@min" in a: x.minheal=sti(a) elif "@max" in a: x.maxheal=sti(a) elif "@delay" in a: x.delheal=sti(a) # Write last entry ItAlloc(x) writeItems() src.close() def sti(x): return x.replace('\n', '').replace('|', '').replace(')', '').replace('Id: ', '').replace('"','').replace(" ","").replace('AegisName: ', '').replace('Name: ','').replace('Sell: ', '').replace('Weight: ', '').replace('Type: ', '').replace('Loc: ', '').replace('Atk: ', '').replace('Matk: ', '').replace('Range: ', '').replace('Def: ', '').replace('EquipLv: ', '').replace(" ", "").replace('@min=','').replace('@max=','').replace('@delay=','').replace(';','') def writeItems(): wikia.write("# Items\n\ + [Healing Items](#healing-items)\n\ + [Usable Items](#usable-items)\n\ + [Generic Items](#generic-items)\n\ + [Ammo](#ammo)\n\ + [Cards](#cards)\n\ + [Pet Eggs](#pet-eggs)\n\ + [Weapons](#weapons)\n\ + [1H Weapons](#1h-weapons)\n\ + [2H Weapons](#2h-weapons)\n\ + [Armors](#armors)\n\ + [Left Accessory](#left-accessory)\n\ + [Right Accessory](#right-accessory)\n\ + [Headgear](#headgear)\n\ + [Chest](#chest)\n\ + [Pants](#pants)\n\ + [Shoes](#shoes)\n\ + [Necklaces](#necklaces)\n\ + [Rings](#rings)\n\ + [Gloves](#gloves)\n\ + [Shields](#shields)\n\ + [Right Hand](#right-hand)\n\ \n\n") # Healing Items wikia.write("## Healing Items\n") wikia.write("Id|Aegis|Price|Weight|Min|Max|Delay|\n") wikia.write("--|-----|-----|------|---|---|-----|\n") for i in IT_HEALING: wikia.write( i.id +"|"+ i.aegis +"|"+ i.price +"|"+ i.weight +"|"+ i.minheal +"|"+ i.maxheal +"|"+ i.delheal +"|\n" ) wikia.write("\n[↑ Return to top](#items)\n\n") # Usable Items wikia.write("## Usable Items\n") wikia.write("Id|Aegis|Name|Price|Weight|\n") wikia.write("--|-----|----|-----|------|\n") for i in IT_USABLE: wikia.write( i.id +"|"+ i.aegis +"|"+ i.name +"|"+ i.price +"|"+ i.weight +"|\n" ) wikia.write("\n[↑ Return to top](#items)\n\n") # Generic Items wikia.write("## Generic Items\n") wikia.write("Id|Aegis|Name|Price|Weight|\n") wikia.write("--|-----|----|-----|------|\n") for i in IT_ETC: wikia.write( i.id +"|"+ i.aegis +"|"+ i.name +"|"+ i.price +"|"+ i.weight +"|\n" ) wikia.write("\n[↑ Return to top](#items)\n\n") # Ammo Items wikia.write("## Ammo\n") wikia.write("Id|Aegis|Name|Weight|Atk|Matk|\n") wikia.write("--|-----|----|------|---|----|\n") for i in IT_AMMO: wikia.write( i.id +"|"+ i.aegis +"|"+ i.name +"|"+ i.weight +"|"+ i.atk +"|"+ i.matk +"|\n" ) wikia.write("\n[↑ Return to top](#items)\n\n") # Card Items wikia.write("## Cards\n") wikia.write("Id|Aegis|Name|Price|Weight|\n") wikia.write("--|-----|----|-----|------|\n") for i in IT_CARD: wikia.write( i.id +"|"+ i.aegis +"|"+ i.name +"|"+ i.price +"|"+ i.weight +"|\n" ) wikia.write("\n[↑ Return to top](#items)\n\n") # Pet Egg Items wikia.write("## Pet Eggs\n") wikia.write("Id|Aegis|Name|Weight|\n") wikia.write("--|-----|----|------|\n") for i in IT_PETEGG: wikia.write( i.id +"|"+ i.aegis +"|"+ i.name +"|"+ i.weight +"|\n" ) wikia.write("\n[↑ Return to top](#items)\n\n") #################################################################### wikia.write("# Weapons\n") # 1 Hand Items wikia.write("## 1H Weapons\n") wikia.write("Id|Aegis|Price|Weight|Atk|Matk|Lvl|\n") wikia.write("--|-----|-----|------|---|----|---|\n") for i in IT_WEAPON['HAND_1']: wikia.write( i.id +"|"+ i.aegis +"|"+ i.price +" GP|"+ i.weight +"g|Atk: "+ i.atk +"|"+ i.matk +"|Lv: "+ i.lvl +"|\n" ) wikia.write("\n[↑ Return to top](#items)\n\n") # 2 Hand Items wikia.write("## 2H Weapons\n") wikia.write("Id|Aegis|Price|Weight|Atk|Matk|Lvl|Range|\n") wikia.write("--|-----|-----|------|---|----|---|-----|\n") for i in IT_WEAPON['HAND_2']: wikia.write( i.id +"|"+ i.aegis +"|"+ i.price +" GP|"+ i.weight +"g|Atk: "+ i.atk +"|"+ i.matk +"|Lv: "+ i.lvl +"|"+ i.range + "|\n" ) wikia.write("\n[↑ Return to top](#items)\n\n") #################################################################### wikia.write("# Armors\n") ArmorWrite("Left Accessory",'EQP_ACC_L') ArmorWrite("Right Accessory",'EQP_ACC_R') ArmorWrite("Headgear",'EQP_HEAD_TOP') ArmorWrite("Chest",'EQP_HEAD_MID') ArmorWrite("Pants",'EQP_HEAD_LOW') ArmorWrite("Shoes",'EQP_SHOES') ArmorWrite("Necklaces",'1024') ArmorWrite("Rings",'2048') ArmorWrite("Gloves",'EQP_GARMENT') ArmorWrite("Shields",'EQP_HAND_L') ArmorWrite("Right Hand",'EQP_HAND_R') # Still need restriction saving """ self.drop=True self.trade=True self.sell=True self.store=True """ def ArmorWrite(name,scope): wikia.write("## "+name+"\n") wikia.write("Id|Aegis|Price|Weight|Def|Lvl|Script|\n") wikia.write("--|-----|-----|------|---|---|------|\n") for i in IT_ARMOR[scope]: wikia.write( i.id +"|"+ i.aegis +"|"+ i.price +" GP|"+ i.weight +"g|Def: "+ i.defs +"|Lv: "+ i.lvl +"|"+ str(i.script) + "|\n" ) wikia.write("\n[↑ Return to top](#items)\n\n") showHeader() testMobs() newItemDB() wikia.close() wikib.close() wikia.close() showFooter() exit(0)