miduo_client/Assets/ManagedResources/~Lua/Modules/Fight/View/ExploreMapView.lua

470 lines
16 KiB
Lua
Raw Normal View History

2021-12-23 13:45:05 +08:00
require("Base/Stack")
require("Modules/Map/Logic/TileMapController")
require("Modules/Map/Logic/TileMapView")
require("Modules/Map/Config/MapConfig")
require("Modules/Map/View/MapPointView")
local mapIconConfig = ConfigManager.GetConfig(ConfigName.MainMapIconConfig)
local iconAction = require("Modules/Fight/View/FightMapIconShowView")
local this = {}
-- 临时可生成怪的区域
local monsterArea = {
[5005] = {
x_pos = {min = 8, max = 28},
y_pos = {min = 8, max = 14},
},
[4002] = {
x_pos = {min = 8, max = 24},
y_pos = {min = 9, max = 23},
},
2021-12-27 15:42:52 +08:00
[4001] = {
x_pos = {min = 8, max = 24},
y_pos = {min = 9, max = 23},
},
[4004] = {
x_pos = {min = 8, max = 24},
y_pos = {min = 9, max = 23},
},
2021-12-23 13:45:05 +08:00
[5002] = {
x_pos = {min = 9, max = 32},
y_pos = {min = 8, max = 16},
},
[5003] = {
x_pos = {min = 8, max = 28},
y_pos = {min = 8, max = 14},
},
[5004] = {
x_pos = {min = 8, max = 27},
y_pos = {min = 8, max = 15},
},
}
--自己角色的出生点
local startUV = {
[5005] = {u = 15, v = 10},
2021-12-27 15:42:52 +08:00
[4001] = {u = 15, v = 15},
2021-12-23 13:45:05 +08:00
[4002] = {u = 15, v = 15},
2021-12-27 15:42:52 +08:00
[4004] = {u = 15, v = 15},
2021-12-23 13:45:05 +08:00
[5002] = {u = 15, v = 15},
[5003] = {u = 15, v = 10},
[5004] = {u = 15, v = 10},
}
-- 允许出现的事件点的图标数量
local iconNum = 20
2021-12-23 13:45:05 +08:00
-- 地图图标的上限值
local maxIcon = 9
local mapCtrl = "MapCtrl"
local effectPath = "c_xy_0012_skeff_slidesk_ballistic"
local m_orginLayer = 0
local m_parent
this.isClose = false
--root FightPointPassMainPanel.gameObject FightPointPassMainPanel脚本
function this:InitComponent(root, parent)
m_orginLayer = 0
m_parent = parent
-- 地图点击拖动
this.root = root
2021-12-24 00:33:33 +08:00
this.dragCtrl = Util.GetGameObject(root, "Ctrl")
2021-12-23 13:45:05 +08:00
this.effectRoot = Util.GetGameObject(root, "effectRoot")
this.buffTip = Util.GetGameObject(this.effectRoot, "money")
this.playerViews = {}
end
function this:AddListener()
2021-12-29 16:05:16 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Explore.UpdateSingleFormation,this.Refresh)
2021-12-23 13:45:05 +08:00
end
function this:RemoveListener()
2021-12-29 16:05:16 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.Explore.UpdateSingleFormation,this.Refresh)
end
function this.Refresh(teamId)
2021-12-31 11:40:42 +08:00
if not this.playerViews[teamId] then
return
end
2021-12-29 16:05:16 +08:00
this.playerViews[teamId]:RefreshHp()
if ExploreManager.FormationData[teamId].state < 1 then
2021-12-31 16:32:08 +08:00
this.playerViews[teamId]:RefreshIsSelf(false)
2021-12-29 16:21:59 +08:00
SubUIManager.Close(this.playerViews[teamId])
this.playerViews[teamId] = nil
2021-12-31 16:32:08 +08:00
if this.playerViews[0].data.formationId == teamId then
2021-12-29 16:05:16 +08:00
this.playerViews[0] = nil
end
end
if not this.playerViews[0] then
for k,v in pairs(this.playerViews) do
2021-12-31 16:32:08 +08:00
if v.data.formationId > 3100 then
2021-12-29 16:05:16 +08:00
this.playerViews[0] = v
2021-12-31 16:32:08 +08:00
this.playerViews[v.data.formationId]:RefreshIsSelf(true)
this.playerViews[0] = this.playerViews[v.data.formationId]
break
2021-12-29 16:05:16 +08:00
end
2021-12-31 16:32:08 +08:00
end
if this.playerViews[0] then
-- 设置相机初始化位置
local v4 = this.playerViews[0].transform.localPosition
v4.z = -50
TileMapView.SetCameraPos(v4)
end
2021-12-29 16:05:16 +08:00
end
2021-12-23 13:45:05 +08:00
end
function this:Init()
this.isClose = false
this.isCanUseIconList = 0
-- 初始化加载地图块数据
this:LoadMapData()
-- 加载一个小人
2021-12-24 14:09:48 +08:00
NetManager.ExplorerMapPlayerInfoRequest(m_parent.mapData.mapId,function(msg)
local NPCList = ExploreManager.InitMapUserInfosData(msg,m_parent.mapData.mapId)
2021-12-27 15:42:52 +08:00
local area = monsterArea[m_parent.mapData.exploreMapId]
local suv = startUV[m_parent.mapData.exploreMapId]
2021-12-24 11:18:03 +08:00
for k,v in pairs(NPCList) do
local index1 = math.random(area.x_pos.min,suv.u - 3)
local index2 = math.random(suv.u + 3,area.x_pos.max)
local index3 = math.random(1,2)
local index4 = math.random(area.y_pos.min,area.y_pos.max)
this.playerViews[v.formationId] = SubUIManager.Open(SubUIConfig.SingleExplorePlayerView,this.mapRoot.transform,this)
2022-01-07 13:43:07 +08:00
this.playerViews[v.formationId]:SetData((index3 == 1 and index1 or index2),index4,v)
2021-12-24 14:09:48 +08:00
if v.formationId > 3100 then
if not this.playerViews[0] then
2021-12-29 16:05:16 +08:00
this.playerViews[v.formationId]:RefreshIsSelf(true)
2021-12-24 14:09:48 +08:00
this.playerViews[0] = this.playerViews[v.formationId]
else
2021-12-29 16:05:16 +08:00
this.playerViews[v.formationId]:RefreshIsSelf(false)
2021-12-24 14:09:48 +08:00
end
else
2021-12-29 16:05:16 +08:00
this.playerViews[v.formationId]:RefreshIsSelf(false)
2021-12-24 11:18:03 +08:00
end
2022-01-07 13:43:07 +08:00
2021-12-29 16:05:16 +08:00
this.playerViews[v.formationId]:Run()
2021-12-31 14:07:56 +08:00
this.playerViews[v.formationId]:RefreshHp(v.formationId)
2021-12-24 11:18:03 +08:00
end
2021-12-24 17:49:54 +08:00
-- 设置相机初始化位置
local v4 = this.playerViews[0].transform.localPosition
v4.z = -50
TileMapView.SetCameraPos(v4)
-- 初始化两个地图标志
this.LoadMapIcon()
2021-12-29 16:05:16 +08:00
--this.SetPlayerViewWalk()
2021-12-24 11:18:03 +08:00
end)
2021-12-23 13:45:05 +08:00
end
function this:LoadMapData()
UIManager.camera.clearFlags = CameraClearFlags.Depth
-- 所有物体的根节点
this.mapRoot = poolManager:LoadAsset(mapCtrl, PoolManager.AssetType.GameObject)
this.mapRoot.name = mapCtrl
this.mapRoot.transform:SetParent(UIManager.uiRoot.transform.parent)
this.mapRoot.transform.position = Vector3.New(0, 0, -100)
TileMapView.fogSize = 2
2021-12-27 15:42:52 +08:00
TileMapView.AwakeInit(this.mapRoot, m_parent.mapData.exploreMapId, nil, Vector2.New(180, 180))
2021-12-23 13:45:05 +08:00
TileMapView.isShowFog = false
TileMapController.IsShieldDrag = function()
--当栈中有逻辑,则拖动可以打断镜头跟随
return false
end
TileMapController.OnClickTile = this.OnClickTile
TileMapController.Init(this.mapRoot, this.dragCtrl)
TileMapView.Init()
-- 设置镜头的尺寸
TileMapView.SetMapScale(Screen.height / 1920)
-- 设置不点击
this.dragCtrl:SetActive(false)
m_orginLayer = m_parent.sortingOrder
end
--加载图标icon
function this.LoadMapIcon()
this.iconList = {}
this.selectIconList = {}
--FightPointPassManager.isBeginFight = false
for i = 1, iconNum do
this.LoadPointIcon(false)
end
end
this.isCanUseIconList = 0
function this.RequestIconList()
if this.isCanUseIconList == 0 then
this.isCanUseIconList = 1
return this.iconList
end
return nil
end
function this.ReleaseIconList()
this.isCanUseIconList = 0
end
function this.AsideTriggerJudge(data,isSelf,_userData)
local isGetIconList = false
local iconList = this.iconList
if not this.threads then
this.threads = {}
end
2021-12-28 17:52:28 +08:00
if this.threads[_userData.data.formationId] then
coroutine.stop(this.threads[_userData.data.formationId])
this.threads[_userData.data.formationId] = nil
2021-12-23 13:45:05 +08:00
end
2021-12-28 17:52:28 +08:00
this.threads[_userData.data.formationId] = coroutine.start(function()
2021-12-23 13:45:05 +08:00
while(not isGetIconList) do
if this.isClose and this.isClose == true then
2021-12-28 17:52:28 +08:00
coroutine.stop(this.threads[_userData.data.formationId])
this.threads[_userData.data.formationId] = nil
2021-12-23 13:45:05 +08:00
this.ReleaseIconList()
coroutine.yield()
end
--Log("没有得到访问权")
iconList = this.RequestIconList()
if iconList and LengthOfTable(iconList) > 0 then
isGetIconList = true
else
--Log("等待中")
coroutine.wait(0.1)
end
end
--Log("得到了访问权")
-- for k,v in pairs(iconList) do
-- --Log("iconList k:"..tostring(k))
-- end
local selfPos = Map_UV2Pos(data.u, data.v)
--Log("selfPos:"..tostring(selfPos))
local posList = {}
posList[1] = Map_UV2Pos(data.u - 1, data.v)
posList[2] = Map_UV2Pos(data.u + 1, data.v)
posList[3] = Map_UV2Pos(data.u, data.v - 1)
posList[4] = Map_UV2Pos(data.u, data.v + 1)
for k,pos in pairs(posList) do
--Log("posList pos:"..tostring(pos))
2021-12-28 17:52:28 +08:00
if iconList[pos] and this.HasSelectIconList(pos,_userData.data.formationId) then
2021-12-23 13:45:05 +08:00
this.RemoveSelectIconList(_userData.eventPointPos)
2021-12-28 17:52:28 +08:00
this.AddSelectIconList(pos,_userData.data.formationId)
2021-12-23 13:45:05 +08:00
--Log("发送了消息")
Game.GlobalEvent:DispatchEvent(GameEvent.GuaJi.getEvent,{goData = _userData, event = iconList[pos], pos = pos})
2021-12-28 17:52:28 +08:00
coroutine.stop(this.threads[_userData.data.formationId])
this.threads[_userData.data.formationId] = nil
2021-12-23 13:45:05 +08:00
this.ReleaseIconList()
coroutine.yield()
end
end
--Log("周围没有事件")
2021-12-28 17:52:28 +08:00
if this.threads[_userData.data.formationId] then
coroutine.stop( this.threads[_userData.data.formationId])
this.threads[_userData.data.formationId] = nil
2021-12-23 13:45:05 +08:00
end
this.ReleaseIconList()
coroutine.yield()
end)
end
function this.HasSelectIconList(pos,uid)
if this.selectIconList[pos] and this.selectIconList[pos] ~= uid then
return false
else
return true
end
end
function this.AddSelectIconList(pos,uid)
this.selectIconList[pos] = uid
end
function this.RemoveSelectIconList(pos)
if this.selectIconList[pos] then
this.selectIconList[pos] = nil
end
end
--- 生成一个图标, 传入校验权重值rand, 是否使用动画
function this.LoadPointIcon(useAnim)
if LengthOfTable(this.iconList) >= iconNum then
return
end
-- 随机一个坐标
2021-12-27 15:42:52 +08:00
local area = monsterArea[m_parent.mapData.exploreMapId]
2021-12-23 13:45:05 +08:00
--Log("area.x_pos.min:"..tostring(area.x_pos.min).." area.x_pos.max:"..tostring(area.x_pos.max))
local u = math.random(area.x_pos.min, area.x_pos.max)
--Log("area.y_pos.min:"..tostring(area.y_pos.min).." area.y_pos.max:"..tostring(area.y_pos.max))
local v = math.random(area.y_pos.min, area.y_pos.max)
--Log("u:"..tostring(u).." v:"..tostring(v))
local pos = Map_UV2Pos(u, v)
local mapPointId = math.random(1,maxIcon)
-- 随机出来的位置已经有图标,则再次随机
if this.iconList[pos] or pos == 1285 or this.IsHaveBitchNear(pos) then
this.LoadPointIcon()
else
local pointView = MapPointView.New(u, v, mapPointId)
if pointView then
pointView.go.transform:SetParent(Util.GetTransform(this.mapRoot, "uiObj#"))
local targetPos = TileMapView.GetLiveTilePos(u, v) * 100
-- 完了这玩意还能从天而降
if useAnim then
pointView.go:GetComponent("RectTransform").anchoredPosition3D = Vector3.New(targetPos.x, 1000, 0)
pointView.go:GetComponent("RectTransform"):DOAnchorPos(targetPos, 0.5, false):OnComplete(function ()
end)
else
pointView.go:GetComponent("RectTransform").anchoredPosition3D = targetPos
end
pointView:SetPointAnimation(pointView.iconId, 1)
pointView.go.transform.localScale = Vector3.one
-- 额外尺寸设置
if pointView.iconId == MapIconType.ICON_GOLD_BOX or pointView.iconId == MapIconType.ICON_NEW_BOX then
pointView.go.transform.localScale = Vector3.New(1.3, 1.3, 1.3)
elseif pointView.iconId == MapIconType.ICON_SUPPLY then
pointView.go.transform.localScale = Vector3.New(0.8, 0.8, 0.8)
end
pointView:OnShow()
pointView:ShowAtkNum(0, false)
pointView:ShowFreshTime(false)
pointView:ShowDialogue(false)
this.iconList[pos] = pointView
2021-12-31 14:07:56 +08:00
this.RemoveSelectIconList(pos)
2021-12-23 13:45:05 +08:00
end
end
end
---------------------------------------------------------------------------------------------设置特效层级
function this:OnSortingOrderChange(orginLayer)
if this.moneyEffect then
for k,v in pairs(this.playerViews) do
v:OnSortingOrderChange(m_parent.sortingOrder)
end
m_orginLayer = m_parent.sortingOrder
end
end
function this.GetCurLayer()
return m_orginLayer
end
-------------------------------------------------------------------------------------------------------------
---============== Point Icon Handle =================================
-- 删除一个图标
function this.DeletePointIcon(pos)
if this.iconList[pos] then
this.iconList[pos]:OnRemovePoint()
this.iconList[pos] = nil
end
end
-- 检测当前图标附近是否有图标
function this.IsHaveBitchNear(pos)
local haveBitch = false
local targetU, targetV = Map_Pos2UV(pos)
for i, v in pairs(this.iconList) do
local u0, v0 = Map_Pos2UV(i)
if math.abs(u0 - targetU) + math.abs(v0 - targetV) <= 2 then
haveBitch = true
break
end
end
return haveBitch
end
--- =============== 行动中的表现处理 =====================================================
-- 退出战斗状态
function this.BattleEnd(selectPointPos,isSelf)
--Log("战斗结束回调")
-- 删点前隐藏那个东西
if this.iconList[selectPointPos] then
this.iconList[selectPointPos]:ShowDialogue(false)
end
-- 删除图标
this.DeletePointIcon(selectPointPos)
this.RemoveSelectIconList(selectPointPos)
end
--- ==================== 角色行走 =====================================
function this.OnClickTile(u, v)
--Log("UIManager.width is -- " .. UIManager.width .. " and Height is " .. UIManager.height)
local v2 = RectTransformUtility.WorldToScreenPoint(TileMapView.GetCamera(), TileMapView.GetLiveTilePos(u, v))
v2 = v2 / math.min(Screen.width/1080, Screen.height/1920)
--Log(string.format("当前点击坐标(%s, %s)", u, v))
--Log(string.format("转换后的屏幕坐标是(%s, %s)", v2.x, v2.y))
end
-- 停止一切该死的行为
function this.StopAction()
for k,v in pairs(this.playerViews) do
v:StopAction()
end
if this.moneyEffect then
this.moneyEffect.gameObject:SetActive(false)
end
if this.threads then
for k,v in pairs(this.threads) do
coroutine.stop(v)
this.threads[k] = nil
end
end
this.threads = {}
this.ReleaseIconList()
this.isClose = true
end
--- ======================================================================
function this.OnGameOver()
-- Log("OnGameOver")
for i, v in pairs(this.playerViews) do
if v then
SubUIManager.Close(v)
end
end
this.playerViews = {}
for i, v in pairs(this.iconList) do
if v then
v:Dispose()
this.iconList[i] = nil
end
end
if this.mapRoot then -- 避免不是主动退出
-- Log("注销一次地图资源")
poolManager:UnLoadAsset(mapCtrl, this.mapRoot, PoolManager.AssetType.GameObject)
poolManager:UnLoadAsset(effectPath, this.moneyEffect, PoolManager.AssetType.GameObject)
UIManager.camera.clearFlags = CameraClearFlags.Skybox
TileMapView.Exit()
TileMapController.Exit()
end
this.mapRoot = nil
this.moneyEffect = nil
end
function this:OnClose()
2021-12-29 16:05:16 +08:00
this:RemoveListener()
2021-12-23 13:45:05 +08:00
-- Log("关闭挂机OnClose")
if this.startTimer then
this.startTimer:Stop()
end
this.startTimer = nil
this.StopAction()
this.OnGameOver()
end
function this:Dispose()
if this.startTimer then
this.startTimer:Stop()
end
this.startTimer = nil
this.StopAction()
this.OnGameOver()
end
return this