miduo_client/Assets/ManagedResources/~Lua/Modules/Battle/View/BattlePanel.lua

666 lines
24 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/BasePanel")
require("Base/Stack")
require("Modules.Battle.Config.PokemonEffectConfig")
local BattleView = require("Modules/Battle/View/BattleView")
BattlePanel = Inherit(BasePanel)
local this = BattlePanel
local battleTimeScaleKey = "battleTimeScaleKey"
local timeCount
local endFunc
local levelId
local isTestFight = false
local isBack = false --是否为战斗回放
local fightType -- 1关卡 2副本 3限时怪, 5兽潮, 6新关卡, 7公会boss
local orginLayer
-- 显示跳过战斗使用
local hadCounted = 0
--初始化组件(用于子类重写)
function this:InitComponent()
BattleView:InitComponent(self)
orginLayer = 0
this.UpRoot = Util.GetGameObject(self.gameObject, "UpRoot")
this.Option = Util.GetGameObject(this.UpRoot, "option")
this.DownRoot = Util.GetGameObject(self.gameObject, "DownRoot")
this.roundText = Util.GetGameObject(this.Option, "timeCount"):GetComponent("Text")
this.orderText = Util.GetGameObject(this.Option, "order/text"):GetComponent("Text")
this.BtnTimeScale = Util.GetGameObject(this.DownRoot, "option/BtnTimeScale")
this.BtnExit = Util.GetGameObject(this.DownRoot, "option/BtnExit")
this.BtnGM = Util.GetGameObject(this.DownRoot, "option/Button")
this.BtnJump = Util.GetGameObject(this.DownRoot, "option/BtnJump")
this.DefResult = Util.GetGameObject(this.UpRoot, "result")
this.AtkResult = Util.GetGameObject(this.DownRoot, "result")
this.Win = Util.GetGameObject(this.gameObject, "Win")
this.Lose = Util.GetGameObject(this.gameObject, "Lose")
this.damagePanel = Util.GetGameObject(this.UpRoot, "damage")
this.damageBoxBg = Util.GetGameObject(this.damagePanel, "bg")
this.damageBoxIcon = Util.GetGameObject(this.damagePanel, "bg/iconRoot/icon"):GetComponent("Image")
this.damageBoxLevel = Util.GetGameObject(this.damagePanel, "lv"):GetComponent("Text")
this.damageProgress = Util.GetGameObject(this.damagePanel, "progress/Fill")
this.damageText = Util.GetGameObject(this.damagePanel, "progress/Text"):GetComponent("Text")
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.BtnTimeScale, function ()
if not BattleManager.IsBattlePlaying() then
return
end
if not BattleManager.IsUnlockBattleSpeed() then
PopupTipPanel.ShowTip(PrivilegeManager.GetPrivilegeOpenTip(PRIVILEGE_TYPE.DoubleTimesFight))
return
end
local scale = BattleManager.GetTimeScale()
scale = math.floor(scale*10 + 0.5)/10
if scale == BATTLE_TIME_SCALE_ONE then
BattleManager.SetTimeScale(BATTLE_TIME_SCALE_TWO)
elseif scale == BATTLE_TIME_SCALE_TWO then
BattleManager.SetTimeScale(BATTLE_TIME_SCALE_ONE)
end
end)
local pauseTime = 31
Util.AddClick(this.BtnExit, function ()
if not BattleManager.IsUnlockBattlePass() then
PopupTipPanel.ShowTip(PrivilegeManager.GetPrivilegeOpenTip(isBack and PRIVILEGE_TYPE.SkipFight or PRIVILEGE_TYPE.ExitFight ))
return
end
if BattleLogic.IsEnd or not BattleManager.IsBattlePlaying() then
return
end
-- 战斗暂停
BattleManager.PauseBattle()
local count = 0
local timer = Timer.New(function ()
if not UIManager.IsOpen(UIName.MsgPanel) then
return
end
count = count + 1
if isBack then
MsgPanel.tipLabel.text = string.format("确认跳过战斗吗(%d秒)", pauseTime - count)
else
MsgPanel.tipLabel.text = string.format("战斗已暂停,是否继续?(%d秒)", pauseTime - count)
end
if count == pauseTime then
MsgPanel.OnRightBtnClick()
return
end
end, 1, pauseTime, true)
local cancelFunc = function ()
this.CastingPass = MsgPanel._toggle.isOn
BattleManager.ResumeBattle()
timer:Stop()
end
local sureFunc = function()
this.CastingPass = MsgPanel._toggle.isOn
BattleLogic.IsEnd = true
BattleView.Clear()
timer:Stop()
-- 事先初始化
this.lastBattleResult = {
result = 0,
lastPos = 0,
}
if isBack then --战斗回放直接跳过
local strs = string.split(levelId, "#")
BattleView.EndBattle(tonumber(strs[2]))
return
end
if fightType == 2 then
-- 必输的操作
NetManager.MapFightResultRequest(1, "", levelId, fightType, function (msg)
this.lastBattleResult.result = msg.result
if msg.lastXY then
this.lastBattleResult.lastPos = msg.lastXY
else
this.lastBattleResult.lastPos = 0
end
this.ShowBattleResult(msg.result)
end)
elseif fightType == 7 or fightType == 10 then
this.lastBattleResult.result = -1
this:ClosePanel()
else
this.ShowBattleResult(0)
end
end
MsgPanel.ShowTwo("战斗已暂停,是否继续?", sureFunc, cancelFunc, "退出", "继续",nil, false, "关闭技能动画")
MsgPanel._toggle.isOn = this.CastingPass
timer:Start()
end)
Util.AddClick(this.Win, function ()
if (isTestFight and GuideManager.IsFirstBattle()) or isBack then
this:ClosePanel()
return
end
if fightType == 1 then --关卡战斗结算
FightManager.BattleEndCallBack(this.lastBattleResult)
UIManager.OpenPanel(UIName.RewardItemPopup,this.lastBattleResult.drop, 1,function() this:ClosePanel() end, 1, true)
elseif fightType == 2 then --副本战斗结算
--UIManager.OpenPanel(UIName.RewardItemPopup, this.lastBattleResult.drop, 2, function()
-- UIManager.OpenPanel(UIName.BattleEndPanel, this, this.lastBattleResult.hpList, this.lastBattleResult.drop, nil, true)
--end)
elseif fightType == 3 then --限时怪战斗结算
UIManager.OpenPanel(UIName.RewardItemPopup,this.lastBattleResult.drop, 1,function() this:ClosePanel() end, 1, true)
elseif fightType == 5 then -- 兽潮来袭
--UIManager.OpenPanel(UIName.RewardItemPopup,this.lastBattleResult.drop, 1,function() this:ClosePanel() end, nil, true)
elseif fightType == 6 then -- 新关卡的战斗
--FightPointPassManager.OnBattleEnd(this.lastBattleResult)
--UIManager.OpenPanel(UIName.RewardItemPopup,this.lastBattleResult.drop, 1,function() this:ClosePanel() end, 1, true)
elseif fightType == 7 then -- 工会boss结算界面
elseif fightType == 8 then -- 远征
-- UIManager.OpenPanel(UIName.RewardItemPopup,this.lastBattleResult.drop, 1,function()
-- UIManager.OpenPanel(UIName.ExpeditionSelectHalidomPanel,function ()
-- this:ClosePanel()
-- end)
--end, 1, true)
end
end)
Util.AddClick(this.Lose, function ()
this:ClosePanel()
end)
--Util.AddClick(Util.GetGameObject(this.Lose, "tip/jieling"), function ()
-- FightManager.curIsInFightArea = 0
-- this:LoseJump(29001)
--end)
Util.AddClick(Util.GetGameObject(this.Lose, "tip/zhaomu"), function ()
FightManager.curIsInFightArea = 0
this:LoseJump(1001)
end)
Util.AddClick(Util.GetGameObject(this.Lose, "tip/chengyuan"), function ()
FightManager.curIsInFightArea = 0
this:LoseJump(22001)
end)
Util.AddClick(Util.GetGameObject(this.Lose, "record"), function ()
UIManager.OpenPanel(UIName.DamageResultPanel, 0)
end)
Util.AddClick(this.BtnGM, function ()
if BattleManager.IsBattlePlaying() and not BattleLogic.IsEnd then
BattleView.EndBattle(1)
BattleLogic.IsEnd = true
end
end)
Util.AddClick(this.BtnJump, function ()
if BattleManager.IsBattlePlaying() and not BattleLogic.IsEnd then
BattleView.EndBattle(1)
BattleLogic.IsEnd = true
end
end)
end
function this:LoseJump(id)
if not MapManager.isInMap then
if JumpManager.CheckJump(id) then
this:ClosePanel()
JumpManager.GoJumpWithoutTip(id)
end
else
PopupTipPanel.ShowTip("副本里不能前往!")
end
end
--添加事件监听(用于子类重写)
function this:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Battle.OnTimeScaleChanged, this.SwitchTimeScale)
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Battle.OnTimeScaleChanged, this.SwitchTimeScale)
end
--获取战斗类型
function this.GetFightType()
if not levelId then
return 2
end
if type(levelId) == "number" then
return 6
end
if levelId == "limit" then
return 3
end
if levelId == "monster" then
return 5
end
if levelId == "GuildBoss" then
return 7
end
if levelId == "execute" then
return 8
end
if levelId == "DailyChallenge" then--日常副本
return 9
end
if levelId == "guildcardelay" then--日常副本
return 10
end
if levelId == "DeathPos" then
return 11
end
return 0
end
function this:OnSortingOrderChange()
Util.AddParticleSortLayer(this.gameObject, this.sortingOrder - orginLayer)
orginLayer = this.sortingOrder
end
--界面打开时调用(用于子类重写)
function this:OnOpen(_fightData, _seed, _fightType, _maxTime, _levelId, _monsterGroupId, _endFunc)
BattleView:OnOpen(_fightData, _seed, _fightType, _maxTime)
levelId = _levelId -- nil 副本战斗 / "back#0" 战斗回放 / 数字 关卡id / "limit" 限时怪 / "
endFunc = _endFunc
timeCount = _maxTime or 300
isBack = levelId and string.find(levelId,"back#") ~= nil --判定是否是战斗回放
fightType = this.GetFightType() --判定战斗类型
hadCounted = 0
if not _seed or levelId == "test" then
isTestFight = true
else
isTestFight = false
end
this.Win:SetActive(false)
this.Lose:SetActive(false)
this.BtnGM:SetActive(AppConst.isOpenGM)
this.BtnJump:SetActive(false)
this.BtnExit:SetActive(FightPointPassManager.GetStopBtnState())
SoundManager.PlayMusic(SoundConfig.BGM_Battle_1, true, function()
SoundManager.PlayMusic(SoundConfig.BGM_Battle_2, false)
end)
-- 如果是回放,判断是否需要显示名字
if isBack then
local data = string.split(_levelId, "#")
local result = tonumber(data[2])
this.nameStr = data[3]
if this.nameStr then
local nameList = string.split(this.nameStr, "|")
BattleView:SetNameStr(this.nameStr)
this.DefResult:SetActive(true)
this.AtkResult:SetActive(true)
Util.GetGameObject(this.AtkResult, "win"):SetActive(result == 1)
Util.GetGameObject(this.AtkResult, "lose"):SetActive(result == 0)
Util.GetGameObject(this.DefResult, "win"):SetActive(result == 0)
Util.GetGameObject(this.DefResult, "lose"):SetActive(result == 1)
Util.GetGameObject(this.AtkResult, "win/Text"):GetComponent("Text").text = nameList[1]
Util.GetGameObject(this.AtkResult, "lose/Text"):GetComponent("Text").text = nameList[1]
Util.GetGameObject(this.DefResult, "win/Text"):GetComponent("Text").text = nameList[2]
Util.GetGameObject(this.DefResult, "lose/Text"):GetComponent("Text").text = nameList[2]
else
this.DefResult:SetActive(false)
this.AtkResult:SetActive(false)
end
else
this.DefResult:SetActive(false)
this.AtkResult:SetActive(false)
end
-- 开始战斗
BattleView:StartBattle()
this.InitPanelData()
end
-- 初始化
function this.InitPanelData()
--this.damagePanel:SetActive(fightType == 7 or fightType == 10)
if fightType == 7 and fightType == 10 then
this.myDamage = 0
this.myDamageLevel = 0
this.RefreshMyDamageShow()
local list = RoleManager.Query(function (r) return r.camp == 1 end)
if list[1] then
list[1].Event:AddEvent(BattleEventName.RoleBeDamaged, function (atkRole, damage, bCrit, finalDmg, damageType, dotType)
--Log("damage:"..damage)
this.myDamage = this.myDamage + damage
this.RefreshMyDamageShow()
end)
end
end
this.InitOption()
end
function this.InitOption()
--显示倒计时
local curRound, maxRound = BattleLogic.GetCurRound()
this.roundText.text = string.format("第%d/%d回合", curRound, maxRound)
hadCounted = 0
if GuideManager.IsFirstBattle() then --新手战战斗特殊处理,不准切手动
this.Option:SetActive(false)
else
this.Option:SetActive(true)
end
Util.GetGameObject(this.BtnTimeScale, "lock"):SetActive(not BattleManager.IsUnlockBattleSpeed())
Util.GetGameObject(this.BtnExit, "lock"):SetActive(not BattleManager.IsUnlockBattlePass())
-- 初始化战斗时间,刷新前端显示
BattleManager.InitTimeScale()
this.SwitchTimeScale()
end
function this.SwitchTimeScale()
local _scale = BattleManager.GetTimeScale()
local child = this.BtnTimeScale.transform.childCount - 3 -- 3倍速时-2
local s = "x".. math.floor(_scale)
for i=1, child do
local g = this.BtnTimeScale.transform:GetChild(i-1).gameObject
g:SetActive(g.name == s)
end
end
function this.BattleEnd(result)
BattleManager.PauseBattle()
--用一个变量接收最近的战斗结果
this.lastBattleResult = {
result = result,
hpList = {},
drop = {},
}
if BattleLogic.IsOpenBattleRecord then
BattleManager.GenerateRecordFile()
end
if isBack then
this.ShowBattleResult(result)
return
end
if isTestFight then
this.ShowBattleResult(GuideManager.IsFirstBattle() and 1 or 0)
return
end
if fightType == 9 then
this.ShowBattleResult(result)
return
end
if fightType == 10 then
this.ShowBattleResult(result)
return
end
if fightType == 11 then
this.ShowBattleResult(result)
return
end
if fightType == 8 then--远征处理
local GetCurNodeInfo = ExpeditionManager.GetCurNodeInfo()
Log("GetCurNodeInfo.sortId "..GetCurNodeInfo.sortId)
NetManager.EndExpeditionBattleRequest(GetCurNodeInfo.sortId, "", function (msg)
this.lastBattleResult.result = msg.result
this.lastBattleResult.drop = msg.drop
--ExpeditionManager.UpdateHeroHpValue(msg.heroInfo)
--ExpeditionManager.UpdateNodeValue(msg) --nodeInfo
this.ShowBattleResult(msg.result, msg)
end)
else
NetManager.MapFightResultRequest(10000, "", levelId, fightType, function (msg)
for i=1, #msg.remainHpList do
Log("服务器剩余血量 : "..msg.remainHpList[i])
this.lastBattleResult.hpList[i] = msg.remainHpList[i]
end
this.lastBattleResult.drop = msg.enventDrop
this.lastBattleResult.missionDrop = msg.missionDrop
this.lastBattleResult.result = msg.result
this.lastBattleResult.mission = msg.mission
this.lastBattleResult.eventId = msg.eventId
this.lastBattleResult.lastTowerTime = msg.lastTowerTime
if msg.lastXY then
this.lastBattleResult.lastPos = msg.lastXY
else
this.lastBattleResult.lastPos = 0
end
this.ShowBattleResult(msg.result, msg)
end)
end
end
function this.ShowBattleResult(result, msg)
SoundManager.StopMusic()
-- 战斗结束时,如果元素光环面板还开着,则先关闭
if UIManager.IsOpen(UIName.ElementPopup) then
UIManager.ClosePanel(UIName.ElementPopup)
end
-- tbRoleDispose = {} --战斗统计前将roleView收集到该容器中tbRole清理掉
-- for _, v in pairs(tbRole) do
-- table.insert(tbRoleDispose, v)
-- end
-- tbRole = {}
if isBack and string.split(levelId, "#")[3] then --战斗回放显示双方信息时,因为结果是相对的,所以直接关闭结算界面
this:ClosePanel()
else
local panelType = 0
if result == 0 then
panelType = 0
this.resultSoundAudio = SoundManager.PlaySound(SoundConfig.Sound_BattleLose)
-- 判断是否显示记录按钮
local haveRecord = BattleRecordManager.isHaveRecord()
Util.GetGameObject(this.Lose, "record"):SetActive(haveRecord)
else
panelType = 1
this.resultSoundAudio = SoundManager.PlaySound(SoundConfig.Sound_BattleWin)
end
if fightType == 7 then
-- 公会boss结算界面
UIManager.OpenPanel(UIName.GuildBossFightResultPopup, msg.enventDrop, msg.missionDrop, msg.essenceValue, function()
this:ClosePanel()
end)
elseif fightType == 10 then
PopupTipPanel.ShowTip("获得积分: "..GuildCarDelayManager.score.." 伤害: "..GuildCarDelayManager.hurt)
this:ClosePanel()
--UIManager.OpenPanel(UIName.GuildBossFightResultPopup, msg.enventDrop, msg.missionDrop, msg.essenceValue, function()
-- this:ClosePanel()
--end)
elseif fightType == 11 then
PopupTipPanel.ShowTip("获得积分: ")
this:ClosePanel()
else
if panelType == 0 then -- 失败
local haveRecord = BattleRecordManager.isHaveRecord()
UIManager.OpenPanel(UIName.BattleFailPopup, this, haveRecord)
else -- 胜利
UIManager.OpenPanel(UIName.BattleWinPopup, this, isTestFight, isBack, fightType, this.lastBattleResult)
end
end
end
end
-- 战斗波次变化回调
function this.OnOrderChanged(order)
-- body
--显示波次
this.orderText.text = string.format("%d/%d", order, BattleLogic.TotalOrder)
end
-- 战斗回合变化回调
function this.OnRoundChanged(round)
-- body
--显示波次
local curRound, maxRound = BattleLogic.GetCurRound()
this.roundText.text = string.format("第%d/%d回合", curRound, maxRound)
-- TODO: 之前关卡N秒后会出现跳过按钮的功能
-- hadCounted = hadCounted + 1
-- if FightPointPassManager.enterFightBattle then
-- this.BtnJump:SetActive(hadCounted >= FightPointPassManager.ShowBtnJumpTime)
-- end
end
-- 由BattleView驱动
function this.OnUpdate()
end
-- 刷新我的伤害显示
function this.RefreshMyDamageShow()
if fightType == 7 or fightType == 10 then
local myDamage = this.myDamage-- *10
local bossRewardConfig = ConfigManager.GetConfig(ConfigName.GuildBossRewardConfig)
local curLevel, curLevelData, nextLevelData
for level, data in ConfigPairs(bossRewardConfig) do
if data.Damage > myDamage then
nextLevelData = data
break
end
curLevel = level
curLevelData = data
end
if not nextLevelData then
nextLevelData = curLevelData
end
-- 有等级变化
if curLevel ~= this.myDamageLevel then
this.myDamageLevel = curLevel
-- 播放升级特效
this.damageBoxBg:SetActive(false)
this.damageBoxBg:SetActive(true)
end
this.damageBoxLevel.text = curLevel or 0
this.damageBoxIcon.sprite = GuildBossManager.GetBoxSpriteByLevel(curLevel or 0)
-- this.damageText.text = myDamage.."/"..nextLevelData.Damage -- 显示总伤害
local curLevelDamage = not curLevelData and 0 or curLevelData.Damage
local deltaDamage = nextLevelData.Damage - curLevelDamage
local myDeltaDamage = myDamage - curLevelDamage
local rate = deltaDamage == 0 and 1 or myDeltaDamage/deltaDamage
this.damageText.text = myDeltaDamage.."/"..deltaDamage -- 显示当前等级伤害
this.damageProgress.transform.localScale = Vector3.New(rate, 1, 1)
end
end
--新手战专用
function this:InitNewEvent()
local event
event = function(roleView) --开战前对话
Game.GlobalEvent:RemoveEvent(GameEvent.Guide.GuideBattleStart, event)
BattleManager.PauseBattle()
StoryManager.DialogueTrigger(138012, function()
BattleManager.ResumeBattle()
end)
event = function(order) --第一波战斗结束时对话
if order == 1 then
BattleLogic.Event:RemoveEvent(BattleEventName.BattleOrderEnd, event)
BattleManager.PauseBattle()
StoryManager.DialogueTrigger(138014, function()
BattleManager.ResumeBattle()
end)
event = function(roleView) --敖丙放技能前对话
if roleView.role.uid == 1 then
Game.GlobalEvent:RemoveEvent(GameEvent.Guide.GuideBattleCDDone, event)
BattleManager.PauseBattle()
StoryManager.DialogueTrigger(138016, function()
BattleManager.ResumeBattle()
end)
event = function(roleView) --哪吒放技能前对话
if roleView.role.uid == 4 then
Game.GlobalEvent:RemoveEvent(GameEvent.Guide.GuideBattleCDDone, event)
BattleManager.PauseBattle()
StoryManager.DialogueTrigger(138017, function()
BattleManager.ResumeBattle()
end)
event = function(result) --战斗结算前对话
BattleLogic.Event:RemoveEvent(BattleEventName.BattleEnd, event)
Timer.New(function ()
StoryManager.DialogueTrigger(138025, function() this.BattleEnd(result) end)
end, 1):Start()
end
BattleLogic.Event:RemoveEvent(BattleEventName.BattleEnd, this.BattleEnd)
BattleLogic.Event:AddEvent(BattleEventName.BattleEnd, event)
end
end
Game.GlobalEvent:AddEvent(GameEvent.Guide.GuideBattleCDDone, event)
end
end
Game.GlobalEvent:AddEvent(GameEvent.Guide.GuideBattleCDDone, event)
end
end
BattleLogic.Event:AddEvent(BattleEventName.BattleOrderEnd, event)
end
Game.GlobalEvent:AddEvent(GameEvent.Guide.GuideBattleStart, event)
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
BattleView:OnClose()
-- 停止音效
--if this.resultSoundAudio then
-- SoundManager.StopSound(this.resultSoundAudio)
--end
--
BattleManager.SetTimeScale(1)
if endFunc then
endFunc(this.lastBattleResult)
end
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
BattleView:OnDestroy()
end
return BattlePanel