miduo_client/Assets/ManagedResources/~Lua/Modules/Map/View/MapControllView.lua

655 lines
20 KiB
Lua
Raw Normal View History

2021-04-21 13:12:04 +08:00
require("Base/Stack")
2020-05-09 13:31:21 +08:00
require("Modules/Map/Logic/TileMapController")
require("Modules/Map/Logic/TileMapView")
local this = {}
local MapPlayerView
local pointHandleView = require("Modules/Map/View/PointHandleView")
local iconShow = require("Modules/Map/View/IconShowView")
local callList = Stack.New()
local funcCanPass = function(data) return data.val <= 1 end
local pathList
-- 是否触发了事件
local isEventTrigger = false
local mapCtrl = "MapCtrl"
local MapPanel
local hasDisposed = false
function this.InitComponent(gameObject, mapPanel, playerView)
2021-04-21 13:12:04 +08:00
this.spLoader = SpriteLoader.New()
2020-05-09 13:31:21 +08:00
MapPanel = mapPanel
MapPlayerView = playerView
this.DragCtrl = Util.GetGameObject(gameObject, "Ctrl")
end
function this.AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Event.PointTriggerEnd, this.OnEventTriggerEnd)
end
function this.RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Event.PointTriggerEnd, this.OnEventTriggerEnd)
end
function this.Init()
hasDisposed = false
this.Ctrl = poolManager:LoadAsset(mapCtrl, PoolManager.AssetType.GameObject)
this.Ctrl.name = mapCtrl
this.Ctrl.transform:SetParent(UIManager.uiRoot.transform.parent)
this.Ctrl.transform.position = Vector3(0, 0, -100)
pointHandleView.Ctrl = this.Ctrl
-- Log("当前地图编号 " .. MapManager.curMapId)
2020-05-09 13:31:21 +08:00
TileMapView.OnInit = this.OnInit
TileMapView.fogSize = MapManager.fogSize
2021-05-27 17:34:59 +08:00
LogGreen("MapManager.curMapId:"..MapManager.curMapId)
2020-05-09 13:31:21 +08:00
TileMapView.AwakeInit(this.Ctrl, MapManager.curMapId, MapManager.wakeCells)
TileMapController.IsShieldDrag = function()
--当栈中有逻辑,则拖动可以打断镜头跟随
this.DragFlag = callList:Count() > 1
return false
end
-- 清空
this.OnRoleDead()
TileMapController.OnClickTile = this.OnClickTile
TileMapController.OnLongClickTile = this.OnLongClickTile
TileMapController.Init(this.Ctrl, this.DragCtrl)
callList:Clear()
end
function this.GetCallListCount()
return callList:Count()
end
function this.OnInit()
end
---==============================================================================
function this.OnLongClickShowPath(u, v)
if this.WalkLimit(false) > 0 then
return
end
--寻路算法,返回的结果是从终点指向起点的坐标列表
pathList = TileMapView.ShowPath(MapPlayerView.leaderMapData.u, MapPlayerView.leaderMapData.v, u, v, funcCanPass)
end
function this.OnLongClickTile()
--寻路路径为空,则不能行走
if this.WalkLimit(true) > 0 then
return
end
if not pathList or #pathList <= 1 then
-- 这里将弹出状态置为false避免因为连续点击时第二次点击到无法寻路的点导致寻路卡死的问题
MapManager.isPoping = false
return
end
--把最终回调最先入栈
callList:Push(function ()
-- 寻路完成弹出状态置为false
MapManager.isPoping = false
MapPanel.PathEnd()
end)
for i=1, #pathList-1 do --最后的点为起点,不处理
local data = pathList[i]
local v3 = TileMapView.GetLiveTilePos(data.u, data.v)
callList:Push(function ()
MapPlayerView.SetRoleDirAction(data.u, data.v)
MapPlayerView.leaderMapData = data
MapPlayerView.leader.transform:DOLocalMove(Vector3(v3.x, v3.y, v3.z - 10), MapManager.leaderMoveSpeed/5, false):OnUpdate(function() --TODO:测试速度
--该标记监听拖动,当正在处理栈事件时,镜头默认居中跟随,此时拖动界面可以打断镜头跟随
if this.DragFlag then
return
end
local v3 = MapPlayerView.leader.transform.localPosition
v3.z = TileMapView.ViewCameraPos.z
TileMapView.SetCameraPos(v3)
TileMapView.UpdateBaseData()
end):OnComplete(function ()
TileMapView.ClearPathTile(data.u, data.v)
MyPCall(function () this.OnMoveStep(data.u, data.v) end)
this.CallListPop()
end):SetEase(Ease.Linear)
end)
end
--若相机未归位则先归位
callList:Push(function ()
local data = MapPlayerView.leaderMapData
local v3 = TileMapView.GetLiveTilePos(data.u, data.v)
v3.z = TileMapView.ViewCameraPos.z
if TileMapView.ViewCameraPos ~= v3 then
TileMapView.CameraTween(data.u, data.v, 0.5, function ()
TileMapView.ClearPathTile(data.u, data.v)
this.CallListPop()
end)
this.DragFlag = false
else
TileMapView.ClearPathTile(data.u, data.v)
this.CallListPop()
end
end)
-- 判断是否正在弹出事件,没有则开始
if not MapManager.isPoping then
MapManager.isPoping = true
this.CallListPop()
end
--栈事件清空前,关闭移动
MapPlayerView.PlayerMove()
end
-- 一部分不可寻路的条件
--- @return 值大于0都是不可寻路的状态
function this.WalkLimit(showTip)
local value = 0
-- 触发了事件不可寻路
if isEventTrigger then value = 1 end
-- 人物死亡不可寻路
if MapManager.deadTime > 0 then value = 2 end
-- 精气值满时不可寻路
if CarbonManager.difficulty == CARBON_TYPE.TRIAL then
if not MapTrialManager.canMove or MapTrialManager.isChangeLevel then
value = 3
end
2021-03-02 16:53:12 +08:00
if MapManager.isRemoving then Log(Language[11283]) value = 4 end
2020-05-09 13:31:21 +08:00
end
2021-05-26 17:27:47 +08:00
-- -- 加入进入标记状态
-- if EndLessMapManager.IsCanNoteState() then
-- value = 5
-- end
2020-05-09 13:31:21 +08:00
if EndLessMapManager.roleIsHungery() then
if showTip then
2021-03-02 16:53:12 +08:00
PopupTipPanel.ShowTip(Language[11284])
2020-05-09 13:31:21 +08:00
this.GodIsBack()
end
value = 6
end
--正在移动时,或点击区域外,点击移动无效
if not MapPlayerView.bLeaderIsIdle then value = 7 end
return value
end
--传说中的相机归位
function this.GodIsBack()
local data = MapPlayerView.leaderMapData
local v3 = TileMapView.GetLiveTilePos(data.u, data.v)
v3.z = TileMapView.ViewCameraPos.z
if TileMapView.ViewCameraPos ~= v3 then
TileMapView.CameraTween(data.u, data.v, 0.5, function ()
TileMapView.ClearPathTile(data.u, data.v)
this.CallListPop()
end)
this.DragFlag = false
end
end
function this.OnClickTile(u, v)
-- 触发了事件不可寻路
if isEventTrigger then return end
-- 人物死亡不可寻路
if MapManager.deadTime > 0 then return end
-- 精气值满时不可寻路
if CarbonManager.difficulty == CARBON_TYPE.TRIAL then
if not MapTrialManager.canMove or MapTrialManager.isChangeLevel then
return
end
2021-03-02 16:53:12 +08:00
if MapManager.isRemoving then Log(Language[11283]) return end
2020-05-09 13:31:21 +08:00
end
--- 判断点击位置是否超出地图区域
local data = TileMapView.GetTileData(u, v)
if not data then
2021-05-26 17:27:47 +08:00
-- if EndLessMapManager.IsCanNoteState() then
-- PopupTipPanel.ShowTip(Language[11285])
-- end
2020-05-09 13:31:21 +08:00
return
end
-- 无尽副本进入地图标记状态
-- =====================================
2021-05-26 17:27:47 +08:00
-- if EndLessMapManager.IsCanNoteState() then
-- if not funcCanPass(data) then
-- PopupTipPanel.ShowTip(Language[11286])
-- return
-- end
2020-05-09 13:31:21 +08:00
2021-05-26 17:27:47 +08:00
-- Log(string.format("坐标位置(%s, %s)", u, v))
-- EndLessMapManager.SetNotePos(u, v)
-- return
-- end
2020-05-09 13:31:21 +08:00
if EndLessMapManager.roleIsHungery() then
2021-03-02 16:53:12 +08:00
PopupTipPanel.ShowTip(Language[11284])
2020-05-09 13:31:21 +08:00
-- 相机没有归位则归位,当次寻路不生效
this.GodIsBack()
return
end
-- 无尽副本进图死亡状态
if CarbonManager.difficulty == CARBON_TYPE.ENDLESS then
2021-05-26 17:27:47 +08:00
local curFomation = EndLessMapManager.formation
if not curFomation or #curFomation < 1 then
PopupTipPanel.ShowTip("请前往编队界面设置作战神将!")
MapManager.endlessEnter = false
2021-05-26 17:27:47 +08:00
return
2020-05-09 13:31:21 +08:00
end
2021-05-26 17:27:47 +08:00
-- if EndLessMapManager.EndLessRoleDead then
-- PopupTipPanel.ShowTip(Language[11287])
-- -- 重登时如果都是死的,上面的判断就可以,如果还有活着的,肯定在队伍中
-- if EndLessMapManager.IsAllDead() then
-- PopupTipPanel.ShowTip(Language[11287])
-- return
-- end
-- if not MapManager.endlessEnter then
-- if not EndLessMapManager.IsMapTeamAlive() then
-- PopupTipPanel.ShowTip(Language[11288])
-- return
-- end
-- end
-- MapManager.endlessEnter = false
-- end
2020-05-09 13:31:21 +08:00
end
-- =====================================
--- 当栈中有逻辑,则点击可以打断栈操作,并清空当前栈
MapPanel.PathEnd()
--- 显示路径开始寻路
this.OnLongClickShowPath(u, v)
this.OnLongClickTile()
end
-- 单次寻路
function this.OnClickFindPath(u, v)
--当栈中有逻辑,则点击可以打断栈操作,并清空当前栈
if callList:Count() > 1 then
-- 相机归位过程中,再次点击寻路,清空栈,相机归位完成栈是空的,无法重置状态
MapManager.isPoping = false
TileMapView.CameraTween(MapPlayerView.leaderMapData.u, MapPlayerView.leaderMapData.v, 0.5)
this.DragFlag = false
MapPanel.PathEnd()
return
end
-- 相机没有归位则归位,当次寻路不生效
local v3 = TileMapView.GetLiveTilePos(MapPlayerView.leaderMapData.u, MapPlayerView.leaderMapData.v)
v3.z = TileMapView.ViewCameraPos.z
if not TileMapView.IsOutBounds(v3) and TileMapView.ViewCameraPos ~= v3 then
TileMapView.CameraTween(MapPlayerView.leaderMapData.u, MapPlayerView.leaderMapData.v, 0.5)
this.DragFlag = false
return
end
local data = this.GetOnceClickPathList(u, v)
if data and funcCanPass(data) then
pathList = {data, MapPlayerView.leaderMapData}
this.OnLongClickTile()
end
end
function this.GetOnceClickPathList(u, v)
local tu, tv
if math.abs(u - MapPlayerView.leaderMapData.u) >= math.abs(v - MapPlayerView.leaderMapData.v) then
if u > MapPlayerView.leaderMapData.u then
tu = MapPlayerView.leaderMapData.u + 1
else
tu = MapPlayerView.leaderMapData.u - 1
end
tv = MapPlayerView.leaderMapData.v
else
if v > MapPlayerView.leaderMapData.v then
tv = MapPlayerView.leaderMapData.v + 1
else
tv = MapPlayerView.leaderMapData.v - 1
end
tu = MapPlayerView.leaderMapData.u
end
local data = TileMapView.GetTileData(tu, tv)
return data
end
-- 角色进入进入标记状态时,只响应单击事件
function this.IsForbitLongClick(state)
if state then
TileMapController.OnLongClickShowPath = nil
end
end
--- ---------------------------------------------------------------
function this.OnRoleDead()
if isEventTrigger then
isEventTrigger = false
end
Log("callList:Count()" .. callList:Count())
if callList:Count() > 0 then
-- 传送等强制设置角色位置,停止弹出状态,并清空当前栈
MapManager.isPoping = false
MapPanel.PathEnd()
end
end
function this.BattleEnd()
MapPlayerView.SetBattleState(false)
end
-- 复位时角色停止寻路
function this.StopWalk()
if callList:Count() > 0 then
-- 传送等强制设置角色位置,停止弹出状态
MapManager.isPoping = false
MapPanel.PathEnd()
end
end
function this.OnMoveStep(u, v)
this.RectangleTrigger(u , v)
this.RefreshFog(u, v, true)
MapPanel.RefreshShow()
local pos = Map_UV2Pos(u, v)
table.insert(MapManager.stepList, pos)
MapPlayerView.ShowPos(u, v)
-- 普通副本,出图时间到,停止行走
if CarbonManager.difficulty == CARBON_TYPE.NORMAL then
if MapManager.isTimeOut or MapManager.progressFull then
this.OnRoleDead()
end
end
MapManager.curPos = pos
--边缘触发检测
this.EdgeEventTrigger(u-1, v)
this.EdgeEventTrigger(u+1, v)
this.EdgeEventTrigger(u, v-1)
this.EdgeEventTrigger(u, v+1)
--覆盖触发检测
this.EventTrigger(u, v)
-- buff管理按照步数刷新buff信息
FoodBuffManager.OnMoveStep()
end
-- 行走时刷新迷雾
function this.RefreshFog(u, v)
-- 刷新地图米迷雾
if TileMapView.isShowFog then
TileMapView.UpdateWarFog(u, v, MapManager.fogSize)
end
end
-- 设置不可刷新区域
function this.isFogArea(u, v)
local canFlush = true
-- 设置边界值
local u0 = 0
local v0 = 0
local u1 = 0
local v1 = 0
if u >= u0 and u <= u1 and v >= v0 and v <= v1 then
canFlush = false
else
canFlush = true
end
return canFlush
end
function this.SetCtrlState(state)
if state then
TileMapController.OnClickTile = nil
TileMapController.OnLongClickTile = nil
TileMapController.OnLongClickShowPath = nil
else
TileMapController.OnClickTile = this.OnClickTile
TileMapController.OnLongClickTile = this.OnLongClickTile
end
TileMapController.SetEnable(not state)
end
function this.EdgeEventTrigger(u, v)
local pos = Map_UV2Pos(u, v)
local pointView = pointHandleView.EventPoint[pos]
-- 周围不存在点,都没必要继续往下
if not pointView then return end
-- 如果当前已经到了地图的限制时间不再触发
2021-03-02 16:53:12 +08:00
if MapManager.isTimeOut then Log(Language[11289]) return end
2020-05-09 13:31:21 +08:00
-- 探索度100%,不再触发事件
if MapManager.progressFull then return end
if CarbonManager.difficulty == CARBON_TYPE.TRIAL then
2021-03-02 16:53:12 +08:00
if not MapTrialManager.canMove then Log(Language[11290]) return end
if MapManager.isRemoving then Log(Language[11283]) return end
2020-05-09 13:31:21 +08:00
end
local triggerFunc = function()
MapManager.MapUpdateEvent(pos, function ()
if pointHandleView.IsAShinningPoint(MapManager.mapPointList[pos]) then
pointHandleView.RemoveTipPoint(u, v)
end
end)
end
callList:Push(function ()
local pointView = pointHandleView.EventPoint[pos]
if not pointView or not pointView.cell or pointView.cell.TriggerRules ~= 1 then --边缘触发
this.CallListPop()
return
end
-- 触发了事件
if not isEventTrigger then
2020-07-23 19:05:43 +08:00
-- Game.GlobalEvent:DispatchEvent(GameEvent.Map.StopWalk)
2020-05-09 13:31:21 +08:00
isEventTrigger = true
EndLessMapManager.isTrigger = true
this.SetCtrlState(true)
end
if pointView and pointView.cell then
pointView:ShowHidePoint()
end
Log("当前地图点 " .. MapManager.mapPointList[pos])
-- --LogGreen("事件开始")
Game.GlobalEvent:DispatchEvent(GameEvent.Map.MaskState,1)
2020-07-23 17:42:17 +08:00
--如果英雄阵亡 无法选择其进行战斗
local num = #MapManager.trialHeroInfo
for i, v in ipairs(MapManager.trialHeroInfo) do
if v.heroHp<=0 then
num = num -1
if num == 0 then
2021-03-02 16:53:12 +08:00
PopupTipPanel.ShowTip(Language[11291])
2020-07-23 17:42:17 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.Event.PointTriggerEnd)
return
end
end
end
2020-05-09 13:31:21 +08:00
2020-07-01 09:40:20 +08:00
local var=PlayerManager.uid.."GeneralPopup_TrialSettingBtn"..1--1是是否自动战斗
2020-05-09 13:31:21 +08:00
if pointView.cell.Style == 1 then
this.SetCtrlState(true)
MapPlayerView.SetRoleBattleAction()
MapPlayerView.SetBattleState(true)
2020-07-01 09:40:20 +08:00
if PlayerPrefs.GetInt(var)==1 then--自动战斗是否开启
Timer.New(function ()
this.SetCtrlState(false)
triggerFunc()
end , 1):Start()
else
this.SetCtrlState(false)
triggerFunc()
end
2020-05-09 13:31:21 +08:00
else
2020-07-16 16:59:46 +08:00
MapPlayerView.SetBattleState(true)
2020-07-01 09:40:20 +08:00
if PlayerPrefs.GetInt(var)==1 then--自动战斗是否开启
Timer.New(function ()
triggerFunc()
end , 1):Start()
else
2020-05-09 13:31:21 +08:00
triggerFunc()
2020-07-01 09:40:20 +08:00
end
2020-05-09 13:31:21 +08:00
end
end)
if pointView and pointView.cell and pointView.cell.TriggerRules == 1 then
--引导阶段监听触发
Game.GlobalEvent:DispatchEvent(GameEvent.Guide.MapPosTriggered, u, v, callList)
end
end
function this.EventTrigger(u, v)
local pos = Map_UV2Pos(u, v)
-- 如果当前已经到了地图的限制时间不再触发
2021-03-02 16:53:12 +08:00
if MapManager.isTimeOut then Log(Language[11289]) return end
2020-05-09 13:31:21 +08:00
if MapManager.progressFull then return end
if CarbonManager.difficulty == CARBON_TYPE.TRIAL and MapTrialManager.isChangeLevel then
Log("换层不触发事件")
2020-05-09 13:31:21 +08:00
end
--触发事件时,将请求加入到逻辑栈中,监听事件点的变化,当事件点不再变化,或者被销毁时,说明事件交互结束
callList:Push(function ()
local pointView = pointHandleView.EventPoint[pos]
if not pointView or not pointView.cell or pointView.cell.TriggerRules ~= 2 then --覆盖触发
this.CallListPop()
return
end
-- 触发了事件
if not isEventTrigger then
2020-07-23 19:05:43 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.Map.StopWalk)
2020-05-09 13:31:21 +08:00
isEventTrigger = true
EndLessMapManager.isTrigger = true
this.SetCtrlState(true)
end
pointView:ShowHidePoint()
Log("当前地图点 " .. MapManager.mapPointList[pos])
2020-05-09 13:31:21 +08:00
MapManager.MapUpdateEvent(pos, function ()
if pointHandleView.IsAShinningPoint(MapManager.mapPointList[pos]) then
pointHandleView.RemoveTipPoint(u, v)
end
end)
end)
end
function this.RectangleTrigger(u, v)
this.AsideTrigger(u - 1, v - 1)
this.AsideTrigger(u , v - 1)
this.AsideTrigger(u + 1, v - 1)
this.AsideTrigger(u - 1, v)
this.AsideTrigger(u + 1, v )
this.AsideTrigger(u - 1, v + 1)
this.AsideTrigger(u , v + 1)
this.AsideTrigger(u + 1, v + 1)
end
-- 玩家周围8个格子触发
function this.AsideTrigger(u, v)
local pos = Map_UV2Pos(u, v)
local eventPoint = pointHandleView.EventPoint[pos]
if eventPoint and eventPoint.cell then
-- 在八格子外的时候设置动画
eventPoint:SetPointAnimation(eventPoint.iconId, 2)
-- 先拿无尽副本开刀
if CarbonManager.difficulty == CARBON_TYPE.ENDLESS then
-- 12 ---> 商人
-- 1 ---> 小怪
if eventPoint.iconId == MapIconType.ICON_BUSY_WANDER_MAN then
iconShow.SetIconShowByType(eventPoint, pos, MapPlayerView)
end
end
end
end
function this.OnEventTriggerEnd()
--Log("this.OnEventTriggerEnd()")
-- 事件结束
if isEventTrigger then
isEventTrigger = false
EndLessMapManager.isTrigger = false
2020-07-01 09:40:20 +08:00
-- if CarbonManager.difficulty == CARBON_TYPE.ENDLESS then
-- -- 激活小伙子
-- -- MapPlayerView.PlayerIdle()
-- end
2020-05-09 13:31:21 +08:00
end
-- 继续寻路
MapPlayerView.SetBattleState(false)
this.CallListPop()
this.SetCtrlState(false)
end
-- 寻路状态初始化
function this.InitPath()
Log("this.InitPath()")
isEventTrigger = false
this.ClearCallList()
this.DragCtrl:SetActive(true)
end
-- 获得事件触发状态
function this.GetTriggerState()
return isEventTrigger
end
function this.CallListPop()
--当事件交互结束,抛出下一个栈
if callList:Count() > 0 then
callList:Pop()()
end
end
function this.ClearCallList()
callList:Clear()
if not hasDisposed then
TileMapView.ClearPath()
end
pathList = nil
end
function this.Dispose()
UIManager.camera.clearFlags = CameraClearFlags.Skybox
hasDisposed = true
TileMapView.Exit()
TileMapController.Exit()
if this.Ctrl then
poolManager:UnLoadAsset(mapCtrl, this.Ctrl, PoolManager.AssetType.GameObject)
end
this.Ctrl = nil
end
2020-06-23 18:36:24 +08:00
return this