miduo_client/Assets/ManagedResources/~Lua/Modules/Map/TrialMapPanel.lua

403 lines
13 KiB
Lua

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
function TrialMapPanel:InitComponent(root, mapPanel)
Log("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.mapTime = Util.GetGameObject(root, "leftDown/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")
end
function TrialMapPanel:BindEvent()
Util.AddClick(this.btnBomb, function ()
if bombNum > 0 then
if MapTrialManager.isHaveBoss then
PopupTipPanel.ShowTip("已经召唤了首领!")
return
else
UIManager.OpenPanel(UIName.TrialOpPanel, 2)
-- 停止自动寻路
ctrlView.OnRoleDead()
end
else
PopupTipPanel.ShowTip("当前没有炸弹!")
end
end)
-- 打开补给点
Util.AddClick(this.buffShop, function()
-- 判断是否有保存的补给点
local buffList = MapTrialManager.GetBuffList()
if not buffList or #buffList <= 0 then
PopupTipPanel.ShowTip("没有保存的补给点")
return
end
UIManager.OpenPanel(UIName.BuffChoosePanel)
end)
-- 打开商店
Util.AddClick(this.normalShop, function()
if not ShopManager.IsActive(SHOP_TYPE.TRIAL_SHOP) then
PopupTipPanel.ShowTip("尚未发现试炼商店")
return
end
UIManager.OpenPanel(UIName.MapShopPanel, SHOP_TYPE.TRIAL_SHOP)
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)
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)
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.InitTrialMission()
this.UpdatePowerValue()
this.UpdateDeadTimes()
this.RefreshBombNum()
this.InitShopInfo()
this.InitBuffInfo()
this.InitBossInfo()
this.powerRoot:SetActive(istrialMap)
this.InitEffect()
this.InitTip()
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("试炼副本第一次进图!")
-- 月卡蛋蛋福利
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()
this.levelNum.text = string.format("试炼副本%s层", MapTrialManager.curTowerLevel)
Log("试炼精气 >>>>>>>>>>>>>>>>>>>> " .. MapTrialManager.powerValue)
powerValue = MapTrialManager.powerValue
this.SetTargetState(powerValue)
powerValue = powerValue <= 0 and 0 or powerValue
powerValue = powerValue >= 100 and 100 or powerValue
--Log("更新数值")
this.powerPercent.text = powerValue
this.sliderValue.fillAmount = powerValue / 100
if powerValue >= 100 then
-- 停止自动寻路
ctrlView.OnRoleDead()
UIManager.OpenPanel(UIName.TrialOpPanel, 1)
end
end
function this.PlayEffect()
--Log("击杀小怪!")
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
function this.InitBossInfo()
if powerValue >= 100 then
UIManager.OpenPanel(UIName.TrialOpPanel, 1)
-- 停止自动寻路
ctrlView.OnRoleDead()
end
end
-- 初始化部buff显示
function this.InitBuffInfo()
if CarbonManager.difficulty ~= 2 then return end
-- 补给点数量显示
local num = 0
local buffList = 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 = "00:00"
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.GetTempBagCountById(43) == 0 or not BagManager.GetTempBagCountById(43) then
bombNum = 0
else
bombNum = BagManager.GetTempBagCountById(43)
end
this.bombNum.text = bombNum
end
-- 设置目标
function this.SetTargetState(value)
local showStr = ""
if value == -1 then
showStr = "击败地图首领!"
else
showStr = "击败所有小怪!"
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("服务器返回消息")
local showStr = "试炼副本" .. MapTrialManager.curTowerLevel ..""
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.OnMissionTimeChange(time)
if CarbonManager.difficulty == 2 then this.TrialShowTime(time) end
end
-- 试炼副本显示时间
function this.TrialShowTime(time)
if MapTrialManager.IsFinalLevel and MapTrialManager.bossDeadTime ~= 0 then
time = MapTrialManager.bossDeadTime
end
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.OnRoleDead()
if CarbonManager.difficulty ~= 2 then return end
this.UpdateDeadTimes()
end
--
function this.UpdateDeadTimes()
local limitDeadTimes = MapTrialManager.GetRelifeTimes()
Log("MapManager.deadCount == " .. MapManager.deadCount)
local leftLife = limitDeadTimes - MapManager.deadCount
leftLife = leftLife < 0 and 0 or leftLife
MapTrialManager.leftLife = leftLife
this.leftLife.text = leftLife
-- 在试炼副本死亡太多直接出图
if CarbonManager.difficulty == 2 then
if MapTrialManager.GetRelifeTimes() - MapManager.deadCount < 0 then -- 次数用完出图
UIManager.OpenPanel(UIName.MapStatsPanel)
end
end
end
--界面关闭时调用(用于子类重写)
function TrialMapPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function TrialMapPanel:OnDestroy()
end
return TrialMapPanel