---@class EquipFunc EquipFunc = {} local this = EquipFunc function this.Init() this.otherEquips = nil this.RegistEvents() end function this.Reset() this.UnRegistEvents() this.otherEquips = nil end function this.RegistEvents() SL:RegisterLUAEvent(LUA_EVENT_ROLE_INFO, this.ResOtherRoleInfoMessage) SL:RegisterLUAEvent(LUA_EVENT_ROLE_PROPERTY_CHANGE,this.LUA_EVENT_ROLE_PROPERTY_CHANGE) end function this.UnRegistEvents() SL:UnRegisterLUAEvent(LUA_EVENT_ROLE_INFO,this.ResOtherRoleInfoMessage) SL:UnRegisterLUAEvent(LUA_EVENT_ROLE_PROPERTY_CHANGE,this.LUA_EVENT_ROLE_PROPERTY_CHANGE) end ------------------------用来显示别人的装备信息-----------start-------------------------------------- ---@param message UserProtos.OtherRoleInfoRes function this.ResOtherRoleInfoMessage(_, message) if message.type == 4 and tostring(message.role.rid) == this.otherRid then local equips = {} for _, v in pairs(message.equipIndex) do local wearBar, pos = SL:GetWearBarAndPosBaseEquipIndex(v.index) if not equips[wearBar] then equips[wearBar] = {} end equips[wearBar][pos] = v.equip end this.otherEquips = equips end end function this.OtherGetEquipWearBarIdPos(id) local index = this.GetEquipIndexByItemId(id) if not index then return end local wearBarId, pos = SL:GetWearBarAndPosBaseEquipIndex(index) return wearBarId, pos end function this.GetEquipIndexByItemId(itemId) if not this.otherEquips then return end for wearBar , posEquipInfo in pairs(this.otherEquips) do for pos, equip in pairs(posEquipInfo) do if(equip.id == itemId) then return this.GetIdxOfEquip(pos,wearBar) end end end end function this.checkOtherEquips() if not this.otherEquips then return false end return true end ------------------------用来显示别人的装备信息-------end------------------------------------------ function this.GetIdxOfEquip(pos,gemWearCellId) if not gemWearCellId then return pos end return gemWearCellId << 16 | pos end -- 获取装备名字颜色 function this.GetEquipNameColor(cfgId) local colorid = SL:GetConfig('cfg_item', cfgId).color return SL:GetConfigMultiKeys('cfg_color', colorid, 'id').color end -- 获取装备强化等级 function this.GetEquipStrengthLevel(item) local strengthLevel = 0 if item.luaExtData ~= "null" and item.luaExtData ~= "" then strengthLevel = SL:JsonDecode(item.luaExtData).strengthlv or 0 end return strengthLevel end ---装备是否可强化 function this.EquipIsCanStrength(equip) if equip then if SL:HasConfig('cfg_equip_strengthen', equip['cfgId']) then ---@type cfg_equip_strengthen_column local strength_tbl = SL:GetConfig('cfg_equip_strengthen', equip['cfgId']) local nowLv = this.GetEquipStrengthLevel(equip) local maxLevel = strength_tbl.maxLevel ---首饰换表处理 local ornament_tbl = SL:HasConfig('cfg_equip_ornamentsMain', equip['cfgId']) if ornament_tbl then maxLevel = InfoManager.equipJewelryInfo:GetCurLevelMaxStrength(equip) end local lv = nowLv + 1 if nowLv >= maxLevel then return false end if SL:HasConfigTwoKeys('cfg_equip_strengthenCost', strength_tbl.costId, lv, 'costGroupId', 'level') then ---@type cfg_equip_strengthenCost_column local strengthenCostCfg = SL:GetConfigTwoKeys('cfg_equip_strengthenCost', strength_tbl.costId, lv, 'costGroupId', 'level') for _, v in ipairs(strengthenCostCfg.cost) do local cfgId = v[1] local needCount = v[2] local bagCount = SL:GetBagItemCount(cfgId) if needCount > bagCount then return false end end else return false end else return false end else return false end return true end ---装备是否可追加 function this.EquipIsCanAppend(equip) if equip then if SL:HasConfig('cfg_equip_appends', equip['cfgId']) then ---@type cfg_equip_appends_column local strength_tbl = SL:GetConfig('cfg_equip_appends', equip['cfgId']) local nowLv = this.GetEquipAppendLevel(equip) local maxLevel = strength_tbl.maxLevel ---首饰换表处理 local ornament_tbl = SL:HasConfig('cfg_equip_ornamentsMain', equip['cfgId']) if ornament_tbl then maxLevel = InfoManager.equipJewelryInfo:GetCurLevelMaxAppend(equip) end local lv = nowLv + 1 if nowLv >= maxLevel then return false end if SL:HasConfigTwoKeys('cfg_equip_appendsCost', strength_tbl.costId, lv, 'costGroupId', 'level') then ---@type cfg_equip_appendsCost_column local strengthenCostCfg = SL:GetConfigTwoKeys('cfg_equip_appendsCost', strength_tbl.costId, lv, 'costGroupId', 'level') for _, v in ipairs(strengthenCostCfg.cost) do local cfgId = v[1] local needCount = v[2] local bagCount = SL:GetBagItemCount(cfgId) if needCount > bagCount then return false end end else return false end else return false end else return false end return true end -- 获取全身装备强化等级 function this.GetAllStrengthLevel() local equipAll = SL:GetMetaValue(EMetaVarGetKey.EQUIP_DATA) if not next(equipAll) or not next(equipAll[1]) then return 0 end local allLevel = 0 for _, v in pairs(equipAll[1]) do local level = this.GetEquipStrengthLevel(v) allLevel = allLevel + level end return allLevel end -- 获取装备追加等级 function this.GetEquipAppendLevel(item) local strengthLevel = 0 if item.luaExtData ~= "null" and item.luaExtData ~= "" then strengthLevel = SL:JsonDecode(item.luaExtData).appendlv or 0 end return strengthLevel end -- 获取全身装备追加等级 function this.GetAllAppendLevel() local equipAll = SL:GetMetaValue(EMetaVarGetKey.EQUIP_DATA) if not next(equipAll) or not next(equipAll[1]) then return 0 end local allLevel = 0 for _, v in pairs(equipAll[1]) do local level = this.GetEquipAppendLevel(v) allLevel = allLevel + level end return allLevel end -- 获取装备流光id function this.GetEquipLiuGuangId(item,strengthlv) if not SL:HasConfig('cfg_equip_strengthen', item.cfgId) then return end local stream = SL:GetConfig('cfg_equip_strengthen', item.cfgId).stream local ret if stream then local strengthLevel =strengthlv or EquipFunc.GetEquipStrengthLevel(item) for _, streamInfo in ipairs(stream) do local nowStrengthLevel = streamInfo[1] if strengthLevel >= nowStrengthLevel then ret = streamInfo[2] else return ret end end end return ret end -- 获取装备强化数据 function this.GetEquipStrengthAttr(item) local strengthenTbl = SL:GetConfig('cfg_equip_strengthen', item.cfgId) if strengthenTbl then local groupId = SL:GetConfig('cfg_equip_strengthen', item.cfgId).groupId local strengthLevel = this.GetEquipStrengthLevel(item) local nowAttrInfo = SL:GetConfigTwoKeys('cfg_equip_strengthenGroup', groupId, strengthLevel, 'group', 'lv') if nowAttrInfo then return nowAttrInfo.att end end return {} end -- 获取装备追加数据 function this.GetEquipAppendAttr(item) local strengthenTbl = SL:GetConfig('cfg_equip_appends', item.cfgId) if strengthenTbl then local groupId = SL:GetConfig('cfg_equip_appends', item.cfgId).groupId local strengthLevel = this.GetEquipAppendLevel(item) local nowAttrInfo = SL:GetConfigTwoKeys('cfg_equip_appendsGroup', groupId, strengthLevel, 'group', 'lv') if nowAttrInfo then return nowAttrInfo.att end end return {} end -- 获取装备再生等级 function this.GetEquipRegenerateLevel(item) local regenerationLevel = 0 if item.luaExtData ~= "null" and item.luaExtData ~= "" then regenerationLevel = SL:JsonDecode(item.luaExtData).regenerationlv or 0 end return tonumber(regenerationLevel) end -- 获取装备再生属性 function this.GetEquipRegenerate(item) if not SL:HasConfig('cfg_equip_regeneration', item.cfgId) then return end local regenerateTbl = SL:GetConfig('cfg_equip_regeneration', item.cfgId) if regenerateTbl then if item.luaExtData ~= "null" and item.luaExtData ~= "" then local tab = SL:JsonDecode(item.luaExtData).regenerationattr return tab end end end function this.GetEquipRegenerateAttr(item) local message = this.GetEquipRegenerate(item) if message then local all_attr_id = {} for i=1,10,1 do if message[tostring(i)] then table.insert(all_attr_id,message[tostring(i)].id) else break end end local att_list = {} for _, v in ipairs(all_attr_id) do local str = SL:GetConfig('cfg_equip_regenerationGroup', v).att local oneList = string.split(str,'#') table.insert(att_list,{type=tonumber(oneList[1]),num=tonumber(oneList[2])}) end return att_list end end ---@param item CommonProtos.Item ---@param strengthenState number ---@param appendState number ---@param rebornState number function this.GetTransferCost(item, strengthenState, appendState, rebornState) local strengthenCost = {} local appendCost = {} local rebornCost = {} local strengthenLevel = EquipFunc.GetEquipStrengthLevel(item) local appendLevel = EquipFunc.GetEquipAppendLevel(item) local rebornLevel = EquipFunc.GetEquipRegenerateLevel(item) ---@type cfg_equip_transfer_column local sourceTbl = SL:GetConfig("cfg_equip_transfer", item.cfgId) if strengthenState == "1" then for _, v in ipairs(sourceTbl.strengthenCost) do if strengthenLevel >= v[1] then strengthenCost["id"] = v[2] strengthenCost["num"] = v[3] else break end end end if appendState == "1" then for _, v in ipairs(sourceTbl.appendsCost) do if appendLevel >= v[1] then appendCost["id"] = v[2] appendCost["num"] = v[3] else break end end end if rebornState == "1" then for _, v in ipairs(sourceTbl.regenerationCost) do if rebornLevel >= v[1] then rebornCost["id"] = v[2] rebornCost["num"] = v[3] else break end end end local totalCost = { id = 0, num = 0 } if strengthenCost.id then totalCost.id = strengthenCost.id totalCost.num = strengthenCost.num + totalCost.num end if appendCost.id then totalCost.id = appendCost.id totalCost.num = appendCost.num + totalCost.num end if rebornCost.id then totalCost.id = rebornCost.id totalCost.num = rebornCost.num + totalCost.num end return totalCost end ---@param sourceItem CommonProtos.Item @转移装备 ---@param targetItem CommonProtos.Item @继承装备 function this.CheckEquipCanTransfer(sourceItem, targetItem) if sourceItem then ---继承装备未曾锻造过 if EquipFunc.GetEquipStrengthLevel(targetItem) == 0 and EquipFunc.GetEquipAppendLevel(targetItem) == 0 then ---目标装备无再生属性 local targetRegenerate = EquipFunc.GetEquipRegenerate(targetItem) if targetRegenerate and next(targetRegenerate) then return false end ---转移装备有属性可转移 if EquipFunc.GetEquipStrengthLevel(sourceItem) > 0 or EquipFunc.GetEquipAppendLevel(sourceItem) > 0 then ---@type cfg_equip_transfer_column local sourceTbl = SL:GetConfig("cfg_equip_transfer", sourceItem.cfgId) ---@type cfg_equip_transfer_column local targetTbl = SL:GetConfig("cfg_equip_transfer", targetItem.cfgId) if targetTbl and sourceTbl then ---隶属同一转移组可转移 if targetTbl.transferGroup == sourceTbl.transferGroup then local regenerate = EquipFunc.GetEquipRegenerate(sourceItem) ---有再生追加判断再生组 if regenerate and next(regenerate) then if targetTbl.regenerationGroup == sourceTbl.regenerationGroup then return true end else return true end end end end end end return false end function this.LUA_EVENT_ROLE_PROPERTY_CHANGE() local strength = SL:GetMetaValue("GET_ATTR_VALUE_BY_ID", EMUCharacterAttrType.strength) local agility = SL:MeData_GetSpecialAttrValue(EMUCharacterAttrType.agility) local intelligence = SL:MeData_GetSpecialAttrValue(EMUCharacterAttrType.intelligence) local itemList_1 = SL:GetWearBarsData(EEquipWearBarType.BaseEquip) local all_take_off = {} if itemList_1 then for _, item in pairs(itemList_1) do local is_off = false local cfg_id = item.cfgId local useAttLimit = SL:GetEquipValue(EMetaVarGetKey.EQUIP_WEAR_LIMIT, "", cfg_id) for _, att in ipairs(useAttLimit) do local att_type = att[1] local att_num = att[2] if att_type == EMUCharacterAttrType.strength then if strength < att_num then is_off = true break end elseif att_type == EMUCharacterAttrType.agility then if agility < att_num then is_off = true break end elseif att_type == EMUCharacterAttrType.intelligence then if intelligence < att_num then is_off = true break end end end if is_off then table.insert(all_take_off,item) end end end if table.count(all_take_off) > 0 then local all_str = "" for idx, item in ipairs(all_take_off) do local tab = SL:GetConfig("cfg_item",item.cfgId) local name = tab.name local color_id = tab.color local color_str = SL:GetConfig("cfg_color",color_id).color local one_str = "" .. name .. "" if idx < #all_take_off then one_str = one_str .. "," end all_str = all_str .. one_str local wearBarId, pos = SL:GetEquipWearBarIdPos(item.id) SL:TakeOffEquip(wearBarId, pos) end local str_cfg = SL:GetConfig("cfg_string",28001).text local str = string.format(str_cfg,all_str) SL:CommonTipsMessage({ showTips = str, sureBtnText = "确定"}) end end ---替换装备背包界面按钮图片 function this:ReplaceEquipBagButton(list) for i, v in ipairs(list) do ---@type cfg_bagButton_column local cfg = SL:GetConfig("cfg_bagButton",i) GUI:Image_loadTexture(v, cfg.icon, "Atlas/UIBagPanel_Out.spriteatlas") GUI:setPosition(v,cfg.position[1],cfg.position[2]) GUI:setPositionZ(v,cfg.position[3]) GUI:setVisible(v,cfg.show == 1) end end