-
Notifications
You must be signed in to change notification settings - Fork 4
/
run_first.lua
177 lines (164 loc) · 3.9 KB
/
run_first.lua
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
function cwd(name)
local chr = os.tmpname():sub(1,1)
if chr == "/" then
-- linux
chr = "/[^/]*$"
else
-- windows
chr = "\\[^\\]*$"
end
return arg[0]:sub(1, arg[0]:find(chr))..(name or '')
end
local path = cwd()
table.find = function(table, value)
for i, v in pairs(table) do
if v == value then
return i
end
end
return false
end
function gen(name, i, items)
local newLine = "\n\t\t\t"
local value = items[i][name]
return (value and newLine..name.." = "..(type(tonumber(value)) == 'number' and value or "\""..value.."\"")..',' or '')
end
local storage = 18000
local attr = {
'weight',
'suppressDrown',
'leveldoor',
'skillAxe',
'magiclevelpoints',
'manashield',
'description',
'shootType',
'healthGain',
'fluidsource',
'absorbPercentPhysical',
'transformEquipTo',
'absorbPercentDeath',
'absorbPercentFire',
'manaGain',
'absorbPercentEarth',
'skillShield',
'speed',
'suppressDrunk',
'damage',
'range',
'fluidSource',
'maleSleeper',
'rotateTo',
'stopduration',
'destroyTo',
'runeSpellName',
'floorchange',
'type',
'count',
'blocking',
'skillFist',
'walkStack',
'containerSize',
'femaleSleeper',
'showcharges',
'allowpickupable',
'maxHitChance',
'partnerDirection',
'elementEnergy',
'absorbPercentManaDrain',
'showattributes',
'fieldabsorbpercentfire',
'absorbPercentIce',
'hitChance',
'showduration',
'replaceable',
'corpseType',
'absorbPercentDrown',
'ticks',
'decayTo',
'defense',
'showcount',
'absorbPercentHoly',
'skillDist',
'maxTextLen',
'ammoType',
'armor',
'elementEarth',
'elementIce',
'transformDeEquipTo',
'invisible',
'duration',
'writeable',
'skillClub',
'effect',
'blockprojectile',
'field',
'extradef',
'absorbPercentMagic',
'attack',
'pickupable',
'start',
'absorbPercentLifeDrain',
'absorbPercentEnergy',
'writeOnceItemId',
'readable',
'allowDistRead',
'skillSword',
'charges',
'elementFire',
'healthTicks',
'manaTicks',
}
function parseItems()
-- location of items.xml
local file = path..'items.xml'
-- save location of items.lua
local fileEx = path..'items.lua'
local outputFile = fileEx
local items = {}
for line in io.lines(file) do
for mi,id,mid,name in line:gmatch('<(%a-)%s*id%s*=%s*"(%d+)"%s*(.-)%s*name%s*=%s*"(.-)"') do
if mi == 'item' then
table.insert(items, {id = id, name = name})
end
end
for key,value in line:gmatch('<attribute key="(.-)" value="(.-)"') do
if key == "slotType" or key == "weaponType" then
items[#items].slot = value
end
for a = 1, #attr do
if key == attr[a] then
items[#items][attr[a]] = value
end
end
end
end
local types = {}
for i = 1, #items do
if items[i].slot then
if not table.find(types, items[i].slot) then
table.insert(types, items[i].slot)
end
end
end
fileEx = io.open(fileEx, "w+")
fileEx:write("items = {\n")
for i = 1, #items do
if items[i].slot then
fileEx:write("\t[\"" .. items[i].name .. "\"] = {\n\t\t\titemid = " .. items[i].id .. ",\n\t\t\tslot = \"" .. items[i].slot .. "\", ")
for b = 1, #attr do
fileEx:write(gen(attr[b], i, items))
end
fileEx:write("\n\t},\n")
end
end
fileEx:write("}")
fileEx:close()
print("#############################")
print("File saved as " .. outputFile)
print("----")
print("Items loaded: " .. #items)
print("Types loaded: " .. #types)
return true
end
parseItems()