战斗回合概念
This commit is contained in:
parent
ab14bce85c
commit
642eb4d247
@ -23,6 +23,19 @@ BattleConst.UNIT_FRONT_DISTANCE = 50
|
||||
BattleConst.MOVE_SPEED = 500 -- 战斗单位的移动速度
|
||||
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 = {
|
||||
STAGE = "1",
|
||||
|
||||
@ -98,13 +98,19 @@ function BattleController:onLinkChange()
|
||||
end
|
||||
|
||||
self.battleUI:refreshSkill(elementTypeMap)
|
||||
Logger.logHighlight("---------onLinkChange--------------")
|
||||
Logger.printTable(elementTypeMap)
|
||||
if mainElementType then
|
||||
Logger.logHighlight("mainElementType " .. mainElementType)
|
||||
end
|
||||
end
|
||||
|
||||
function BattleController:onRoundBegin()
|
||||
|
||||
end
|
||||
|
||||
function BattleController:onEliminationBegin()
|
||||
|
||||
end
|
||||
|
||||
-- *************各个子模块的战斗需要重写的方法 END*************
|
||||
|
||||
function BattleController:ctor()
|
||||
@ -114,7 +120,10 @@ end
|
||||
function BattleController:init(params)
|
||||
params = params or {}
|
||||
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.defUnits = {}
|
||||
self.allUnits = {}
|
||||
@ -125,7 +134,6 @@ function BattleController:init(params)
|
||||
BattleScheduler:init()
|
||||
BattleHelper:init()
|
||||
self:prepareFight()
|
||||
self:battleStart()
|
||||
end
|
||||
|
||||
function BattleController:prepareFight()
|
||||
@ -144,7 +152,7 @@ function BattleController:prepareFight()
|
||||
BattleHelper:setEffectTextCache(self.battleUI:getBattleNumber())
|
||||
self:initAtkUnits(onPreloadFinished)
|
||||
self:initDefUnits(onPreloadFinished)
|
||||
self:generateBoard()
|
||||
self:battleStart()
|
||||
end)
|
||||
self:loadOtherRes(onPreloadFinished)
|
||||
end
|
||||
@ -195,9 +203,117 @@ function BattleController:battleStart()
|
||||
self.tickSid = BattleScheduler:scheduleGlobal(function(dt)
|
||||
self:_tick(dt)
|
||||
end, 0)
|
||||
self:enterNextWave()
|
||||
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)
|
||||
if self.roundStep ~= BattleConst.BATTLE_ROUND_STEP.ON_ELIMINATION then
|
||||
return
|
||||
end
|
||||
local entity = self.battleData:getGridEntity(posId)
|
||||
if not entity:canLink() then
|
||||
return
|
||||
@ -412,9 +528,7 @@ function BattleController:onLinkOver()
|
||||
self.battleUI:disableUITouch()
|
||||
self.battleUI:eliminationAni(sequence, function()
|
||||
self:generateInstructions(skillEntity, linkElementType, influenceElementType, elementTypeMap)
|
||||
self:exeInstructions(function()
|
||||
self:fillBoard()
|
||||
end)
|
||||
self:enterAtkStep()
|
||||
end)
|
||||
end
|
||||
|
||||
@ -479,6 +593,7 @@ end
|
||||
function BattleController:onFillBoardOver()
|
||||
self:generateSkill()
|
||||
self.battleUI:refreshSkill()
|
||||
self:enterRoundEnd()
|
||||
end
|
||||
|
||||
function BattleController:generateInstructions(skillEntity, elementType, influenceElementType, elementTypeMap)
|
||||
@ -548,16 +663,18 @@ end
|
||||
function BattleController:exeInstructions(callback)
|
||||
Logger.logHighlight("--------exeInstructions----------")
|
||||
Logger.printTable(self.instructions)
|
||||
if #self.instructions <= 0 then
|
||||
if not self.instructions or #self.instructions <= 0 then
|
||||
callback()
|
||||
return
|
||||
end
|
||||
local instruction = table.remove(self.instructions)
|
||||
local func = BattleController._doInstruction[instruction.name]
|
||||
if func then
|
||||
func(self, instruction, callback)
|
||||
func(self, instruction, function()
|
||||
self:exeInstructions(callback)
|
||||
end)
|
||||
else
|
||||
callback()
|
||||
self:exeInstructions(callback)
|
||||
end
|
||||
end
|
||||
|
||||
@ -571,42 +688,49 @@ function BattleController:generateBoard()
|
||||
return
|
||||
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
|
||||
self.curBoardIndex = (self.curBoardIndex or 0) + 1
|
||||
local board = boardList[self.curBoardIndex]
|
||||
self.battleData:refreshBoard(board)
|
||||
self.battleUI:initGridCell()
|
||||
self:enterRoundBegin()
|
||||
end
|
||||
|
||||
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 = {}
|
||||
for posId, entity in pairs(self.battleData:getGridEnties()) do
|
||||
if entity:isEmptyIdle() then
|
||||
table.insert(posidList, posId)
|
||||
end
|
||||
end
|
||||
|
||||
posidList = table.shuffle(posidList)
|
||||
local newSkillId = {}
|
||||
for index, info in ipairs(skillList) do
|
||||
if posidList[1] then
|
||||
newSkillId[index] = info
|
||||
newSkillId[index].posId = table.remove(posidList)
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
self.battleUI:cacheSkillAni(newSkillId, true, callback)
|
||||
else
|
||||
if callback then
|
||||
callback()
|
||||
end
|
||||
end
|
||||
|
||||
self.battleUI:cacheSkillAni(skillList, false, function()
|
||||
self.curBoardIndex = (self.curBoardIndex or 0) + 1
|
||||
local board = boardList[self.curBoardIndex]
|
||||
self.battleData:refreshBoard(board)
|
||||
self.battleUI:initGridCell()
|
||||
|
||||
if skillCount > 0 then
|
||||
local posidList = {}
|
||||
for posId, entity in pairs(self.battleData:getGridEnties()) do
|
||||
if entity:isEmptyIdle() then
|
||||
table.insert(posidList, posId)
|
||||
end
|
||||
end
|
||||
|
||||
posidList = table.shuffle(posidList)
|
||||
local newSkillId = {}
|
||||
for index, info in ipairs(skillList) do
|
||||
if posidList[1] then
|
||||
newSkillId[index] = info
|
||||
newSkillId[index].posId = table.remove(posidList)
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
self.battleUI:cacheSkillAni(newSkillId, true)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function BattleController:generateSkill()
|
||||
@ -988,6 +1112,10 @@ function BattleController:_tick(dt)
|
||||
self:tick(dt)
|
||||
end
|
||||
|
||||
function BattleController:battleEnd()
|
||||
self:controllBattleEnd()
|
||||
end
|
||||
|
||||
function BattleController:clear()
|
||||
if self.alreadyClear then
|
||||
return
|
||||
|
||||
@ -73,4 +73,8 @@ function BattleControllerStage:getNotInvolvedSkills()
|
||||
return self.notInvolvedSkills
|
||||
end
|
||||
|
||||
function BattleControllerStage:controllBattleEnd()
|
||||
|
||||
end
|
||||
|
||||
return BattleControllerStage
|
||||
@ -186,6 +186,7 @@ function BattleUI:showBoardMask(elementType)
|
||||
end
|
||||
|
||||
function BattleUI:eliminationAni(sequence, callback)
|
||||
self:showMask(true)
|
||||
if not sequence then
|
||||
if callback then
|
||||
callback()
|
||||
@ -193,7 +194,6 @@ function BattleUI:eliminationAni(sequence, callback)
|
||||
return
|
||||
end
|
||||
|
||||
self.boardMask:setVisible(true)
|
||||
self.boardMask:getTransform():SetAsLastSibling()
|
||||
if self.eliminationAniSeq then
|
||||
self.eliminationAniSeq:Kill()
|
||||
@ -240,12 +240,12 @@ function BattleUI:eliminationAni(sequence, callback)
|
||||
callback()
|
||||
end
|
||||
|
||||
self.boardMask:setVisible(false)
|
||||
self:refreshSkill()
|
||||
end)
|
||||
end
|
||||
|
||||
function BattleUI:fallGrid(listInfo, callback)
|
||||
self:showMask(false)
|
||||
self.fallAniCount = 0
|
||||
for posId, info in pairs(listInfo) do
|
||||
self.fallAniCount = self.fallAniCount + 1
|
||||
@ -416,6 +416,13 @@ function BattleUI:doCachePopAni(skillInfo, callback)
|
||||
end)
|
||||
end
|
||||
|
||||
function BattleUI:showMask(show)
|
||||
if not self.boardMask then
|
||||
return
|
||||
end
|
||||
self.boardMask:setVisible(show)
|
||||
end
|
||||
|
||||
function BattleUI:clear()
|
||||
if self.alreadyClear then
|
||||
return
|
||||
|
||||
@ -274,6 +274,29 @@ function BattleData:changeSkillId(elementType, newId)
|
||||
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)
|
||||
local data = nil
|
||||
if side == BattleConst.SIDE_ATK then
|
||||
|
||||
@ -107,4 +107,8 @@ function BattleTeamEntity:die()
|
||||
self.isDead = true
|
||||
end
|
||||
|
||||
function BattleTeamEntity:getIsDead()
|
||||
return self.isDead
|
||||
end
|
||||
|
||||
return BattleTeamEntity
|
||||
Loading…
x
Reference in New Issue
Block a user