local HorseEquip_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local HorseEquipLevelGeneralItem = DataSheetManager.ConstData:GetDataByID("HorseEquipLevelGeneralItem").IntValue local HorseEquipLevelGeneralItemExp = DataSheetManager.ConstData:GetDataByID("HorseEquipLevelGeneralItemExp").IntValue HorseEquip_Controller.PositionImage = { [1] = ConstAssetPathConfig.Path9, [2] = ConstAssetPathConfig.AssetPath58, [3] = ConstAssetPathConfig.AssetPath59, [4] = ConstAssetPathConfig.AssetPath60, } private.horseEquipGs = {} private.ArmorCfgExpData = {} private.ArmorMaxLv = 0 private.HorseEquipGsData = {} private.horseEquipStatusData = {} -- k为horseId v-{isCanEquip是否可装备, isCanUpLv是否可升级} private.isHasHorseCanEquip = false private.isHasHorseEquipCanUpLv = false function HorseEquip_Controller.OnStartup() EventSystem.Regist(EventID.AcquireSystemRedAfterUnlock, private.CalculateEquipRedPoint) -- enterWorld数据初始化结束 EventSystem.Regist(EventID.UI_UpdateWarHorseEquipInfo, private.CalculateEquipRedPoint) -- 战装数据变化 EventSystem.Regist(EventID.HorseEquip_UpdateBag, private.CalculateEquipRedPoint) -- 战装背包数据变化 EventSystem.Regist(EventID.TeamLevelUpdate, private.CalculateEquipRedPoint) -- 战队等级发生变化 EventSystem.Regist(EventID.FunctionUnlockUpdate, private.RefreshInfoByFunction) -- GMS开关变化时刷新 CTL.Bag.RegisteEventByItemId(HorseEquipLevelGeneralItem, private.CalculateEquipRedPoint) -- 装甲材料数据变化 for _, v in DataSheetManager.HorseEquipEnhance:GetEnumerator() do private.ArmorCfgExpData[v.EnhanceLevel] = v.Exp private.ArmorMaxLv = v.EnhanceLevel end for _, v in DataSheetManager.HorseEquipData:GetEnumerator() do private.HorseEquipGsData[v.ID] = UTL.Attr.CalculateFight(DataSheetManager.HorseEquipData:GetDataByID(v.ID).Attr_Table) end end function private.RefreshInfoByFunction(funcId, isUnlock) if funcId == MDL.Unlock.FunctionType.HorseEquip then private.CalculateEquipRedPoint() end end --装甲最大等级 function HorseEquip_Controller.GetArmorMaxLv() return private.ArmorMaxLv end --装甲升到上限等级需要的经验 function HorseEquip_Controller.GetArmorLimitLvUpNeedExp(curLv, limitLv) local totalNeedExp = 0 for i = curLv+1, limitLv do totalNeedExp = totalNeedExp + private.ArmorCfgExpData[i] end return totalNeedExp end --装甲经验可升到的等级 function HorseEquip_Controller.GetArmorArrivedLv(curLv, limitLv, curExp) local arrivedLv = 0 for i = curLv+1, limitLv do curExp = curExp - private.ArmorCfgExpData[i] if curExp < 0 then break end arrivedLv = i end return arrivedLv end --装甲经验升到可升到的等级后剩余的经验 function HorseEquip_Controller.GetArmorArrivedLvLeftExp(curLv, arrivedLv, curExp) if arrivedLv == private.ArmorMaxLv then return 0 end local leftExp = curExp for i = curLv+1, arrivedLv do leftExp = leftExp - private.ArmorCfgExpData[i] end return leftExp end --升级装甲可消耗的道具与获得经验(装甲石) function HorseEquip_Controller.GetGeneralMaterialItem() return HorseEquipLevelGeneralItem, HorseEquipLevelGeneralItemExp end function HorseEquip_Controller.OpenEquipTips(horseId, targetEquipId, equippedEquipId, isChildTips, isOffset) UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseEquipTipBase, {horseId = horseId, targetEquipId = targetEquipId, equippedEquipId = equippedEquipId, isChildTips = isChildTips, isOffset = isOffset}, Const_UI_Lua.UIEnum.UIHorseSoulTipBase) end function HorseEquip_Controller.GotoHorseEquip() if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.HorseEquip) then local activeHorses = MDL.WarHorse.GetActiveHorseInfoDic() if activeHorses then for _, v in pairs (activeHorses) do if v.HeroID then CTL.WarHorse.OpenSubPanel(CTL.WarHorse.Horse_EnterType.Formation, v.ConfigInfo, CTL.WarHorse.Horse_TabIndex.Equip) return end end end CTL.Tips.AddTipsMsg(Const_IDS.IDS_Resonance_Horse_NoOne) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_1317_InfoCode_Guild_GuildInviteTargetFunctionLock) end end --未装备时,服务器会发送"0"过来 function HorseEquip_Controller.JudgeEquipId(equipId) return not string.isNilOrEmpty(equipId) and equipId ~= 0 end --玩家未装备战装最大等阶 function HorseEquip_Controller.GetMaxHorseNotWearingEquipStage() local maxStage = 1 for i, v in ipairs(MDL.HorseEquip.GetEquipMaterialList()) do if not MDL.HorseEquip.JudgeIfEquip(v) then local equipInfo = MDL.HorseEquip.GetEquipInfoById(v) if equipInfo.equipData.EquipStage > maxStage then maxStage = equipInfo.equipData.EquipStage end end end return maxStage end --返回装备的穿戴等级,等级不足标红 function HorseEquip_Controller.GetEquipLevel(equipLevel) local teamLevel = MDL.Player.GetRoleInfo() local equipLev = UTL.Item.GetNobilityByTeamLevel(equipLevel) -- 爵位转换 local result = teamLevel >= equipLevel and equipLev or UTL.Color.FormatRedColor(equipLev) return result end --一键选择材料 function HorseEquip_Controller.AutoSelectMaterial(selectedStage, totalNeedExp) local isEnough = false local materialIdList = {} local materialDict = {} local generalItemCount = UTL.Item.GetItemStockCount(HorseEquipLevelGeneralItem) local generalNeed = generalItemCount if generalNeed > 0 then for num = 1, generalItemCount do if HorseEquipLevelGeneralItemExp * num >= totalNeedExp then generalNeed = num break end end table.insert(materialIdList, HorseEquipLevelGeneralItem) materialDict[HorseEquipLevelGeneralItem] = generalNeed if totalNeedExp - HorseEquipLevelGeneralItemExp * generalNeed <= 0 then isEnough = true return isEnough, materialIdList, materialDict else totalNeedExp = totalNeedExp - HorseEquipLevelGeneralItemExp * generalNeed end end for i, v in ipairs(MDL.HorseEquip.GetEquipMaterialList()) do if not MDL.HorseEquip.JudgeIfEquip(v) then local equipInfo = MDL.HorseEquip.GetEquipInfoById(v) if equipInfo.equipData.EquipStage > selectedStage then break end totalNeedExp = totalNeedExp - equipInfo.equipData.OfferExp table.insert(materialIdList, v) materialDict[v] = 1 if totalNeedExp <= 0 then isEnough = true return isEnough, materialIdList, materialDict end end end return isEnough, materialIdList, materialDict end --region 红点相关 function private.CalculateEquipRedPoint() private.CalculateIsHasHorseCanChange() if private.isHasHorseCanEquip or private.isHasHorseEquipCanUpLv then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.WarHorse_Equip) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.WarHorse_Equip) end end --计算所有坐骑是否有可穿装备的,是否有可升级战装的 function private.CalculateIsHasHorseCanChange() if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.HorseEquip) then return end table.clear(private.horseEquipStatusData) private.isHasHorseCanEquip = false private.isHasHorseEquipCanUpLv = false local isCanEquip, isCanUpLv for _,heroInfo in MDL.Player.GetLineUpHeroInfoEnumerator() do if heroInfo then local horseInfo = heroInfo.horseInfo if horseInfo and horseInfo.Id ~= 0 then private.horseEquipStatusData[horseInfo.Id] = {} --可穿装备 isCanEquip = private.IsHorseCanEquip(horseInfo.Id) private.horseEquipStatusData[horseInfo.Id].isCanEquip = isCanEquip if isCanEquip then private.isHasHorseCanEquip = true end --可升级 isCanUpLv = private.IsHorseArmorCanUpLv(horseInfo.Id) private.horseEquipStatusData[horseInfo.Id].isCanUpLv = isCanUpLv if isCanUpLv then private.isHasHorseEquipCanUpLv = true end end end end end function private.IsHorseCanEquip(horseId) for i = 1, 4 do --只有4个槽位 if HorseEquip_Controller.IsPosCanEquip(horseId,i) then return true end end return false end --该位置是否可以装装备 function HorseEquip_Controller.IsPosCanEquip(horseId, pos) local equipInfo = MDL.HorseEquip.GetEquipSlotInfoByHorseId(horseId, pos) local equipId = equipInfo and equipInfo.Id if not HorseEquip_Controller.JudgeEquipId(equipId) then for i, v in ipairs(MDL.HorseEquip.GetEquipItemList()) do local equipInfo = MDL.HorseEquip.GetEquipInfoById(v) if not equipInfo.equipHorseId and equipInfo.equipData.EquipType == pos then if MDL.HeroSelect.GetTeamLevel() >= equipInfo.equipData.EquipLevel then return true end end end else for i, v in ipairs(MDL.HorseEquip.GetEquipItemList()) do local bagEquipInfo = MDL.HorseEquip.GetEquipInfoById(v) if not bagEquipInfo.equipHorseId and bagEquipInfo.equipData.EquipType == pos then local gs1 = HorseEquip_Controller.GetEquipGs(bagEquipInfo.cfgId) local gs2 = HorseEquip_Controller.GetEquipGs(equipInfo.CfgId) if gs1 > gs2 and MDL.HeroSelect.GetTeamLevel() >= bagEquipInfo.equipData.EquipLevel then return true end end end end return false end function private.IsHorseArmorCanUpLv(horseId) if not private.IsHorseArmorActive(horseId) then return false end local needExp = private.GetHorseArmorUpNextLvNeedExp(horseId) if needExp == 0 then return false end local stage = private.GetHorseUpLvEquipStageCondition(horseId) local isEnough = HorseEquip_Controller.AutoSelectMaterial(stage, needExp) return isEnough end function private.IsHorseArmorActive(horseId) local equipInfoList = MDL.HorseEquip.GetEquipSlotInfoByHorseId(horseId) for i, v in ipairs(equipInfoList) do if not HorseEquip_Controller.JudgeEquipId(v.Id) then return false end end return true end function private.GetHorseArmorUpNextLvNeedExp(horseId) local armorInfo = MDL.HorseEquip.GetArmorInfo(horseId) if armorInfo.level == private.ArmorMaxLv or armorInfo.level == private.GetArmorLimitLv(horseId) then return 0 end local nextLvArmorCfg = DataSheetManager.HorseEquipEnhance:GetDataByEnhanceLevel(armorInfo.level + 1) return nextLvArmorCfg.Exp - armorInfo.exp end function private.GetArmorLimitLv(horseId) local equipInfoList = MDL.HorseEquip.GetEquipSlotInfoByHorseId(horseId) local limitLv = 0 for i, v in ipairs(equipInfoList) do local equipInfo = MDL.HorseEquip.GetEquipInfoById(v.Id) limitLv = limitLv + equipInfo.equipData.OfferLevel end return limitLv end --穿戴的战装最小等阶 function private.GetHorseUpLvEquipStageCondition(horseId) local equipInfoList = MDL.HorseEquip.GetEquipSlotInfoByHorseId(horseId) local equipStage = 0 for i, v in ipairs(equipInfoList) do local equipInfo = MDL.HorseEquip.GetEquipInfoById(v.Id) if i == 1 then equipStage = equipInfo.equipData.EquipStage else if equipStage > equipInfo.equipData.EquipStage then equipStage = equipInfo.equipData.EquipStage end end end return equipStage end -- 某个坐骑战装红点 function HorseEquip_Controller.CheckIfHorseEquipHasRp(horseId) local horseEquipStatusData = private.horseEquipStatusData[horseId] if horseEquipStatusData then return horseEquipStatusData.isCanEquip or horseEquipStatusData.isCanUpLv end return false end -- 某个坐骑装甲是否可升级 function HorseEquip_Controller.IsHorseArmorCanUpLv(horseId) local horseEquipStatusData = private.horseEquipStatusData[horseId] if horseEquipStatusData then return horseEquipStatusData.isCanUpLv end return false end -- 某个坐骑是否可装备 function HorseEquip_Controller.IsHorseCanEquip(horseId) local horseEquipStatusData = private.horseEquipStatusData[horseId] if horseEquipStatusData then return horseEquipStatusData.isCanEquip end return false end --endregion 红点相关 --计算坐骑战装战力 function HorseEquip_Controller.CalculateHorseEquipGs(horseID) local slotList = MDL.HorseEquip.GetEquipSlotInfoByHorseId(horseID) local totalAttrList = {} for i, v in ipairs(slotList) do if HorseEquip_Controller.JudgeEquipId(v.Id) then UTL.Attr.CombineAttr(totalAttrList, HorseEquip_Controller.GetEquipAttrTable(v.CfgId)) end end local armorInfo = MDL.HorseEquip.GetArmorInfo(horseID) local armorAttrData = DataSheetManager.HorseEquipEnhance:GetDataByEnhanceLevel(armorInfo.level).Attr_Table UTL.Attr.CombineAttr(totalAttrList, armorAttrData) private.horseEquipGs[horseID] = UTL.Attr.CalculateFight(totalAttrList) end function HorseEquip_Controller.GetHorseEquipGs(horseID) return private.horseEquipGs[horseID] or 0 end -- 基础属性 function HorseEquip_Controller.GetEquipAttrTable(equipId) return DataSheetManager.HorseEquipData:GetDataByID(equipId).Attr_Table end -- 战装战力 function HorseEquip_Controller.GetEquipGs(equipId) return private.HorseEquipGsData[equipId] end local function SortAttr(a, b) return a.AttrType < b.AttrType end -- 战装属性 function HorseEquip_Controller.GetHorseAttr(horseID) local isEquiped = false local attrList = {} local slotList = MDL.HorseEquip.GetEquipSlotInfoByHorseId(horseID) for i, v in ipairs(slotList) do if CTL.HorseEquip.JudgeEquipId(v.Id) then isEquiped = true UTL.Attr.CombineAttr(attrList, CTL.HorseEquip.GetEquipAttrTable(v.CfgId)) end end local armorInfo = MDL.HorseEquip.GetArmorInfo(horseID) local armorAttrData = DataSheetManager.HorseEquipEnhance:GetDataByEnhanceLevel(armorInfo.level).Attr_Table UTL.Attr.CombineAttr(attrList, armorAttrData) table.sort(attrList, SortAttr) return attrList, isEquiped end return HorseEquip_Controller