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

1025 lines
35 KiB
Lua
Raw Normal View History

2021-04-21 13:12:04 +08:00
require("Base/BasePanel")
2020-05-09 13:31:21 +08:00
require("Modules.Battle.Config.PokemonEffectConfig")
local FEAConfig = require("Modules/Battle/Config/FightEffectAudioConfig")
2020-06-08 13:57:30 +08:00
-- local RoleShowView = require("Modules/Battle/View/BattleRoleShowView")
2020-05-09 13:31:21 +08:00
local BattleView = {}
local this = BattleView
--敌军站位分布
--敌军站位根节点Y坐标
2020-09-03 11:37:36 +08:00
local posY = 380
2020-05-09 13:31:21 +08:00
local posOffset = 0
local tbRole = {}
local tbRoleDispose = {}
2020-11-01 15:46:48 +08:00
local tbMonster = {}
local tbMonsterDispose = {}
2020-05-09 13:31:21 +08:00
local playerHP = 0
local playerMaxHP = 0
local enemyHP = 0
local enemyMaxHP = 0
local playerTmpHp
local enemyTmpHp
local delayRecycleList = {}
local LastDebugTime -- 点击调试键的时间间隔需要大于0.1秒
local scene = {
"r_zhandou_changjing016",
"r_zhandou_changjing016",
"r_zhandou_changjing016",
}
local loadAsset = function(path)
local go = poolManager:LoadAsset(path, PoolManager.AssetType.GameObject)
local layer = tonumber(go.name) or 0
local battleSorting = BattleManager.GetBattleSorting()
Util.AddParticleSortLayer(go, battleSorting - layer)
go.name = tostring(battleSorting)
--- 播放音效
local audioData = FEAConfig.GetAudioData(path)
if audioData then
SoundManager.PlaySound(audioData.name)
end
return go
end
--所有需要延迟回收的资源走该接口,当回调执行前界面已被销毁时,不会报错
local addDelayRecycleRes = function(path, go, recycleTime, delayFunc, delayTime)
if not delayRecycleList[path] then
delayRecycleList[path] = {}
end
table.insert(delayRecycleList[path], go)
if delayTime and delayTime < recycleTime then
Timer.New(delayFunc, delayTime):Start()
Timer.New(function ()
if not delayRecycleList[path] then return end
go:SetActive(false)
for i=1, #delayRecycleList[path] do
if delayRecycleList[path][i] == go then
poolManager:UnLoadAsset(path, go, PoolManager.AssetType.GameObject)
table.remove(delayRecycleList[path], i)
break
end
end
end, recycleTime):Start()
else
Timer.New(function ()
if not delayRecycleList[path] then return end
go:SetActive(false)
for i=1, #delayRecycleList[path] do
if delayRecycleList[path][i] == go then
poolManager:UnLoadAsset(path, go, PoolManager.AssetType.GameObject)
table.remove(delayRecycleList[path], i)
break
end
end
if delayFunc then
delayFunc()
end
end, recycleTime):Start()
end
end
2021-04-27 13:32:41 +08:00
function this:GetABossRage(i)
local rage = this.bossRageRoot.transform:Find("rage_"..i)
if not rage then
rage = newObjToParent(this.bossRage, this.bossRageRoot)
rage.transform.localScale = Vector3.one * 1.5
rage:SetActive(false)
rage.name = "rage_"..i
end
return rage
end
2020-05-09 13:31:21 +08:00
2020-11-01 15:46:48 +08:00
function this:InitComponent(root, go)
2021-04-21 13:12:04 +08:00
this.spLoader = SpriteLoader.New()
2021-04-22 17:54:03 +08:00
BattleManager.SetSpLoader(this.spLoader)
2020-05-09 13:31:21 +08:00
-- body
this.root = root
2020-11-01 15:46:48 +08:00
this.gameObject = go.gameObject
this.transform = go.transform
2020-05-09 13:31:21 +08:00
this.BG = Util.GetGameObject(self.gameObject, "BG")
2020-06-18 20:39:29 +08:00
-- this.LastBG = Util.GetGameObject(self.gameObject, "LastBG")
2020-05-09 13:31:21 +08:00
this.BuffItem = Util.GetGameObject(this.gameObject, "BuffIcon")
this.RoleItem = Util.GetGameObject(this.gameObject, "Role")
this.EnemyItem = Util.GetGameObject(this.gameObject, "Enemy")
this.EnemyItem2 = Util.GetGameObject(this.gameObject, "Enemy2")
2020-11-01 15:46:48 +08:00
this.Monster = Util.GetGameObject(this.gameObject, "Monster")
2020-05-09 13:31:21 +08:00
this.UpRoot = Util.GetGameObject(this.gameObject, "UpRoot")
this.DownRoot = Util.GetGameObject(this.gameObject, "DownRoot")
this.DiffMonster = Util.GetGameObject(this.DownRoot, "teamSkill")
this.DiffMonsterFlag = false
this.DiffMonsterSlider = Util.GetGameObject(this.DiffMonster, "slider"):GetComponent("Image")
this.DiffMonsterIcon = Util.GetGameObject(this.DiffMonster, "icon"):GetComponent("Image")
this.EnemyDiffMonster = Util.GetGameObject(this.UpRoot, "teamSkill")
this.EnemyDiffMonsterFlag = false
this.EnemyDiffMonsterSlider = Util.GetGameObject(this.EnemyDiffMonster, "slider"):GetComponent("Image")
this.EnemyDiffMonsterIcon = Util.GetGameObject(this.EnemyDiffMonster, "icon"):GetComponent("Image")
2021-04-27 13:32:41 +08:00
this.bossRoot = Util.GetGameObject(this.UpRoot, "boss")
this.bossBuffRoot = Util.GetGameObject(this.bossRoot, "buff")
this.bossRageRoot = Util.GetGameObject(this.bossRoot, "rage")
this.bossRage = Util.GetGameObject(this.bossRoot, "rage/Image")
this.bossRageList = {}
for i = 1, 10 do
this.bossRageList[i] = this:GetABossRage(i)
end
2020-05-09 13:31:21 +08:00
Util.GetGameObject(this.UpRoot, "EnemyHP"):SetActive(false)
Util.GetGameObject(this.DownRoot, "PlayerHP"):SetActive(false)
this.EnemyHP = Util.GetGameObject(this.UpRoot, "EnemyHP/hp"):GetComponent("Image")
this.EnemyHPTxt = Util.GetGameObject(this.UpRoot, "EnemyHP/Text"):GetComponent("Text")
this.PlayerHP = Util.GetGameObject(this.DownRoot, "PlayerHP/hp"):GetComponent("Image")
this.PlayerHPTxt = Util.GetGameObject(this.DownRoot, "PlayerHP/Text"):GetComponent("Text")
this.PlayerPanel = Util.GetGameObject(self.gameObject, "RolePanel")
this.EnemyPanel = Util.GetGameObject(self.gameObject, "EnemyPanel")
this.FirstEffect = Util.GetGameObject(this.gameObject, "Start")
this.ThirdEffect = Util.GetGameObject(this.gameObject, "Third")
this.skillEffectRoot = Util.GetGameObject(this.gameObject, "skillEffectRoot")
this.Cache = Util.GetGameObject(this.gameObject, "cache")
2020-11-01 15:46:48 +08:00
--人物角色costing
2020-05-09 13:31:21 +08:00
this.enemySkillCast = Util.GetGameObject(this.transform, "EnemySkillCast")
2020-06-13 11:47:13 +08:00
this.enemySkillCastRoot = Util.GetGameObject(this.transform, "EnemySkillCast/TongYong_Casting_Shang/DongHua/RENWU")
2020-11-01 15:46:48 +08:00
2020-05-09 13:31:21 +08:00
this.mySkillCast = Util.GetGameObject(this.transform, "mySkillCast")
2020-06-13 11:47:13 +08:00
this.mySkillCastRoot = Util.GetGameObject(this.transform, "mySkillCast/TongYong_Casting_Xia/DongHua/RENWU")
2020-11-01 15:46:48 +08:00
--灵兽casting
this.lingshouCastUp = Util.GetGameObject(this.transform, "LingshouCastUp")
this.lingshouCastUpRoot = Util.GetGameObject(this.transform, "LingshouCastUp/EFFECT_Casting_LingShou_Shang/DongHua/RENWU")
this.lingshouCastDown = Util.GetGameObject(this.transform, "LingshouCastDown")
this.lingshouCastDownRoot = Util.GetGameObject(this.transform, "LingshouCastDown/EFFECT_Casting_LingShou_Xia/DongHua/RENWU")
this.enemyMonster=Util.GetGameObject(this.transform, "enemyMonster")
this.playerMonster=Util.GetGameObject(this.transform, "playerMonster")
2020-05-09 13:31:21 +08:00
this.ElementalResonanceView = SubUIManager.Open(SubUIConfig.ElementalResonanceView, self.gameObject.transform)
this.ElementalResonanceView2 = SubUIManager.Open(SubUIConfig.ElementalResonanceView, self.gameObject.transform)
this.ElementalResonanceView.elementalResonanceBtn:SetActive(false)
this.ElementalResonanceView2.elementalResonanceBtn:SetActive(false)
this.mySkillCast:SetActive(false)
this.enemySkillCast:SetActive(false)
this.lingshouCastUp:SetActive(false)
this.lingshouCastDown:SetActive(false)
2020-11-01 15:46:48 +08:00
this.MonsterList = {}
for i = 1, 6 do
this.MonsterList[i] = Util.GetGameObject(this.gameObject, "playerMonster/list/"..i)
this.MonsterList[6 + i] = Util.GetGameObject(this.gameObject, "enemyMonster/list/"..i)
end
2021-10-20 21:33:37 +08:00
this.MonsterList[100] = Util.GetGameObject(this.gameObject, "playerMonster/list/100")
this.MonsterList[101] = Util.GetGameObject(this.gameObject, "enemyMonster/list/101")
2020-12-17 18:36:08 +08:00
this.fightIdText = Util.GetGameObject(this.gameObject, "fightId"):GetComponent("Text")
2020-05-09 13:31:21 +08:00
end
function this:BindEvent()
end
-- 正常接口
2021-04-27 13:32:41 +08:00
function this:OnOpen(data, _fightType, isBoss)
2020-12-17 18:36:08 +08:00
this.ElementalResonanceView:OnOpen({sortOrder = BattleManager.GetBattleSorting()})
this.ElementalResonanceView2:OnOpen({sortOrder = BattleManager.GetBattleSorting()})
2020-05-09 13:31:21 +08:00
this:Init()
2021-04-27 13:32:41 +08:00
this:SetData(data.fightData, data.fightSeed, data.fightType, data.maxRound, data.fightId, isBoss)
2021-03-09 17:19:00 +08:00
this.fightType = _fightType
2020-05-09 13:31:21 +08:00
end
2020-05-15 16:52:35 +08:00
function this:OnSortingOrderChange(battleSorting)
-- 层级
this.FirstEffect:GetComponent("Canvas").sortingOrder = battleSorting + 30
this.skillEffectRoot:GetComponent("Canvas").sortingOrder = battleSorting + 40
local skillSorting = battleSorting + 90
2020-06-13 11:47:13 +08:00
this.mySkillCast:GetComponent("Canvas").sortingOrder = skillSorting
this.enemySkillCast:GetComponent("Canvas").sortingOrder = skillSorting
2020-11-01 15:46:48 +08:00
this.enemyMonster:GetComponent("Canvas").sortingOrder = battleSorting+200
this.playerMonster:GetComponent("Canvas").sortingOrder = battleSorting+200
this.lingshouCastUp:GetComponent("Canvas").sortingOrder = skillSorting
this.lingshouCastDown:GetComponent("Canvas").sortingOrder = skillSorting
2020-06-13 11:47:13 +08:00
if not self.oSortingOrder then
self.oSortingOrder = skillSorting
Util.AddParticleSortLayer(self.mySkillCast, skillSorting)
Util.AddParticleSortLayer(self.enemySkillCast, skillSorting)
2020-11-01 15:46:48 +08:00
Util.AddParticleSortLayer(self.lingshouCastUp,skillSorting)
Util.AddParticleSortLayer(self.lingshouCastDown,skillSorting)
2020-06-13 11:47:13 +08:00
else
Util.AddParticleSortLayer(self.mySkillCast, skillSorting - self.oSortingOrder)
Util.AddParticleSortLayer(self.enemySkillCast, skillSorting - self.oSortingOrder)
2020-11-01 15:46:48 +08:00
Util.AddParticleSortLayer(self.lingshouCastUp,skillSorting- self.oSortingOrder)
Util.AddParticleSortLayer(self.lingshouCastDown,skillSorting- self.oSortingOrder)
2020-06-13 11:47:13 +08:00
end
2020-05-15 16:52:35 +08:00
for _, v in pairs(tbRole) do
v:OnSortingOrderChange(battleSorting)
end
for _, v in pairs(tbRoleDispose) do
v:OnSortingOrderChange(battleSorting)
end
for _, v in pairs(tbMonster) do
v:OnSortingOrderChange(battleSorting)
end
for _, v in pairs(tbMonsterDispose) do
v:OnSortingOrderChange(battleSorting)
end
2020-05-15 16:52:35 +08:00
end
2020-05-09 13:31:21 +08:00
-- 初始化界面
function this:Init()
-- 初始化战斗对象池
BattlePool.Init(this.Cache)
BattlePool.Register(BATTLE_POOL_TYPE.MY_ROLE, this.RoleItem)
BattlePool.Register(BATTLE_POOL_TYPE.ENEMY_ROLE, this.EnemyItem)
BattlePool.Register(BATTLE_POOL_TYPE.ENEMY_ROLE_2, this.EnemyItem2)
BattlePool.Register(BATTLE_POOL_TYPE.BUFF_VIEW, this.BuffItem)
2020-11-01 15:46:48 +08:00
BattlePool.Register(BATTLE_POOL_TYPE.Monster, this.Monster)
2020-05-09 13:31:21 +08:00
-- 层级
local battleSorting = BattleManager.GetBattleSorting()
this.FirstEffect:GetComponent("Canvas").sortingOrder = battleSorting + 30
this.skillEffectRoot:GetComponent("Canvas").sortingOrder = battleSorting + 40
this.mySkillCast:GetComponent("Canvas").sortingOrder = battleSorting + 300
this.enemySkillCast:GetComponent("Canvas").sortingOrder = battleSorting + 300
2020-11-01 15:46:48 +08:00
this.lingshouCastUp:GetComponent("Canvas").sortingOrder = battleSorting+300
this.lingshouCastDown:GetComponent("Canvas").sortingOrder = battleSorting+300
2020-05-09 13:31:21 +08:00
-- 异妖显示
this.DiffMonster:SetActive(false)
this.DiffMonsterFlag = false
this.EnemyDiffMonster:SetActive(false)
this.EnemyDiffMonsterFlag = false
UIManager.camera.clearFlags = CameraClearFlags.Skybox
this.InitBattleEvent()
2020-05-25 19:16:23 +08:00
for i=1, 6 do
local shadow = Util.GetGameObject(this.EnemyPanel, "live_"..i.."/shadow")
shadow:SetActive(false)
2020-11-01 15:46:48 +08:00
this.MonsterList[i]:SetActive(false)
this.MonsterList[6 + i]:SetActive(false)
2020-05-25 19:16:23 +08:00
end
2020-05-09 13:31:21 +08:00
end
-- 设置数据数据
2021-04-27 13:32:41 +08:00
function this:SetData(_fightData, _seed, _battleType, _maxRound, _fightId, _isBoss)
2020-05-09 13:31:21 +08:00
-- body
this.fightData = _fightData
this.seed = _seed
this.battleType = _battleType or 0
2020-05-11 09:38:52 +08:00
this.maxRound = _maxRound
2020-12-17 18:36:08 +08:00
this.fightId = _fightId
2021-04-27 13:32:41 +08:00
this.isBoss = _isBoss
this.bossRoot:SetActive(_isBoss)
2020-05-09 13:31:21 +08:00
--
if not this.seed then
this.seed = math.random(0, 2147483647)
LogBlue("随机生成了 随机种子 == ".. this.seed)
2020-05-09 13:31:21 +08:00
end
if IsOpenBattleDebug then
LogWarn(BattleManager.PrintBattleTable(_fightData))
LogWarn(this.seed)
LastDebugTime = Time.realtimeSinceStartup
end
-- 设置角色展示界面数据
2020-06-08 13:57:30 +08:00
-- RoleShowView.SetData(_fightData)
2020-07-30 10:57:29 +08:00
-- 加入战斗记录
local record = {
fightData = this.fightData,
fightSeed = this.seed,
fightType = this.battleType,
2020-12-17 18:36:08 +08:00
maxRound = this.maxRound,
fightId = this.fightId
2020-07-30 10:57:29 +08:00
}
this.recordId = BattleRecordManager.SetBattleRecord(record)
BattleRecordManager.SetBattleBothNameStr(this.nameStr, this.recordId)
2020-12-17 18:36:08 +08:00
this.fightIdText.text = this.fightId or ""
2020-05-09 13:31:21 +08:00
end
-- 设置攻击双方的名称
function this:SetNameStr(_nameStr)
this.nameStr = _nameStr
end
-- 开始战斗
function this:StartBattle()
--
this.InitBattleData()
-- 初始化战斗数据
FixedUpdateBeat:Add(this.OnUpdate, self)
-- 不再预加载资源
this.BattleOrderChange(1)
2020-05-09 13:31:21 +08:00
end
-- 暂停战斗
function this:PauseBattle()
BattleManager.PauseBattle()
end
-- 继续战斗
function this:ResumeBattle()
BattleManager.ResumeBattle()
end
--
function this:StopBattle()
BattleManager.StopBattle()
end
-- 结束战斗
function this.EndBattle(result)
2020-12-17 18:36:08 +08:00
--前端
local hpList={}
2021-03-12 14:31:52 +08:00
table.insert(hpList,Language[10227])
2020-12-17 18:36:08 +08:00
for i = 1, 6 do
local role=RoleManager.GetRole(0,i)
if role then
table.insert(hpList,role:GetRoleData(RoleDataName.Hp))
end
end
2021-03-12 14:31:52 +08:00
table.insert(hpList,Language[10228])
2020-12-17 18:36:08 +08:00
for i = 1, 6 do
local role=RoleManager.GetRole(1,i)
if role then
table.insert(hpList,role:GetRoleData(RoleDataName.Hp))
end
end
2021-03-12 14:31:52 +08:00
table.insert(hpList,Language[10229])
2020-12-17 18:36:08 +08:00
table.insert(hpList,result)
LogWarn(BattleManager.PrintBattleTable(hpList))
2020-05-09 13:31:21 +08:00
-- 清空数据
this.Clear()
2020-07-30 10:57:29 +08:00
-- 判断结果
result = result or BattleRecordManager.GetBattleRecordResult(this.recordId)
2020-07-15 17:33:19 +08:00
2020-05-09 13:31:21 +08:00
-- 战斗结束
this.root.BattleEnd(result)
end
--
function this.Clear()
2020-12-17 18:36:08 +08:00
--战斗统计前将roleView收集到该容器中tbRole清理掉
2020-05-09 13:31:21 +08:00
for _, v in pairs(tbRole) do
table.insert(tbRoleDispose, v)
end
tbRole = {}
2020-11-01 15:46:48 +08:00
for _, v in pairs(tbMonster) do
table.insert(tbMonsterDispose, v)
end
tbMonster = {}
2020-05-09 13:31:21 +08:00
end
-- 初始化战斗数据
function this.InitBattleData()
Random.SetSeed(this.seed)
--BattleLogic.IsOpenBattleRecord = true
2020-12-17 18:36:08 +08:00
BattleLogic.Init(this.fightData, {uid = PlayerManager.uid, fightId = this.fightId}, this.maxRound)
2020-05-09 13:31:21 +08:00
BattleLogic.Type = this.battleType
this.InitBattleEvent()
2021-04-27 13:32:41 +08:00
-- this.EnemyPanel:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, posY)
2020-05-09 13:31:21 +08:00
end
-- 注册战斗事件
function this.InitBattleEvent()
BattleLogic.Event:AddEvent(BattleEventName.AddRole, this.OnAddRole)
2020-11-01 15:46:48 +08:00
BattleLogic.Event:AddEvent(BattleEventName.AddMonster, this.OnAddMonster)
2020-05-09 13:31:21 +08:00
BattleLogic.Event:AddEvent(BattleEventName.RemoveRole, this.OnRemoveRole)
2020-11-01 15:46:48 +08:00
BattleLogic.Event:AddEvent(BattleEventName.RemoveMonster, this.OnRemoveMonster)
2020-05-09 13:31:21 +08:00
BattleLogic.Event:AddEvent(BattleEventName.BattleEnd, this.EndBattle)
BattleLogic.Event:AddEvent(BattleEventName.BattleOrderChange, this.BattleOrderChange)
BattleLogic.Event:AddEvent(BattleEventName.BattleRoundChange, this.BattleRoundChange)
BattleLogic.Event:AddEvent(BattleEventName.BattleRoundEnd, this.BattleRoundEnd)
2020-10-19 21:06:01 +08:00
BattleLogic.Event:AddEvent(BattleEventName.RoleTurnStart, this.RoleTurnChange)
2021-11-10 11:03:18 +08:00
BattleLogic.Event:AddEvent(BattleEventName.BattleStart, this.OnBattleStart)
2020-05-09 13:31:21 +08:00
end
-- 清除战斗数据
function this.ClearBattleEvent()
BattleLogic.Event:RemoveEvent(BattleEventName.AddRole, this.OnAddRole)
2020-11-01 15:46:48 +08:00
BattleLogic.Event:RemoveEvent(BattleEventName.AddMonster, this.OnAddMonster)
2020-05-09 13:31:21 +08:00
BattleLogic.Event:RemoveEvent(BattleEventName.RemoveRole, this.OnRemoveRole)
2020-11-01 15:46:48 +08:00
BattleLogic.Event:RemoveEvent(BattleEventName.RemoveMonster, this.OnRemoveMonster)
2020-05-09 13:31:21 +08:00
BattleLogic.Event:RemoveEvent(BattleEventName.BattleEnd, this.EndBattle)
BattleLogic.Event:RemoveEvent(BattleEventName.BattleOrderChange, this.BattleOrderChange)
BattleLogic.Event:RemoveEvent(BattleEventName.BattleRoundChange, this.BattleRoundChange)
BattleLogic.Event:RemoveEvent(BattleEventName.BattleRoundEnd, this.BattleRoundEnd)
2020-10-19 21:06:01 +08:00
BattleLogic.Event:RemoveEvent(BattleEventName.RoleTurnStart, this.RoleTurnChange)
2021-11-10 11:03:18 +08:00
BattleLogic.Event:RemoveEvent(BattleEventName.BattleStart, this.OnBattleStart)
2020-05-09 13:31:21 +08:00
end
--敌军出现的表现
2021-03-15 18:37:16 +08:00
function this.EnemyAppear(isStart)
2020-05-09 13:31:21 +08:00
SoundManager.PlaySound(SoundConfig.Sound_BattleStart_03)
local go = this.FirstEffect
2020-06-08 13:57:30 +08:00
go:SetActive(true)
2020-05-09 13:31:21 +08:00
--TODO:动态计算敌军站位
for i=1, 6 do
local index = i
local enemyLivePos = Util.GetTransform(this.EnemyPanel, "live_"..i)
local enemyPos = Util.GetTransform(this.EnemyPanel, tostring(i))
local scale = i > 3 and 0.5 or 0.6
2020-06-08 13:57:30 +08:00
enemyLivePos:DOScale(Vector3.one * scale * 1.1, 0.5):SetEase(Ease.OutExpo)
enemyPos:DOScale(Vector3.one * 1.1, 0.5):SetEase(Ease.OutExpo):OnComplete(function ()
enemyLivePos:DOScale(Vector3.one * scale, 0.2):SetEase(Ease.InExpo)
enemyPos:DOScale(Vector3.one, 0.2):SetEase(Ease.InExpo):OnComplete(function ()
if index == 6 then
2020-05-09 13:31:21 +08:00
--显示血条
for r, v in pairs(tbRole) do
if r.camp == 0 then
playerTmpHp = playerTmpHp + r:GetRoleData(RoleDataName.Hp)
else
enemyTmpHp = enemyTmpHp + r:GetRoleData(RoleDataName.Hp)
end
end
Timer.New(function ()
go:SetActive(false)
playerHP = 0
2021-03-12 14:31:52 +08:00
this.PlayerHPTxt.text = Language[10230]..math.floor(playerHP / playerMaxHP * 100).."%"
2020-05-09 13:31:21 +08:00
enemyHP = 0
2021-03-12 14:31:52 +08:00
this.EnemyHPTxt.text = Language[10231]..math.floor(enemyHP / enemyMaxHP * 100).."%"
2020-05-09 13:31:21 +08:00
2021-03-15 18:37:16 +08:00
if isStart then
Timer.New(function ()
if BattleLogic.CurOrder == 1 then
BattleManager.StartBattle()
else
BattleManager.ResumeBattle()
end
end, 0.1):Start()
end
2020-05-09 13:31:21 +08:00
if BattleLogic.CurOrder == 1 then
Game.GlobalEvent:DispatchEvent(GameEvent.Guide.GuideBattleStart)
end
2020-06-08 13:57:30 +08:00
end, 0.5):Start()
2020-05-09 13:31:21 +08:00
end
end)
2020-06-08 13:57:30 +08:00
end):SetDelay(0.2):OnStart(function ()
2020-06-03 19:09:01 +08:00
if enemyLivePos.childCount > 0 and RoleManager.GetRole(1, i) then
2020-11-01 15:46:48 +08:00
local go2 = BattleManager.LoadAsset("fx_Effect_enemy_birth")
2020-05-09 13:31:21 +08:00
go2.transform:SetParent(this.EnemyPanel.transform)
go2.transform.localScale = Vector3.one
2020-06-03 19:09:01 +08:00
go2.transform.position = enemyPos.position + Vector3.New(0, 120, 0)*0.00375
2020-05-09 13:31:21 +08:00
go2:SetActive(true)
addDelayRecycleRes("fx_Effect_enemy_birth", go2, 2)
end
end)
end
end
2021-11-10 11:03:18 +08:00
-- 战斗开始回调
function this.OnBattleStart()
-- 回调UI层
if this.root.OnBattleStart then
this.root.OnBattleStart()
end
end
2020-10-19 21:06:01 +08:00
-- 角色轮转回调(不出手的位置不会回调)
function this.RoleTurnChange(role)
-- 回调UI层
if this.root.RoleTurnChange then
this.root.RoleTurnChange(role)
end
end
-- 回合结束
function this.BattleRoundEnd(Round)
-- 回调UI层
if this.root.BattleRoundEnd then
this.root.BattleRoundEnd(Round)
end
end
2020-05-09 13:31:21 +08:00
-- 回合变化
function this.BattleRoundChange(Round)
-- 回调UI层
this.root.OnRoundChanged(Round)
-- 异妖CD
if this.DiffMonsterFlag then
local slider = BattleLogic.GetTeamSkillCastSlider(0)
this.DiffMonsterSlider.fillAmount = slider
end
if this.EnemyDiffMonsterFlag then
local slider = BattleLogic.GetTeamSkillCastSlider(1)
this.EnemyDiffMonsterSlider.fillAmount = slider
end
end
-- 战斗波次变化
function this.BattleOrderChange(order)
-- 回调UI层
2020-11-01 15:46:48 +08:00
if this.root.OnOrderChanged then
this.root.OnOrderChanged(order)
end
2020-05-09 13:31:21 +08:00
2020-05-15 16:52:35 +08:00
this.ElementalResonanceView.elementalResonanceBtn:SetActive(true)
this.ElementalResonanceView2.elementalResonanceBtn:SetActive(true)
local curFormation = FormationManager.GetFormationByID(FormationManager.currentFormationIndex)
this.ElementalResonanceView:GetElementalType(curFormation.teamHeroInfos,1)
this.ElementalResonanceView:SetPosition(2)
if this.fightData.enemyData[order] then
this.ElementalResonanceView2:GetElementalType(this.fightData.enemyData[order], 2, order)
this.ElementalResonanceView2:SetPosition(3)
2020-05-09 13:31:21 +08:00
end
2020-05-15 16:52:35 +08:00
2020-05-09 13:31:21 +08:00
if this.tween1 then
this.tween1:Kill()
end
if this.tween2 then
this.tween2:Kill()
end
enemyMaxHP = 0
enemyHP = 0
playerTmpHp = 0
enemyTmpHp = 0
this.PlayerHPTxt.text = ""
this.EnemyHPTxt.text = ""
this.EnemyHP.fillAmount = 0
this.PlayerHP.fillAmount = 0
BattleManager.PauseBattle()
if order > 1 then
PlayUIAnimBack(this.gameObject,function ()
for _,v in pairs(tbRole) do
v.hpSlider.fillAmount = 0
v.hpPassSlider.fillAmount = 0
v.hpCache = 0
if v.spSlider then
v.spSlider.fillAmount = 0
end
end
PlayUIAnim(this.gameObject)
2021-03-15 18:37:16 +08:00
this.EnemyAppear(true)
2020-05-09 13:31:21 +08:00
end)
else
this.UpRoot:SetActive(false)
this.DownRoot:SetActive(false)
this.PlayerPanel:SetActive(false)
this.UpRoot:SetActive(true)
this.DownRoot:SetActive(true)
PlayUIAnim(this.gameObject)
playerMaxHP = 0
this.PlayerPanel:SetActive(true)
PlayUIAnim(this.PlayerPanel)
2021-03-15 18:37:16 +08:00
2021-02-22 20:19:16 +08:00
BattleLogic.InitOrder()--初始显示双方英雄
local func = function ()--显示英雄信息后的战斗逻辑
if BattleLogic.CurOrder == 1 then
BattleManager.StartBattle()
else
BattleManager.ResumeBattle()
end
BattleLogic.StartTurnRound()
2021-02-22 20:19:16 +08:00
end
--判断是否需要显示boss信息
2021-02-25 21:08:11 +08:00
local data = ConfigManager.GetConfigData(ConfigName.MainLevelConfig,FightPointPassManager.curOpenFight)
local key = PlayerPrefs.GetInt(PlayerManager.uid.."BattleBossShow"..FightPointPassManager.curOpenFight)
2021-03-15 18:37:16 +08:00
if this.fightType == BATTLE_TYPE.STORY_FIGHT and data.BossPreview and data.BossPreview > 0 and key == 0 then
this.EnemyAppear(false)--设置敌人
Timer.New(function ()
2021-02-22 20:19:16 +08:00
UIManager.OpenPanel(UIName.BattleBossInfoPanel,function ()
func()
end)
2021-03-15 18:37:16 +08:00
end,1.5):Start()
else
this.EnemyAppear(true)--设置敌人
2021-03-15 20:35:16 +08:00
Timer.New(function ()
func()
end,1.5):Start()
2021-03-15 18:37:16 +08:00
end
2020-05-09 13:31:21 +08:00
end
--刷新敌军站位
2021-04-27 13:32:41 +08:00
-- local v3 = this.EnemyPanel:GetComponent("RectTransform").anchoredPosition
2020-05-09 13:31:21 +08:00
this.EnemyPanel.transform.localScale = Vector3.one
2021-04-27 13:32:41 +08:00
-- this.EnemyPanel:GetComponent("RectTransform").anchoredPosition = Vector2.New(v3.x, posY)
if this.isBoss then
-- boss位置修正
this.EnemyPanel:GetComponent("RectTransform").anchoredPosition = Vector3.New(73, 280, 0)
else
this.EnemyPanel:GetComponent("RectTransform").anchoredPosition = Vector3.New(0, 380, 0)
end
2020-05-09 13:31:21 +08:00
for i=1, 6 do
local enemyPos = Util.GetTransform(this.EnemyPanel, tostring(i))
local enemyLivePos = Util.GetTransform(this.EnemyPanel, "live_"..i)
enemyPos.localScale = Vector3.zero
enemyLivePos.localScale = Vector3.zero
local myPos = Util.GetTransform(this.PlayerPanel, "View/"..i.."/root")
2021-04-22 18:26:48 +08:00
myPos:GetComponent("Image").sprite = this.spLoader:LoadSprite("bd_xinkapaifan")
2020-05-09 13:31:21 +08:00
myPos.localScale = Vector3.one
end
end
function this.OnAddRole(data)
local go
if data.camp == 0 then
local parent = Util.GetTransform(this.PlayerPanel, "View/"..data.position.."/root")
go = BattlePool.GetItem(parent, BATTLE_POOL_TYPE.MY_ROLE)
playerHP = playerHP + data:GetRoleData(RoleDataName.Hp)
playerMaxHP = playerMaxHP + data:GetRoleData(RoleDataName.MaxHp)
2020-11-01 15:46:48 +08:00
tbRole[data] = PlayerView.New(go, data, data.position, this)
2020-05-09 13:31:21 +08:00
else
local enemyPos = Util.GetTransform(this.EnemyPanel, tostring(data.position))
go = BattlePool.GetItem(enemyPos, data.position <= 3 and BATTLE_POOL_TYPE.ENEMY_ROLE or BATTLE_POOL_TYPE.ENEMY_ROLE_2)
enemyHP = enemyHP + data:GetRoleData(RoleDataName.Hp)
enemyMaxHP = enemyMaxHP + data:GetRoleData(RoleDataName.MaxHp)
2021-04-27 13:32:41 +08:00
local isBoss = false
if this.isBoss and data.position == 2 then
isBoss = true
end
tbRole[data] = EnemyView.New(go, data, data.position, this, isBoss)
2020-05-09 13:31:21 +08:00
end
go.transform.localScale = Vector3.one
go.transform.localPosition = Vector3.zero
go.transform.anchoredPosition = Vector2.zero
go:SetActive(true)
end
function this.OnRemoveRole(data)
local view = tbRole[data]
if view then
view:Dispose()
tbRole[data] = nil
end
end
2020-11-01 15:46:48 +08:00
function this.OnAddMonster(data)
LogPink(data.camp.."addmonster"..data.position)
2021-10-20 21:33:37 +08:00
local posIndex=0
if data.position==100 then
posIndex=data.camp + data.position
else
posIndex=data.camp * 6 + data.position
end
local parent = this.MonsterList[posIndex]
if parent then
parent:SetActive(true)
local go = BattlePool.GetItem(parent.transform, BATTLE_POOL_TYPE.Monster)
tbMonster[data] = MonsterView.New(go, data, data.position, this)
go.transform.localScale = Vector3.one
go.transform.localPosition = Vector3.zero
go.transform.anchoredPosition = Vector2.zero
if posIndex>=100 then
go:SetActive(false)
else
go:SetActive(true)
end
end
2020-11-01 15:46:48 +08:00
end
-- 遍历灵兽列表
function this.ForeachMonster(func)
for _, monster in pairs(tbMonster) do
if func then
func(monster)
end
end
end
-- 移除灵兽
2020-11-01 15:46:48 +08:00
function this.OnRemoveMonster(data)
local view = tbMonster[data]
if view then
view:Dispose()
tbMonster[data] = nil
end
end
2020-05-09 13:31:21 +08:00
function this.GetRoleView(role)
return tbRole[role]
end
-- 设置角色高亮
function this.SetRoleHighLight(caster, targets, func)
-- 没有目标全部高亮
if not caster and not targets then
for _, role in pairs(tbRole) do
role:SetHighLight(true, 1, 0.2)
end
-- 避免战斗结束时状态显示错误的问题
if tbRoleDispose then
for _, role in pairs(tbRoleDispose) do
role:SetHighLight(true, 1, 0.2)
end
end
if func then func() end
return
end
--
local i = 0
local max = 0
local function _Count()
i = i + 1
if i >= max then
if func then func() end
end
end
for _, role in pairs(tbRole) do
max = max + 1
role:SetHighLight(false, 0.95, 0.2, _Count)
end
2020-11-01 15:46:48 +08:00
if caster and caster.role.type == BattleUnitType.Role then
2020-05-09 13:31:21 +08:00
max = max - 1
caster:SetHighLight(true, 1.5, 0.2)
end
if targets then
for _, data in ipairs(targets) do
if caster ~= tbRole[data] then
max = max - 1
2020-06-13 11:47:13 +08:00
tbRole[data]:SetHighLight(true, 1, 0.2)
2020-05-09 13:31:21 +08:00
end
end
end
if max == 0 then
if func then func() end
end
end
--(新手引导专用)查找同一站位的人,敌方死亡,我方存活的
function this.GuideCheckEnemyDead(role)
if not role:IsDead() and role.camp == 0 then
for r, v in pairs(tbRole) do
if r:IsDead() and r.camp == 1 and r.position == role.position then
return true
end
end
end
return false
end
function this.OnUpdate()
2020-11-01 15:46:48 +08:00
-- 引导战斗暂停
if BattleManager.IsGuidePause() then
return
end
-- 判断是否结束
2020-05-25 19:16:23 +08:00
if BattleLogic.IsEnd then
-- 所有角色血条
for r, v in pairs(tbRoleDispose) do
v:Update()
end
end
2020-05-09 13:31:21 +08:00
if BattleManager.IsBattlePlaying() and not BattleLogic.IsEnd then
BattleLogic.Update()
-- 再检测一次战斗结束
if BattleLogic.IsEnd then return end
playerTmpHp = 0
enemyTmpHp = 0
-- 所有角色血条
for r, v in pairs(tbRole) do
v:Update()
if r.camp == 0 then
playerTmpHp = playerTmpHp + r:GetRoleData(RoleDataName.Hp)
else
enemyTmpHp = enemyTmpHp + r:GetRoleData(RoleDataName.Hp)
end
end
-- 我方总血条
if playerTmpHp ~= playerHP then
local f1 = playerHP
local f2 = playerTmpHp
if this.tween1 then
this.tween1:Kill()
end
this.tween1 = DoTween.To(DG.Tweening.Core.DOGetter_float( function () return f1 end),
DG.Tweening.Core.DOSetter_float(function (t)
this.PlayerHP.fillAmount = t / playerMaxHP
end), f2, 0.5):SetEase(Ease.Linear)
playerHP = playerTmpHp
2021-03-12 14:31:52 +08:00
this.PlayerHPTxt.text = Language[10230]..math.floor(playerHP / playerMaxHP * 100).."%"
2020-05-09 13:31:21 +08:00
end
-- 敌方总血条
if enemyTmpHp ~= enemyHP then
local f1 = enemyHP
local f2 = enemyTmpHp
if this.tween2 then
this.tween2:Kill()
end
this.tween2 = DoTween.To(DG.Tweening.Core.DOGetter_float( function () return f1 end),
DG.Tweening.Core.DOSetter_float(function (t)
this.EnemyHP.fillAmount = t / enemyMaxHP
end), f2, 0.5):SetEase(Ease.Linear)
enemyHP = enemyTmpHp
2021-03-12 14:31:52 +08:00
this.EnemyHPTxt.text = Language[10231]..math.floor(enemyHP / enemyMaxHP * 100).."%"
2020-05-09 13:31:21 +08:00
end
-- 驱动上层界面
this.root.OnUpdate()
end
end
function this.OnSkillCast(skill)
local type = skill.teamSkillType
local camp = skill.owner.camp
local pokemonConfig = PokemonEffectConfig[type]
if camp == 0 then
Util.SetGray(this.DiffMonster, true)
else
Util.SetGray(this.EnemyDiffMonster, true)
end
if camp == 1 then
local yiPath2 = pokemonConfig.aoe
2020-11-01 15:46:48 +08:00
local go3 = BattleManager.LoadAsset(yiPath2)
2020-05-09 13:31:21 +08:00
go3.transform:SetParent(this.transform)
go3.transform.localScale = Vector3.one
go3.transform.localPosition = camp == 0 and Vector3.New(0,100,0) or Vector3.New(0,-674,0)
go3:SetActive(true)
this.BG:GetComponent("RectTransform"):DOShakeAnchorPos(1, Vector2.New(500, 100), 100, 50, false, true)
addDelayRecycleRes(yiPath2, go3, 3)
return
end
2020-11-01 15:46:48 +08:00
local go = BattleManager.LoadAsset("casting_skill")
2020-05-09 13:31:21 +08:00
go:GetComponent("Canvas").sortingOrder = this.root.sortingOrder + 100
go.transform:SetParent(this.gameObject.transform)
go.transform.localScale = Vector3.one
go.transform.localPosition = Vector3.zero
go:SetActive(true)
local path = pokemonConfig.live
local scale = pokemonConfig.scale
local tran = Util.GetTransform(go, "player")
local liveGO = poolManager:LoadAsset(path, PoolManager.AssetType.GameObject)
liveGO.transform:SetParent(tran)
liveGO.transform.localScale = Vector3.one * scale
liveGO.transform.localPosition = Vector3.New(0, 0, 0)
liveGO:SetActive(true)
liveGO:GetComponent("SkeletonGraphic"):DOFade(1, 0)
liveGO:GetComponent("SkeletonGraphic"):DOColor(Color.New(1,1,1,1), 0)
BattleManager.PauseBattle()
addDelayRecycleRes("casting_skill", go, 1.6, function ()
local yiPath1 = pokemonConfig.screen
2020-11-01 15:46:48 +08:00
local go2 = BattleManager.LoadAsset(yiPath1)
2020-05-09 13:31:21 +08:00
go2.transform:SetParent(this.transform)
go2.transform.localScale = Vector3.one
go2.transform.localPosition = Vector3.zero
go2:SetActive(true)
addDelayRecycleRes(yiPath1, go2, pokemonConfig.screenCD + 3, function ()
local yiPath2 = pokemonConfig.aoe
2020-11-01 15:46:48 +08:00
local go3 = BattleManager.LoadAsset(yiPath2)
2020-05-09 13:31:21 +08:00
go3.transform:SetParent(this.transform)
go3.transform.localScale = Vector3.one
go3.transform.localPosition = camp == 0 and Vector3.New(0,100,0) or Vector3.New(0,-674,0)
go3:SetActive(true)
this.BG:GetComponent("RectTransform"):DOShakeAnchorPos(1, Vector2.New(500, 100), 100, 50, false, true)
BattleManager.ResumeBattle()
addDelayRecycleRes(yiPath2, go3, 3)
end, pokemonConfig.screenCD)
end)
addDelayRecycleRes(path, liveGO, 1.6)
end
-- 清除角色
function this:ClearRole()
for _, view in pairs(tbRole) do
view:Dispose()
end
tbRole = {}
end
-- 参数:object 抖动物体 timeScale 震动时长 dx, dy震动偏移量
local isShaking = false
function this:SetShake(object, timeScale, dx, dy, callBack)
if isShaking then return end
isShaking = true
if not object then
object = this.gameObject
end
if not timeScale or timeScale == 0 then
timeScale = 0.2
end
if not dx or not dy or dy == 0 and dx == 0 then
dx = 100
dy = 100
end
object:GetComponent("RectTransform"):DOShakeAnchorPos(timeScale, Vector2.New(dx, dy),
500, 90, true, true):OnComplete(function ()
if callBack then callBack() end
isShaking = false
end)
end
2021-04-27 13:32:41 +08:00
-- 设置boss怒气显示
function this:SetBossRage(rage)
if rage <= #this.bossRageList then
for i = 1, #this.bossRageList do
this.bossRageList[i]:SetActive(i<=rage)
end
else
for i = 1, rage do
if not this.bossRageList[i] then
this.bossRageList[i] = this:GetABossRage(i)
end
this.bossRageList[i]:SetActive(i<=rage)
end
end
end
2020-05-09 13:31:21 +08:00
--界面关闭时调用(用于子类重写)
function this:OnClose()
-- 回收所有延迟资源
BattleManager.RecycleAllDelayRes()
2020-12-17 18:36:08 +08:00
--
2020-05-09 13:31:21 +08:00
FixedUpdateBeat:Remove(this.OnUpdate, self)
2020-12-17 18:36:08 +08:00
-- 清空
this.Clear()
2020-05-09 13:31:21 +08:00
for _, v in pairs(tbRoleDispose) do
v:Dispose()
end
tbRoleDispose = {}
for _, v in pairs(tbMonsterDispose) do
v:Dispose()
end
tbMonsterDispose = {}
2020-05-09 13:31:21 +08:00
for k, v in pairs(delayRecycleList) do
for i=1, #v do
poolManager:UnLoadAsset(k, v[i], PoolManager.AssetType.GameObject)
end
delayRecycleList[k] = nil
end
2020-05-09 13:31:21 +08:00
BattlePool.Clear()
poolManager:ClearPool()
2020-06-23 18:36:24 +08:00
this.mySkillCast:SetActive(false)
this.enemySkillCast:SetActive(false)
2020-11-01 15:46:48 +08:00
this.lingshouCastUp:SetActive(false)
this.lingshouCastDown:SetActive(false)
2020-05-09 13:31:21 +08:00
--
BattleManager.StopBattle()
this.ClearBattleEvent()
2020-05-09 13:31:21 +08:00
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
2021-04-21 13:12:04 +08:00
this.spLoader:Destroy()
2021-04-22 17:54:03 +08:00
BattleManager.SetSpLoader(nil)
2020-05-09 13:31:21 +08:00
SubUIManager.Close(this.ElementalResonanceView)
SubUIManager.Close(this.ElementalResonanceView2)
BattlePool.Destroy()
2020-11-01 15:46:48 +08:00
-- 回收所有延迟资源
BattleManager.RecycleAllDelayRes()
2020-05-09 13:31:21 +08:00
end
2020-06-23 18:36:24 +08:00
return BattleView