local WarHorse_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local FightIcon = "zq_icon_zhanli" --战力icon local ATTR_TXT_COLOR = "70c664" -- 检测过期皮肤时间延迟常量, 界面表现上延迟30秒 WarHorse_Controller.TIME_OUT_DELAY_VAL = 30 WarHorse_Controller.Horse_TabIndex = { Break = 1, --突破界面 HorseSoul = 2, --魂珠界面 Equip = 3, --战装界面 Appearance = 4, -- 坐骑皮肤 Info = 5, --信息界面 } --养成界面的进入方式 WarHorse_Controller.Horse_EnterType = { Formation = 1, --阵容界面 WarHorse = 2, --坐骑一级界面 } function WarHorse_Controller.OnStartup() EventSystem.Regist(EventID.BagItem_Update, private.CheckIfWarHorseAndFormationRed) EventSystem.Regist(EventID.UI_UpdateWarHorseInfo, private.CheckIfWarHorseAndFormationRed) EventSystem.Regist(EventID.AcquireSystemRedAfterUnlock, private.CheckIfWarHorseAndFormationRed) EventSystem.Regist(EventID.UI_HorseSoul_EquipUpdate, private.CheckIfWarHorseRed) EventSystem.Regist(EventID.HorseSoulPearl_UpdateBag, private.CheckIfWarHorseRed) EventSystem.Regist(EventID.FunctionUnlockUpdate, private.RefreshInfoByFunction) private.heroList = {} end function private.CheckIfWarHorseAndFormationRed() private.CheckIfWarHorseRed() private.CheckIfFormationRed() end --开关玩法时执行 function private.RefreshInfoByFunction(funcId, isUnlock) if funcId == MDL.Unlock.FunctionType.WarHorse then if not isUnlock then private.EndAndCloseWarHorse() end end end function private.EndAndCloseWarHorse() logging.log(LTAG.LOG, "EndAndCloseWarHorse") UIManager.CloseView(Const_UI_Lua.UIEnum.UICommonNoteView) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPreviewItemTips) UIManager.CloseView(Const_UI_Lua.UIEnum.UIWarHorseBreak) UIManager.CloseView(Const_UI_Lua.UIEnum.UIWarHorseInfo) UIManager.CloseView(Const_UI_Lua.UIEnum.UIWarHorseInfoView) UIManager.CloseView(Const_UI_Lua.UIEnum.UIResonanceInfo) UIManager.CloseView(Const_UI_Lua.UIEnum.UIWarHorseRelationPopUp) UIManager.CloseView(Const_UI_Lua.UIEnum.UIWarHorseAttrInfoView) EventSystem.Dispatch(EventID.UI_WarHorse_OnCloseGamePlay) end function WarHorse_Controller.OpenMainPanel() UIManager.OpenView(Const_UI_Lua.UIEnum.UIWarHorse) end function WarHorse_Controller.OpenWearPanel(heroId,info) local context = { HeroID = heroId, HorseInfo = info } UIManager.OpenView(Const_UI_Lua.UIEnum.UIWarHorseChangeView,context) end ---@param tabIndex 除信息突破两个默认页签外的其他TabIndex空未默认 ---@param horseId 跳转到某个坐骑可为nil ---@param appearanceId 跳转到某个坐骑外观可为nil function WarHorse_Controller.OpenHorseUI(tabIndex, horseId, appearanceId) --跳转到某个坐骑 if horseId then local config = DataSheetManager.HorseData:GetDataByHorseID(horseId) WarHorse_Controller.OpenSubPanel(WarHorse_Controller.Horse_EnterType.WarHorse, config, tabIndex) return end local activeHorses = MDL.WarHorse.GetActiveHorseInfoDic() local activeHorse local tabIndex = tabIndex and tabIndex or nil for _, v in pairs (activeHorses) do activeHorse = v if v.HeroID then CTL.WarHorse.OpenSubPanel(WarHorse_Controller.Horse_EnterType.WarHorse, v.ConfigInfo, tabIndex, appearanceId) return end end if activeHorse then CTL.WarHorse.OpenSubPanel(WarHorse_Controller.Horse_EnterType.WarHorse, activeHorse.ConfigInfo, tabIndex, appearanceId) else local config = DataSheetManager.HorseData:GetDataByHorseID(1) WarHorse_Controller.OpenSubPanel(WarHorse_Controller.Horse_EnterType.WarHorse, config, WarHorse_Controller.Horse_TabIndex.Info, appearanceId) end end --养成界面 function WarHorse_Controller.OpenSubPanel(enterType,configInfo,tabIndex,appearanceId) --tabIndex不传,已激活默认在突破页签下,未激活在信息页签 local tab = tabIndex if tab == nil then tab = WarHorse_Controller.GetDefaultTabIndex(configInfo.HorseID) end local context = { config = configInfo, enterType = enterType, tabIndex = tab, appearanceId = appearanceId } UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIWarHorseBasePanel,context) end function WarHorse_Controller.GetDefaultTabIndex(horseID) local tab if MDL.WarHorse.GetInfoByID(horseID) then tab = WarHorse_Controller.Horse_TabIndex.Break else tab = WarHorse_Controller.Horse_TabIndex.Info end return tab end function WarHorse_Controller.OpenPreviewPanel(horseID) UIManager.OpenView(Const_UI_Lua.UIEnum.UIWarHorseInfoView,{HorseID = horseID}) end function WarHorse_Controller.ActiveSuccess(horseID) UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIWarHorseSuccess, {HorseID = horseID}) end function WarHorse_Controller.GetAttrItemShow(starConfig,index) local content = "" local attrID = starConfig.AttrRepeat[index] local config = DataSheetManager.HorseStarAttr:GetDataByAttrRepeatID(attrID) if config then --只有1条属性 local attr = config.Attr_Table[1] local attrName = DataSheetManager.AttrData:GetDataByID(attr.AttrType).Name local attrValue = attr.AttrNum return UIUtils.GetLocalizedTxt(Const_IDS[attrName])..UTL.Color.FormatGreenColor("+"..attrValue) end return content end --获取下一个突破所需的材料 function WarHorse_Controller.GetNextBreakItemConfig(horseID) local info = MDL.WarHorse.GetInfoByID(horseID) if info and info.HorseInfo then local curStarConfig = DataSheetManager.HorseStar:GetDataByHorseID_Star(horseID,info.HorseInfo.starLevel) local nextStage = info.HorseInfo.starStage + 1 if nextStage > #curStarConfig.ItemRepeat then --下一个突破阶段 local isSuccess, nextStarConfig = DataSheetManager.HorseStar:TryGetDataByHorseID_Star(horseID,info.HorseInfo.starLevel + 1) if isSuccess then return DataSheetManager.HorseStarItem:GetDataByItemRepeatID(nextStarConfig.ItemRepeat[1]).Item_Table end else return DataSheetManager.HorseStarItem:GetDataByItemRepeatID(curStarConfig.ItemRepeat[nextStage]).Item_Table end end return nil end --region 战骑羁绊 function WarHorse_Controller.ChangeEquipWarHorse(heroAID, heroBID) WarHorse_Controller.PushHorseRelationActiveShow(heroAID) WarHorse_Controller.PushHorseRelationActiveShow(heroBID) CTL.Tips.PopRelationShowPanel() end function WarHorse_Controller.PushHorseRelationActiveShow(heroID) -- 获取武将装备的战骑 local info = MDL.WarHorse.GetInfoByHeroID(heroID) if not info then return end local horseID = info.ID -- 判断坐骑武将 是否激活了战骑羁绊 local curRelation = WarHorse_Controller.GetHorousBreakRelation(horseID, heroID, false) if not curRelation then return end table.insert(MDL.Tips.RelationShowUpPanelQueue, { heroID = heroID, horseID = horseID, RelationPanelType = CTL.Tips.RelationPanelType.HorseRelation }) end -- 根据horseID获取对应的坐骑突破等级 function WarHorse_Controller.GetCurHorousBreak(horseID) local activeInfo = MDL.WarHorse.GetInfoByID(horseID) local horseBreakLV = 0 -- 坐骑未激活,或者没有找到该坐骑默认突破等级为0 local isActive = false if activeInfo then horseBreakLV = activeInfo.HorseInfo.starLevel isActive = true end return horseBreakLV, isActive end -- 根据horseID获取对应的坐骑激活(当前/下一级)羁绊的突破等级 -- isNextBreak 为false 为当前,为true 为下一级 function WarHorse_Controller.GetHorousRelationBreakLV(horseID, isNextBreak) -- 获取HorseID对应的坐骑突破等级 local horseBreakLV = WarHorse_Controller.GetCurHorousBreak(horseID) local relationBreakLV = nil if not DataSheetManager.HorseRelation:GetDataByHorseID_HeroID(horseID) then return relationBreakLV end -- 如果表中没有数据直接返回 -- 表中一个坐骑所有英雄的的羁绊等级一致,这里取出第一项用于查找等级 local relationData = nil for _, dataList in DataSheetManager.HorseRelation:GetDataByHorseID_HeroID(horseID) do if not relationData then relationData = dataList break end end -- 获取触发羁绊的突破等级 for _, data in ipairs(relationData.Relation_Table) do if isNextBreak then if horseBreakLV < data.RelationLevel and relationBreakLV == nil then relationBreakLV = data.RelationLevel end else if horseBreakLV >= data.RelationLevel then relationBreakLV = data.RelationLevel end end end return relationBreakLV end -- 根据horseID、heroID获取对应的坐骑的羁绊数据 -- isNextBreak 为false 取当前激活的羁绊数据,为true 取下一级激活的羁绊数据 function WarHorse_Controller.GetHorousBreakRelation(horseID, heroID, isNextBreak) -- 获取HorseID对应的坐骑突破等级 local horseBreakLV = WarHorse_Controller.GetCurHorousBreak(horseID) local relationData = nil local success, relation = DataSheetManager.HorseRelation:TryGetDataByHorseID_HeroID(horseID, heroID) if not success then return relationData end -- 如果表中该战骑没有英雄数据直接返回 for _, data in ipairs(relation.Relation_Table) do if isNextBreak then if horseBreakLV < data.RelationLevel and relationData == nil then relationData = data end else if horseBreakLV >= data.RelationLevel then relationData = data end end end return relationData end -- 排序规则:已拥有高品质武将>专属坐骑武将>已拥有低品质武将>未拥有高品质武将>未拥有低品质武将 local function RelationHeroSort(a, b) local hasHeroA = MDL.HeroSelect.IsHasHero(a.HeroID) local hasHeroB = MDL.HeroSelect.IsHasHero(b.HeroID) if hasHeroA ~= hasHeroB then return hasHeroA else if a.SpecialRelation == b.SpecialRelation then local heroA = DataSheetManager.HeroNum:GetDataByID(a.HeroID) local heroB = DataSheetManager.HeroNum:GetDataByID(b.HeroID) if heroA.HeroQuality ~= heroB.HeroQuality then return heroA.HeroQuality > heroB.HeroQuality else return a.HeroID < b.HeroID end else return a.SpecialRelation > b.SpecialRelation end end end local function IpairsValue(tab, i) i = i + 1 local data = tab[i] if data then return i, tab[i] else return nil end end -- 根据horseID获取该坐骑的羁绊武将列表 function WarHorse_Controller.GetHorseRelationHeroList(horseID) local index = 1 local HorseRelationList = {} private.heroList = {} -- 添加元素 if DataSheetManager.HorseRelation:GetDataByHorseID_HeroID(horseID) ~= nil then -- 确定该坐骑有羁绊武将 for _, data in DataSheetManager.HorseRelation:GetDataByHorseID_HeroID(horseID) do if MDL.HideGolden.IsShowGoldenByID(LuaConst.ShowGoldenType.Hero, data.HeroID) then HorseRelationList[index] = data index = index + 1 end end end -- 移除元素 for i = #HorseRelationList, index, -1 do table.remove(HorseRelationList, i) end -- 对列表进行排序 table.sort(HorseRelationList, RelationHeroSort) for k,v in ipairs(HorseRelationList) do table.insert(private.heroList, v.HeroID) end return IpairsValue, private.heroList, 0 end -- 根据horseID、heroID获取技能战力 function WarHorse_Controller.GetHorousRelationSkillGs(horseID, heroId) local skillGs = 0 local curRelation = WarHorse_Controller.GetHorousBreakRelation(horseID, heroId, false) if curRelation then local skillData = DataSheetManager.HorseSkillData:GetDataByHorseSkill(curRelation.RelationSkill) if skillData then skillGs = skillData.HorseSkillGS end end return skillGs end --endregion --region 战骑红点 --是否可激活 function WarHorse_Controller.CheckHorseIfEnableActive(configInfo) if configInfo then if MDL.WarHorse.GetInfoByID(configInfo.HorseID) then return false end local costItem = configInfo.Item_Table[1] --目前为1个材料 local costNum = costItem.ItemNum local costID = costItem.ItemID if MDL.Bag.GetItemCount(costID) >= costNum then return true end end return false end --战骑是否可突破 function WarHorse_Controller.CheckIfWarHorseBreak(horseID) local info = MDL.WarHorse.GetInfoByID(horseID) if info then local itemConfig = WarHorse_Controller.GetNextBreakItemConfig(horseID) if itemConfig then local isNotEnough = false for _,v in ipairs(itemConfig) do local costNum = v.ItemNum local costID = v.ItemID if MDL.Bag.GetItemCount(costID) < costNum then isNotEnough = true break end end if isNotEnough == false then return true end end end return false end function private.CheckIfWarHorseRed() CTL.RedPoint.AddOneRedPointFunc(private.RealCheckIfWarHorseRed) end --战骑入口红点 --后续模块不要再用这种方式计算红点了,应该使用AddRedPoint(子模块红点) function private.RealCheckIfWarHorseRed() local isRed = false if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.WarHorse) then for _,configInfo in DataSheetManager.HorseData:GetEnumerator() do --激活红点 if WarHorse_Controller.CheckHorseIfEnableActive(configInfo) then isRed = true break end --突破红点 if WarHorse_Controller.CheckIfWarHorseBreak(configInfo.HorseID) then isRed = true break end -- 魂珠红点 if CTL.HorseSoul.CheckIfWarHorseSoul(configInfo.HorseID) then isRed = true break end end end if isRed then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.WarHorse_OldMoudles) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.WarHorse_OldMoudles) end end function private.CheckIfFormationRed() CTL.RedPoint.AddOneRedPointFunc(private.RealCheckIfFormationRed) end --总阵容战骑红点 function private.RealCheckIfFormationRed() if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.WarHorse) then local isRed = false local lineUpIds = MDL.Player.GetHeroLinUpIds() for i = 1, #lineUpIds do if WarHorse_Controller.CheckHeroHorseRed(lineUpIds[i]) then isRed = true break end end if isRed then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_WarHorse) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_WarHorse) end else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_WarHorse) end end function WarHorse_Controller.CheckHeroHorseRed(heroId) local info = MDL.WarHorse.GetInfoByHeroID(heroId) if info then --替换红点 if WarHorse_Controller.CheckHeroHorseIfReplace(heroId, info.ID) then return true end --突破红点 if WarHorse_Controller.CheckIfWarHorseBreak(info.ID) then return true end --魂珠红点 if CTL.HorseSoul.CheckIfHorseSoulHasRp(info.ID) then return true end --战装红点 local horseEquipRedPoint = CTL.HorseEquip.CheckIfHorseEquipHasRp(info.ID) if horseEquipRedPoint then return true end else --穿戴红点 return WarHorse_Controller.CheckHeroHorseIfWear(heroId) end return false end --坐骑穿戴红点 function WarHorse_Controller.CheckHeroHorseIfWear(heroId) local dic = MDL.WarHorse.GetActiveHorseInfoDic() if dic then if heroId > 0 then local info = MDL.WarHorse.GetInfoByHeroID(heroId) if info == nil then for _,v in pairs(dic) do if v.HeroID == nil then return true end end end end end return false end --坐骑替换红点 function WarHorse_Controller.CheckHeroHorseIfReplace(heroId, horseID) --存在无人穿戴的高战力的坐骑 local dic = MDL.WarHorse.GetActiveHorseInfoDic() if dic then local fight = 0 local info = MDL.WarHorse.GetInfoByID(horseID) if info and info.HeroID then -- 这里计算战斗力 需要 加上羁绊技能战力 fight = info.HorseInfo.gs + WarHorse_Controller.GetHorousRelationSkillGs(horseID, heroId) for _,v in pairs(dic) do if v.HeroID == nil then -- 这里计算战斗力 需要 加上羁绊技能战力 local infoGS = v.HorseInfo.gs infoGS = infoGS + WarHorse_Controller.GetHorousRelationSkillGs(v.ConfigInfo.HorseID, heroId) if infoGS > fight then return true end end end end end return false end --endregion function WarHorse_Controller.SetStateTimerTxt(appearanceID, timerComp, parentComp) local appearanceData = MDL.WarHorse.GetAppearanceInfoByID(appearanceID) local activeState = MDL.WarHorse.GetOwnType(appearanceID) if activeState <= MDL.WarHorse.OwnedType.Forever then timerComp:EndTimer() timerComp:SetCDLabel(UIUtils.GetLocalizedTxt(Const_IDS["IDS_HorseAppearance_GotForever"])) elseif activeState == MDL.WarHorse.OwnedType.TimeLimit then local time = appearanceData.endTime + WarHorse_Controller.TIME_OUT_DELAY_VAL - UTL.Time.GetServerTimestamp() timerComp:SetDHMSStr( UIUtils.GetLocalizedTxt(Const_IDS["IDS_HorseAppearance_Period1"]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_HorseAppearance_Period2"]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_HorseAppearance_Period3"]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_HorseAppearance_Period4"]) ) timerComp:ResetAndBeginCustomTimer(false, time, 0, nil) else timerComp:EndTimer() timerComp:SetCDLabel(nil) UIUtils.SetActive(parentComp, false) end end function WarHorse_Controller.OnClickChangeBattleAppearance(horseID, appearanceID) -- 该皮肤未拥有 if MDL.WarHorse.GetOwnType(appearanceID) > MDL.WarHorse.OwnedType.TimeLimit then CTL.Tips.AddTipsMsg(Const_IDS["IDS_HorseAppearance_NotGotTip"]) return end -- 坐骑皮肤已被其他马装备 local oldOwnerHorseID = MDL.WarHorse.GetEquippedHorseIDByAppearanceID(appearanceID) if oldOwnerHorseID > 0 and oldOwnerHorseID ~= horseID then local oldOwnerHorseData = MDL.WarHorse.GetInfoByID(oldOwnerHorseID).ConfigInfo local newOwnerHorseData = MDL.WarHorse.GetInfoByID(horseID).ConfigInfo local desc = string.FormatByIdsId(Const_IDS["IDS_HorseAppearance_Change"], UIUtils.GetLocalizedTxt(Const_IDS[oldOwnerHorseData.HorseName]), UIUtils.GetLocalizedTxt(Const_IDS[newOwnerHorseData.HorseName])) UTL.MessageBox.ShowOKCancelBox(nil, desc, function() print("here")MDL.WarHorse.HorseAppearanceLineSetReq(horseID, appearanceID) end) return end MDL.WarHorse.HorseAppearanceLineSetReq(horseID, appearanceID) end function WarHorse_Controller.IsAppearanceGotRed() for _, v in ipairs(MDL.WarHorse.GetAppearanceDataList()) do if v.IsNew and MDL.WarHorse.GetOwnType(v.ID) <= MDL.WarHorse.OwnedType.TimeLimit then return true end end return false end -- 背包内物品是否有红点 function WarHorse_Controller.ItemAppearanceInBagHasRed(itemID) local appearanceData = MDL.WarHorse.GetAppearanceDataByItemID(itemID) local ownType = MDL.WarHorse.GetOwnType(appearanceData.ID) if ownType == MDL.WarHorse.OwnedType.TimeLimit then return true else return ownType >= MDL.WarHorse.OwnedType.Overdue end end -- 获取战斗内坐骑真实数据 function WarHorse_Controller.GetCurRealHorseDataByHorseID(horseID) local horseInfo = MDL.WarHorse.GetInfoByID(horseID) local equippedAppearanceID = horseInfo and horseInfo.HorseInfo.horseAppearanceId or 0 if equippedAppearanceID > 0 then return MDL.WarHorse.GetAppearanceInfoByID(equippedAppearanceID) else return DataSheetManager.HorseData:GetDataByHorseID(horseID) end end -- 卸下坐骑皮肤、形象 function WarHorse_Controller.TakeOffAppearance(appearanceID) if appearanceID and appearanceID > 0 then -- 更新当前主城形象 if appearanceID == MDL.WarHorse.GetCurAppearanceShowID() then MDL.WarHorse.HorseAppearanceShowChangeReq(0) end -- 更新战斗中坐骑皮肤 local curEquippedHorseID = MDL.WarHorse.GetEquippedHorseIDByAppearanceID(appearanceID) if curEquippedHorseID > 0 then MDL.WarHorse.HorseAppearanceLineSetReq(curEquippedHorseID, 0) end end end -- 形象设置界面位移 function WarHorse_Controller.GetHorseSettingAppearanceXYZ(appearanceID) local xyzArr = MDL.WarHorse.GetAppearanceInfoByID(appearanceID).SettingModelXYZ return xyzArr[1], xyzArr[2], xyzArr[3] end -- 养成界面位移 function WarHorse_Controller.GetHorseBattleAppearanceXYZ(horseDataConfig) if horseDataConfig.ModelXYZ and #horseDataConfig.ModelXYZ > 0 then return horseDataConfig.ModelXYZ[1], horseDataConfig.ModelXYZ[2], horseDataConfig.ModelXYZ[3] else return 0, 0, horseDataConfig.Position_Z end end -- 排行榜界面位移 function WarHorse_Controller.GetHorseRankModelXYZ(horseDataConfig, x, y, z) if horseDataConfig.RankModelXYZ and #horseDataConfig.RankModelXYZ > 0 then return horseDataConfig.RankModelXYZ[1], horseDataConfig.RankModelXYZ[2], horseDataConfig.RankModelXYZ[3] else return x, y, z end end function WarHorse_Controller.IsWarHorseAppearanceTab(index) return index == WarHorse_Controller.Horse_TabIndex.Appearance end function WarHorse_Controller.IsUsingLowModel() if SettingAPI.deviceLevel == 0 then return true end if UNITY_IOS then return SystemInfo.systemMemorySize < 3200 end return false end ---@public 获取坐骑品质等级 function WarHorse_Controller.GetHorseQuality(horseId) local appearanceWearID = MDL.WarHorse.GetEquippedAppearanceIDByHorseID(horseId) if appearanceWearID > 0 then local appearanceData = DataSheetManager.HorseAppearance:GetDataByID(appearanceWearID) if appearanceData and appearanceData.Color > 0 then return appearanceData.Color end end return DataSheetManager.HorseData:GetDataByHorseID(horseId).HorseQuality end function WarHorse_Controller.GetBreakMax(horseID) local max = -1 for key, value in DataSheetManager.HorseStar:GetDataByHorseID_Star(horseID) do max = max + 1 end return max end return WarHorse_Controller