1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-28 17:40:26 +00:00
opus/sys/apis/itemDB.lua

39 lines
750 B
Lua
Raw Normal View History

local TableDB = require('tableDB')
2017-07-24 02:37:07 +00:00
local itemDB = TableDB({ fileName = 'usr/etc/items.db' })
function itemDB:get(key)
local item = TableDB.get(self, key)
if item then
return item
end
if key[2] ~= 0 then
item = TableDB.get(self, { key[1], 0, key[3] })
if item and item.maxDamage > 0 then
2017-07-24 02:37:07 +00:00
item = Util.shallowCopy(item)
item.damage = key[2]
item.displayName = string.format('%s (damage: %d)', item.displayName, item.damage)
return item
end
end
end
function itemDB:add(key, item)
if item.maxDamage > 0 then
key = { key[1], 0, key[3] }
end
TableDB.add(self, key, item)
end
function itemDB:makeKey(item)
return { item.name, item.damage, item.nbtHash }
end
itemDB:load()
return itemDB