--- 无尽副本 --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by aaa. --- DateTime: 2019/7/30 16:30 --- EndLessMapView = {} local this = EndLessMapView local endLessData = ConfigManager.GetConfig(ConfigName.EndlessMapConfig) local challengeMapConfig = ConfigManager.GetConfig(ConfigName.ChallengeMapConfig) local ctrlView = require("Modules/Map/View/MapControllView") local pointView = require("Modules/Map/View/PointHandleView") local MapPanel this.isPanelClose = false -- 刷新前的行动力,用于判断递减 local preEnergy = 0 -- 当前地图扣除行动力的类型 local COST_TYPE = { WALK = 1, DEAD = 2, TRANSPORT = 3, } -- 当前地图行走与死亡消耗的行动力 local deadCost = 0 local walkCost = 0 function this.InitComponent(gameObject, mapPanel) MapPanel = mapPanel -- 地图名字显示 this.areaName = Util.GetGameObject(gameObject, "endLessTitle/AreaImg/mapName"):GetComponent("Text") this.btnReset = Util.GetGameObject(gameObject, "rightDown/btnReset") this.btnFormat = Util.GetGameObject(gameObject, "rightDown/btnFormat") this.btnNote = Util.GetGameObject(gameObject, "rightDown/btnNote") -- 谢置按钮 this.btnSet = Util.GetGameObject(gameObject, "rightUp/btnSetting") -- 行动力显示 this.energyInfo = Util.GetGameObject(gameObject, "stepROot/bg/energyInfo"):GetComponent("Text") this.totalEnergy = Util.GetGameObject(gameObject, "stepROot/bg/total"):GetComponent("Text") this.btnAddEnergy = Util.GetGameObject(gameObject, "stepROot/bg/add") this.energyRoot = Util.GetGameObject(gameObject, "stepROot") -- 行动力警告显示 this.warn = Util.GetGameObject(gameObject, "EndLessEffect/effect") this.warnRoot = Util.GetGameObject(gameObject, "EndLessEffect") -- 根节点 this.endLessTitleRoot = Util.GetGameObject(gameObject, "endLessTitle") -- 道刷刷新倒计时 this.bgTime = Util.GetGameObject(gameObject, "stepROot/bg/Bgtime") this.actCountTime = Util.GetGameObject(this.bgTime, "time"):GetComponent("Text") -- 购买行动力的货币 this.moneyNum = Util.GetGameObject(gameObject, "endLessTitle/frame/num") this.moneyIcon = Util.GetGameObject(gameObject, "endLessTitle/frame/icon") this.helpBtn=Util.GetGameObject(gameObject,"helpBtn") this.helpPos=this.helpBtn:GetComponent("RectTransform").localPosition this.helpBtn:SetActive(false) end function this.OnSortingOrderChange() end function this.BindEvent() --帮助按钮 Util.AddClick(this.helpBtn,function() if ctrlView.GetCallListCount() > 1 then PopupTipPanel.ShowTip(Language[11259]) return end UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.Sunro,this.helpPos.x,this.helpPos.y) end) -- 重置 Util.AddClick(this.btnReset, function () if ctrlView.GetCallListCount() > 1 then PopupTipPanel.ShowTip(Language[11259]) return end if not this.CanClick() then return end -- 复位角色的状态 MsgPanel.ShowTwo(Language[11277], nil, function() this.ResetRoleState() end) end) Util.AddClick(this.btnFormat, function () if ctrlView.GetCallListCount() > 1 then PopupTipPanel.ShowTip(Language[11259]) return end if not this.CanClick() then return end NetManager.RequestAllHeroHp(function () -- UIManager.OpenPanel(UIName.FormationPanel, FORMATION_TYPE.CARBON, MapManager.curMapId) UIManager.OpenPanel(UIName.FormationPanelV2, FORMATION_TYPE.CARBON, MapManager.curMapId) EndLessMapManager.openedFormat = true end) end) Util.AddClick(this.btnNote, function () if ctrlView.GetCallListCount() > 1 then PopupTipPanel.ShowTip(Language[11259]) return end if not this.CanClick() then return end --标记状态设置显示 this.SetNoteShow() end) Util.AddClick(this.btnAddEnergy, function () if ctrlView.GetCallListCount() > 1 then PopupTipPanel.ShowTip(Language[11259]) return end Log("行走路径长度 ----- " .. #MapManager.stepList) if not this.CanClick() then return end if #MapManager.stepList > 0 then MapManager.MapUpdateEvent(-1000, function () Log("购买之前同步位置!!") UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = 1 }) end) else UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = 1 }) end end) -- Util.AddClick(this.btnSet, function () -- UIManager.OpenPanel(UIName.SettingPopup) -- end) end function this.AddListener() Game.GlobalEvent:AddEvent(GameEvent.Map.OnAddNotePoint, this.SetNoteShow) Game.GlobalEvent:AddEvent(GameEvent.Map.OnRemoveNotePoint, this.SetNoteShow) Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.GetBagEnergy) Game.GlobalEvent:AddEvent(GameEvent.Map.EnergyFull, EndLessMapManager.EndlessRedCheck) end function this.RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Map.OnAddNotePoint, this.SetNoteShow) Game.GlobalEvent:RemoveEvent(GameEvent.Map.OnRemoveNotePoint, this.SetNoteShow) Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.GetBagEnergy) Game.GlobalEvent:RemoveEvent(GameEvent.Map.EnergyFull, EndLessMapManager.EndlessRedCheck) end function this.OnOpen() -- 初始化组件显示 this.InitCompShow(CarbonManager.difficulty) if not this.IsEndLessMap() then return end -- 初始化各种标志的状态 this.InitBoolState() -- 开始探索请求 -- this.StartExplore() -- MapPanel.SetRoleShow(MapManager.mapScale, MapManager.roleInitPos,0) -- 设置任务显示 this.SetTipShow() -- 初始化行动力消耗的类型数值 this.InitCostValue() this.RefreshEnergyValue(true, 0) this.RefreshEnergyShow() Util.GetGameObject(MapPanel.gameObject, "centerDown/selectHero"):SetActive(false) this.helpBtn:SetActive(false) -- 检测引导 GuideManager.CheckCarbonGuild(CARBON_TYPE.ENDLESS) end function this.OnShow() if not this.IsEndLessMap() then return end -- 避免其他界面打开时不刷新问题 -- 界面再次打开时,如果没有主动刷新过,则不需要刷新显示 --if not EndLessMapManager.isUpdateOnClose and not EndLessMapManager.openedFormat then -- this.GetBagEnergy() -- EndLessMapManager.isUpdateOnClose = false --end -- 如果全屏界面打开时刷新过,重新激活界面需要刷新一次 if EndLessMapManager.isUpdateOnClose then this.GetBagEnergy() EndLessMapManager.isUpdateOnClose = false end -- 从编队界面切换回来,刷新事件点的战力显示 if EndLessMapManager.openedFormat then pointView.RefreshAtkShow() end EndLessMapManager.openedFormat = false this.isPanelClose = false -- 刷新倒计时显示 this.ShowCountTime() end -- ================ 进入地图的正常流程 =============== -- function this.StartExplore() -- if not this.IsEndLessMap() then return end -- if MapManager.isOpen == false then -- NetManager.CarbonMissionStartRequest(function(msg) -- Log("服务器返回消息") -- MapPanel.SetRoleShow(MapManager.mapScale, MapManager.roleInitPos) -- PlayerManager.startTime = PlayerManager.serverTime -- MissionManager.missionTime = 0 -- MapManager.isOpen = true -- end) -- end -- end function this.InitCompShow(carbonType) if carbonType ~= CARBON_TYPE.ENDLESS then return end this.areaName.gameObject:SetActive(carbonType == CARBON_TYPE.ENDLESS) this.btnReset:SetActive(carbonType == CARBON_TYPE.ENDLESS) this.btnFormat:SetActive(carbonType == CARBON_TYPE.ENDLESS) this.btnNote:SetActive(false) -- this.warnRoot:SetActive(carbonType == CARBON_TYPE.ENDLESS) -- this.warn:SetActive(false) this.btnSet:SetActive(carbonType == CARBON_TYPE.ENDLESS) this.endLessTitleRoot:SetActive(carbonType == CARBON_TYPE.ENDLESS) this.btnSet:SetActive(carbonType == CARBON_TYPE.ENDLESS) this.energyRoot:SetActive(carbonType == CARBON_TYPE.ENDLESS) end -- ================================================ -- ============ 初始化设置 ========================= function this.IsEndLessMap() return CarbonManager.difficulty == CARBON_TYPE.ENDLESS end function this.SetTipShow() Log("MapManager.curMapId ========== " .. MapManager.curMapId) -- if not this.IsEndLessMap() then return end if not endLessData[MapManager.curMapId] then Log(Language[11278]) return end this.areaName.text = GetLanguageStrById(endLessData[MapManager.curMapId].Info) EndLessMapManager.curMapName = GetLanguageStrById(endLessData[MapManager.curMapId].Info) end function this.InitBoolState() EndLessMapManager.isCanNote = false EndLessMapManager.justEnterMap = true EndLessMapManager.isReset = false end -- =================================================== -- ========= 各种按键操作的设置 ========================= -- 复位设置 function this.ResetRoleState() --if not this.CanClick() then return end -- 重置角色位置(目前没有表现,做一下延迟) Timer.New(function () -- 通信一次 NetManager.RequestResetState(function () PopupTipPanel.ShowTip(Language[11279]) -- 初始位置 local position = challengeMapConfig[MapManager.curMapId].Position local initPos = position[1] * 256 + position[2] -- 前端同步位置 MapManager.curPos = initPos -- 重置队伍以及妖灵师的血量, 同时重置位置 Game.GlobalEvent:DispatchEvent(GameEvent.Formation.OnResetFormationHp, initPos) -- 请求一次血量, 复位之后请求一次血量 NetManager.RequestAllHeroHp(function () --Log("复位之后请求一次血量数据") end) -- 刷新迷雾 local u,v = Map_Pos2UV(initPos) TileMapView.UpdateWarFog(u, v, MapManager.fogSize) FormationManager.SetOneKeyGoWithoutUI(FormationTypeDef.FORMATION_ENDLESS_MAP,20) end) end, 0.2):Start() -- 进入复位状态 EndLessMapManager.isReset = true end -- 标记设置 function this.SetNoteShow() -- 进入标记状态 EndLessMapManager.isCanNote = not EndLessMapManager.isCanNote local canNote = EndLessMapManager.isCanNote MapPanel.BtnBack:SetActive(not canNote) this.btnReset:SetActive(not canNote) this.btnFormat:SetActive(not canNote) this.btnSet:SetActive(not canNote) ctrlView.IsForbitLongClick(canNote) end -- 按钮可点击的判断 function this.CanClick() local canClick = true -- 如果正在触发事件,不可复位 if ctrlView.GetTriggerState() then PopupTipPanel.ShowTip(Language[11280]) return false end -- 正在寻路 if ctrlView.GetCallListCount() > 1 then PopupTipPanel.ShowTip(Language[11281]) return false end return canClick end --- ============= 行动力刷新显示 ============================== function this.OnRoleMove(u, v) -- 只有无尽副本才执行 if not this.IsEndLessMap() then return end this.RefreshEnergyValue(false, COST_TYPE.WALK) end -- 初始化数值 function this.InitCostValue() local mapData = endLessData[MapManager.curMapId] walkCost = mapData.WalkCost deadCost = mapData.DeathCost -- 同步一次道具数据 this.GetBagEnergy() -- 显示你有多少钱钱 this.moneyNum:GetComponent("Text").text = BagManager.GetTotalItemNum(1201) this.moneyIcon:GetComponent("Image").sprite = SetIcon(1201) end -- 根据类型刷新行动力数值 function this.RefreshEnergyValue(isInit, costType) -- 只是初始化返回 -- LogBlue("两次吧") if isInit then return end if EndLessMapManager.justEnterMap then EndLessMapManager.justEnterMap = false Log("刚进图的那一步不扣行动力") return end local curEnergy = EndLessMapManager.leftEnergy preEnergy = curEnergy -- 行走 if costType == COST_TYPE.WALK then curEnergy = curEnergy - walkCost <= 0 and 0 or curEnergy - walkCost -- 只要动一哈就不再是复位状态 EndLessMapManager.isReset = false -- 消除死亡状态 EndLessMapManager.EndLessRoleDead = false -- 消除重登状态 MapManager.isReloadEnter = false -- 行走时剩余行动力警告 if curEnergy == 5 and preEnergy > 5 then -- 停止寻路 if ctrlView.GetCallListCount() > 1 then ctrlView.StopWalk() end -- this.PlayWarnEffect() end -- 死翘翘 elseif costType == COST_TYPE.DEAD then -- 传送 elseif costType == COST_TYPE.TRANSPORT then end EndLessMapManager.leftEnergy = curEnergy EndLessMapManager.isHungery() this.RefreshEnergyShow() -- 行动力从满状态切换到不满时启动定时器, 告诉服务器我走了 if preEnergy == EndLessMapManager.GetTotalEnergy() and curEnergy < EndLessMapManager.GetTotalEnergy() then MapManager.MapUpdateEvent(-1000, function () Log("满行动力状态切换同步倒计时") this.ShowCountTime() end) end end -- 刷新行动力组件显示 function this.RefreshEnergyShow() local curEnergy = EndLessMapManager.leftEnergy if curEnergy <= 0 then ctrlView.StopWalk() end local totalEnergy = EndLessMapManager.GetTotalEnergy() -- 设置一下颜色 local str = "" if curEnergy <= 5 then str = string.format("%s", tostring(curEnergy)) else str = tostring(curEnergy) end this.energyInfo.text = str this.totalEnergy.text = totalEnergy end -- 刷新数值 function this.GetBagEnergy() -- 无尽副本才刷新 if not this.IsEndLessMap() then return end EndLessMapManager.leftEnergy = BagManager.GetItemCountById(1) Log("获取背包剩余行动力" .. BagManager.GetItemCountById(1)) EndLessMapManager.isHungery() this.RefreshEnergyShow() -- 显示你有多少钱钱 this.moneyNum:GetComponent("Text").text = BagManager.GetTotalItemNum(1201) this.moneyIcon:GetComponent("Image").sprite = SetIcon(1201) end -- 无尽副本中角色死翘翘 function this.OnRoleDead() this.RefreshEnergyValue(false, COST_TYPE.DEAD) -- 死亡退出触发事件状态 EndLessMapManager.isTrigger = false -- 看看是否是死光光了 if EndLessMapManager.IsAllDead() then PopupTipPanel.ShowTip(Language[11282]) this.ResetRoleState() end end -- 无尽副本在地图之间传送 function this.OnRoleTransport(func) EndLessMapManager.GetLeftEnergy(function () this.RefreshEnergyValue(false, COST_TYPE.TRANSPORT) if func then func() end end) end -- 行动力警告特效 -- function this.PlayWarnEffect() -- this.warn:SetActive(true) -- local timer = Timer.New(function () -- this.warn:SetActive(false) -- end, 1.6) -- timer:Start() -- end -- 行动力是否显示倒计时 function this.ShowCountTime() this.timer = nil this.actCountTime.text = "" this.bgTime:SetActive(not EndLessMapManager.EnergyEnough()) -- 初始化是判断一次 if not EndLessMapManager.EnergyEnough() then -- 启动倒计时 this.timer = Timer.New(function () local leftTime = AutoRecoverManager.GetRecoverTime(1) if EndLessMapManager.EnergyEnough()then -- 行动力恢复已满 this.actCountTime.text = "" if this.isPanelClose then if this.timer then this.timer:Stop() end this.bgTime:SetActive(false) end else this.actCountTime.text = GetTimeMaoHaoStrBySeconds(math.floor(leftTime)) end end, 1, -1, true) this.timer:Start() end end --- ========================================================== function this.OnClose() if not this.IsEndLessMap() then return end -- this.warn:SetActive(false) this.isPanelClose = true EndLessMapManager.isUpdateOnClose = false if this.timer then this.timer:Stop() this.timer = nil end end function this.OnDestroy() if not this.IsEndLessMap() then return end end return EndLessMapView