You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
893 B
Lua
45 lines
893 B
Lua
local util = require('./piazza-util')
|
|
local user = require'./models/user'
|
|
local customprice = require'./models/customprice'
|
|
|
|
local item = {}
|
|
|
|
item.setdb = function(db)
|
|
item.db = db
|
|
end
|
|
|
|
item.defaults = {
|
|
name = ''
|
|
}
|
|
|
|
item.create = function(t)
|
|
-- util.setdefaults(t, item.defaults)
|
|
--if t.name == nil then
|
|
-- t.name = t.brand .. ' ' .. t.model .. ' (' .. t.color .. ')'
|
|
--end
|
|
return t
|
|
end
|
|
|
|
item.new = function(t)
|
|
t = t or {}
|
|
local i = item.create(t)
|
|
i.type = 'item'
|
|
i.image_ids = {}
|
|
i.inventory = 0
|
|
item.db:insertrecord(i)
|
|
return i
|
|
end
|
|
|
|
item.priceof = function(item_record, user_record)
|
|
local customprice_record = customprice.find(item_record, user_record)
|
|
if customprice_record ~= nil then
|
|
return customprice_record.price
|
|
end
|
|
if user.isgold(user_record) then
|
|
return item_record.price_gold
|
|
end
|
|
return item_record.price_silver
|
|
end
|
|
|
|
return item
|