战斗回合概念

This commit is contained in:
xiekaidong 2023-04-14 17:59:12 +08:00
parent ab14bce85c
commit 642eb4d247
6 changed files with 226 additions and 47 deletions

View File

@ -23,6 +23,19 @@ BattleConst.UNIT_FRONT_DISTANCE = 50
BattleConst.MOVE_SPEED = 500 -- 战斗单位的移动速度 BattleConst.MOVE_SPEED = 500 -- 战斗单位的移动速度
BattleConst.HURT_STATE_CRIT = 1 -- 暴击 BattleConst.HURT_STATE_CRIT = 1 -- 暴击
BattleConst.BATTLE_ROUND_STEP = {
WAIT_BEGIN = 0, -- 等待开始
ON_BEGIN = 1, -- 回合开始
ON_ELIMINATION_BEGIN = 3, -- 消除开始
ON_ELIMINATION = 4, -- 等待消除
ON_ATK_STEP = 5, -- 攻击方行动
ON_ATK_STEP_OVER = 6, -- 攻击方行动结束(可能直接跳转到刷新棋盘/回合结束)
ON_DEF_STEP = 7, -- 防守方行动
ON_DEF_STEP_OVER = 8, -- 防守方行动结束(可能直接跳转到刷新棋盘/回合结束)
ON_REFRESH_BOARD = 9, -- 刷新棋盘
ON_END = 10, -- 回合结束
}
-- 为方便存储,这里使用字符串 -- 为方便存储,这里使用字符串
BattleConst.BATTLE_TYPE = { BattleConst.BATTLE_TYPE = {
STAGE = "1", STAGE = "1",

View File

@ -98,13 +98,19 @@ function BattleController:onLinkChange()
end end
self.battleUI:refreshSkill(elementTypeMap) self.battleUI:refreshSkill(elementTypeMap)
Logger.logHighlight("---------onLinkChange--------------")
Logger.printTable(elementTypeMap)
if mainElementType then if mainElementType then
Logger.logHighlight("mainElementType " .. mainElementType) Logger.logHighlight("mainElementType " .. mainElementType)
end end
end end
function BattleController:onRoundBegin()
end
function BattleController:onEliminationBegin()
end
-- *************各个子模块的战斗需要重写的方法 END************* -- *************各个子模块的战斗需要重写的方法 END*************
function BattleController:ctor() function BattleController:ctor()
@ -114,7 +120,10 @@ end
function BattleController:init(params) function BattleController:init(params)
params = params or {} params = params or {}
self.chapterId = self:getChapterId() self.chapterId = self:getChapterId()
self.waveIndex = 1 self.waveIndex = 0
self.maxWaveIndex = self:getMaxWave()
self.victory = false
self.roundStep = BattleConst.BATTLE_ROUND_STEP.WAIT_BEGIN
self.atkUnits = {} self.atkUnits = {}
self.defUnits = {} self.defUnits = {}
self.allUnits = {} self.allUnits = {}
@ -125,7 +134,6 @@ function BattleController:init(params)
BattleScheduler:init() BattleScheduler:init()
BattleHelper:init() BattleHelper:init()
self:prepareFight() self:prepareFight()
self:battleStart()
end end
function BattleController:prepareFight() function BattleController:prepareFight()
@ -144,7 +152,7 @@ function BattleController:prepareFight()
BattleHelper:setEffectTextCache(self.battleUI:getBattleNumber()) BattleHelper:setEffectTextCache(self.battleUI:getBattleNumber())
self:initAtkUnits(onPreloadFinished) self:initAtkUnits(onPreloadFinished)
self:initDefUnits(onPreloadFinished) self:initDefUnits(onPreloadFinished)
self:generateBoard() self:battleStart()
end) end)
self:loadOtherRes(onPreloadFinished) self:loadOtherRes(onPreloadFinished)
end end
@ -195,9 +203,117 @@ function BattleController:battleStart()
self.tickSid = BattleScheduler:scheduleGlobal(function(dt) self.tickSid = BattleScheduler:scheduleGlobal(function(dt)
self:_tick(dt) self:_tick(dt)
end, 0) end, 0)
self:enterNextWave()
end end
---- start 回合步骤
function BattleController:enterNextWave()
local atkTeam = self.battleData:getAtkTeam()
if not atkTeam or atkTeam:getIsDead() then
self.victory = false
self:battleEnd()
return
end
if self.waveIndex >= self.maxWaveIndex then
self.victory = true
self:battleEnd()
return
end
self.waveIndex = self.waveIndex + 1
if self.waveIndex == 1 then -- 第一波
self:generateBoard()
return
end
if self.isBossWave then -- 如果上一波是boss波次则重新生成棋盘
self:putBoardCacheSkill(function()
self:generateBoard()
end)
else
self:enterRoundBegin()
end
end
function BattleController:enterRoundBegin()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_BEGIN
self:onRoundBegin()
self:enterEliminationBegin()
end
function BattleController:enterEliminationBegin()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_BEGIN
self:onEliminationBegin()
self:popBoardCacheSkill(function()
self:enterElimination()
end)
end
function BattleController:enterElimination()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_ELIMINATION
end
function BattleController:enterAtkStep()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_ATK_STEP
self:exeInstructions(function()
self:enterAtkStepOver()
end)
end
function BattleController:enterAtkStepOver()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_ATK_STEP_OVER
local defTeam = self.battleData:getDefTeam()
if defTeam or defTeam:getIsDead() then -- 怪物死了, 直接进入刷新逻辑
self:enterRefreshBoard()
return
end
self:enterDefStep()
end
function BattleController:enterDefStep()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_DEF_STEP
-- defTodo
self:enterDefStepOver()
end
function BattleController:enterDefStepOver()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_DEF_STEP_OVER
local atkTeam = self.battleData:getAtkTeam()
if not atkTeam or atkTeam:getIsDead() then -- 英雄死了, 直接结算
self:enterNextWave()
return
end
---- 临时直接调用
self:enterRefreshBoard()
end
function BattleController:enterRefreshBoard()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_REFRESH_BOARD
self:fillBoard()
end
function BattleController:enterRoundEnd()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_END
local defTeam = self.battleData:getDefTeam()
if defTeam or defTeam:getIsDead() then -- 怪物死了, 直接进入刷新逻辑
self:enterNextWave()
return
end
self:enterRoundBegin()
end
---- end回合步骤
function BattleController:onTouchEvent(eventType, posId) function BattleController:onTouchEvent(eventType, posId)
if self.roundStep ~= BattleConst.BATTLE_ROUND_STEP.ON_ELIMINATION then
return
end
local entity = self.battleData:getGridEntity(posId) local entity = self.battleData:getGridEntity(posId)
if not entity:canLink() then if not entity:canLink() then
return return
@ -412,9 +528,7 @@ function BattleController:onLinkOver()
self.battleUI:disableUITouch() self.battleUI:disableUITouch()
self.battleUI:eliminationAni(sequence, function() self.battleUI:eliminationAni(sequence, function()
self:generateInstructions(skillEntity, linkElementType, influenceElementType, elementTypeMap) self:generateInstructions(skillEntity, linkElementType, influenceElementType, elementTypeMap)
self:exeInstructions(function() self:enterAtkStep()
self:fillBoard()
end)
end) end)
end end
@ -479,6 +593,7 @@ end
function BattleController:onFillBoardOver() function BattleController:onFillBoardOver()
self:generateSkill() self:generateSkill()
self.battleUI:refreshSkill() self.battleUI:refreshSkill()
self:enterRoundEnd()
end end
function BattleController:generateInstructions(skillEntity, elementType, influenceElementType, elementTypeMap) function BattleController:generateInstructions(skillEntity, elementType, influenceElementType, elementTypeMap)
@ -548,16 +663,18 @@ end
function BattleController:exeInstructions(callback) function BattleController:exeInstructions(callback)
Logger.logHighlight("--------exeInstructions----------") Logger.logHighlight("--------exeInstructions----------")
Logger.printTable(self.instructions) Logger.printTable(self.instructions)
if #self.instructions <= 0 then if not self.instructions or #self.instructions <= 0 then
callback() callback()
return return
end end
local instruction = table.remove(self.instructions) local instruction = table.remove(self.instructions)
local func = BattleController._doInstruction[instruction.name] local func = BattleController._doInstruction[instruction.name]
if func then if func then
func(self, instruction, callback) func(self, instruction, function()
self:exeInstructions(callback)
end)
else else
callback() self:exeInstructions(callback)
end end
end end
@ -571,22 +688,26 @@ function BattleController:generateBoard()
return return
end end
local skillCount = 0
local skillList = {}
for posId, entity in pairs(self.battleData:getGridEnties()) do
if entity:getSkillId() then
table.insert(skillList, {skillId = entity:getSkillId(), posId = posId})
skillCount = skillCount + 1
end
end
self.battleUI:cacheSkillAni(skillList, false, function()
self.curBoardIndex = (self.curBoardIndex or 0) + 1 self.curBoardIndex = (self.curBoardIndex or 0) + 1
local board = boardList[self.curBoardIndex] local board = boardList[self.curBoardIndex]
self.battleData:refreshBoard(board) self.battleData:refreshBoard(board)
self.battleUI:initGridCell() self.battleUI:initGridCell()
self:enterRoundBegin()
end
if skillCount > 0 then function BattleController:putBoardCacheSkill(callback)
if not self.battleUI then
return
end
self.battleData:cacheBoardSkill()
local skillList, skillCount = self.battleData:getCacheBoardSkill()
self.battleUI:cacheSkillAni(skillList, false, callback)
end
function BattleController:popBoardCacheSkill(callback)
local skillList, skillCount = self.battleData:getCacheBoardSkill()
self.battleData:clearCacheBoardSkill()
if self.battleUI and skillCount > 0 then
local posidList = {} local posidList = {}
for posId, entity in pairs(self.battleData:getGridEnties()) do for posId, entity in pairs(self.battleData:getGridEnties()) do
if entity:isEmptyIdle() then if entity:isEmptyIdle() then
@ -604,9 +725,12 @@ function BattleController:generateBoard()
break break
end end
end end
self.battleUI:cacheSkillAni(newSkillId, true) self.battleUI:cacheSkillAni(newSkillId, true, callback)
else
if callback then
callback()
end
end end
end)
end end
function BattleController:generateSkill() function BattleController:generateSkill()
@ -988,6 +1112,10 @@ function BattleController:_tick(dt)
self:tick(dt) self:tick(dt)
end end
function BattleController:battleEnd()
self:controllBattleEnd()
end
function BattleController:clear() function BattleController:clear()
if self.alreadyClear then if self.alreadyClear then
return return

View File

@ -73,4 +73,8 @@ function BattleControllerStage:getNotInvolvedSkills()
return self.notInvolvedSkills return self.notInvolvedSkills
end end
function BattleControllerStage:controllBattleEnd()
end
return BattleControllerStage return BattleControllerStage

View File

@ -186,6 +186,7 @@ function BattleUI:showBoardMask(elementType)
end end
function BattleUI:eliminationAni(sequence, callback) function BattleUI:eliminationAni(sequence, callback)
self:showMask(true)
if not sequence then if not sequence then
if callback then if callback then
callback() callback()
@ -193,7 +194,6 @@ function BattleUI:eliminationAni(sequence, callback)
return return
end end
self.boardMask:setVisible(true)
self.boardMask:getTransform():SetAsLastSibling() self.boardMask:getTransform():SetAsLastSibling()
if self.eliminationAniSeq then if self.eliminationAniSeq then
self.eliminationAniSeq:Kill() self.eliminationAniSeq:Kill()
@ -240,12 +240,12 @@ function BattleUI:eliminationAni(sequence, callback)
callback() callback()
end end
self.boardMask:setVisible(false)
self:refreshSkill() self:refreshSkill()
end) end)
end end
function BattleUI:fallGrid(listInfo, callback) function BattleUI:fallGrid(listInfo, callback)
self:showMask(false)
self.fallAniCount = 0 self.fallAniCount = 0
for posId, info in pairs(listInfo) do for posId, info in pairs(listInfo) do
self.fallAniCount = self.fallAniCount + 1 self.fallAniCount = self.fallAniCount + 1
@ -416,6 +416,13 @@ function BattleUI:doCachePopAni(skillInfo, callback)
end) end)
end end
function BattleUI:showMask(show)
if not self.boardMask then
return
end
self.boardMask:setVisible(show)
end
function BattleUI:clear() function BattleUI:clear()
if self.alreadyClear then if self.alreadyClear then
return return

View File

@ -274,6 +274,29 @@ function BattleData:changeSkillId(elementType, newId)
end end
end end
function BattleData:cacheBoardSkill()
self.cacheSkillList = {}
self.cacheSkillCount = 0
for posId, entity in pairs(self:getGridEnties()) do
if entity:getSkillId() then
table.insert(self.cacheSkillList, {skillId = entity:getSkillId(), posId = posId})
self.cacheSkillCount = self.cacheSkillCount + 1
end
end
end
function BattleData:getCacheBoardSkill()
if not self.cacheSkillList then
return self.cacheSkillList, 0
end
return self.cacheSkillList, self.cacheSkillCount
end
function BattleData:clearCacheBoardSkill()
self.cacheSkillList = {}
self.cacheSkillCount = 0
end
function BattleData:initTeam(side) function BattleData:initTeam(side)
local data = nil local data = nil
if side == BattleConst.SIDE_ATK then if side == BattleConst.SIDE_ATK then

View File

@ -107,4 +107,8 @@ function BattleTeamEntity:die()
self.isDead = true self.isDead = true
end end
function BattleTeamEntity:getIsDead()
return self.isDead
end
return BattleTeamEntity return BattleTeamEntity