91 lines
1.6 KiB
Lua
91 lines
1.6 KiB
Lua
local ItemEntity = class("ItemEntity", BaseData)
|
|
|
|
function ItemEntity:ctor(id, num)
|
|
self.data.id = id
|
|
self.data.num = num
|
|
self.data.isDirty = false
|
|
self.config = nil
|
|
|
|
self:_loadConfig(id)
|
|
end
|
|
|
|
function ItemEntity:getConfig(id)
|
|
local ItemCfg = ConfigManager:getConfig("item")
|
|
local config = ItemCfg[id]
|
|
return config
|
|
end
|
|
|
|
function ItemEntity:_loadConfig(id)
|
|
local config = self:getConfig(id)
|
|
self.config = config
|
|
end
|
|
|
|
function ItemEntity:setDirty()
|
|
self.data.isDirty = not self.data.isDirty
|
|
end
|
|
|
|
-- id
|
|
function ItemEntity:getId()
|
|
return self.data.id
|
|
end
|
|
|
|
-- 道具数量
|
|
function ItemEntity:getNum()
|
|
return self.data.num
|
|
end
|
|
|
|
-- 加减道具数量
|
|
function ItemEntity:addNum(num)
|
|
self.data.num = self.data.num + num
|
|
self:setDirty()
|
|
end
|
|
|
|
-- 设置数量
|
|
function ItemEntity:setNum(num)
|
|
self.data.num = num
|
|
self:setDirty()
|
|
end
|
|
|
|
-- 道具类型
|
|
function ItemEntity:getItemType()
|
|
return self.config.type
|
|
end
|
|
|
|
-- 品质
|
|
function ItemEntity:getQuality()
|
|
return self.config.qlt
|
|
end
|
|
|
|
-- 稀有度
|
|
function ItemEntity:getRarity()
|
|
return self.config.rarity
|
|
end
|
|
|
|
function ItemEntity:getFrameRes()
|
|
return GConst.ATLAS_PATH.ICON_ITEM, "frame_" .. self.config.qlt
|
|
end
|
|
|
|
function ItemEntity:getIconRes()
|
|
return GConst.ATLAS_PATH.ICON_ITEM, self.config.icon
|
|
end
|
|
|
|
-- 其他参数
|
|
function ItemEntity:getParam()
|
|
return self.config.parameter
|
|
end
|
|
|
|
-- 道具描述
|
|
function ItemEntity:getName()
|
|
return I18N:getText("item", self.data.id, "name")
|
|
end
|
|
|
|
-- 道具描述
|
|
function ItemEntity:getDesc()
|
|
return I18N:getText("item", self.data.id, "desc")
|
|
end
|
|
|
|
function ItemEntity:getItemType()
|
|
return self.config.type
|
|
end
|
|
|
|
return ItemEntity |