local Pet_Controller = {} local EventSystem = require('Event/EventSystem') local private = {} local Const_Render_ID = 38024 local Const_God_Render_ID = 38025 local HanMapCityID = 8 local Const_Star_Limit_Normal = 5 --一代宠物星级上限 local Const_Star_Limit_Normal2 = 9 --二代宠物星级上限 local Const_Star_Limit_Max = 10 local Const_RuneMerge_Count = 4 Pet_Controller.INITIAL_BAG_VOLUME = DataSheetManager.ConstData:GetDataByID("PetBagInitialNew").IntValue Pet_Controller.MAX_BAG_VOLUME = DataSheetManager.ConstData:GetDataByID("PetBagMax").IntValue Pet_Controller.MAIN_SLOT_UNLOCK_ID = { [1] = DataSheetManager.PetEquip:GetDataByID(1).TriggerID, [2] = DataSheetManager.PetEquip:GetDataByID(3).TriggerID, [3] = DataSheetManager.PetEquip:GetDataByID(5).TriggerID, } Pet_Controller.SUB_SLOT_UNLOCK_CONFIG = { [1] = DataSheetManager.PetEquip:GetDataByID(2), [2] = DataSheetManager.PetEquip:GetDataByID(4), [3] = DataSheetManager.PetEquip:GetDataByID(6), } Pet_Controller.TOTAL_SKILL_COUNT = 3 Pet_Controller.MAX_SKILL_LEVEL = 4 --符文技能最大等级,天地玄黄 Pet_Controller.MAX_SLOT = 3 --最大槽位数 Pet_Controller.RuneOptConfirmKey_ReplaceSame = 1 Pet_Controller.RuneOptConfirmKey_ReplaceRand = 2 Pet_Controller.RuneOptConfirmKey_MaxMerge = 3 Pet_Controller.ConstPetItemEffectID = 625001 local FAKE_PET_PEDIGREE_EXTRA = DataSheetManager.ConstData:GetDataByID("PetTalentExtraParentAdd").IntValue local FAKE_PET_PEDIGREE = DataSheetManager.ConstData:GetDataByID("PetTalentExtraAdd").IntValue local PEDIGREE_MIX_IMG = "Atlas/UI_Pet/ty_icon_xx" local ShoutCDTime = DataSheetManager.ConstData:GetDataByID("TeamNoticeCD").IntValue local ITEM_CONSUME_ID = DataSheetManager.ConstData:GetDataByID("PetCatchCost").IntValue Pet_Controller.BaseViewType = { Detail = Const_UI_Lua.UIEnum.UIPetDetailBase, -- 信息 LevelUp = Const_UI_Lua.UIEnum.UIPetLevelUp, -- 升级 } Pet_Controller.PetPopPanelType = { Active = 1, -- 激活成功 Reproduction = 2, -- 繁殖成功 Catch = 3, -- 捕捉成功 Mutation = 4, -- 变异成功 Advanced = 5, -- 进阶 EggActive = 6, --宠物激活 } Pet_Controller.ReleasePanelType = { CatchAndReproduction = 1, InBagRelease = 2 } Pet_Controller.ChangePetPanelType = { Main = 1, Assistance = 2, } Pet_Controller.PetStageTxt = { [MDL.Pet.PetQuality.Normal] = { [MDL.Pet.PetState.Basic] = UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetGeneral), [MDL.Pet.PetState.Mutation] = UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetVariation), }, [MDL.Pet.PetQuality.God] = { [MDL.Pet.PetState.Basic] = UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetAdvance1), [MDL.Pet.PetState.Mutation] = UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetAdvance2), [MDL.Pet.PetState.Ultimate] = UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetAdvance3), }, } --天地玄黄 Pet_Controller.RuneSkillLevelIDS = { Const_IDS.IDS_PetRune7, Const_IDS.IDS_PetRune6, Const_IDS.IDS_PetRune5, Const_IDS.IDS_PetRune4, } Pet_Controller.SkillType = { NormalAttack = 1, --普攻 UsableSkill = 2, --主动 PassiveSkill = 3, --被动 } Pet_Controller.SkillTypeDesc = { Const_IDS.IDS_Pet_SkillGet1, Const_IDS.IDS_Pet_SkillGet2, Const_IDS.IDS_Pet_SkillGet3, } function Pet_Controller.OnStartup() EventSystem.Regist(EventID.Pet_CloseCatchUpView, private.CloseCatchViewByS2C) EventSystem.Regist(EventID.Pet_OnCatchAction, private.CatchWildPet) EventSystem.Regist(EventID.UI_Pet_PopCatchPanel, private.OnSuccessPopCatch) EventSystem.Regist(EventID.AfterTownLevelBegin, private.OnReadyToTarget) EventSystem.Regist(EventID.FunctionUnlockUpdate, private.CheckFunctionUnlock) EventSystem.Regist(EventID.UI_Pet_UpdateRuneBagItem, private.CheckRuneMergeRed) EventSystem.Regist(EventID.UI_Pet_UpdateRuneBagItem, private.CheckRuneStudyRed) CTL.Bag.RegisteEventByItemId(ITEM_CONSUME_ID, Pet_Controller.CheckCatchReward) private.tempAttrTab = {} private.lastShoutTimeStamp = 0 Pet_Controller.IsUseExtraBreedMat = false --繁殖是否额外使用道具 private.runeOptConfirmDict = {} private.isBreedRoomInValid = false CTL.Bag.RegisteEventByItemType(LuaConst.ItemType.Pet, Pet_Controller.CheckIfLevelUp, nil, LuaConst.ItemMaterialsType.ExpPill) CTL.Bag.RegisteEventByItemType(LuaConst.ItemType.Pet, private.CheckGodActiveAndBreak, nil, LuaConst.ItemMaterialsType.JingHunStone) CTL.Bag.RegisteEventByItemType(LuaConst.ItemType.Pet, private.CheckRuneBreakRed, nil, LuaConst.ItemMaterialsType.AdvanceMaterials) CTL.Bag.RegisteEventByItemType(LuaConst.ItemType.Pet, private.ForceUseRelationSkillItem, nil, LuaConst.ItemMaterialsType.BreakPill) end function private.CheckFunctionUnlock() if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Pet) == false then --处理GMS关闭,统一关掉宠物相关界面 UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetLearnPopup) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetChangeView) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetChangeConfirm) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetRuneIllustratedHandbook) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetReleasePopUp) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetReproductionPopUp) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetInvitedMultiPanel) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetInvitePopUp) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetReproductionGet) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetUnlockAssistancePanel) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetRenamePanel) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIGodPetRuneBase) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIPetCatchPopUp) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIPetReproduction) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIPetSuccinct) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIPetActiveSuccess) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIPetArray) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIPetFormation) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIPetIllustratedHandbook) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIPetBasePanel) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIGodPetBreak) end private.CheckOneTimeRed() end function private.CloseCatchViewByS2C() if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIPetCatchPopUp) then UIManager.CloseView(Const_UI_Lua.UIEnum.UIPetCatchPopUp) end end function Pet_Controller.SetPetStar(group, petPedigree, petGeneration) local starLimit = Const_Star_Limit_Max if petGeneration == 1 then starLimit = math.max(Const_Star_Limit_Normal, petPedigree) else starLimit = math.max(Const_Star_Limit_Normal2, petPedigree) end --保证动效一致,先全部隐藏 for i, v in ipairs(group) do v.state_Star:SetState(0) end for i, v in ipairs(group) do if i <= starLimit then UIUtils.SetActive(v.gameObject, true) if petPedigree >= i then v.state_Star:SetState(1) end else UIUtils.SetActive(v.gameObject, false) end end end function Pet_Controller.SetPetSign(group_Sign, petInfo, petConfig) if petConfig.Quality == MDL.Pet.PetQuality.God then group_Sign.state_Sign:SetState(0) UIUtils.SetLabelText(group_Sign.lab_SignGod, Const_IDS.IDS_GodPet) group_Sign.txt_Type.text = Pet_Controller.GetGodBreakDesc(petInfo, true) else if petInfo.petVariation == MDL.Pet.PetState.Basic then group_Sign.state_Sign:SetState(2) UIUtils.SetLabelText(group_Sign.lab_SignNormal, Const_IDS.IDS_PetGeneral) group_Sign.txt_Type.text = Pet_Controller.GetGenerationTxt(petInfo.petGeneration, true) else group_Sign.state_Sign:SetState(1) group_Sign.lab_SignVariation.text = UTL.Color.FormatTextByColor("8e5cb5", UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetVariation)) group_Sign.txt_Type.text = Pet_Controller.GetGenerationTxt(petInfo.petGeneration, true) end end end function Pet_Controller.GetGodBreakDesc(petInfo, withOffset) local godPetStarCfg = DataSheetManager.GodPetStar:GetDataByPetID_PetStar(petInfo.petType, petInfo.bigBreak) --判断当前是否最大值,需要用TryGet读取下一行 local success = DataSheetManager.GodPetStar:TryGetDataByPetID_PetStar(godPetStarCfg.PetID, godPetStarCfg.PetStar + 1) if success then local count = 0 for i, v in DataSheetManager.GodPetStar:GetEnumerator() do if v.PetID == godPetStarCfg.PetID and v.Stage < godPetStarCfg.Stage then count = count + 1 end end local offset = godPetStarCfg.PetStar - count if godPetStarCfg.Stage == 0 then if withOffset then return UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetAdvance1) .. "+" .. offset else return UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetAdvance1) end elseif godPetStarCfg.Stage == 1 then if withOffset then return UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetAdvance2) .. "+" .. offset else return UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetAdvance2) end elseif godPetStarCfg.Stage == 2 then return UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetAdvance3) end else return UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetAdvance3) end end function Pet_Controller.GetNextRuneCfg(slotInfo) local success, nextRuneCfg = DataSheetManager.PetRuneStar:TryGetDataByID_PointId(slotInfo.talismanBigBreak, slotInfo.talismanSmallBreak + 1) if success == false then --当前是最后一个点,下一个配置需要主键+1读,可能已经是最高等级,读不到下一个等级配置了,因此用TryGet来读表 success, nextRuneCfg = DataSheetManager.PetRuneStar:TryGetDataByID_PointId(slotInfo.talismanBigBreak + 1, 0) end return nextRuneCfg end function Pet_Controller.SetIsBreedRoomInValid(value) private.isBreedRoomInValid = value end function Pet_Controller.GetIsBreedRoomValid() return private.isBreedRoomInValid end -- 抓捕野生宠物 function private.CatchWildPet(npcID) if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Pet) == false then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_3013_InfoCode_FunctionLock) return end local entity, Info = SyncMoveManager.GetObjectEntityAndBasicInfo(npcID) if entity == nil then logging.error(LTAG.ERROR, "抓捕野生宠物,发现宠物已经不存在了! ") return end if entity.components.record:GetVariable("petIsInCapturing") then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_4015_InfoCode_Pet_Catch3) return end local tempInfo = Info.scenePetInfo local petCfg = DataSheetManager.PetData:GetDataByID_Stage(tempInfo.petId, tempInfo.petIsVariation) if MDL.HeroSelect.GetTeamLevel() < petCfg.TakeLevel then CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_Pet_GetLevelCant, UTL.Item.GetNobilityByTeamLevel(petCfg.TakeLevel))) return end SystemManager.StopAutoFightPathInTown(LogicUpdateManager._curEntity) private.CatchCache = table.pack(tempInfo.petId, tempInfo.petSex, tempInfo.petIsVariation, tempInfo.petPedigree) MDL.Pet.StartCapturePetReq(MDL.Pet.CatchOptType.Lock, npcID, tempInfo.petId, tempInfo.petIsVariation) end function private.OnSuccessPopCatch() local petId, petSex, variationState, petPedigree = table.unpack(private.CatchCache) if MDL.Pet.GetActiveCount() >= MDL.Pet.GetBagMaxCount() then CTL.Tips.AddTipsMsg(Const_IDS.IDS_PetCatch10) return end UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetCatchPopUp, { petTypeID = petId, petSex = petSex, variationState = variationState, petPedigree = petPedigree, generation = 1, }) end function Pet_Controller.PopSuccessPanel(panelType, petUniqueID, unSavePetInfo) local param = { panelType = panelType, petUniqueID = petUniqueID } local tempInfo = petUniqueID and MDL.Pet.GetActiveInfo(petUniqueID) if tempInfo then param.petInfo = tempInfo.Info param.petConfig = tempInfo.Config param.isReqGet = false else param.petInfo = unSavePetInfo param.petConfig = DataSheetManager.PetData:GetDataByID_Stage(unSavePetInfo.petType, unSavePetInfo.petVariation) param.isReqGet = true end UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIPetActiveSuccess, param) end function Pet_Controller.GetGenerationTxt(generation, withColor) if generation == 1 then return UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetFirst) end if withColor then return UTL.Color.FormatTextByColor("60b176", UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetSecond)) else return UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetSecond) end end function Pet_Controller.GetSkillType(skillId) for _, cfg in DataSheetManager.PetData:GetEnumerator() do for i, v in ipairs(cfg.TalentSkill) do if v == skillId then if cfg.Quality == MDL.Pet.PetQuality.God then if i == 1 then return Pet_Controller.SkillType.NormalAttack else return Pet_Controller.SkillType.PassiveSkill end else if #cfg.TalentSkill == 1 then return Pet_Controller.SkillType.NormalAttack else return Pet_Controller.SkillType.PassiveSkill end end end end for i, v in ipairs(cfg.ChildTalentSkill) do if v == skillId then return Pet_Controller.SkillType.UsableSkill end end end return 0 end function private.GetPetModelData(path, className) if private.petModelCfg == nil then private.petModelCfg = require("Modules/Pet/PetModelCfg"):new() end return private.petModelCfg.GetData(className, path) end function Pet_Controller.GetRenderTextureModelParam(petConfig, className) local monsterModelData = DataSheetManager.MonsterModelData:GetDataByID(petConfig.PetModelID) local renderId = Const_Render_ID if petConfig.Quality == MDL.Pet.PetQuality.God then if petConfig.Stage == MDL.Pet.PetState.Mutation or petConfig.Stage == MDL.Pet.PetState.Ultimate then renderId = Const_God_Render_ID end end local data = private.GetPetModelData(monsterModelData.Path, className) return monsterModelData.Path, data.ModelScale, nil, renderId, petConfig.ModelIdleAnim, nil, petConfig.PetShowEffect, data.ModelXYZ, data.ModelRot end function Pet_Controller.GetDevelopModelParam(petCfg, className) local monsterModelData = DataSheetManager.MonsterModelData:GetDataByID(petCfg.PetModelID) local data = private.GetPetModelData(monsterModelData.Path, className) return monsterModelData.Path, petCfg.PetModelLight, data.ModelXYZ, data.ModelScale, data.ModelRot, nil, petCfg.PetShowEffect, petCfg.ModelIdleAnim end function Pet_Controller.AddBagVolume() local curCount = MDL.Pet.GetBagMaxCount() if curCount >= Pet_Controller.MAX_BAG_VOLUME then return end local targetCount = curCount - Pet_Controller.INITIAL_BAG_VOLUME + 1 local config = DataSheetManager.PetBag:GetDataByID(targetCount) local content = string.FormatByIdsId( Const_IDS.IDS_PetBagAdd, UTL.Item.GetItemName(config.ItemID) .. config.ItemNum, curCount, curCount + 1 ) UTL.MessageBox.ShowOKCancelBox(nil, content, MDL.Pet.PetListExpandReq) end function Pet_Controller.GetPetPedigreeImgText(pedigree) return string.format("%s", pedigree, PEDIGREE_MIX_IMG) end -- 设置宠物道具图标 function Pet_Controller.SetPetIconComp(img_Icon, img_Quality, txt_Lv, petTypeID, petStage, petLevel) local config = DataSheetManager.PetData:GetDataByID_Stage(petTypeID, petStage) if img_Icon then UIUtils.SetImageByAssetBundle(img_Icon, config.PetIcon) end if img_Quality then -- 目前只有日本地区区分彩金和暗金宠物底图,其他地区品质同意为金色。 if GameAppInfo.IsJapanesePackage() then UTL.Color.SetQualityImageByType(img_Quality, config.PetQualityFrame, UTL.Color.QualityType.PetFrame) end end if txt_Lv then UIUtils.SetLabel(txt_Lv, UTL.Item.GetNobilityByTeamLevel(petLevel)) end end function Pet_Controller.SetPetName(label, petInfo, petCfg) if string.isNilOrEmpty(petInfo.petName) == false then label.text = petInfo.petName else UIUtils.SetLabelText(label, Const_IDS[petCfg.PetName]) end end function Pet_Controller.SetTalentIcon(talentType, label, icon) local cfg = DataSheetManager.PetTalentType:GetDataByTalentType(talentType) UIUtils.SetLabelText(label, Const_IDS[cfg.TalentNameIDS]) UTL.Attr.SetAttrIcon(icon, cfg.Attr_Table[1].AttrType) end function Pet_Controller.GetTalentTab(petCfg, petInfo) local talentTb if petCfg.Quality == MDL.Pet.PetQuality.Normal then talentTb = petCfg.Talent_Table else if petInfo then local godPetStar = DataSheetManager.GodPetStar:GetDataByPetID_PetStar(petCfg.ID, petInfo.bigBreak) if godPetStar.GodPetStarTalentID == 0 then talentTb = petCfg.Talent_Table else local godPetStarTalent = DataSheetManager.GodPetStarTalent:GetDataByID(godPetStar.GodPetStarTalentID) talentTb = godPetStarTalent.Talent_Table end else talentTb = petCfg.Talent_Table end end return talentTb end function Pet_Controller.ShowTalentDesc(petCfg, petInfo, index, target) local talentTb = Pet_Controller.GetTalentTab(petCfg, petInfo) local talentCfg = DataSheetManager.PetTalentType:GetDataByTalentType(talentTb[index].TalentType) UIManager.OpenView(Const_UI_Lua.UIEnum.UIDescriptionPanel, { target = target, posType = LuaConst.DescriptionPanelType.Center, offsetX = 0, text = Const_IDS[talentCfg.TalentDesIDS] }) end -- 设置宠物资质信息 function Pet_Controller.SetPetAptitude(aptCompArr, petInfo, petCfg, isNew) local talentTb local isFull = false --神宠和普通宠的资质最大值读不同配置 if petCfg.Quality == MDL.Pet.PetQuality.Normal then talentTb = petCfg.Talent_Table else local godPetStar = DataSheetManager.GodPetStar:GetDataByPetID_PetStar(petCfg.ID, petInfo.bigBreak) if godPetStar.GodPetStarTalentID == 0 then --满了 isFull = true talentTb = petCfg.Talent_Table else local godPetStarTalent = DataSheetManager.GodPetStarTalent:GetDataByID(godPetStar.GodPetStarTalentID) talentTb = godPetStarTalent.Talent_Table end end local fakeVal if Pet_Controller.IsPetGenerationEquals(petInfo, 1, false) then fakeVal = FAKE_PET_PEDIGREE_EXTRA else fakeVal = FAKE_PET_PEDIGREE end local curAptitude = isNew and petInfo.newAptitude or petInfo.petAptitude for idx, collection in ipairs(aptCompArr) do local aptConfig = talentTb[idx] Pet_Controller.SetTalentIcon(aptConfig.TalentType, collection.lab_HP, collection.sprite_HP) for i, v in ipairs(curAptitude) do if v.aptitudeType == aptConfig.TalentType then if isFull then UIUtils.SetLabel(collection.txt_HPPresent, v.aptitudeValue + fakeVal) collection.slider_XP.value = 1 else UIUtils.SetLabel(collection.txt_HPPresent, v.aptitudeValue + fakeVal .. "/" .. aptConfig.TalentMax + fakeVal) collection.slider_XP.value = (v.aptitudeValue + fakeVal) / (aptConfig.TalentMax + fakeVal) end break end end end end -- 预览设置宠物资质预览信息 function Pet_Controller.SetPetAptitudePreviewInfo(aptCompArr, talentTb) for idx, collection in ipairs(aptCompArr) do Pet_Controller.SetTalentIcon(talentTb[idx].TalentType, collection.lab_HP, collection.sprite_HP) UIUtils.SetLabel(collection.txt_HPPresent, talentTb[idx].TalentMax + FAKE_PET_PEDIGREE) collection.slider_XP.value = 0 end end -- 设置宠物技能 function Pet_Controller.SetTalentSkillGroup(cellArr, skillArr) local max = math.max(#skillArr, Pet_Controller.TOTAL_SKILL_COUNT) for i, v in ipairs(cellArr) do if i <= max then UIUtils.SetActive(v.gameObject, true) if skillArr[i] then v.skill_state:SetState(0) Pet_Controller.SetTalentSkillCell(skillArr[i], v.sprite_Skill, v.txt_SkillType) else v.skill_state:SetState(1) if v.txt_SkillType then UIUtils.SetLabelText(v.txt_SkillType, Pet_Controller.SkillTypeDesc[i]) end end else UIUtils.SetActive(v.gameObject, false) end end end function Pet_Controller.SetTalentSkillCell(talentSkillID, img_Skill, txt_SkillName) local skillConfig = DataSheetManager.PetTalentSkill:GetDataByID(talentSkillID) if img_Skill then UIUtils.SetImageByAssetBundle(img_Skill, skillConfig.SkillIcon) end if txt_SkillName then private.SetSkillName(txt_SkillName, talentSkillID) end end function private.SetSkillName(txt, skillId) for _, cfg in DataSheetManager.PetData:GetEnumerator() do if cfg.Quality == MDL.Pet.PetQuality.God then for i, v in ipairs(cfg.TalentSkill) do if v == skillId then --神宠直接显示技能名字 UIUtils.SetLabelText(txt, Const_IDS[DataSheetManager.PetTalentSkill:GetDataByID(skillId).SkillName]) return end end for i, v in ipairs(cfg.ChildTalentSkill) do if v == skillId then --神宠直接显示技能名字 UIUtils.SetLabelText(txt, Const_IDS[DataSheetManager.PetTalentSkill:GetDataByID(skillId).SkillName]) return end end end end local skillType = Pet_Controller.GetSkillType(skillId) if skillType > 0 then UIUtils.SetLabelText(txt, Pet_Controller.SkillTypeDesc[skillType]) end end function Pet_Controller.ShowSkillUnlockTips(index) if index == 2 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Pet_RuneGetSkillWay1) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Pet_RuneGetSkillWay2) end end function Pet_Controller.ShowSkillTips(talentSkillID) local skillConfig = DataSheetManager.PetTalentSkill:GetDataByID(talentSkillID) UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetSkillTips, { SkillIcon = skillConfig.SkillIcon, SkillName = skillConfig.SkillName, SkillDesc = skillConfig.SkillDesc, SkillType1 = skillConfig.SkillType1, SkillType2 = skillConfig.SkillType2 }) end function Pet_Controller.ShowRuneSkillTips(runeSkillId, isChildTips) --runeSkillId可能是羁绊符文,因此用TryGet来读表 local success, skillConfig = DataSheetManager.PetRuneSkill:TryGetDataByPetRuneID(runeSkillId) local skillDesc if success == false then skillConfig = DataSheetManager.PetRelationSkill:GetDataByRelationSkillID(runeSkillId) skillDesc = UTL.String.FormatCombineTextByID(skillConfig.RuneMainDes) --羁绊符文的描述需要由同类多个等级的描述拼接 local relationTab for _, info in DataSheetManager.PetRelation:GetEnumerator() do for _, v in ipairs(info.Relation_Table) do if v.RelationSkill == runeSkillId then relationTab = info.Relation_Table break end end end for _, v in ipairs(relationTab) do local cfg = DataSheetManager.PetRelationSkill:GetDataByRelationSkillID(v.RelationSkill) skillDesc = skillDesc .. "\n" .. UTL.String.FormatCombineTextByID(cfg.RuneDes) end else skillDesc = skillConfig.RuneDes end UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetSkillTips, { SkillIcon = skillConfig.RuneIcon, SkillName = skillConfig.RuneName, SkillDesc = skillDesc, SkillType1 = skillConfig.SkillType1, SkillType2 = skillConfig.SkillType2, isChildTips = isChildTips }) end function Pet_Controller.GoToPet(petConfig) UIManager.RecoverTopView() CTL.HomeMain.CloseOpenView() private.findingTarget = nil local curLevelId = BattleDataGetter.GetLevelID() for i, v in ipairs(petConfig.GoScene1) do if curLevelId == v then private.findingTarget = petConfig.GoScene2[i] private.OnReadyToTarget() break else if v == HanMapCityID then if CTL.Country.CheckIfCanGoToCountryMap() then private.findingTarget = petConfig.GoScene2[i] CTL.Country.CheckConveyCountryMap(v) break end else if CTL.MiniMap.GoToMap(v) then private.findingTarget = petConfig.GoScene2[i] break end end end end end function private.OnReadyToTarget() if private.findingTarget then NotSyncBattleSetter.FindPathByLevelItemIDAndRide(BattleDataGetter.GetLevelID(), private.findingTarget) private.findingTarget = nil end end function Pet_Controller.GetPetTitle(petInfo) local isLineUp = false local runeSkillLevelSum, aptitudeSum = 0, 0 for i, v in ipairs(petInfo.petAptitude) do aptitudeSum = aptitudeSum + v.aptitudeValue end local slotInfo = MDL.Pet.GetSlotInfoByPetUniqueID(petInfo.petUniqId) if slotInfo then isLineUp = true for i, v in ipairs(slotInfo.talismanSkill) do local runeCfg = DataSheetManager.PetRuneSkill:GetDataByPetRuneID(v) runeSkillLevelSum = runeSkillLevelSum + runeCfg.RuneLevel end local relationSkill = Pet_Controller.GetRelationSkill(petInfo.petUniqId) if relationSkill > 0 then local relationSkillCfg = DataSheetManager.PetRelationSkill:GetDataByRelationSkillID(relationSkill) runeSkillLevelSum = runeSkillLevelSum + relationSkillCfg.RuneLevel end end return Pet_Controller.GetTitleContent(isLineUp, runeSkillLevelSum, aptitudeSum) end --获取羁绊技能 function Pet_Controller.GetRelationSkill(petUniqId) local relationSkill = 0 local slotInfo = MDL.Pet.GetSlotInfoByPetUniqueID(petUniqId) if slotInfo then local targetHeroId = Pet_Controller.GetPetEquipHeroID(petUniqId) if targetHeroId > 0 then local relationId = MDL.Pet.GetHeroRelationId(targetHeroId) if relationId then local maxLevelRuneCount = 0 --最高等级的符文数量 for i, v in ipairs(slotInfo.talismanSkill) do local runeCfg = DataSheetManager.PetRuneSkill:GetDataByPetRuneID(v) if runeCfg.RuneLevel == Pet_Controller.MAX_SKILL_LEVEL then maxLevelRuneCount = maxLevelRuneCount + 1 end end local relationCfg = DataSheetManager.PetRelation:GetDataByItemID(relationId) for _, relation in ipairs(relationCfg.Relation_Table) do if maxLevelRuneCount >= relation.RelationLevel then --要遍历找到最大的技能 relationSkill = relation.RelationSkill end end end end end return relationSkill end function Pet_Controller.GetTitleContent(isLineUp, runeSkillLevelSum, aptitudeSum) local runeDesc, aptitudeDesc local score = 0 for i, v in DataSheetManager.PetTitle:GetEnumerator() do if v.PetTitleType == 1 then if isLineUp and runeSkillLevelSum >= v.PetTitleLevel[1] and runeSkillLevelSum <= v.PetTitleLevel[2] then runeDesc = v.PetTitleDes score = score + v.PetTitleScore end else if aptitudeSum >= v.PetTitleLevel[1] and aptitudeSum <= v.PetTitleLevel[2] then aptitudeDesc = v.PetTitleDes score = score + v.PetTitleScore end end if runeDesc and aptitudeDesc then break end end local color for i, v in DataSheetManager.PetTitleColor:GetEnumerator() do if score >= v.TitleScore[1] and score <= v.TitleScore[2] then color = v.TitleColor break end end if runeDesc then return UTL.Color.FormatTextByColor(color, string.Concat(UIUtils.GetLocalizedTxt(Const_IDS[runeDesc]), UIUtils.GetLocalizedTxt(Const_IDS[aptitudeDesc]))) else return UTL.Color.FormatTextByColor(color, UIUtils.GetLocalizedTxt(Const_IDS[aptitudeDesc])) end end function Pet_Controller.FormatGrowUpScoreText(txt, petInfo, petCfg) local isGod = petCfg.Quality == MDL.Pet.PetQuality.God local curScore = Pet_Controller.GetGrowUpScore(petInfo.petAptitude, petInfo.petPedigree, isGod) if isGod == false and petInfo.petGeneration == 1 then txt.text = UTL.Color.FormatWhiteColor(curScore) else local maxAptitude = Pet_Controller.GetMaxAptitude(petCfg, petInfo.petPedigree, isGod) local maxScore = Pet_Controller.CalcuGrowUpScore(maxAptitude, petInfo.petPedigree, isGod) if maxScore < curScore then curScore = maxScore end txt.text = UTL.Color.FormatWhiteColor(curScore .. "/") .. UTL.Color.FormatTextByColor("F9D33A", maxScore) end end function Pet_Controller.GetMaxAptitude(petCfg, petPedigree, isGod) local total = 0 if isGod then --神宠要读下一行数据 local _, cfg = DataSheetManager.PetData:TryGetDataByID_Stage(petCfg.ID, petCfg.Stage + 1) if cfg then for i, v in ipairs(cfg.Talent_Table) do total = total + private.GetAptitudeValue(v.TalentType, v.TalentMax) end else for i, v in ipairs(petCfg.Talent_Table) do total = total + private.GetAptitudeValue(v.TalentType, v.TalentMax) end end else local cfg = DataSheetManager.PetTalentRefine:GetDataByTalentRefineID_ParentStar(petCfg.TalentRefineID, petPedigree) return cfg.MaxTalentSorce end return total end function private.GetAptitudeValue(type, value) local talentCfg = DataSheetManager.PetTalentType:GetDataByTalentType(type) local base = DataSheetManager.ConstData:GetDataByID("PetScoreParameter3").IntValue return value * talentCfg.TalentScoreFactor / base end -- 获取成长评分 function Pet_Controller.GetGrowUpScore(petAptitude, petPedigree, isGod) local talentTotal = 0 for _, v in ipairs(petAptitude) do local value = 0 if v.aptitudeValue then value = private.GetAptitudeValue(v.aptitudeType, v.aptitudeValue) end if v.TalentMax then value = private.GetAptitudeValue(v.TalentType, v.TalentMax) end talentTotal = talentTotal + value end return Pet_Controller.CalcuGrowUpScore(talentTotal, petPedigree, isGod) end function Pet_Controller.CalcuGrowUpScore(totalAptitudeNum, petPedigree, isGod) local param1 = DataSheetManager.ConstData:GetDataByID("PetScoreParameter1").IntValue local base = DataSheetManager.ConstData:GetDataByID("PetScoreParameter3").IntValue local param2 = DataSheetManager.ConstData:GetDataByID("PetScoreParameter2").IntValue / base local petLineageRate = DataSheetManager.PetLineageStar:GetDataByLineageStar(petPedigree).Score if isGod then local extra = DataSheetManager.ConstData:GetDataByID("SuperPetScoreParameter").IntValue return extra + math.ceil(param1 * (1 + param2 * totalAptitudeNum / 5) * (1 + petLineageRate / base)) else return math.ceil(param1 * (1 + param2 * totalAptitudeNum / 5) * (1 + petLineageRate / base)) end end --找出与上一行数据的属性差值,策划保证只有一条差值 function Pet_Controller.GetBreakDiffAttr(level, pointId) table.clear(private.tempAttrTab) local curCfg = DataSheetManager.PetRuneStar:GetDataByID_PointId(level, pointId) --尝试找上一行数据,可能找不到,所以用TryGet local success, lastCfg = DataSheetManager.PetRuneStar:TryGetDataByID_PointId(level, pointId - 1) if success == false then --上个孔位找不到,找上个等级的最高基本的孔 if level == 0 then --没有更低的等级了,直接返回当前配置的属性即可 return curCfg.Attr_Table[1] end for i, v in DataSheetManager.PetRuneStar:GetDataByID_PointId(level - 1) do if lastCfg == nil or lastCfg.PointId < v.PointId then lastCfg = v end end end for _, new in ipairs(curCfg.Attr_Table) do local isDiff = true for _, last in ipairs(lastCfg.Attr_Table) do if new.AttrType == last.AttrType then if new.AttrNum > last.AttrNum then private.tempAttrTab.AttrType = new.AttrType private.tempAttrTab.AttrNum = new.AttrNum - last.AttrNum return private.tempAttrTab end isDiff = false break end end if isDiff then private.tempAttrTab.AttrType = new.AttrType private.tempAttrTab.AttrNum = new.AttrNum return private.tempAttrTab end end return nil end --获取融合列表 function Pet_Controller.CollectMergeList(selectDict, selectLevel) if table.getDictCount(selectDict) >= 4 then return nil end local serverId = next(selectDict) if serverId == nil then if selectLevel == 0 then local dict = {} for _, v in pairs(MDL.Pet.GetRuneBagDict()) do local cfg = DataSheetManager.PetRuneSkill:GetDataByPetRuneID(v.cfgId) --只能一键放入天级别以下的 if cfg.RuneLevel < Pet_Controller.MAX_SKILL_LEVEL then if dict[cfg.RuneLevel] == nil then dict[cfg.RuneLevel] = { v } else table.insert(dict[cfg.RuneLevel], v) end end end for i = 1, Pet_Controller.MAX_SKILL_LEVEL do if dict[i] and #dict[i] >= DataSheetManager.PetRuneCompose:GetDataByLevel(i).RuneNum then table.sort(dict[i], MDL.Pet.SortRuneBagRule) return dict[i] end end else if selectLevel == Pet_Controller.MAX_SKILL_LEVEL then return nil end local result = {} for _, v in pairs(MDL.Pet.GetRuneBagDict()) do local cfg = DataSheetManager.PetRuneSkill:GetDataByPetRuneID(v.cfgId) if cfg.RuneLevel == selectLevel then table.insert(result, v) end end table.sort(result, MDL.Pet.SortRuneBagRule) return result end else local targetLevel = MDL.Pet.GetRuneCfgByID(serverId).RuneLevel if targetLevel >= Pet_Controller.MAX_SKILL_LEVEL then return nil end local result = {} for _, v in pairs(MDL.Pet.GetRuneBagDict()) do if selectDict[v.id] == nil then local cfg = DataSheetManager.PetRuneSkill:GetDataByPetRuneID(v.cfgId) if cfg.RuneLevel == targetLevel then table.insert(result, v) end end end table.sort(result, MDL.Pet.SortRuneBagRule) return result end return nil end --宠物繁殖排序:可捕捉等级>血脉,繁殖次数为0直接排最后 function private.ReproductionSortRule(a, b) local level_a = a.Config.TakeLevel local level_b = b.Config.TakeLevel local pedigree_a = a.Info.petPedigree local pedigree_b = b.Info.petPedigree local times_a = a.Config.BornNum - a.Info.breedTimes local times_b = b.Config.BornNum - b.Info.breedTimes local type_a = a.Config.ID local type_b = b.Config.ID if times_a == 0 and times_b == 0 then if level_a == level_b then if pedigree_a == pedigree_b then return type_a < type_b end return pedigree_a > pedigree_b end return level_a > level_b elseif times_a > 0 and times_b == 0 then return true elseif times_a == 0 and times_b > 0 then return false elseif times_a > 0 and times_b > 0 then if level_a == level_b then if pedigree_a == pedigree_b then return type_a < type_b end return pedigree_a > pedigree_b end return level_a > level_b end end function Pet_Controller.GetSortedReproductionPetList() local result = {} --初代非神宠、非上阵和非助阵的 for i, v in ipairs(MDL.Pet.GetOrderedList()) do if Pet_Controller.IsPetGenerationEquals(v.Info, 1, false) and MDL.Pet.IsPetLineUp(v.Info.petUniqId) == false and MDL.Pet.IsPetAssistanceFight(v.Info.petUniqId) == false then table.insert(result, v) end end table.sort(result, private.ReproductionSortRule) return result end --发超链,找人繁殖 function Pet_Controller.ShutBreedMsg(channelType, content, pedigree, petId) local currentTime = UTL.Time.GetServerTimestamp() if private.lastShoutTimeStamp ~= 0 then if currentTime - private.lastShoutTimeStamp < ShoutCDTime then return false end end if MDL.ChannelChat.SendPetBreedMsg(channelType, content, pedigree, petId) then private.lastShoutTimeStamp = currentTime return true end return false end function Pet_Controller.GetShutTimeCD() local shoutCdTime = 0 if private.lastShoutTimeStamp ~= 0 then shoutCdTime = ShoutCDTime - (UTL.Time.GetServerTimestamp() - private.lastShoutTimeStamp) end return shoutCdTime < 0 and 0 or shoutCdTime end function Pet_Controller.EnterPetBreedRoom(petUniqId) local breedState = MDL.Pet.GetPetBreedState() if breedState == MDL.Pet.BreedState.UnBreed then CTL.Pet.SetIsBreedRoomInValid(false) UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIPetReproduction, { petUniqId = petUniqId }) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetReproductionGet) end end function Pet_Controller.OpenBreadApply() UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetInvitedMultiPanel) end --处理宠物繁殖相关的消息球 function Pet_Controller.ProcessBreedNotice() CTL.HomeMain.RemoveMainNotice(CTL.HomeMain.NoticeType.PetBreeding) CTL.HomeMain.RemoveMainNotice(CTL.HomeMain.NoticeType.PetBreedFinish) local breedState = MDL.Pet.GetPetBreedState() if breedState == MDL.Pet.BreedState.Breeding then CTL.HomeMain.AddMainNotice(CTL.HomeMain.NoticeType.PetBreeding) elseif breedState == MDL.Pet.BreedState.Finish then CTL.HomeMain.AddMainNotice(CTL.HomeMain.NoticeType.PetBreedFinish) end end function Pet_Controller.GetPetEquipHeroID(petUniqId) local slotId = MDL.Pet.GetSlotIdByPetUniqueID(petUniqId) local heroSlotIds = MDL.Player.GetHeroLinUpIds() local index = MDL.Pet.GetMainFormationIndexBySlotId(slotId) * 2 - 1 return heroSlotIds[index] end function Pet_Controller.SetLastSelectInfo(petUniqueID, tabIndex) private.lastSelectPetUniqId = petUniqueID private.lastSelectTabIndex = tabIndex end function Pet_Controller.GetLastSelectInfo() return private.lastSelectPetUniqId, private.lastSelectTabIndex end function Pet_Controller.CompareRuneNum(lev1, lev2) --有可能读不到0级的配置,所以用TryGet local _, cfg1 = DataSheetManager.PetRuneStar:TryGetDataByID_PointId(lev1, 0) local cfg2, success if lev2 == 0 then success, cfg2 = DataSheetManager.PetRuneStar:TryGetDataByID_PointId(lev2, 1) else success, cfg2 = DataSheetManager.PetRuneStar:TryGetDataByID_PointId(lev2, 0) end if cfg1 and cfg2 then return cfg1.RuneNum > cfg2.RuneNum end return false end function Pet_Controller.SetRuneOptConfirm(key, state) private.runeOptConfirmDict[key] = state end function Pet_Controller.GetRuneOptConfirm(key) return private.runeOptConfirmDict[key] or false end --打开捕捉界面 function Pet_Controller.DoCatchPet() UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIPetIllustratedHandbook, { isCatch = true }) end --打开图鉴界面(神宠-完全体、普通宠物=成长体) function Pet_Controller.OpenPetIllustratedHandbookUI(petId) if petId then local succ, cfg = DataSheetManager.PetData:TryGetDataByID_Stage(petId, MDL.Pet.PetState.Ultimate) if succ then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIPetIllustratedHandbook, { selectPetCfg = cfg }) else UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIPetIllustratedHandbook, { selectPetCfg = DataSheetManager.PetData:GetDataByID_Stage(petId, MDL.Pet.PetState.Basic) }) end else UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIPetIllustratedHandbook) end end function private.ForceUseRelationSkillItem() TimerUtil.Interval(private.DelayActiveRelationSkill, 0.5, 1) end function private.DelayActiveRelationSkill() for _, v in DataSheetManager.PetRelation:GetEnumerator() do local count = MDL.Bag.GetItemCountInOneCell(v.ItemID) if count > 0 then MDL.Pet.ActivateRelationRuneSkillReq(v.ItemID) break end end end function Pet_Controller.CheckRedAfterEnterWorld() Pet_Controller.CheckIfLevelUp() Pet_Controller.CheckPetIfLineUp() Pet_Controller.CheckBreedReward() Pet_Controller.CheckCatchReward() private.CheckGodActiveAndBreak() private.CheckRuneRed() private.CheckOneTimeRed() end --系统开启后,在图鉴按钮上增加1个点击后消失的一次性红点 function private.CheckOneTimeRed(funcId) if funcId ~= MDL.Unlock.FunctionType.Pet then return end if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Pet) == false then CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_OneTimeNotice) --GMS关闭,移除所有提示 CTL.HomeMain.RemoveMainNotice(CTL.HomeMain.NoticeType.PetBreeding) CTL.HomeMain.RemoveMainNotice(CTL.HomeMain.NoticeType.PetBreedFinish) return end if MDL.RedPoint.GetOneTimeRedPointInfoByType(MDL.RedPoint.RedPointType.PetIllustratedHandbook) == 0 then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_OneTimeNotice) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_OneTimeNotice) end end function Pet_Controller.TryRemoveOneTimeTed() if MDL.RedPoint.GetOneTimeRedPointInfoByType(MDL.RedPoint.RedPointType.PetIllustratedHandbook) == 0 then CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_OneTimeNotice) MDL.RedPoint.OneTimeRedPointRequest(MDL.RedPoint.RedPointType.PetIllustratedHandbook, 1) end end --是否可升级,只判断上阵的宠物 function Pet_Controller.CheckIfLevelUp() local isRed = false --只找上阵槽位 for i = 1, Pet_Controller.MAX_SLOT do local slotInfo = MDL.Pet.GetSlotInfoBySlotId(i) if slotInfo then local data = MDL.Pet.GetActiveInfo(slotInfo.petUniqId) if data then if Pet_Controller.CheckPetIfLevelUp(data.Config, data.Info) then isRed = true break end end end end if isRed then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_LevelUp) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_LevelUp) end end --宠物是否可升级 function Pet_Controller.CheckPetIfLevelUp(petCfg, petInfo) local levelUpConfig = DataSheetManager.PetLevelUp:GetDataByLevelUpID_PetLevel(petCfg.LevelUpID, petInfo.petLevel) if MDL.HeroSelect.GetTeamLevel() < levelUpConfig.HeroStarLimit then return false end --普通宠需要二代才能升级 if Pet_Controller.IsPetGenerationEquals(petInfo, 1, false) then return false end local needExp = levelUpConfig.NeedExp - petInfo.petExp if needExp > 0 then local curExp = 0 for _, v in DataSheetManager.PetLevelMaterial:GetEnumerator() do local curCount = MDL.Bag.GetItemCount(v.ItemID) or 0 curExp = curExp + curCount * v.ProvideExp if curExp >= needExp then return true end end end return false end --神宠是否可激活、进阶,材料是一致的 function private.CheckGodActiveAndBreak() CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Pet_GodActive) for i, v in DataSheetManager.PetData:GetEnumerator() do if v.Quality == MDL.Pet.PetQuality.God and MDL.Pet.CanActiveGodPet(v.ID) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Pet_GodActive) break end end CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Pet_GodBreak) for i, v in ipairs(MDL.Pet.GetOrderedList()) do if v.Info.petQuality == MDL.Pet.PetQuality.God and Pet_Controller.CanGodPetBreak(v.Info) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Pet_GodBreak) break end end end --神宠是否可进阶 function Pet_Controller.CanGodPetBreak(petInfo) local godPetStarCfg = DataSheetManager.GodPetStar:GetDataByPetID_PetStar(petInfo.petType, petInfo.bigBreak) if godPetStarCfg.GodPetStarTalentID > 0 then local godTalentCfg = DataSheetManager.GodPetStarTalent:GetDataByID(godPetStarCfg.GodPetStarTalentID) local costItem if #godPetStarCfg.Item_Table > 0 and petInfo.smallBreak == godTalentCfg.StarNum then costItem = godPetStarCfg.Item_Table[1] else costItem = godTalentCfg.Item_Table[1] end local curNum = MDL.Bag.GetItemCount(costItem.ItemID) or 0 if curNum >= costItem.ItemNum then return true end end return false end function private.CheckRuneRed() private.CheckRuneBreakRed() private.CheckRuneMergeRed() private.CheckRuneStudyRed() end function private.CheckRuneBreakRed() CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_Rune_Break) for i = 1, Pet_Controller.MAX_SLOT do if Pet_Controller.CheckRuneBreak(i) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_Rune_Break) break end end end function private.CheckRuneMergeRed() CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_Rune_Merge) local time = MDL.RedPoint.GetRedPointTimeByType(MDL.RedPoint.RedPointType.PetRuneMerge) if time == nil or (time > 0 and UTL.Time.IsTimestampCrossDay(time)) then if Pet_Controller.CheckRuneMerge() then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_Rune_Merge) end end end --当普&良&精级符文大于4个时,显示符文红点 function Pet_Controller.CheckRuneMerge() local count = 0 for _, v in pairs(MDL.Pet.GetRuneBagDict()) do local cfg = DataSheetManager.PetRuneSkill:GetDataByPetRuneID(v.cfgId) if cfg.RuneLevel < Pet_Controller.MAX_SKILL_LEVEL then count = count + 1 if count >= Const_RuneMerge_Count then return true end end end return false end --检查槽位上是否有符文可突破 function Pet_Controller.CheckRuneBreak(slotId) local slotInfo = MDL.Pet.GetSlotInfoBySlotId(slotId) if slotInfo and MDL.Pet.GetActiveInfo(slotInfo.petUniqId) then local nextRuneCfg = Pet_Controller.GetNextRuneCfg(slotInfo) if nextRuneCfg then local isEnough = true for i, itemCfg in ipairs(nextRuneCfg.Item_Table) do local count = MDL.Bag.GetItemCount(itemCfg.ItemID) or 0 if count < itemCfg.ItemNum then isEnough = false break end end return isEnough end end return false end --当背包中有比已学习的符文更高级的符文时 function Pet_Controller.CheckRuneStudy(slotId) local rpType = private.GetRuneStudyRPType(slotId) local time = MDL.RedPoint.GetRedPointTimeByType(rpType) if time == nil or (time > 0 and UTL.Time.IsTimestampCrossDay(time)) then local slotInfo = MDL.Pet.GetSlotInfoBySlotId(slotId) if slotInfo and MDL.Pet.GetActiveInfo(slotInfo.petUniqId) then local minLevelRuneCfg local curTypeDict = {} --1.判断符文背包中有没同类型等级更高的符文 for i, v in ipairs(slotInfo.talismanSkill) do local runeCfg = DataSheetManager.PetRuneSkill:GetDataByPetRuneID(v) curTypeDict[runeCfg.RuneType] = 1 if runeCfg.RuneLevel < Pet_Controller.MAX_SKILL_LEVEL then local rune = MDL.Pet.GetRuneByLevel_Type(runeCfg.RuneLevel + 1, runeCfg.RuneType) if rune then return true end if minLevelRuneCfg == nil or minLevelRuneCfg.RuneLevel > runeCfg.RuneLevel then minLevelRuneCfg = runeCfg end end end --2.背包里有没比身上最低等级的符文更高级的符文,且跟身上穿戴的符文不是一个类型 if minLevelRuneCfg then for _, v in pairs(MDL.Pet.GetRuneBagDict()) do local cfg = DataSheetManager.PetRuneSkill:GetDataByPetRuneID(v.cfgId) if cfg.RuneLevel > minLevelRuneCfg.RuneLevel and curTypeDict[cfg.RuneType] == nil then return true end end end end end return false end function private.GetRuneStudyRPType(slotId) local rpType if slotId == 1 then rpType = MDL.RedPoint.RedPointType.PetRuneStudy_Slot1 elseif slotId == 2 then rpType = MDL.RedPoint.RedPointType.PetRuneStudy_Slot2 else rpType = MDL.RedPoint.RedPointType.PetRuneStudy_Slot3 end return rpType end function Pet_Controller.RemoveRuneStudyRed(slotId) local rpType = private.GetRuneStudyRPType(slotId) MDL.RedPoint.OneTimeRedPointRequest(rpType, 1, true) end function private.CheckRuneStudyRed() CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_Rune_Study) for i = 1, Pet_Controller.MAX_SLOT do if Pet_Controller.CheckRuneStudy(i) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_Rune_Study) break end end end function Pet_Controller.TryRemoveStudyRed(slotId) local isRed = false for i = 1, CTL.Pet.MAX_SLOT do if i ~= slotId and CTL.Pet.CheckRuneStudy(slotId) == true then isRed = true break end end if isRed == false then CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_Rune_Study) end end function Pet_Controller.GetRuneRed(slotId) local slotInfo = MDL.Pet.GetSlotInfoBySlotId(slotId) if slotInfo == nil or MDL.Pet.GetActiveInfo(slotInfo.petUniqId) == nil then return false end local isRed = CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.Formation_Pet_Rune_Merge) if isRed == false then isRed = Pet_Controller.CheckRuneBreak(slotId) or Pet_Controller.CheckRuneStudy(slotId) end return isRed end --是否可上阵、可替换 function Pet_Controller.CheckPetIfLineUp() CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_MainLineUp) for i = 1, Pet_Controller.MAX_SLOT do if Pet_Controller.CheckMainSlotIfLineUp(i) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_MainLineUp) break end end private.CheckSubSlotLineUpRed() end function private.CheckSubSlotLineUpRed() if GameAppInfo.IsVietnamPackage() then --越南地区屏蔽灵宠红点 return end CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_AssistLineUp) for i = 1, Pet_Controller.MAX_SLOT do if Pet_Controller.CheckAssistSlotIfLineUp(i) then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Formation_Pet_AssistLineUp) break end end --如果有副槽位未解锁,监听Currency CTL.Currency.UnRegisteEventByCurrencyType(MDL.Currency.CurrencyType.GoldIngot, private.CheckSubSlotLineUpRed) for i, _ in ipairs(Pet_Controller.SUB_SLOT_UNLOCK_CONFIG) do local state = MDL.Pet.GetAssistanceState(i) if state == MDL.Pet.AssistanceSlotState.Locked and Pet_Controller.IsPetSlotUnlock(i) == false then CTL.Currency.RegisteEventByCurrencyType(MDL.Currency.CurrencyType.GoldIngot, private.CheckSubSlotLineUpRed) break end end end --主槽位是否可上阵、替换 function Pet_Controller.CheckMainSlotIfLineUp(slotId) local isLineUp = false local slotInfo = MDL.Pet.GetSlotInfoBySlotId(slotId) if slotInfo then local data = MDL.Pet.GetActiveInfo(slotInfo.petUniqId) if data then isLineUp = true --是否有未上阵战力高且需要同类的,或者未上阵同类的 for _, v in ipairs(MDL.Pet.GetOrderedList()) do if Pet_Controller.IsPetGenerationEquals(v.Info, 2, true) and v.Info.baseGS > data.Info.baseGS and MDL.Pet.IsPetTypeAssistanceFight(v.Config.ID) == false then if (v.Config.ID == data.Config.ID) or (MDL.HeroSelect.GetTeamLevel() >= v.Config.TakeLevel and MDL.Pet.IsPetTypeLineUp(v.Config.ID) == false) then return true end end end end end --判断背包是否有剩余宠物 if isLineUp == false then --先判断是否解锁 if not MDL.Unlock.IsTriggerIdComplete(Pet_Controller.MAIN_SLOT_UNLOCK_ID[slotId]) then return false end for _, v in ipairs(MDL.Pet.GetOrderedList()) do --同一个类型不能上阵 if MDL.HeroSelect.GetTeamLevel() >= v.Config.TakeLevel and Pet_Controller.IsPetGenerationEquals(v.Info, 2, true) and MDL.Pet.IsPetTypeLineUp(v.Config.ID) == false and MDL.Pet.IsPetTypeAssistanceFight(v.Config.ID) == false then return true end end end return false end --助战槽位是否可上阵、替换 function Pet_Controller.CheckAssistSlotIfLineUp(slotId) local state, petUniqId = MDL.Pet.GetAssistanceState(slotId) if state == MDL.Pet.AssistanceSlotState.Locked then --可解锁也给红点 return Pet_Controller.IsPetSlotUnlock(slotId) elseif state == MDL.Pet.AssistanceSlotState.Unlock then for _, v in ipairs(MDL.Pet.GetOrderedList()) do --同一个类型不能上阵 if Pet_Controller.IsPetGenerationEquals(v.Info, 2, true) and MDL.Pet.IsPetTypeLineUp(v.Config.ID) == false and MDL.Pet.IsPetTypeAssistanceFight(v.Config.ID) == false then return true end end elseif state == MDL.Pet.AssistanceSlotState.LineUp then local data = MDL.Pet.GetActiveInfo(petUniqId) for _, v in ipairs(MDL.Pet.GetOrderedList()) do if Pet_Controller.IsPetGenerationEquals(v.Info, 2, true) and v.Info.baseGS > data.Info.baseGS then if (v.Config.ID == data.Config.ID) or (MDL.HeroSelect.GetTeamLevel() >= v.Config.TakeLevel and MDL.Pet.IsPetTypeLineUp(v.Config.ID) == false and MDL.Pet.IsPetTypeAssistanceFight(v.Config.ID) == false) then return true end end end end return false end function Pet_Controller.CheckBreedReward() if Pet_Controller.CheckIfGetBreedReward() then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.Pet_BreedReward) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Pet_BreedReward) end end function Pet_Controller.CheckCatchReward() local times, hasReward = MDL.Pet.GetDailyCatchInfo() local totalTimes = DataSheetManager.ActivityData:GetDataByID(LuaConst.ActivityType.PetCatch).DailyRefreshTimes if times >= totalTimes and hasReward == false then EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.PetCatch, true) return end if times < totalTimes and MDL.Bag.GetItemCount(DataSheetManager.ConstData:GetDataByID("PetCatchCost").IntValue) > 0 then EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.PetCatch, true) else EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.PetCatch, false) end end --是否可以领取周繁殖奖励 function Pet_Controller.CheckIfGetBreedReward() --必须依赖身上有一代宠 if MDL.Pet.CheckPetGeneration(1, false) == false then return false end local times, hasReward = MDL.Pet.GetWeekBreedTimeInfo() if hasReward then return false end local totalTimes = DataSheetManager.ConstData:GetDataByID("PetBreedWeeklyTaskNum").IntValue if times >= totalTimes then return true end return false end function Pet_Controller.CheckPetLineUpRed(lineUpPetUniqId, petUniqId, type) local tempInfo = MDL.Pet.GetActiveInfo(petUniqId) local petInfo, petConfig = tempInfo.Info, tempInfo.Config if Pet_Controller.IsPetGenerationEquals(petInfo, 2, true) and MDL.Pet.IsPetAssistanceFight(petUniqId) == false then if MDL.HeroSelect.GetTeamLevel() >= petConfig.TakeLevel then if lineUpPetUniqId then local lineUpData = MDL.Pet.GetActiveInfo(lineUpPetUniqId) if petInfo.baseGS > lineUpData.Info.baseGS then if petConfig.ID == lineUpData.Config.ID or (MDL.Pet.IsPetTypeLineUp(petConfig.ID) == false and MDL.Pet.IsPetTypeAssistanceFight(petConfig.ID) == false) then return true end end else if MDL.Pet.IsPetTypeLineUp(petConfig.ID) == false and MDL.Pet.IsPetTypeAssistanceFight(petConfig.ID) == false then return true end end end end return false end function Pet_Controller.ChoosePet() UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetChoosePopUp) end function Pet_Controller.ShowOKCancelToggleBox(content, okCB, toggleCB, itemId, leftContent, rightContent) local context = { title = Const_IDS.IDS_COMMON_PROMPT, content = content, toggleContent = UIUtils.GetLocalizedTxt(Const_IDS.IDS_EquipRefine_QuickTips2), okCB = okCB, toggleCB = toggleCB, okBtnText = Const_IDS.IDS_BUTTON_CONFIRM, cancelBtnText = Const_IDS.IDS_BUTTON_CANCEL, type = UTL.MessageBox.BoxType.WithToggle, itemId = itemId, leftContent = leftContent, rightContent = rightContent, } UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetLearnPopup, context) end function Pet_Controller.FormatLineUpRuneName(txt, state, index, runeBreak) state:SetState(index - 1) local breakContent = UTL.Color.FormatTextByColor("E4C96C", "+" .. runeBreak) if index == 1 then txt.text = string.Concat(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Pet_Rune1), breakContent) elseif index == 2 then txt.text = string.Concat(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Pet_Rune2), breakContent) elseif index == 3 then txt.text = string.Concat(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Pet_Rune3), breakContent) end end --宠物代数是否满足 function Pet_Controller.IsPetGenerationEquals(petInfo, tarGeneration, allowGod) if allowGod and petInfo.petQuality == MDL.Pet.PetQuality.God then return true end if petInfo.petQuality == MDL.Pet.PetQuality.Normal and petInfo.petGeneration == tarGeneration then return true end return false end function Pet_Controller.IsPetSlotUnlock(slotIndex) local cfg = Pet_Controller.SUB_SLOT_UNLOCK_CONFIG[slotIndex] local isTriggerUnlock = MDL.Unlock.IsTriggerIdComplete(cfg.TriggerID) if isTriggerUnlock then local needCount = cfg.item[2] if MDL.Currency.IsMoneyEnough(cfg.item[1], needCount) then return true end end return false end function Pet_Controller.ViewPetShareInfo(petUniqId, acid) MDL.Pet.ViewPetShareReq(acid, petUniqId) end function Pet_Controller.SharePet(petData) CTL.HomeMain.CloseViewBackHomeMain() local petInfo, petCfg = petData.Info, petData.Config local petName = UIUtils.GetLocalizedTxt(Const_IDS[petCfg.PetName]) local chatItemName = string.FormatByIdsKey("IDS_Chat_item", petName) CTL.ChannelChat.AddInputContentToCache(chatItemName, CTL.ChannelChat.HyperlinkTag.PetShare .. "|" .. petInfo.petUniqId .. "|" .. petCfg.ID .. "|" .. petCfg.Stage .. "|" .. BattleDataGetter.GetAcID()) MDL.ChannelChat.SetNotSendMsg(chatItemName) local sendChatCfgId = DataSheetManager.ConstData:GetDataByID("BagShowItemSendToChannelID").IntValue local channelId = MDL.ChannelChat.GetChannelIdByCfgID(sendChatCfgId) UIManager.OpenView(Const_UI_Lua.UIEnum.UIChannelChatMain, { LastMsgChannelId = channelId }) end function Pet_Controller.ProcessSharePetMsg(chatMsgData) local petUniqId = CTL.ChannelChat.GetPetShareContext(chatMsgData) if string.isNilOrEmpty(petUniqId) == false then local petData = MDL.Pet.GetActiveInfo(petUniqId) if petData then local petName = UIUtils.GetLocalizedTxt(Const_IDS[petData.Config.PetName]) local chatItemName = string.FormatByIdsKey("IDS_Chat_item", petName) --清理超链缓存 CTL.ChannelChat.RemoveInputContentByKey(chatItemName) MDL.Pet.PetShareReq(petUniqId) end end end return Pet_Controller