miduo_client/Assets/ManagedResources/~Lua/Modules/Battle/Test/BattleTestPanel.lua

687 lines
22 KiB
Lua

require("Base/BasePanel")
require("Base/Stack")
require("Modules.Battle.Config.PokemonEffectConfig")
require("Modules.Battle.Test.View.AllSetView")
require("Modules.Battle.Test.View.MonsterSetView")
require("Modules.Battle.Test.View.RoleSetView")
require("Modules.Battle.Test.View.SkillSetView")
local MonsterGroup = ConfigManager.GetConfig(ConfigName.MonsterGroup)
local SpriteAnimalSkill = ConfigManager.GetConfig(ConfigName.SpiritAnimalSkill)
local shenbing=ConfigManager.GetConfig(ConfigName.ShenBingSkill)
local BattleView = require("Modules/Battle/View/BattleView")
BattleTestPanel = Inherit(BasePanel)
local this = BattleTestPanel
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
local TestFightData = {
playerData = { teamSkill = {}, teamPassive = {} },
enemyData = {{teamSkill = {}, teamPassive = {} }},
}
local roleTestData = {}
local monsterTestData = {}
local allTestData = {}
local _IsStart = false
local _IsCanNext = false
--初始化组件(用于子类重写)
function this:InitComponent()
this.spLoader = SpriteLoader.New()
orginLayer = 0
this.BattlePanel = Util.GetGameObject(self.gameObject, "BattlePanel")
BattleView:InitComponent(this, this.BattlePanel)
this.UpRoot = Util.GetGameObject(this.BattlePanel, "UpRoot")
this.DownRoot = Util.GetGameObject(this.BattlePanel, "DownRoot")
this.Option = Util.GetGameObject(this.UpRoot, "option")
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.tOption = Util.GetGameObject(self.gameObject, "Test/option")
this.BtnStrat = Util.GetGameObject(this.tOption, "BtnStrat")
this.BtnPause = Util.GetGameObject(this.tOption, "BtnPause")
this.BtnNext = Util.GetGameObject(this.tOption, "BtnNext")
this.IsSingle = Util.GetGameObject(this.tOption, "isSingle"):GetComponent("Toggle")
this.IsSkill = Util.GetGameObject(this.tOption, "isSkill"):GetComponent("Toggle")
this.btnLoadMy = Util.GetGameObject(this.tOption, "loadMy")
this.btnLoadMonster = Util.GetGameObject(this.tOption, "loadMonster")
this.monsterGroupId = Util.GetGameObject(this.tOption, "loadMonster/InputField"):GetComponent("InputField")
this.SkillOption = Util.GetGameObject(self.gameObject, "skillOption")
this.RoleSkillOption = Util.GetGameObject(self.gameObject, "skillOption/Role")
-- 初始化设置界面
RoleSetView:Init(Util.GetGameObject(self.gameObject, "roleSet"))
MonsterSetView:Init(Util.GetGameObject(self.gameObject, "monsterSet"))
AllSetView:Init(Util.GetGameObject(self.gameObject, "allSet"))
SkillSetView:Init(Util.GetGameObject(self.gameObject, "skillSet"))
this.MyRolePosList = {}
this.EnemyRolePosList = {}
for i = 1 , 6 do
this.MyRolePosList[i] = Util.GetGameObject(self.gameObject, "Test/role/"..i.."/root")
this.EnemyRolePosList[i] = Util.GetGameObject(self.gameObject, "Test/enemy/btn"..i)
end
-- 灵兽
this.MonsterSkillOption = Util.GetGameObject(self.gameObject, "skillOption/Monster")
this.EnemyMonsterSet = Util.GetGameObject(this.MonsterSkillOption, "enemyMonster/set")
this.PlayerMonsterSet = Util.GetGameObject(this.MonsterSkillOption, "playerMonster/set")
this.EnemyMonsterList = {}
this.PlayerMonsterList = {}
for i = 1 , 6 do
this.EnemyMonsterList[i] = Util.GetGameObject(this.MonsterSkillOption, "enemyMonster/list/"..i.."/cast")
this.PlayerMonsterList[i] = Util.GetGameObject(this.MonsterSkillOption, "playerMonster/list/"..i.."/cast")
end
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.BtnTimeScale, function ()
if Time.timeScale > 2 then
Time.timeScale = 0.5
else
Time.timeScale = math.floor(Time.timeScale + 1)
end
this.SwitchTimeScale()
end)
Util.AddClick(this.BtnStrat, function ()
-- 开始战斗
if _IsStart then
--TODO:
BattleView:StopBattle()
_IsStart = false
this.RoleSkillOption:SetActive(false)
BattleView.Clear()
BattleView:OnClose2()
BattleView.InitBattleEvent()
this.RefreshAllRoleShow()
LogRed("战斗已停止")
else
LogRed("战斗开始")
BattleView:ClearRole()
this:SetData()
BattleView:StartBattle()
BattleLogic.SetIsDebug(this.IsSingle.isOn)
BattleLogic.Event:AddEvent(BattleEventName.DebugStop, this.OnDebugStop)
this.InitSkillOption()
_IsStart = true
end
end)
Util.AddClick(this.BtnPause, function ()
if _IsStart then
-- 战斗暂停
if BattleManager.IsBattlePlaying() then
BattleManager.PauseBattle()
else
BattleManager.ResumeBattle()
end
end
end)
Util.AddClick(this.BtnNext, function ()
if _IsCanNext then
_IsCanNext = false
BattleLogic.TurnRound(true)
end
end)
this.IsSingle.onValueChanged:AddListener(function(state)
if not state then
this.IsSkill.isOn = false
end
end)
this.IsSkill.onValueChanged:AddListener(function(state)
if state then
this.IsSingle.isOn = true
end
end)
Util.AddClick(this.btnLoadMy, function ()
TestFightData.playerData = BattleManager.GetBattlePlayerData()
if not TestFightData.playerData then
PopupTipPanel.ShowTip(Language[10206])
return
end
-- 加载角色
this.RefreshAllRoleShow()
end)
Util.AddClick(this.btnLoadMonster, function ()
local gId = tonumber(this.monsterGroupId.text)
if not gId then
PopupTipPanel.ShowTip(Language[10207])
return
end
TestFightData.enemyData = BattleManager.GetBattleEnemyData(gId)
if not TestFightData.enemyData[1] then
PopupTipPanel.ShowTip(Language[10208])
return
end
-- 加载角色
this.RefreshAllRoleShow()
end)
--
for i = 1 , 6 do
Util.AddClick(this.MyRolePosList[i], function()
if _IsStart then
PopupTipPanel.ShowTip(Language[10209])
return
end
RoleSetView:Show(0, i, roleTestData[i], this.ApplyRoleData)
end)
Util.AddClick(this.EnemyRolePosList[i], function()
if _IsStart then
PopupTipPanel.ShowTip(Language[10209])
return
end
RoleSetView:Show(1, i, roleTestData[i+6], this.ApplyRoleData)
end)
end
Util.AddClick(this.EnemyMonsterSet, function ()
Log("EnemyMonsterSet")
if _IsStart then
PopupTipPanel.ShowTip(Language[10209])
return
end
MonsterSetView:Show(1, monsterTestData, this.ApplyMonsterData)
end)
Util.AddClick(this.PlayerMonsterSet, function ()
Log("PlayerMonsterSet")
if _IsStart then
PopupTipPanel.ShowTip(Language[10209])
return
end
MonsterSetView:Show(0, monsterTestData, this.ApplyMonsterData)
end)
end
function this:LoseJump(id)
if not MapManager.Mapping then
if JumpManager.CheckJump(id) then
this:ClosePanel()
JumpManager.GoJumpWithoutTip(id)
end
else
PopupTipPanel.ShowTip(Language[10210])
end
end
--添加事件监听(用于子类重写)
function this:AddListener()
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
end
--
function this.OnDebugStop()
_IsCanNext = true
end
function this:OnSortingOrderChange()
Util.AddParticleSortLayer(this.gameObject, this.sortingOrder - orginLayer)
orginLayer = this.sortingOrder
BattleView:OnSortingOrderChange(this.sortingOrder)
this.UpRoot:GetComponent("Canvas").sortingOrder = this.sortingOrder + 10
this.DownRoot:GetComponent("Canvas").sortingOrder = this.sortingOrder + 10
end
--界面打开时调用(用于子类重写)
function this:OnOpen()
BattleView:Init()
TestFightData = {
playerData = { teamSkill = {}, teamPassive = {} },
enemyData = {{teamSkill = {}, teamPassive = {} }},
}
this.InitPanelData()
-- SoundManager.PlayMusic(SoundConfig.BGM_Battle_1, true, function()
SoundManager.PlayMusic(SoundConfig.BGM_Battle_2, false)
-- end)
this.SkillOption:GetComponent("Canvas").sortingOrder = BattleManager.GetBattleSorting() + 20
end
-- 设置数据
function this:SetData()
BattleView:SetData(TestFightData, nil, 1, 90)
end
-- 根据当前设置生成战斗数据
function this.RefreshFightData(type)
if not type or type == 1 then
-- 清除所有数据
this.ClearRoleData()
-- 重新添加
for i = 1, 12 do
local role = roleTestData[i]
if role then
local data = {}
data.camp = math.floor((i-1)/6)
data.position = (i - 1) % 6 + 1
data.monsterId = role.monsterId
data.roleId = role.roleId
local roleData
if role.roleId > 10000 then
roleData = ConfigManager.GetConfigData(ConfigName.HeroConfig, data.roleId)
else
roleData = ConfigManager.GetConfigData(ConfigName.MonsterConfig, data.monsterId)
end
data.element = roleData.PropertyName
data.professionId = roleData.Profession
data.quality = roleData.Quality
data.star = role.star
data.skinId=role.skinId
--LogError("skinId==="..role.skinId)
data.type = 1
data.job=roleData.Job
local paskill = string.split(role.passivity, "#")
data.passivity = BattleManager.GetPassivityData(paskill) or {}
data.property = {}
for pi = 1, 25 do
data.property[pi] = role.props[pi] or 0
end
data.teamDamage=data.property[4]
data.skill = BattleManager.GetSkillData(role.skill,role.skinId) or {}
data.superSkill = BattleManager.GetSkillData(role.superSkill) or {}
-- 添加角色数据
this.AddRoleData(data)
end
end
-- 刷新角色显示
this.RefreshAllRoleShow()
end
-- 灵兽数据刷新
if not type or type == 2 then
-- 清除所有数据
this.ClearMonsterData()
this.ClearWeaponData()
-- 重新添加
for i = 1, 12 do
local monster = monsterTestData[i]
if monster then
local data = {}
data.camp = math.floor((i-1)/6)
data.position = (i - 1) % 6 + 1
data.id = monster.id
data.star = monster.star
data.teamDamage=monster.props[2]
data.property = {}
for pi = 1, 25 do
data.property[pi] = monster.props[pi] or 0
end
local isPokemon=true
local MSkillId = data.id..data.star
LogError("data.id=="..data.id.." data.star=="..data.star)
data.skill={}
data.skill[1] = BattleManager.MonsterSkillAdapter(MSkillId) or {}
if monster.skillId~=nil and monster.skillId~=0 then
LogError("data.skill=="..monster.skillId)
--data.position=100
data.skill[1] = BattleManager.PlayerSkillAdapter(monster.skillId) or {}
end
if monster.weaponId~=nil and monster.weaponId~=0 then
LogError("data.weaponskill=="..monster.weaponId)
isPokemon=false
local pokemonUnit=shenbing[monster.weaponId]
if pokemonUnit and pokemonUnit.SkillIDList then
LogError("神兵技能+++++++++++++++++++++")
monster.id=pokemonUnit.SpiritAnimalMatch
data.id=pokemonUnit.SpiritAnimalMatch
data.skill={}
--for i = 1, #pokemonUnit.SkillIDList do
data.skill[1]=BattleManager.WeaponSkillAdapter(monster.weaponId)
if pokemonUnit.PassiveSkill then
--LogError("pokemonUnit.PassiveSkill=="..pokemonUnit.PassiveSkill)
--local passs=string.split(pokemonUnit.PassiveSkill, "#")
local passs=pokemonUnit.PassiveSkill
local passivityList = {}
for j = 1, #passs do
LogError("神兵被动============="..passs[j])
table.insert(passivityList, tonumber(passs[j]))
end
data.passivity = BattleManager.GetPassivityData(passivityList)
end
--end
end
end
-- 添加角色数据
this.AddMonsterData(data,isPokemon)
end
end
-- 刷新显示
this.RefreshAllMonsterShow()
end
if not type or type == 3 then
end
--
--LogGreen("战斗数据刷新 " .. BattleManager.PrintBattleTable(TestFightData))
end
function this.ApplyMonsterData(data)
monsterTestData = data
this.RefreshFightData(2)
return true
end
function this.ClearMonsterData(camp)
if camp == 0 then
TestFightData.playerData.monsterList = {}
elseif camp == 1 then
TestFightData.enemyData[1].monsterList = {}
else -- 全清
TestFightData.playerData.monsterList = {}
TestFightData.enemyData[1].monsterList = {}
end
end
function this.ClearWeaponData(camp)
if camp == 0 then
TestFightData.playerData.weaponList = {}
elseif camp == 1 then
TestFightData.enemyData[1].weaponList = {}
else -- 全清
TestFightData.playerData.weaponList = {}
TestFightData.enemyData[1].weaponList = {}
end
end
function this.AddMonsterData(data,_isPokemon)
local camp = data.camp
local pos = data.position
if camp == 0 then
local rIndex
for index, role in ipairs(TestFightData.playerData.monsterList) do
if role.position == pos then
rIndex = index
break
end
end
if _isPokemon then
if rIndex then
TestFightData.playerData.monsterList[rIndex] = data
else
table.insert(TestFightData.playerData.monsterList, data)
end
else
if rIndex then
TestFightData.playerData.weaponList[rIndex] = data
else
table.insert(TestFightData.playerData.weaponList, data)
end
end
else
local rIndex
for index, role in ipairs(TestFightData.enemyData[1].monsterList) do
if role.position == pos then
rIndex = index
break
end
end
if _isPokemon then
if rIndex then
TestFightData.enemyData[1].monsterList[rIndex] = data
else
table.insert(TestFightData.enemyData[1].monsterList, data)
end
else
if rIndex then
TestFightData.enemyData[1].weaponList[rIndex] = data
else
table.insert(TestFightData.enemyData[1].weaponList, data)
end
end
end
end
-- 角色数据
function this.ApplyRoleData(camp, pos, data)
if camp == 0 then
roleTestData[pos] = data
else
roleTestData[pos+6] = data
end
this.RefreshFightData(1)
end
-- 清除人物数据
function this.ClearRoleData(camp)
for i = 1, 6 do
if camp == 0 then
TestFightData.playerData[i] = nil
elseif camp == 1 then
TestFightData.enemyData[1][i] = nil
else -- 全清
TestFightData.playerData[i] = nil
TestFightData.enemyData[1][i] = nil
end
end
end
-- 增加一个数据
function this.AddRoleData(data)
local camp = data.camp
local pos = data.position
if camp == 0 then
local rIndex
for index, role in ipairs(TestFightData.playerData) do
if role.position == pos then
rIndex = index
break
end
end
if rIndex then
TestFightData.playerData[rIndex] = data
else
table.insert(TestFightData.playerData, data)
end
else
local rIndex
for index, role in ipairs(TestFightData.enemyData[1]) do
if role.position == pos then
rIndex = index
break
end
end
if rIndex then
TestFightData.enemyData[1][rIndex] = data
else
table.insert(TestFightData.enemyData[1], data)
end
end
end
-- 刷新显示
function this.RefreshAllRoleShow()
BattleView:ClearRole()
-- body
if TestFightData.enemyData[1] then
-- 加载角色
for _, data in ipairs(TestFightData.enemyData[1]) do
RoleManager.AddRole(data, data.position)
end
end
if TestFightData.playerData then
-- 加载角色
for _, data in ipairs(TestFightData.playerData) do
RoleManager.AddRole(data, data.position)
end
end
end
function this.RefreshAllMonsterShow()
-- 灵兽
if TestFightData.enemyData[1] and TestFightData.enemyData[1].monsterList then
for _, data in ipairs(TestFightData.enemyData[1].monsterList) do
if data.id then
MonsterManager.AddMonster(data)
end
end
end
if TestFightData.playerData and TestFightData.playerData.monsterList then
-- 加载角色
for _, data in ipairs(TestFightData.playerData.monsterList) do
if data.id then
MonsterManager.AddMonster(data)
end
end
end
end
-- 全局被动
function this.ApplyAllData(camp, data)
end
-- 初始化
function this.InitPanelData()
--显示倒计时
local curRound, maxRound = BattleLogic.GetCurRound()
this.roundText.text = string.format(Language[10211], curRound, maxRound)
hadCounted = 0
this.Option:SetActive(true)
this.SwitchTimeScale()
end
function this.SwitchTimeScale()
local _scale = math.floor(Time.timeScale)
local child = this.BtnTimeScale.transform.childCount - 3 -- 3倍速时-2
local s = "x".. _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()
--LogGreen("战斗结果 = "..result)
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[10211], curRound, maxRound)
end
-- 由BattleView驱动
function this.OnUpdate()
end
-- 初始化技能选项
function this.InitSkillOption()
this.RoleSkillOption:SetActive(this.IsSkill.isOn)
if this.IsSkill.isOn then
for i = 1, 12 do
local camp = math.floor((i-1)/6)
local pos = i - camp*6
local btn1 = Util.GetGameObject(this.RoleSkillOption, i.."/1")
local btn2 = Util.GetGameObject(this.RoleSkillOption, i.."/2")
local btn3 = Util.GetGameObject(this.RoleSkillOption, i.."/3")
Util.AddOnceClick(btn1, function()
if _IsCanNext then
local role = RoleManager.GetRole(camp, pos)
if not role then return end
_IsCanNext = false
role:ForceCastSkill(1, nil, function()
_IsCanNext = true
end)
end
end)
Util.AddOnceClick(btn2, function()
if _IsCanNext then
local role = RoleManager.GetRole(camp, pos)
if not role then return end
_IsCanNext = false
role:ForceCastSkill(2, nil, function()
_IsCanNext = true
end)
end
end)
Util.AddOnceClick(btn3, function()
SkillSetView:Show(camp, pos, BattleView)
end)
end
end
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
BattleView:OnClose()
Time.timeScale = 1
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
BattleView:OnDestroy()
this.spLoader:Destroy()
end
return this