TrialMapPanel = {} local this = TrialMapPanel local istrialMap = false local MapPanel local bombNum = 0 local powerValue = 0 local ctrlView = require("Modules/Map/View/MapControllView") local targetPos = Vector2.New(109, 289) local orginLayer = 0 local heroList={} --选择英雄预设容器 local trailConfig = ConfigManager.GetConfig(ConfigName.TrialConfig) local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig) local trialSetting=ConfigManager.GetConfig(ConfigName.TrialSetting) local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig) local MonsterConfig=ConfigManager.GetConfig(ConfigName.MonsterConfig) local MonsterGroupConfig = ConfigManager.GetConfig(ConfigName.MonsterGroup) local ArtConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig) local oldChoosed=nil--上一个选中英雄 local monsterGroupId function TrialMapPanel:InitComponent(root, mapPanel) orginLayer = 0 MapPanel = mapPanel -- 剩余复活次数 this.leftLife = Util.GetGameObject(root, "leftDown/leftLifeRoot/leftTimes"):GetComponent("Text") this.leftLifeRoot = Util.GetGameObject(root, "leftDown/leftLifeRoot") -- 精气 this.powerRoot = Util.GetGameObject(root, "leftDown/active") this.levelNum = Util.GetGameObject(root, "leftUp/curLevel"):GetComponent("Text") this.powerPercent = Util.GetGameObject(root, "leftDown/active/value"):GetComponent("Text") this.sliderValue = Util.GetGameObject(root, "leftDown/active/progress"):GetComponent("Image") -- 显示时间 this.timeRoot=Util.GetGameObject(root,"leftUp/timeRoot") this.mapTime = Util.GetGameObject(this.timeRoot, "Time"):GetComponent("Text") this.DragCtrl = Util.GetGameObject(root, "Ctrl") -- 初始化任务显示 this.targetRoot = Util.GetGameObject(root, "TargetRoot/textShowRoot/missionRoot/MisPre1") this.targetText = Util.GetGameObject(this.targetRoot, "context"):GetComponent("Text") -- 炸弹 this.btnBomb = Util.GetGameObject(root, "rightDown/btnBomb") this.bombNum = Util.GetGameObject(this.btnBomb, "num"):GetComponent("Text") this.buffShop = Util.GetGameObject(root, "rightDown/buff") this.buffNum = Util.GetGameObject(this.buffShop, "num"):GetComponent("Text") -- 试炼副本商店 this.normalShop = Util.GetGameObject(root, "rightDown/shop") this.shopNum = Util.GetGameObject(this.normalShop, "num"):GetComponent("Text") this.effectRoot = Util.GetGameObject(root, "fireRoot") this.fire = Util.GetGameObject(this.effectRoot, "UI_effect_shilian_huo") this.guiji = Util.GetGameObject(this.effectRoot, "UI_effect_shilian_guiji") this.chufa = Util.GetGameObject(this.powerRoot, "UI_effect_shilian_chufa") -- 月卡福利炸弹提示 this.bombTip = Util.GetGameObject(this.btnBomb, "bombTip") --选择英雄 this.selectHero=Util.GetGameObject(root,"centerDown/selectHero") this.s_grid=Util.GetGameObject(this.selectHero,"grid") this.s_pre=Util.GetGameObject(this.s_grid,"pre") this.upView = SubUIManager.Open(SubUIConfig.UpView, root.transform, { showType = UpViewOpenType.ShowLeft }) this.helpBtn=Util.GetGameObject(root,"helpBtn") this.helpPos=this.helpBtn:GetComponent("RectTransform").localPosition end function TrialMapPanel:BindEvent() Util.AddClick(this.btnBomb, function () UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.TrialBomb) end) -- 打开补给点 Util.AddClick(this.buffShop, function() -- 判断是否有保存的补给点 if #FoodBuffManager.GetBuffPropList()<=0 then PopupTipPanel.ShowTip(Language[11250]) return end UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.TrialGain,0) end) -- 打开商店 Util.AddClick(this.normalShop, function() if not ShopManager.IsActive(SHOP_TYPE.TRIAL_SHOP) then PopupTipPanel.ShowTip(Language[10381]) return end UIManager.OpenPanel(UIName.MapShopPanel, SHOP_TYPE.TRIAL_SHOP) end) --帮助按钮 Util.AddClick(this.helpBtn,function() UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.Resolve_Recall,this.helpPos.x,this.helpPos.y) end) --设置按钮 Util.AddClick(MapPanel.btnSetting, function () UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.TrialSetting) end) end --添加事件监听(用于子类重写) function TrialMapPanel:AddListener() Game.GlobalEvent:AddEvent(GameEvent.TrialMap.OnPowerValueChanged, this.OnPowerValueChange) Game.GlobalEvent:AddEvent(GameEvent.Bag.OnTempBagChanged, this.OnTempBagChanged) Game.GlobalEvent:AddEvent(GameEvent.FoodBuff.OnFoodBuffStateChanged, this.InitBuffInfo) Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.RefreshBombNum) Game.GlobalEvent:AddEvent(GameEvent.Map.ShowEnemyInfo, this.ShowEnemyInfo) Game.GlobalEvent:AddEvent(GameEvent.Map.RefreshHeroHp, this.SetSelectHero) Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.InitShopInfo) end --移除事件监听(用于子类重写) function TrialMapPanel:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.TrialMap.OnPowerValueChanged, this.OnPowerValueChange) Game.GlobalEvent:RemoveEvent(GameEvent.Bag.OnTempBagChanged, this.OnTempBagChanged) Game.GlobalEvent:RemoveEvent(GameEvent.FoodBuff.OnFoodBuffStateChanged, this.InitBuffInfo) Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.RefreshBombNum) Game.GlobalEvent:RemoveEvent(GameEvent.Map.ShowEnemyInfo, this.ShowEnemyInfo) Game.GlobalEvent:RemoveEvent(GameEvent.Map.RefreshHeroHp, this.SetSelectHero) Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.InitShopInfo) end --界面打开时调用(用于子类重写) function TrialMapPanel:OnOpen() this.powerRoot:SetActive(CarbonManager.difficulty == 2) this.btnBomb:SetActive(CarbonManager.difficulty == 2) -- 商店 this.buffShop:SetActive(CarbonManager.difficulty == CARBON_TYPE.TRIAL) this.normalShop:SetActive(CarbonManager.difficulty == CARBON_TYPE.TRIAL) if CarbonManager.difficulty ~= 2 then return end this.InitShowState() -- 检测引导 GuideManager.CheckCarbonGuild(CARBON_TYPE.TRIAL) end function TrialMapPanel:OnShow() -- if CarbonManager.difficulty ~= 2 then return end -- this.InitShowState() end function this.InitShowState() if CarbonManager.difficulty ~= 2 then return end istrialMap = CarbonManager.difficulty == 2 if istrialMap then this.InitTrial() end this.upView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main }) this.helpBtn:SetActive(istrialMap) MapPanel.btnBag.gameObject:SetActive(false) MapPanel.btnTeam.gameObject:SetActive(false) MapPanel.btnSetting.gameObject:SetActive(true) MapPanel.btnRank.gameObject:SetActive(true) MapPanel.btnXingYao.gameObject:SetActive(true) MapPanel.btnReward.gameObject:SetActive(true) MapPanel.warnRoot:SetActive(false) MapPanel.warn:SetActive(false) this.CheckTrialHeroInfo() this.InitTrialMission() this.UpdatePowerValue() -- this.UpdateDeadTimes() this.RefreshBombNum() this.InitShopInfo() this.InitBuffInfo() -- this.InitBossInfo() this.powerRoot:SetActive(istrialMap) this.InitEffect() this.InitTip() this.TrialShowTime() end function this.InitEffect() this.guiji:SetActive(false) this.chufa:SetActive(false) this.fire:SetActive(false) end function this.InitTip() this.bombTip:SetActive(false) if MapTrialManager.firstEnter then Log(Language[11251]) -- 月卡蛋蛋福利 if MapTrialManager.firstEnter and BagManager.GetTempBagCountById(43) >= 2 then this.bombTip:SetActive(true) local index = 0 local timer timer = Timer.New(function() index = index + 1 if index == 5 then this.bombTip:SetActive(false) timer:Stop() end end, 1, 5, true) timer:Start() end end end -- 刷新精气值 function this.UpdatePowerValue() if MapTrialManager.curTowerLevel>10000 then this.levelNum.text = string.format(Language[11252], "?") else this.levelNum.text = string.format(Language[11252], MapTrialManager.curTowerLevel) end LogPink(Language[11253] .. MapTrialManager.curTowerLevel) powerValue = MapTrialManager.powerValue this.SetTargetState(powerValue) local _value= powerValue--表现值 _value= _value <= 0 and 0 or _value _value = _value >= 100 and 100 or _value --Log("更新数值") this.powerPercent.text = _value this.sliderValue.fillAmount = _value / 100 -- -1时召唤boss if powerValue == -1 then -- 停止自动寻路 -- ctrlView.OnRoleDead() UIManager.OpenPanel(UIName.TrialOpPanel, 1) end end function this.PlayEffect() Log(Language[11254]) if MapTrialManager.powerValue == -1 or MapTrialManager.powerValue == 0 then this.UpdatePowerValue() else this.fire:SetActive(true) this.fire:GetComponent("RectTransform").anchoredPosition = MapTrialManager.rolePos this.guiji:GetComponent("RectTransform").anchoredPosition = MapTrialManager.rolePos local timer = Timer.New(function () this.fire:SetActive(false) this.guiji:SetActive(true) -- 设置动画 this.guiji:GetComponent("RectTransform"):DOAnchorPos(targetPos, 0.5, false):OnComplete(function () --Log("轨迹完成") this.chufa:SetActive(true) this.guiji:SetActive(false) end) end, 0.3):Start() Timer.New(function () this.UpdatePowerValue() this.InitEffect() end, 1):Start() end end function this.OnPowerValueChange() if CarbonManager.difficulty ~= 2 then return end -- 先放特效在更新数值 this.PlayEffect() end function this.OnSortingOrderChange() Util.AddParticleSortLayer(this.chufa, MapPanel.sortingOrder - orginLayer) orginLayer = MapPanel.sortingOrder end -- 初始化部buff显示 function this.InitBuffInfo() if CarbonManager.difficulty ~= 2 then return end -- 补给点数量显示 local num = 0 local buffList = FoodBuffManager.GetBuffPropList()--MapTrialManager.GetBuffList() if buffList then num = #buffList end this.buffNum.text = num end -- 初始化部商店显示 function this.InitShopInfo() -- 刷新一遍商店数据 ShopManager.RequestAllShopData(function() local shopData = ShopManager.GetShopDataByType(SHOP_TYPE.TRIAL_SHOP) if not shopData or #shopData.storeItem <= 0 then this.shopNum.text = "0" return end -- 获取可购买的商品数量 local itemNum = 0 for _, item in ipairs(shopData.storeItem) do local limitCount = ShopManager.GetShopItemLimitBuyCount(item.id) if limitCount == -1 or limitCount - item.buyNum > 0 then itemNum = itemNum + 1 end end this.shopNum.text = itemNum end) end -- 试炼副本任务初始化 function this.InitTrialMission() -- this.leftLifeRoot:SetActive(istrialMap) this.powerRoot:SetActive(istrialMap) local imgDone = Util.GetGameObject(this.targetRoot, "imgDone") local imgDoing = Util.GetGameObject(this.targetRoot, "imgDoing") imgDone:SetActive(false) imgDoing:SetActive(false) this.SetTargetState() this.mapTime.text = Language[11255] end -- 刷新临时背包数据 function this.OnTempBagChanged() if CarbonManager.difficulty == 2 then this.RefreshBombNum() end end -- 刷新砸炸弹数量 function this.RefreshBombNum() -- 试炼副本才执行 bombNum = 0 if CarbonManager.difficulty ~= CARBON_TYPE.TRIAL then return end if BagManager.GetItemCountById(43) == 0 or not BagManager.GetItemCountById(43) then bombNum = 0 else bombNum = BagManager.GetItemCountById(43) end this.bombNum.text = bombNum end -- 设置目标 function this.SetTargetState(value) local showStr = "" if value == -1 then showStr = Language[11256] else showStr = Language[11257] end this.targetText.text = showStr end -- 试炼副本的初始化 function this.InitTrial() Log("MapManager.isOpen " .. tostring(MapManager.isOpen)) -- 初始化状态 this.DragCtrl:SetActive(true) MapTrialManager.isChangeLevel = false MapTrialManager.canMove = true MapManager.isRemoving = false MapManager.deadTime = 0 if not MapManager.isOpen then this.TrialMissionStart() end end -- 试炼副本进图流程 function this.TrialMissionStart() NetManager.CarbonMissionStartRequest(function(msg) Log(Language[11258]) local showStr = Language[11259] .. MapTrialManager.curTowerLevel ..Language[10319] UIManager.OpenPanel(UIName.CurlingTipPanel, showStr) MapPanel.SetRoleShow(MapManager.mapScale, MapManager.roleInitPos) PlayerManager.startTime = PlayerManager.serverTime MissionManager.missionTime = 0 MapManager.isOpen = true end) end -- 试炼副本显示时间 function this.TrialShowTime() if this.timer then this.timer:Stop() this.timer = nil end local serData = ActTimeCtrlManager.GetSerDataByTypeId(30) local freshTime = serData.endTime this.timer = Timer.New(function() if not this.timer or not this.mapTime then return end local t=freshTime - PlayerManager.serverTime if t<=0 then t=0 MapTrialManager.ClearTrialRewardInfo() --清空奖励信息 MapTrialManager.SetKillCount(0) --重置已杀小怪数量 end this.mapTime.text = TimeToHMS(t)..Language[11260] end, 1, -1, true) this.timer:Start() -- this.mapTime.text = this.FormatTime(time) end -- 转换时间 function this.FormatTime(time) local str = "" local ten_minute = math.modf(time / 600) local minute = math.modf(time / 60) % 10 local ten_second = math.modf( time / 10) % 6 local second = time % 10 str = ten_minute ..minute .. ":" .. ten_second .. second return str end --检查试炼阵容信息 function this.CheckTrialHeroInfo() MapTrialManager.isFirstIn=true if #MapManager.trialHeroInfo==0 then LogPink(Language[11261]) UIManager.OpenPanel(UIName.FormationEditPopup,function(d) this.SetSelectHero(true,d,false) end) else -- for i, v in ipairs(MapManager.trialHeroInfo) do -- LogPink(v.heroId.." "..v.tmpId.." "..v.star.." "..v.heroHp) -- end this.SetSelectHero(false,nil,true) --true从入口进入副本 默认选择第一个Hero end end function TrialMapPanel:OnClose() oldChoosed=nil if this.timer then this.timer:Stop() this.timer = nil end end function TrialMapPanel:OnDestroy() SubUIManager.Close(this.upView) heroList={} end --设置选择英雄界面 isFirstIn你的第一次 isFirstData你第一次射的东西 isMainIn你每次 function this.SetSelectHero(isFirstIn,isFirstData,isMainIn) local itemId=trialSetting[1].HealingId[1] local itemNum=trialSetting[1].HealingId[2] this.selectHero:SetActive(true) local d={} if isFirstIn then--若是第一次进 此时我必有该英雄 不用担心是已删除英雄 通过HeroDid去获取数据 for n, did in ipairs(isFirstData) do local h=HeroManager.GetSingleHeroData(did) table.insert(MapManager.trialHeroInfo,{heroId=h.dynamicId,tmpId=h.id,star=h.star,heroHp=10000,level=h.lv}) end end d=MapManager.trialHeroInfo for k = 1, this.s_grid.transform.childCount do this.s_grid.transform:GetChild(k-1).gameObject:SetActive(false) end local closeChoosed=function() --有开着选择的全关了 for i, v in ipairs(heroList) do local c=Util.GetGameObject(v,"choosed").gameObject if c.activeSelf then c:SetActive(false) end end end for i, v in ipairs(d) do if MapTrialManager.selectHeroDid ~= "" then if MapTrialManager.selectHeroDid==v.heroId and v.heroHp <= 0 then MapTrialManager.selectHeroDid = "" end end end for i, v in ipairs(d) do local o= heroList[i] if not o then o=newObjToParent(this.s_pre,this.s_grid) o.name="pre"..i heroList[i]=o end o.gameObject:SetActive(true) local frame=Util.GetGameObject(o,"frame"):GetComponent("Image") local icon=Util.GetGameObject(o,"icon"):GetComponent("Image") local pro=Util.GetGameObject(o,"proIcon"):GetComponent("Image") local lv=Util.GetGameObject(o,"lv/Text"):GetComponent("Text") local star=Util.GetGameObject(o,"star") local choosed=Util.GetGameObject(o,"choosed") local hpExp=Util.GetGameObject(o,"hpExp"):GetComponent("Slider") frame.sprite=Util.LoadSprite(GetHeroQuantityImageByquality(heroConfig[v.tmpId].Quality, v.star)) icon.sprite= Util.LoadSprite(GetResourcePath(heroConfig[v.tmpId].Icon)) pro.sprite=Util.LoadSprite(GetProStrImageByProNum(heroConfig[v.tmpId].PropertyName)) lv.text=v.level SetHeroStars(star, v.star) --选择 if isFirstIn then choosed:SetActive(i==1) if i==1 then MapTrialManager.selectHeroDid=v.heroId end elseif isMainIn then if MapTrialManager.selectHeroDid ~= "" then choosed:SetActive(MapTrialManager.selectHeroDid==v.heroId and v.heroHp >0) else if v.heroHp >0 then choosed:SetActive(true) MapTrialManager.selectHeroDid=v.heroId else choosed:SetActive(false) MapTrialManager.selectHeroDid="" end end else choosed:SetActive(MapTrialManager.selectHeroDid==v.heroId) end --血量相关 hpExp.value=v.heroHp/10000 Util.SetGray(o,v.heroHp<=0)--死啦 Util.AddOnceClick(o,function() if v.heroHp>0 then closeChoosed() choosed:SetActive(true) MapTrialManager.selectHeroDid=v.heroId else PopupTipPanel.ShowTip(Language[11247]) end end) end --刷新英雄选择面板时 检测血量 若有低于40%血量的英雄 给选择Hero加血 --再遍历一次防止下面的return 打断上面for循环表现的正常赋值 --这里只关于自动嗑药逻辑 for k, v in ipairs(d) do --若存在该设置参数并为已勾选状态 =1 否则=0 local t=(PlayerPrefs.HasKey(PlayerManager.uid.."GeneralPopup_TrialSettingBtn"..2) and PlayerPrefs.GetInt(PlayerManager.uid.."GeneralPopup_TrialSettingBtn"..2)==1) and 1 or 0 if t==0 then return end if MapTrialManager.selectHeroDid== v.heroId then if v.heroHp<=0 then PopupTipPanel.ShowTip(string.format(Language[11262],itemConfig[itemId].Name)) return end end --若血量小于自动回复百分比 并且 有血量 if v.heroHp/100000 then if (itemNum-MapManager.addHpCount)<=0 then PopupTipPanel.ShowTip(string.format(Language[11263],itemConfig[itemId].Name)) return end if BagManager.GetItemCountById(itemId)<=0 then PopupTipPanel.ShowTip(string.format(Language[11264],itemConfig[itemId].Name,itemConfig[itemId].Name)) return end NetManager.UseAddHpItemRequest(MapTrialManager.selectHeroDid,function() local curHeroHp=0 if v.heroId==MapTrialManager.selectHeroDid then curHeroHp=v.heroHp end curHeroHp=curHeroHp+5000 --5000增加的血量也是要配表的 if curHeroHp>=10000 then curHeroHp=10000 end MapTrialManager.SetHeroHp({curHeroHp},MapTrialManager.selectHeroDid,function() PopupTipPanel.ShowTip(string.format(Language[11265],itemConfig[itemId].Name)) end) end) end end end --显示敌人信息面板 function this.ShowEnemyInfo(_monsterGroupId,eventId,showValues) UIManager.OpenPanel(UIName.ShowEnemyInfoPanel,_monsterGroupId) end function this.KillAllBitch() --杀死所有的小怪 MapManager.isRemoving = true local pointData = trailConfig[MapTrialManager.curTowerLevel].MonsterPoint for i = 1, #pointData do local mapPointId = pointData[i][1] if mapPointId then Log(Language[11266] .. mapPointId) MapManager.DeletePos(mapPointId) end end MapManager.isRemoving = false end return TrialMapPanel