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

529 lines
19 KiB
Lua

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 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.BG = Util.GetGameObject(self.gameObject, "BG")
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.ButtonLock = Util.GetGameObject(this.DownRoot, "option/Button/lock")
this.BtnGM = Util.GetGameObject(this.DownRoot, "option/Button")
this.submit = Util.GetGameObject(this.DownRoot, "bg")
this.DefResult = Util.GetGameObject(this.UpRoot, "result")
this.AtkResult = Util.GetGameObject(this.DownRoot, "result")
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.AddLongPressClick(this.submit, function()
BattleRecordManager.SubmitBattleRecord()
end, 0.5)
Util.AddClick(this.BtnTimeScale, function ()
if not BattleManager.IsCanOperate() 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)
Util.AddClick(this.ButtonLock, function ()
PopupTipPanel.ShowTip(Language[12246])
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.IsCanOperate() 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(Language[10255], pauseTime - count)
else
MsgPanel.tipLabel.text = string.format(Language[10256], 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 --战斗回放直接跳过
if not this.fightResult then
LogError(Language[10257])
end
BattleView.EndBattle(this.fightResult or 0)
return
end
if fightType == BATTLE_TYPE.MAP_FIGHT then
-- 必输的操作
NetManager.MapFightResultRequest(1, "", "", 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 == BATTLE_TYPE.GUILD_BOSS and fightType == BATTLE_TYPE.GUILD_CAR_DELAY then
this.lastBattleResult.result = -1
this:ClosePanel()
else
this.ShowBattleResult(0)
end
end
MsgPanel.ShowTwo(Language[10258], sureFunc, cancelFunc, Language[10259], Language[10260],nil, false, Language[10261])
MsgPanel._toggle.isOn = this.CastingPass
timer:Start()
end)
Util.AddClick(this.BtnGM, function ()
if BattleManager.IsCanOperate() and not BattleLogic.IsEnd then
BattleView.EndBattle()
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(Language[10250])
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:OnSortingOrderChange()
Util.AddParticleSortLayer(this.gameObject, this.sortingOrder - orginLayer)
orginLayer = this.sortingOrder
BattleView:OnSortingOrderChange(this.sortingOrder)
end
--界面打开时调用(用于子类重写)
function this:OnOpen(_fightData, _fightType, _endFunc)
BattleView:OnOpen(_fightData)
endFunc = _endFunc
fightType = _fightType --判定战斗类型
isBack = _fightType == BATTLE_TYPE.BACK --判定是否是战斗回放
hadCounted = 0
-- LogPink(fightType)
this.BG:GetComponent("Image").sprite = Util.LoadSprite(BattleManager.GetBattleBg(fightType))
-- this.BtnGM:SetActive(AppConst.isOpenGM)
this.BtnExit:SetActive(false)--FightPointPassManager.GetStopBtnState())
SoundManager.PlayMusic(SoundConfig.BGM_Battle_1, true, function()
SoundManager.PlayMusic(SoundConfig.BGM_Battle_2, false)
end)
this.fightResult = nil
-- 清空名字数据
BattleView:SetNameStr(nil)
this.DefResult:SetActive(false)
this.AtkResult:SetActive(false)
-- 开始战斗
BattleView:StartBattle()
this.InitPanelData()
end
-- 设置战斗结果
function this:SetResult(result)
this.fightResult = result
end
-- 外部调用
function this:ShowNameShow(result, str)
if true then return end
this.fightResult = result
if str then
local nameList = string.split(str, "|")
BattleView:SetNameStr(str)
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
end
-- 初始化
function this.InitPanelData()
if fightType == BATTLE_TYPE.GUILD_BOSS and fightType == BATTLE_TYPE.GUILD_CAR_DELAY 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(Language[10252], curRound, maxRound)
hadCounted = 0
this.Option:SetActive(true)
Util.GetGameObject(this.BtnTimeScale, "lock"):SetActive(not BattleManager.IsUnlockBattleSpeed())
local IsUnLockBattlePass = BattleManager.IsUnlockBattlePass() or (fightType == BATTLE_TYPE.BACK)--or AppConst.isOpenGM
Util.GetGameObject(this.BtnExit, "lock"):SetActive(not IsUnLockBattlePass)
if AppConst.isOpenGM then
Util.GetGameObject(this.BtnGM, "lock"):SetActive(false)
else
Util.GetGameObject(this.BtnGM, "lock"):SetActive(not IsUnLockBattlePass)
this.BtnGM:GetComponent("Button").interactable = IsUnLockBattlePass
end
-- 初始化战斗时间,刷新前端显示
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()
-- 强制停止倍速
Time.timeScale = 1
-- 设置音效播放的速度
SoundManager.SetAudioSpeed(1)
--用一个变量接收最近的战斗结果
this.lastBattleResult = {
result = result,
hpList = {},
drop = {},
}
-- 需要和服务器确认结果
if fightType == BATTLE_TYPE.MAP_FIGHT
or fightType == BATTLE_TYPE.MONSTER_CAMP
or fightType == BATTLE_TYPE.STORY_FIGHT
or fightType == BATTLE_TYPE.GUILD_BOSS then
local levelId = FightPointPassManager.GetCurFightId()
NetManager.MapFightResultRequest(10000, "", levelId, fightType, function (msg)
for i=1, #msg.remainHpList do
Log(Language[10262]..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)
elseif fightType == BATTLE_TYPE.EXECUTE_FIGHT then--远征处理
if ExpeditionManager.ExpeditionState == 1 then
local GetCurNodeInfo = ExpeditionManager.curAttackNodeInfo
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
this:ClosePanel()
ExpeditionManager.RefreshPanelShowByState()
end
else
-- 直接显示结果
this.ShowBattleResult(result)
end
end
function this.ShowBattleResult(result, msg)
SoundManager.StopMusic()
-- 战斗结束时,如果元素光环面板还开着,则先关闭
if UIManager.IsOpen(UIName.ElementPopup) then
UIManager.ClosePanel(UIName.ElementPopup)
end
-- 回放直接关闭界面
if fightType == BATTLE_TYPE.BACK then
this:ClosePanel()
return
end
-- 播放结算音效
if result == 0 then
this.resultSoundAudio = SoundManager.PlaySound(SoundConfig.Sound_BattleLose)
else
this.resultSoundAudio = SoundManager.PlaySound(SoundConfig.Sound_BattleWin)
end
-- 公会boss结算界面
if fightType == BATTLE_TYPE.GUILD_BOSS then
UIManager.OpenPanel(UIName.GuildBossFightResultPopup, msg.enventDrop, msg.missionDrop, msg.essenceValue, function()
this:ClosePanel()
end)
-- 车迟斗法结算界面特殊显示
elseif fightType == BATTLE_TYPE.GUILD_CAR_DELAY and GuildCarDelayManager.progress == 1 then
-- 延时执行避免事件冲突
Timer.New(function()
local bestData, allDamage= BattleRecordManager.GetBattleBestData()
if bestData then
-- 胜利显示本场比赛的表现最好的英雄
UIManager.OpenPanel(UIName.BattleBestPopup, bestData.roleId, bestData.damage, allDamage, function(_BattleBestPopup)
-- 打开关卡奖励界面
UIManager.OpenPanel(UIName.RewardItemPopup,nil, 1,function()
--车迟挑战cd计时
GuildCarDelayManager.SetCdTime(GuildCarDelayProType.Challenge)
if _BattleBestPopup then
_BattleBestPopup:ClosePanel()
end
this:ClosePanel()
end, 3,true,true)
end)
end
end, 0.1):Start()
-- 十绝阵结算界面特殊显示
elseif fightType == BATTLE_TYPE.DEATH_POS then
-- 延时执行避免事件冲突
Timer.New(function()
local bestData, allDamage= BattleRecordManager.GetBattleBestData()
if bestData then
-- 胜利显示本场比赛的表现最好的英雄
UIManager.OpenPanel(UIName.BattleBestPopup, bestData.roleId, bestData.damage, allDamage, function(_BattleBestPopup)
-- 打开关卡奖励界面
UIManager.OpenPanel(UIName.RewardItemPopup, DeathPosManager.drop, 1,function()
if _BattleBestPopup then
_BattleBestPopup:ClosePanel()
end
this:ClosePanel()
end, 4,true,true)
end)
end
end, 0.1):Start()
else
if result == 0 then -- 失败
local haveRecord = BattleRecordManager.isHaveRecord()
UIManager.OpenPanel(UIName.BattleFailPopup, this, haveRecord,nil,fightType)
else -- 胜利
UIManager.OpenPanel(UIName.BattleWinPopup, this, isBack, fightType, this.lastBattleResult)
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(Language[10252], curRound, maxRound)
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:OnClose()
BattleView:OnClose()
-- 停止音效
--if this.resultSoundAudio then
-- SoundManager.StopSound(this.resultSoundAudio)
--end
--
-- BattleManager.SetTimeScale(1)
-- 真正生效的敌方
Time.timeScale = 1
-- 设置音效播放的速度
SoundManager.SetAudioSpeed(1)
if endFunc then
endFunc(this.lastBattleResult)
end
--检测是否需要弹每日任务飘窗
TaskManager.RefreshShowDailyMissionTipPanel()
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
BattleView:OnDestroy()
end
return BattlePanel