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

554 lines
19 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 = {}
--地图id
local mapIdList = {
[1] = 5002,
[2] = 5003,
[3] = 5005,
[4] = 4002,
[5] = 5004,
}
-- 临时可生成怪的区域
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},
},
[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},
[4002] = {u = 15, v = 15},
[5002] = {u = 15, v = 15},
[5003] = {u = 15, v = 10},
[5004] = {u = 15, v = 10},
}
-- 允许出现的事件点的图标数量
local iconNum = 9
-- 地图图标的上限值
local maxIcon = 9
local mapCtrl = "MapCtrl"
local effectPath = "c_xy_0012_skeff_slidesk_ballistic"
-- 当前关卡地图编号
local m_curMapId = 1011
local m_orginLayer = 0
local m_parent
this.isClose = false
--root FightPointPassMainPanel.gameObject FightPointPassMainPanel脚本
function this:InitComponent(root, parent)
Log("初始化地图资源")
m_orginLayer = 0
m_parent = parent
-- 地图点击拖动
this.root = root
this.dragCtrl = Util.GetGameObject(root, "Bg/Ctrl")
this.effectRoot = Util.GetGameObject(root, "effectRoot")
this.buffTip = Util.GetGameObject(this.effectRoot, "money")
-- 箱子
this.boxEffect = Util.GetGameObject(root, "boxRoot/UI_effect_GuaJi_Box_BaoDian")
this.playerViews = {}
local str = ConfigManager.GetConfigData(ConfigName.SpecialConfig,111).Value
local strList = string.split(str,"#")
if strList and #strList > 0 then
local num = math.random(1,#strList)
FightPointPassManager.randomNum = num
end
end
function this:AddListener()
end
function this:RemoveListener()
end
function this:Init()
this.isClose = false
this.isCanUseIconList = 0
this.fightType= 0
local hangArr=ConfigManager.GetConfigData(ConfigName.MainLevelConfig, FightPointPassManager.curOpenFight).Hang
if hangArr then
this.fightType=hangArr[1]
end
-- 初始化加载地图块数据
this:LoadMapData()
-- 加载一个小人
local tempconfig = ConfigManager.GetConfigData(ConfigName.ChallengeMapConfig,m_curMapId)
if not this.playerViews[0] then
--Log(m_curMapId)
if ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.guajigongneng) then
iconNum = 20
local randomNum = 0--math.random(2,3)
PlayerManager.GetFightMapPlayerNPCData(randomNum,function(NPCList)
if this.isClose then
return
end
--Log("NPCList:"..LengthOfTable(NPCList))
local index = 1
local area = monsterArea[m_curMapId]
local suv = startUV[m_curMapId]
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[index] = SubUIManager.Open(SubUIConfig.SingleFightPlayerView,this.mapRoot.transform,this)
this.playerViews[index]:SetData((index3 == 1 and index1 or index2),index4,false,v)
index = index + 1
end
end)
else
iconNum = 4
end
this.playerViews[0] = SubUIManager.Open(SubUIConfig.SingleFightPlayerView,this.mapRoot.transform,this)
this.playerViews[0]:SetData(startUV[m_curMapId].u,startUV[m_curMapId].v,true)
end
-- 设置相机初始化位置
local v4 = this.playerViews[0].transform.localPosition
v4.z = -50
TileMapView.SetCameraPos(v4)
-- 初始化两个地图标志
this.LoadMapIcon()
if this.fightType~=2 then
this.SetPlayerViewWalk()
else
m_parent.PlayWeiAnim()
this.startTimer2 = Timer.New(function ()
m_parent:PlayerKillAllSkill()
end,7)
this.startTimer2:Start()
end
-- for k, v in pairs(this.iconList) do
-- v.RunTargetPos(startUV[m_curMapId].u,startUV[m_curMapId].v)
-- end
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
local curChapter = FightPointPassManager.GetCurChapterIndex()
local index = 1
index = math.floor((curChapter - 1) % 5 + 1)
-- --Log(curChapter)
-- --Log(index)
m_curMapId = mapIdList[index]
-- LogPink("#mapIdList:"..#mapIdList.." m_curMapId:"..m_curMapId.." curChapter:"..curChapter.." index:"..index.." State:"..tostring(FightPointPassManager.isOpenNewChapter))
TileMapView.AwakeInit(this.mapRoot, m_curMapId, nil, Vector2.New(180, 180))
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)
-- 挂机特效
this.moneyEffect = poolManager:LoadAsset(effectPath, PoolManager.AssetType.GameObject)
this.moneyEffect.transform:SetParent(this.effectRoot.transform)
this.moneyEffect.transform.localScale = Vector3.one
this.moneyEffect.transform.localPosition = Vector3.New(0, 0, 0)
this.moneyEffect:SetActive(false)
Util.AddParticleSortLayer(this.moneyEffect, m_parent.sortingOrder - m_orginLayer)
Util.AddParticleSortLayer(this.boxEffect, m_parent.sortingOrder - m_orginLayer)
m_orginLayer = m_parent.sortingOrder
this.boxEffect:SetActive(false)
end
--加载图标icon
function this.LoadMapIcon()
this.iconList = {}
this.selectIconList = {}
--FightPointPassManager.isBeginFight = false
for i = 1, iconNum do
this.LoadPointIcon(false)
end
end
function this.SetPlayerViewWalk()
if this.startTimer then
this.startTimer:Stop()
this.startTimer = nil
end
this.startTimer = Timer.New(function ()
for k,v in pairs(this.playerViews) do
v:SetRoleHitTarget()
end
end,1.5)
this.startTimer:Start()
end
this.isCanUseIconList = 0
function this.RequestIconList()
--Log(" this.isCanUseIconList:".. tostring(this.isCanUseIconList))
if this.isCanUseIconList == 0 then
this.isCanUseIconList = 1
--Log(" this.iconList:".. tostring(this.iconList))
return this.iconList
end
return nil
end
function this.ReleaseIconList()
this.isCanUseIconList = 0
end
function this.AsideTriggerJudge(data,isSelf,_userData)
--Log("data:"..tostring(data).." pos:"..tostring(Map_UV2Pos(data.u - 1, data.v).. " isSelf:"..tostring(isSelf).. " Self:"..tostring(_userData).. " Self:".." "..tostring(_userData.userId)))
local isGetIconList = false
local iconList = this.iconList
if not this.threads then
this.threads = {}
end
if this.threads[_userData.userId] then
coroutine.stop(this.threads[_userData.userId])
this.threads[_userData.userId] = nil
end
this.threads[_userData.userId] = coroutine.start(function()
while(not isGetIconList) do
if this.isClose and this.isClose == true then
coroutine.stop(this.threads[_userData.userId])
this.threads[_userData.userId] = nil
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))
if iconList[pos] and this.HasSelectIconList(pos,_userData.userId) then
this.RemoveSelectIconList(_userData.eventPointPos)
this.AddSelectIconList(pos,_userData.userId)
--Log("发送了消息")
Game.GlobalEvent:DispatchEvent(GameEvent.GuaJi.getEvent,{goData = _userData, event = iconList[pos], pos = pos})
coroutine.stop(this.threads[_userData.userId])
this.threads[_userData.userId] = nil
this.ReleaseIconList()
coroutine.yield()
elseif FightPointPassManager.talkingTime == 0 or (GetTimeStamp() - FightPointPassManager.talkingTime >= 60) then
if isSelf and this.playerViews and LengthOfTable(this.playerViews) > 1 then
for k,v in pairs(this.playerViews) do
if not v.isSelf and Map_UV2Pos(v.roleCurPos.u, v.roleCurPos.v) == pos and v.state == 0 then
FightPointPassManager.talkingTime = GetTimeStamp()
--Log("发送了消息")
Game.GlobalEvent:DispatchEvent(GameEvent.GuaJi.getEvent,{goData = _userData,event = v,pos = pos})
coroutine.stop(this.threads[_userData.userId])
this.threads[_userData.userId] = nil
this.ReleaseIconList()
coroutine.yield()
end
end
end
end
end
--Log("周围没有事件")
if this.threads[_userData.userId] then
coroutine.stop( this.threads[_userData.userId])
this.threads[_userData.userId] = nil
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
-- 随机一个坐标
local area = monsterArea[m_curMapId]
--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) or mapPointId==5 or mapPointId==7 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)
if this.fightType==2 then
pointView:RunTargetPos(startUV[m_curMapId].u,startUV[m_curMapId].v)
end
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
end
end
end
---------------------------------------------------------------------------------------------设置特效层级
function this:OnSortingOrderChange(orginLayer)
if this.moneyEffect and this.boxEffect then
Util.AddParticleSortLayer(this.moneyEffect, m_parent.sortingOrder - m_orginLayer)
Util.AddParticleSortLayer(this.boxEffect, m_parent.sortingOrder - m_orginLayer)
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)
local str = ConfigManager.GetConfigData(ConfigName.SpecialConfig,111).Value
local strList = string.split(str,"#")
if strList and #strList > 0 then
local num = math.random(1,#strList)
FightPointPassManager.randomNum = num
end
m_parent.RefreshFightBtnShow()
end
----全部小怪死亡
function this.AllBattleEnd()
for k, v in pairs(this.iconList) do
this.BattleEnd(k)
end
this.fightType=0
this.LoadMapIcon()
this.SetPlayerViewWalk()
if this.startTimer2 then
this.startTimer2:Stop()
end
this.startTimer2 = nil
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()
-- Log("关闭挂机OnClose")
if this.startTimer then
this.startTimer:Stop()
end
this.startTimer = nil
if this.startTimer2 then
this.startTimer2:Stop()
end
this.startTimer2 = nil
this.StopAction()
this.OnGameOver()
end
function this:Dispose()
if this.startTimer then
this.startTimer:Stop()
end
this.startTimer = nil
if this.startTimer2 then
this.startTimer2:Stop()
end
this.startTimer2 = nil
this.StopAction()
this.OnGameOver()
end
return this