249 lines
		
	
	
		
			7.9 KiB
		
	
	
	
		
			Lua
		
	
			
		
		
	
	
			249 lines
		
	
	
		
			7.9 KiB
		
	
	
	
		
			Lua
		
	
require("Base/BasePanel")
 | 
						|
require("Base/Stack")
 | 
						|
require("Modules.Battle.Config.PokemonEffectConfig")
 | 
						|
local BattleView = require("Modules/Battle/View/BattleView")
 | 
						|
local GuideBattleLogic = require("Modules/Battle/View/GuideBattleLogic")
 | 
						|
GuideBattlePanel = Inherit(BasePanel)
 | 
						|
 | 
						|
local this = GuideBattlePanel
 | 
						|
 | 
						|
local timeCount
 | 
						|
local endFunc
 | 
						|
local isBack = false --是否为战斗回放
 | 
						|
local fightType -- 1关卡 2副本 3限时怪, 5兽潮, 6新关卡, 7公会boss
 | 
						|
local orginLayer
 | 
						|
--初始化组件(用于子类重写)
 | 
						|
function this:InitComponent()
 | 
						|
    this.spLoader = SpriteLoader.New()
 | 
						|
    BattleView.oSortingOrder = nil
 | 
						|
    BattleView:InitComponent(self, self.gameObject)
 | 
						|
    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.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.BtnGM, function ()
 | 
						|
        if BattleManager.IsCanOperate() and not BattleLogic.IsEnd then
 | 
						|
            BattleView.EndBattle()
 | 
						|
            BattleLogic.IsEnd = true
 | 
						|
        end
 | 
						|
    end)
 | 
						|
 | 
						|
end
 | 
						|
 | 
						|
--添加事件监听(用于子类重写)
 | 
						|
function this:AddListener()
 | 
						|
    Game.GlobalEvent:AddEvent(GameEvent.Player.OnChangeName, this.OnNameChange)
 | 
						|
end
 | 
						|
 | 
						|
--移除事件监听(用于子类重写)
 | 
						|
function this:RemoveListener()
 | 
						|
    Game.GlobalEvent:RemoveEvent(GameEvent.Player.OnChangeName, this.OnNameChange)
 | 
						|
end
 | 
						|
 | 
						|
function this:OnSortingOrderChange()
 | 
						|
    Util.AddParticleSortLayer(this.gameObject, this.sortingOrder - orginLayer)
 | 
						|
    orginLayer = this.sortingOrder
 | 
						|
 | 
						|
    BattleView:OnSortingOrderChange(this.sortingOrder)
 | 
						|
end
 | 
						|
 | 
						|
--界面打开时调用(用于子类重写)
 | 
						|
function this:OnOpen(_fightData, _endFunc, guideType)
 | 
						|
    GuideBattleLogic:Init(guideType)
 | 
						|
    BattleView:OnOpen(_fightData)
 | 
						|
    this.guideType = guideType
 | 
						|
    endFunc = _endFunc
 | 
						|
 | 
						|
    fightType = BATTLE_TYPE.Test --判定战斗类型
 | 
						|
    if _fightData.bg then
 | 
						|
        this.BG:GetComponent("Image").sprite = this.spLoader:LoadSprite(_fightData.bg)
 | 
						|
    else
 | 
						|
        this.BG:GetComponent("Image").sprite = this.spLoader:LoadSprite(BattleManager.GetBattleBg(fightType))
 | 
						|
    end
 | 
						|
 | 
						|
    this.BtnGM:SetActive(guideType ~= 3)
 | 
						|
    this.ButtonLock:SetActive(false)
 | 
						|
    this.BtnTimeScale:SetActive(false)
 | 
						|
    this.damagePanel:SetActive(false)
 | 
						|
 | 
						|
    -- SoundManager.PlayMusic(SoundConfig.BGM_Battle_1, true, function()
 | 
						|
        SoundManager.PlayMusic(SoundConfig.BGM_Battle_2, false)
 | 
						|
    -- end)
 | 
						|
 | 
						|
    this.fightResult = nil
 | 
						|
 | 
						|
    -- 清空名字数据
 | 
						|
    this.DefResult:SetActive(false)
 | 
						|
    this.AtkResult:SetActive(false)
 | 
						|
 | 
						|
    -- 开始战斗
 | 
						|
    BattleView:StartBattle()
 | 
						|
 | 
						|
 | 
						|
    this.InitPanelData()
 | 
						|
end
 | 
						|
 | 
						|
-- 初始化
 | 
						|
function this.InitPanelData()
 | 
						|
    this.InitOption()
 | 
						|
end
 | 
						|
 | 
						|
function this.InitOption()
 | 
						|
    --显示倒计时
 | 
						|
    local curRound, maxRound = BattleLogic.GetCurRound()
 | 
						|
    this.roundText.text = string.format(Language[10211], curRound, maxRound)
 | 
						|
    
 | 
						|
    -- 初始化战斗时间,刷新前端显示
 | 
						|
    Time.timeScale = BATTLE_TIME_SCALE_ONE
 | 
						|
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 UIManager.IsOpen(UIName.ElementPopup) then
 | 
						|
        UIManager.ClosePanel(UIName.ElementPopup)
 | 
						|
    end
 | 
						|
    
 | 
						|
    -- 检测需要在战斗结束时显示的引导
 | 
						|
    GuideBattleLogic:OnBattleEnd(function()
 | 
						|
        -- 直接显示结果
 | 
						|
        this:ClosePanel()
 | 
						|
    end)
 | 
						|
end
 | 
						|
 | 
						|
function this.OnBattleStart(order)
 | 
						|
    --显示波次
 | 
						|
    GuideBattleLogic:OnBattleStart()
 | 
						|
end
 | 
						|
 | 
						|
-- 技能释放完成
 | 
						|
function this.OnSkillCastEnd(skill)
 | 
						|
    -- 
 | 
						|
    GuideBattleLogic:OnSkillCastEnd(skill)
 | 
						|
end
 | 
						|
 | 
						|
 | 
						|
function this.OnOrderChanged(order)
 | 
						|
    --显示波次
 | 
						|
    this.orderText.text = string.format("%d/%d", order, BattleLogic.TotalOrder)
 | 
						|
end
 | 
						|
 | 
						|
-- 战斗回合变化回调
 | 
						|
this.curRound = 1
 | 
						|
function this.OnRoundChanged(round)
 | 
						|
    -- 轮数变化
 | 
						|
    this.curRound = round
 | 
						|
    --显示波次
 | 
						|
    local curRound, maxRound = BattleLogic.GetCurRound()
 | 
						|
    this.roundText.text = string.format(Language[10211], curRound, maxRound)
 | 
						|
end
 | 
						|
 | 
						|
-- 回合结束
 | 
						|
function this.BattleRoundEnd(Round)
 | 
						|
    -- 回调UI层
 | 
						|
    GuideBattleLogic:BattleRoundEnd(Round)
 | 
						|
end
 | 
						|
 | 
						|
-- 角色轮转回调
 | 
						|
function this.RoleTurnChange(role)
 | 
						|
    GuideBattleLogic:RoleTurnChange(this.curRound, role)
 | 
						|
end
 | 
						|
 | 
						|
-- 由BattleView驱动
 | 
						|
function this.OnUpdate()
 | 
						|
    
 | 
						|
end
 | 
						|
 | 
						|
-- 当改变姓名的时候
 | 
						|
function this.OnNameChange()
 | 
						|
    if this.guideType == 3 and NameManager.roleSex ~= ROLE_SEX.BOY then
 | 
						|
        BattleView.ForeachMonster(function(monster)
 | 
						|
            if monster.role.position == 100 and monster.camp == 0 then
 | 
						|
                -- 删除原来的
 | 
						|
                GameObject.DestroyImmediate(monster.RoleLiveGO2)
 | 
						|
                -- casting技能立绘 替换成女角色
 | 
						|
                monster.livePath="live2d_npc_girl"
 | 
						|
                monster.RoleLiveGO2 = poolManager:LoadLive(monster.livePath, monster.skillCastRoot.gameObject.transform.parent, Vector3.one, Vector3.zero)
 | 
						|
                monster.RoleLiveGO2.transform:SetParent(monster.skillCastRoot.gameObject.transform)
 | 
						|
                monster.RoleLiveGO2:GetComponent("RectTransform").anchoredPosition = Vector2.New(monster.offset[1], monster.offset[2])
 | 
						|
                monster.RoleLiveGO2.transform.localScale = Vector3.one * monster.play_liveScale
 | 
						|
                monster.RoleLiveGO2:SetActive(false)
 | 
						|
                monster.RoleLiveGOGraphic2 = monster.RoleLiveGO2:GetComponent("SkeletonGraphic")
 | 
						|
                monster.RoleLiveGOTran2 = monster.RoleLiveGO2:GetComponent("RectTransform")
 | 
						|
                monster.RoleLiveGOGraphic2.AnimationState:SetAnimation(0, "idle", true)
 | 
						|
                monster.RoleLiveGOTran2.sizeDelta = Vector2.New(1000, 1000)
 | 
						|
            end
 | 
						|
        end)
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
--界面关闭时调用(用于子类重写)
 | 
						|
function this:OnClose()
 | 
						|
    BattleView:OnClose()
 | 
						|
    if endFunc then
 | 
						|
        endFunc(this.lastBattleResult)
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
--界面销毁时调用(用于子类重写)
 | 
						|
function this:OnDestroy()
 | 
						|
    BattleView:OnDestroy()
 | 
						|
    this.spLoader:Destroy()
 | 
						|
end
 | 
						|
 | 
						|
return GuideBattlePanel |