summaryrefslogtreecommitdiff
path: root/hercules/code/server/tmw/itemdb.py
blob: 43c8342f19b33afc61f5d65113096922d2fedb64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# -*- coding: utf8 -*-
#
# Copyright (C) 2014  Evol Online
# Author: Andrei Karas (4144)

import os
import re

from code.configutils import writeStartScript, writeEndScript, writeIntField, writeStrField
from code.fileutils import readFile

def getItemDbFile(srcDir):
    files = os.listdir(srcDir)
    for srcFile in files:
        if srcFile.find("item_db") >= 0:
            yield srcFile

def replaceStr(line):
    vals = [
        ("setskill ", "addtoskill "),
        ("zeny", "Zeny"),
        ("sc_poison", "SC_POISON"),
        ("sc_slowpoison", "SC_SLOWPOISON"),
        ("sex", "Sex"),
        ("SEX", "Sex"),

        (".gat", ""),
        ("Bugleg", "BugLeg"),
        ("set BugLeg, 0;", "//set BugLeg, 0;"),
        ("set CaveSnakeLamp, 0;", "//set CaveSnakeLamp, 0;"),
        ("set Class, @BaseClass;", "//set Class, @BaseClass;"),
        ("goto_Exit;", "goto L_Exit;"),
        ("if @spants_state < 7 goto", "if(@spants_state < 7) goto"),
        ("isdead()", "ispcdead()"),
        ("changeSex", "changecharsex()"),
        ("getpartnerid2()", "getpartnerid()"),

        ("getmap()", "getmapname()"),
        ("L_end", "L_End"),
        ("gmcommand", "atcommand"),
        ("MF_NOSAVE", "mf_nosave"),
        ("S_update_var", "S_Update_Var"),
        ("L_teach", "L_Teach"),
        ("L_focus", "L_Focus"),
        ("L_unfocus", "L_Unfocus"),
        ("L_main", "L_Main"),
        ("L_next", "L_Next"),
        ("L_close", "L_Close"),
        ("@NpcName$", "@npcname$"),
        ("@cost", "@Cost"),
        ("@TEMP", "@temp"),
        ("L_Menuitems", "L_MenuItems"),
        ("L_no_item", "L_No_Item"),
        ("L_no_water", "L_No_Water"),
        ("L_NOT_ENOUGH", "L_No_Water"),
        ("L_bye", "L_Bye"),
        ("L_NOHELP", "L_NoHelp"),
        ("L_Eyepatch", "L_EyePatch"),
        ("@PC_STAMINA", "@pc_stamina"),
        ("L_magic", "L_Magic"),
        ("L_cont", "L_Cont"),
        ("L_accept", "L_Accept"),
        ("L_no_event", "L_No_Event"),
        ("L_event_done", "L_Event_Done"),
        ("L_nobeer", "L_NoBeer"),
        ("L_iron", "L_Iron"),
        ("L_sulphur", "L_Sulphur"),
        ("L_red", "L_Red"),
        ("L_yellow", "L_Yellow"),
        ("L_green", "L_Green"),
        ("L_orange", "L_Orange"),
        ("L_pink", "L_Pink"),
        ("L_purple", "L_Purple"),
        ("L_question", "L_Question"),
        ("L_quest", "L_Quest"),
        ("L_dead", "L_Dead"),
        ("L_menu", "L_Menu"),
        ("L_give", "L_Give"),
        ("@Items$", "@items$"),
        ("@menuItems$", "@menuitems$"),
        ("L_Teach_initial", "L_Teach_Initial"),
        ("L_finish", "L_Finish"),
        ("L_No_ash", "L_No_Ash"),
        ("L_No_water", "L_No_Water"),
        ("L_cave", "L_Cave"),
        ("L_farewell", "L_Farewell"),
        ("@Q_forestbow_", "@Q_Forestbow_"),
        ("L_game", "L_Game"),
        ("L_good", "L_Good"),
        ("L_abort", "L_Abort"),
        ("@menuID", "@menuid"),
        ("L_NO_ITEM", "L_No_Item"),
        ("L_HELP", "L_Help"),
        ("L_Noitem", "L_NoItem"),
        ("L_No_fur", "L_No_Fur"),
        ("@EXP", "@Exp"),
        ("L_water", "L_Water"),
        ("L_get", "L_Get"),
        ("L_happy", "L_Happy"),
        ("L_cheat", "L_Cheat"),
        ("@Reward_EXP", "@Reward_Exp"),
        ("@REWARD_EXP", "@Reward_Exp"),
        ("L_no_money", "L_No_Money"),
        ("@MinLevel", "@minLevel"),
        ("L_return", "L_Return"),
        ("L_intro", "L_Intro"),
        ("L_full", "L_Full"),
        ("@minlevel", "@minLevel"),
        ("@MinLevel", "@minLevel"),
        ("L_Cleanup", "L_CleanUp"),
        ("L_Alreadystarted", "L_AlreadyStarted"),
        ("@amount", "@Amount"),
        ("L_again", "L_Again"),
        ("L_no_potion", "L_No_Potion"),
        ("L_wizard_hat", "L_Wizard_Hat"),
        ("L_notenough", "L_NotEnough"),
        ("L_offer", "L_Offer"),
        ("L_giveup", "L_GiveUp"),
        ("L_not_ready", "L_Not_Ready"),
        ("@MobID", "@mobId"),
        ("@mobID", "@mobId"),
        ("L_naked", "L_Naked"),
        ("L_shortcut", "L_Shortcut"),
        ("L_shirt", "L_Shirt"),
        ("L_goodjob", "L_GoodJob"),
        ("L_kill", "L_Kill"),
        ("L_nothing", "L_Nothing"),
        ("L_lowlevel", "L_LowLevel"),
        ("@mask", "@Mask"),
        ("Foice", "FoiceItem"),
        ("LanternaJack", "LanternaJackItem"),
        # fix at same time usage with same name function and variable
        ("\"DailyQuestPoints\"", "\"DailyQuestPointsFunc\""),
        ("sc_adrenaline", "SC_ADRENALINE"),
    ]

    for val in vals:
        line = line.replace(val[0], val[1])
    return line

def getItType(it):
    try:
        i=int(it)
    except:
        i=None
    if i == 0:
        return '"IT_HEALING"'
    elif i == 2:
        return '"IT_USABLE"'
    elif i == 3:
        return '"IT_ETC"'
    elif i == 4:
        return '"IT_WEAPON"'
    elif i == 5:
        return '"IT_ARMOR"'
    elif i == 6:
        return '"IT_CARD"'
    elif i == 7:
        return '"IT_HEALING"'
    elif i == 2:
        return '"IT_HEALING"'
    elif i == 2:
        return '"IT_HEALING"'
    elif i == 2:
        return '"IT_HEALING"'
    else:
        print("Unrecognized item type: %s" % it)
        return '"IT_ETC"'

def convertItemDb(isNew):
    srcDir = "oldserverdata/world/map/db/"
    dstFile = "newserverdata/db/re/item_db.conf"
    if os.path.isfile(dstFile):
        os.remove(dstFile)
    constsFile = "newserverdata/db/const.txt"
    if os.path.isfile(constsFile):
        os.remove(constsFile)
    fieldsSplit = re.compile(",")
    scriptsSplit = re.compile("},")
    scriptsTextClean = re.compile('([{}])')
    scriptsTextComma = re.compile('^,')
    scriptsTextColon = re.compile('; ')
    items = dict()

    tpl = readFile("templates/item_db.tpl")
    with open(dstFile, "w") as w:
        w.write(tpl)
        with open(constsFile, "a") as c:
            c.write("// items\n")
            for srcFile in getItemDbFile(srcDir):
                with open(srcDir + srcFile, "r") as r:
                    for line in r:
                        if len(line) < 2 or line[0] == "#" or line[0:2] == "//":
                            continue
                        line = replaceStr(line)
                        rows = fieldsSplit.split(line)
                        if len(rows) < 5 or rows[0] == "0":
                            continue

                        sz = len(rows)
                        if sz > 19:
                            sz = 19
                        for f in xrange(0, sz):
                            rows[f] = rows[f].strip()

                        items[rows[1]] = {'id':rows[0],'buy':rows[4],'name':rows[1]}
                        items[rows[0]] = {'id':rows[0],'buy':rows[4],'name':rows[1]}
                        items[int(rows[0])] = {'id':rows[0],'buy':rows[4],'name':rows[1]}
                        # set all values then write
                        w.write("{\n")
                        c.write("{0}\t{1}\n".format(rows[1], rows[0]))
                        writeIntField(w, "Id", rows[0])
                        writeStrField(w, "AegisName", rows[1])
                        if isNew == True:
                            offset = -1
                        else:
                            offset = 0
                        writeStrField(w, "Name", rows[offset + 2])
                        if rows[offset + 3] == "0":
                            itemType = "2"
                        else:
                            itemType = rows[offset + 3]
                        writeIntField(w, "Type", itemType)

                        writeIntField(w, "Buy", rows[offset + 4])
                        if int(rows[offset + 4])*.75 <= int(rows[offset + 5])*1.24:
                            writeIntField(w, "Sell", str(int(int(rows[offset + 4])*.50)))
                        else:
                            writeIntField(w, "Sell", rows[offset + 5])
                        writeIntField(w, "Weight", rows[offset + 6])
                        writeIntField(w, "Atk", rows[offset + 7])
                        writeIntField(w, "Matk", "0")
                        writeIntField(w, "Def", rows[offset + 8])
                        writeIntField(w, "Range", rows[offset + 9])
                        writeIntField(w, "Slots", "0")
                        writeIntField(w, "Gender", rows[offset + 12])
                        writeIntField(w, "Loc", rows[offset + 13])
                        writeIntField(w, "WeaponLv", rows[offset + 14])
                        writeIntField(w, "EquipLv", rows[offset + 15])
                        writeIntField(w, "Refine", "false")
                        if isNew == True:
                            offset = 2
                        else:
                            offset = 0
                        if rows[offset + 13] == "2":
                            writeIntField(w, "ViewSprite", "1")
                        elif rows[offset + 13] == "34":
                            writeIntField(w, "ViewSprite", "11")
                        elif rows[offset + 13] == "32768":
                            writeIntField(w, "ViewSprite", "1")
                        elif itemType == "4": # weapon
                            writeIntField(w, "ViewSprite", "1")
                        else:
                            writeIntField(w, "View", rows[0])
                        writeIntField(w, "BindOnEquip", "false")
                        writeIntField(w, "BuyingStore", "false")
                        writeIntField(w, "Delay", "0")
                        writeIntField(w, "Sprite", "0")

                        scripts = ""
                        if isNew == True:
                            offset = -1
                        else:
                            offset = 0
                        for f in xrange(offset + 17, len(rows)):
                            scripts = scripts + ", " + rows[f]
                        rows = scriptsSplit.split(scripts)
                        # Needs .split(';') and \n each 
                        if len(rows) > 1:
                            UseScript = scriptsTextColon.sub(';',scriptsTextComma.sub('', scriptsTextClean.sub('', rows[0]))).strip().split(';')
                            EquipScript = scriptsTextColon.sub(';',scriptsTextComma.sub('', scriptsTextClean.sub('', rows[1]))).strip().split(';')
                        else:
                            UseScript = ""
                            EquipScript = ""
                        # move to for stmt
                        if len(UseScript) > 1:
                            writeStartScript(w, "Script")
                            for uline in UseScript:
                                if len(uline) > 0:
                                    w.write("        {0};\n".format(uline))
                            writeEndScript(w)
                        if len(EquipScript) > 1:
                            writeStartScript(w, "OnEquipScript")
                            for eline in EquipScript:
                                if len(eline) > 0:
                                    w.write("        {0};\n".format(eline))
                            writeEndScript(w)

                        w.write("},\n")
        w.write(")\n")
    return items