130 lines
2.8 KiB
Lua
130 lines
2.8 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.sort = nil
|
|
|
|
self:_loadConfig(id)
|
|
self:checkForceLockAndAddNum(num)
|
|
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
|
|
|
|
-- obj类型
|
|
function ItemEntity:getType()
|
|
return GConst.REWARD_TYPE.ITEM
|
|
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:checkForceLockAndAddNum()
|
|
self:setDirty()
|
|
end
|
|
|
|
function ItemEntity:checkForceLockAndAddNum()
|
|
local type = self:getItemType()
|
|
if type == GConst.ItemConst.ITEM_TYPE.HERO_FRAGMENT then
|
|
local heroEntity = DataManager.HeroData:getHeroById(self:getId())
|
|
-- local qlt = DataManager.HeroData:getHeroQlt(self:getId())
|
|
-- local fragmentId = DataManager.ForceData:getForceItemIdByQlt(self:getId())
|
|
if heroEntity:getLv() <= 0 then
|
|
DataManager.HeroData:setHeroLv(self:getId(), 1)
|
|
self.data.num = self.data.num - 1
|
|
-- BIReport:postForceUnlock(self:getId())
|
|
end
|
|
-- 不转换万能碎片
|
|
-- local parameter = self:getParam()
|
|
-- if qlt >= 5 and parameter and parameter[3] then
|
|
-- DataManager.HeroData:addSummonUnlockItemCount(self.data.num * parameter[3])
|
|
-- -- DataManager.BagData.ItemData:addItemNumById(fragmentId, self.data.num * parameter[3], BIReport.ITEM_GET_TYPE.FORCE_SUMMON_EXCHANGE)
|
|
-- self.data.num = 0
|
|
-- end
|
|
end
|
|
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:getInBag()
|
|
return not self.config.inbag or self.config.inbag ~= 1
|
|
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:getSort()
|
|
if self.sort then
|
|
return self.sort
|
|
end
|
|
self.sort = self.data.id + self.config.qlt * 100000000
|
|
return self.sort
|
|
end
|
|
|
|
|
|
return ItemEntity |