------------------------------------------------ -- 道具格子 ------------------------------------------------ local HeroExcel = require("excel.hero") local EquipExcel = require("excel.equip") local FuwenExcel = require("excel.fuwen") local SkinExcel = require("excel.skin") local Util = require("common.Util") local ItemDefine = require("bag.ItemDefine") local SuipianLogic = require("bag.SuipianLogic") local RoleAttr = require("role.RoleAttr") local EquipLogic = require("equip.EquipLogic") -- 填充装备,道具信息 function makeItem(net, itemID, itemCnt, shuijingAttrID, itemGrid, itemIndex, opFlag, equipQuality, gemBonus, sourceType) local itemConfig = ItemDefine.getConfig(itemID) net.id = itemConfig and itemID or 0 net.cnt = itemConfig and itemCnt or 0 net.name = itemConfig and itemConfig.name or "" net.mainType = itemConfig and itemConfig.mainType or 0 net.subType = itemConfig and itemConfig.subType or 0 net.order = itemConfig and itemConfig.order or 0 net.icon = itemConfig and itemConfig.icon or 0 net.desc1 = itemConfig and itemConfig.desc1 or "" net.desc2 = itemConfig and itemConfig.desc2 or "" local priceId = itemConfig and itemConfig.price and itemConfig.price[1] or 0 local priceConfig = ItemDefine.getConfig(priceId) net.priceIcon = priceConfig and priceConfig.icon or 0 net.price = itemConfig and itemConfig.price and itemConfig.price[2] or 0 net.rare = itemConfig and itemConfig.rare or 0 net.score = itemConfig and itemConfig.score or 0 net.getway = net.getway or {} net.getway[0] = (itemConfig and itemConfig.getway) and #itemConfig.getway or 0 for i=1, net.getway[0] do net.getway[i] = itemConfig.getway[i] end net.panelID = itemConfig and itemConfig.panelID or 0 net.isShow = itemConfig and itemConfig.isShow or 0 net.effects = itemConfig and itemConfig.effects or 0 net.opflag = opFlag or getOpflag(itemConfig) or 0 net.suipian = net.suipian or {} net.equip = net.equip or {} net.fuwen= net.fuwen or {} net.suipian[0] = 0 net.equip[0] = 0 net.fuwen[0] = 0 net.sourceType = sourceType or 0 if not itemConfig then return end makeItemSuipian(net, itemConfig) makeItemFuwen(net, itemID, itemConfig, itemGrid, itemIndex) makeItemEquip(net, itemConfig, itemGrid, itemIndex, shuijingAttrID, equipQuality, gemBonus) end function makeFuwenSkill(net, skillID, skillLockList) local skillConfig = FuwenExcel.skill[skillID] net.skillID = skillID net.skillIcon = skillConfig.icon net.skillName = skillConfig.name net.skillDesc = skillConfig.desc net.lv = skillConfig.lv net.isRare = skillConfig.rare or 0 net.isOnlyBinshu = 0 if skillConfig.isBingshuSkill == 1 and skillConfig.isFuwenSkill == 0 then net.isOnlyBinshu = 1 end net.isLock = 0 if skillLockList and skillLockList[skillID] then net.isLock = 1 end end function makeItemFuwen(net, itemID, itemConfig, fuwenGrid, fuwenIndex) if itemConfig.mainType ~= ItemDefine.MAINTYPE_FUWEN then return end local netTemp = nil if net.fuwen then net.fuwen[0] = 1 net.fuwen[1] = net.fuwen[1] or {} netTemp = net.fuwen[1] else netTemp = net end netTemp.id = itemID netTemp.index = fuwenIndex or 0 netTemp.fenjieGet = itemConfig.fenjieJinghua netTemp.refine = 0 netTemp.attrs = netTemp.attrs or {} netTemp.attrs[0] = 0 netTemp.skills = netTemp.skills or {} netTemp.skills[0] = 0 netTemp.zhandouli = 0 if fuwenGrid ~= nil then netTemp.refine = fuwenGrid.refine or 0 local zhandouli = 0 for zz = 1, #fuwenGrid.attr do local key = fuwenGrid.attr[zz][1] local value = fuwenGrid.attr[zz][2] local isLock = fuwenGrid.attr[zz][3] netTemp.attrs[zz] = netTemp.attrs[zz] or {} -- netTemp.attrs[zz].key = key -- netTemp.attrs[zz].value = value netTemp.attrs[zz].attrArray = netTemp.attrs[zz].attrArray or {key = 0, value = 0} netTemp.attrs[zz].attrArray.key = key netTemp.attrs[zz].attrArray.value = value netTemp.attrs[zz].isLock = isLock or 0 zhandouli = zhandouli + RoleAttr.getPointByKey(key) * value end netTemp.attrs[0] = #fuwenGrid.attr if fuwenGrid.skill == nil then netTemp.skills[0] = 0 else local skillLockList = fuwenGrid.skillLockList for zz = 1,#fuwenGrid.skill do local skillID = fuwenGrid.skill[zz] netTemp.skills[zz] = netTemp.skills[zz] or {} makeFuwenSkill(netTemp.skills[zz], skillID, skillLockList) end netTemp.skills[0] = #fuwenGrid.skill end netTemp.zhandouli = math.floor(zhandouli) end end function makeItemEquip(net, itemConfig, equipGrid, equipIndex, shuijingAttrID, equipQuality, gemBonus) if itemConfig.mainType ~= ItemDefine.MAINTYPE_EQUIP then return end net.equip[0] = 1 net.equip[1] = net.equip[1] or {} net.equip[1].index = equipIndex or 0 net.equip[1].level = itemConfig.level net.equip[1].exp = itemConfig.shenqiExp or 0 net.equip[1].star = itemConfig.star or 0 net.equip[1].uuid = equipGrid and equipGrid.uuid or "" net.equip[1].putUuid = equipGrid and equipGrid.putUuid or "" net.equip[1].args = net.equip[1].args or {} net.equip[1].args[0] = 0 net.equip[1].suitID = itemConfig.suit or 0 local maxQuality = EquipLogic.getEquipMaxQuality(itemConfig) net.rare = equipGrid and equipGrid.quality or equipQuality or maxQuality -- 装备基础属性 if itemConfig.subType == ItemDefine.EQUIP_SUBTYPE_SHUIJIN then -- 水晶属性 net.equip[1].attr = net.equip[1].attr or {} net.equip[1].attr[0] = 0 net.equip[1].args[0] = 1 local upcf = EquipExcel.shuijingUpNeed[net.id] net.equip[1].args[1] = (not upcf or upcf.nextID < 1) and 1 or 0 -- 是否满级 if shuijingAttrID then local shuijingConfig = EquipExcel.shuijingAttr[shuijingAttrID] local shuijingAttrTB = shuijingConfig.attr net.equip[1].attr[0] = #shuijingAttrTB for i=1, net.equip[1].attr[0] do net.equip[1].attr[i] = net.equip[1].attr[i] or {} net.equip[1].attr[i].key = shuijingAttrTB[i][1] net.equip[1].attr[i].value = shuijingAttrTB[i][2] end end else local baseRate = EquipLogic.getEquipBaseRate(net.rare) net.score = math.floor(net.score * baseRate) local succinctRate = baseRate local baseAttrInfo = itemConfig.base if equipGrid and equipGrid.baseAttr then baseAttrInfo = equipGrid.baseAttr end net.equip[1].effects[0] = 0 net.equip[1].heroExclusive = "" if itemConfig.subType == ItemDefine.EQUIP_SUBTYPE_RING or itemConfig.subType == ItemDefine.EQUIP_SUBTYPE_AMULET then baseRate = 1 --装备特效 if equipGrid then local effectLen = 0 local msgEffects = net.equip[1].effects for effectId in pairs(equipGrid.effectList or {}) do effectLen = effectLen + 1 local effectCfg = EquipExcel.texiao[effectId] msgEffects[effectLen].name = effectCfg.name msgEffects[effectLen].color = effectCfg.quality msgEffects[effectLen].attr.key = effectCfg.attrs[1][1] msgEffects[effectLen].attr.value = effectCfg.attrs[1][2] end msgEffects[0] = effectLen -- 英雄专属 if equipGrid.exclusiveHeroId then local heroCfg = HeroExcel.hero[equipGrid.exclusiveHeroId] net.equip[1].heroExclusive = heroCfg.name end end end --宝石 net.equip[1].gemBaseAttr[0] = 0 if gemBonus then net.equip[1].gemBaseAttr[0] = #baseAttrInfo end -- 基础属性 net.equip[1].baseAttr = {} net.equip[1].baseAttr[0] = #baseAttrInfo for i=1, net.equip[1].baseAttr[0] do net.equip[1].baseAttr[i] = net.equip[1].baseAttr[i] or {} net.equip[1].baseAttr[i].key = baseAttrInfo[i][1] net.equip[1].baseAttr[i].value = math.floor(baseAttrInfo[i][2] * baseRate) if gemBonus then net.equip[1].gemBaseAttr[i].key = baseAttrInfo[i][1] if itemConfig.subType == ItemDefine.EQUIP_SUBTYPE_RING or itemConfig.subType == ItemDefine.EQUIP_SUBTYPE_AMULET then net.equip[1].gemBaseAttr[i].value = math.floor(baseAttrInfo[i][2] * baseRate * gemBonus.sp_base) else net.equip[1].gemBaseAttr[i].value = math.floor(baseAttrInfo[i][2] * baseRate * gemBonus.base) end end end -- 洗练属性 local attrLen = 0 net.equip[1].tzAttr = net.equip[1].tzAttr or {} if equipGrid then EquipLogic.checkAttr(equipGrid) -- for key, value in pairs(equipGrid.attr) do -- attrLen = attrLen + 1 -- net.equip[1].tzAttr[attrLen] = net.equip[1].tzAttr[attrLen] or {} -- net.equip[1].tzAttr[attrLen].attr.key = key -- net.equip[1].tzAttr[attrLen].value = math.floor(value * baseRate) -- end for idx, v in ipairs(equipGrid.attr) do net.equip[1].tzAttr[idx] = net.equip[1].tzAttr[idx] or {} net.equip[1].tzAttr[idx].attr.key = v[1] net.equip[1].tzAttr[idx].attr.value = math.floor(v[2] * succinctRate) net.equip[1].tzAttr[idx].color = v[3] or 1 net.equip[1].tzAttr[idx].lock = v[4] or 0 net.equip[1].tzAttr[0] = idx end else local randomAttr = EquipLogic.getEquipTzAttr(itemConfig) if randomAttr then -- for _, attr in pairs(randomAttr) do -- attrLen = attrLen + 1 -- net.equip[1].tzAttr[attrLen] = net.equip[1].tzAttr[attrLen] or {} -- net.equip[1].tzAttr[attrLen].key = attr[1] -- net.equip[1].tzAttr[attrLen].value = attr[2] -- end for idx, v in ipairs(randomAttr) do attrLen = attrLen + 1 net.equip[1].tzAttr[idx] = net.equip[1].tzAttr[idx] or {} net.equip[1].tzAttr[idx].attr.key = v[1] net.equip[1].tzAttr[idx].attr.value = v[2] net.equip[1].tzAttr[idx].color = v[3] or 1 net.equip[1].tzAttr[idx].lock = v[4] or 0 -- net.equip[1].tzAttr[0] = idx end end net.equip[1].tzAttr[0] = attrLen end -- net.equip[1].tzAttr[0] = attrLen end if itemConfig.subType == ItemDefine.EQUIP_SUBTYPE_SHENQI then local shenqiUpNeedConfig = EquipExcel.shenqiUpNeed[net.id] local nextID = shenqiUpNeedConfig and shenqiUpNeedConfig.nextID net.equip[1].args = net.equip[1].args or {} net.equip[1].args[0] = 1 net.equip[1].args[1] = (not nextID or nextID < 1) and 1 or 0 end -- 装备套装属性 net.equip[1].suit = net.equip[1].suit or {} net.equip[1].suit[0] = 0 if itemConfig.suitIm then net.equip[1].suit = net.equip[1].suit or {} net.equip[1].suit[0] = 1 net.equip[1].suit[1] = net.equip[1].suit[1] or {} net.equip[1].suit[1].attr = net.equip[1].suit[1].attr or {} net.equip[1].suit[1].attr[0] = #itemConfig.suitIm net.equip[1].suit[1].gemAttr[0] = 0 if gemBonus then net.equip[1].suit[1].gemAttr[0] = #itemConfig.suitIm end for i=1,net.equip[1].suit[1].attr[0] do net.equip[1].suit[1].attr[i] = net.equip[1].suit[1].attr[i] or {} net.equip[1].suit[1].attr[i].key = itemConfig.suitIm[i][1] net.equip[1].suit[1].attr[i].value = itemConfig.suitIm[i][2] if gemBonus and (gemBonus[i+1] or gemBonus.sp_suit) then net.equip[1].suit[1].gemAttr[i] = net.equip[1].suit[1].gemAttr[i] or {} net.equip[1].suit[1].gemAttr[i].key = itemConfig.suitIm[i][1] if itemConfig.subType == ItemDefine.EQUIP_SUBTYPE_RING or itemConfig.subType == ItemDefine.EQUIP_SUBTYPE_AMULET then net.equip[1].suit[1].gemAttr[i].value = gemBonus.sp_suit * 100 else --这里i+1的原因是,装备套装属性配置suitIm中, idx为1的value是2件套加成, idx为2的是3件套加成,以此类推 net.equip[1].suit[1].gemAttr[i].value = gemBonus[i+1] * 100 --转成百分比发给客户端 end end end net.equip[1].suit[1].id = itemConfig.suit net.equip[1].suit[1].name = itemConfig.suitName net.equip[1].suit[1].num = itemConfig.suitNum end -- 装备职业专属属性 net.equip[1].job = itemConfig.job net.equip[1].jobAttr = net.equip[1].jobAttr or {} net.equip[1].jobAttr[0] = #itemConfig.jobAttr for i = 1, net.equip[1].jobAttr[0] do net.equip[1].jobAttr[i] = net.equip[1].jobAttr[i] or {} net.equip[1].jobAttr[i].key = itemConfig.jobAttr[i][1] net.equip[1].jobAttr[i].value = itemConfig.jobAttr[i][2] end -- 装备阵营专属属性 net.equip[1].camp = itemConfig.camp net.equip[1].campAttr = net.equip[1].campAttr or {} net.equip[1].campAttr[0] = #itemConfig.campAttr for i = 1, net.equip[1].campAttr[0] do net.equip[1].campAttr[i] = net.equip[1].campAttr[i] or {} net.equip[1].campAttr[i].key = itemConfig.campAttr[i][1] net.equip[1].campAttr[i].value = itemConfig.campAttr[i][2] end end -- 封装碎片信息 Suipian function makeItemSuipian(net, itemConfig) if itemConfig.mainType ~= ItemDefine.MAINTYPE_ITEM then return end if itemConfig.subType ~= ItemDefine.ITEM_SUBTYPE_SUIPIAN and itemConfig.subType ~= ItemDefine.ITEM_SUBTYPE_SUIPIAN_SKIN and itemConfig.subType ~= ItemDefine.ITEM_SUBTYPE_SUIPIAN_TALISMAM and itemConfig.subType ~= ItemDefine.ITEM_SUBTYPE_SUIPIAN_RELIC then return end net.suipian[0] = 1 net.suipian[1] = net.suipian[1] or {} net.suipian[1].fullcnt = itemConfig.fullCnt net.suipian[1].get = itemConfig.get[1] or 0 if itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN or itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN_SKIN then net.suipian[1].camp = itemConfig.cond[1] or 0 net.suipian[1].star = itemConfig.cond[2] or 0 local heroID = itemConfig.get[3] local heroConfig = HeroExcel.hero[heroID] net.suipian[1].grade = heroConfig and heroConfig.grade or 0 if itemConfig.get[1] == SuipianLogic.SUMMON_TYPE_TARGET then local dropType = itemConfig.get[2] if dropType == SuipianLogic.SUMMON_SUBTYPE_HERO then local heroID = itemConfig.get[3] local heroConfig = HeroExcel.hero[heroID] if heroConfig then net.suipian[1].camp = heroConfig.camp net.suipian[1].star = heroConfig.star net.icon = heroConfig.head end end end elseif itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN_TALISMAM or itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN_RELIC then net.suipian[1].camp = 0 net.suipian[1].star = 0 net.suipian[1].grade = itemConfig.rare or 0 end end --------------------------------------------- 可操作 ------------------------------------------------------- -- 可操作行为 function getOpflagAtBag(id) local itemConfig = ItemDefine.getConfig(id) if not itemConfig then return flag end if itemConfig then itemConfig.id = id end local flag = 0 -- 使用道具 if canUse(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_USE) end -- 使用箱子 if canUseBox(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_USE_BOX) end -- 批量使用 if canUseBatch(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_USE_BATCH) end -- 详情 if canDetail(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_DETAIL) end -- 是否可出售 if canSell(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_SELL) end -- 是否用来源 if canSource(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_SOURCE) end -- 是否可以合成 if canHeCheng(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_HECHENG) end -- 能否穿戴 if canEquip(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_EQUIP) end -- 能否重铸 if canCZhu(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_CZHU) end -- 能否分解 if canFJie(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_FJIE) end return flag end function getOpflag(itemConfig) local flag = 0 if not itemConfig then return flag end -- 预览 if canYulan(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_YULAN) end -- 是否用来源 if canSource(itemConfig) then flag = Util.setBit(flag, ItemDefine.ITEM_OP_SOURCE) end return flag end -- 可否使用 function canUse(itemConfig) if not itemConfig then return end if not itemConfig.panelID then return end return itemConfig.panelID > 0 end -- 可否使用 function canUseBox(itemConfig) if not itemConfig then return end if not itemConfig.cmd then return end local cmdstr = itemConfig.cmd[1] if not cmdstr then return end if cmdstr == "box" then return true end end -- 是否可出售 function canSell(itemConfig) if not itemConfig then return end if not itemConfig.price then return end return #itemConfig.price > 0 end -- 是否可出售 function canSource(itemConfig) if not itemConfig then return end if not itemConfig.getway then return end return #itemConfig.getway > 0 end -- 可否批量使用 function canUseBatch(itemConfig) if not itemConfig then return end if not itemConfig.cmd then return end local cmdstr = itemConfig.cmd[1] if not cmdstr then return end if cmdstr == "box" or "UseSkinItem" == cmdstr then return end return true end -- 可否预览 function canYulan(itemConfig) if not itemConfig then return end local cmdStr = itemConfig.cmd and itemConfig.cmd[1] if cmdStr and cmdStr == "box" then return true end --[[local getWay = itemConfig.get and itemConfig.get[1] if getWay == SuipianLogic.SUMMON_TYPE_DROP or getWay == SuipianLogic.SUMMON_TYPE_HERO_SP or getWay == SuipianLogic.SUMMON_TYPE_SHENQI_SP then local suipianType = itemConfig.get[2] if suipianType == SuipianLogic.SUMMON_SUBTYPE_HERO or suipianType == SuipianLogic.SUMMON_SUBTYPE_EQUIP then return true end end]] end -- 可否查看英雄详情 function canDetail(itemConfig) local getWay = itemConfig.get and itemConfig.get[1] if getWay == SuipianLogic.SUMMON_TYPE_TARGET then local suipianType = itemConfig.get[2] if suipianType == SuipianLogic.SUMMON_SUBTYPE_HERO then local heroID = itemConfig.get[3] if HeroExcel.hero[heroID] then return true end end if suipianType == SuipianLogic.SUMMON_SUBTYPE_SKIN then local skinID = itemConfig.get[3] if SkinExcel.skin[skinID] then return true end end end end -- 可否合成 function canHeCheng(itemConfig) local getWay = itemConfig.get and itemConfig.get[1] if getWay == SuipianLogic.SUMMON_TYPE_TARGET or getWay == SuipianLogic.SUMMON_TYPE_DROP then local suipianType = itemConfig.get[2] if suipianType == SuipianLogic.SUMMON_SUBTYPE_HERO then return true end if suipianType == SuipianLogic.SUMMON_SUBTYPE_SKIN then return true end if suipianType == SuipianLogic.SUMMON_SUBTYPE_TALISAM then return true end if suipianType == SuipianLogic.SUMMON_SUBTYPE_RELIC then return true end end if ItemDefine.isFuwen(itemConfig.id) then return true end end -- 可否穿戴 function canEquip(itemConfig) if ItemDefine.isEquip(itemConfig.id) then return true end if ItemDefine.isFuwen(itemConfig.id) then return true end end -- 可否重铸 function canCZhu(itemConfig) if ItemDefine.isFuwen(itemConfig.id) then return true end end -- 可否重铸 function canFJie(itemConfig) if ItemDefine.isFuwen(itemConfig.id) then return true end end