c1_lua/lua/app/module/battle/controller/battle_controller_pvp.lua
2023-06-28 21:24:15 +08:00

297 lines
9.1 KiB
Lua

local BattleHelper = require "app/module/battle/helper/battle_helper"
local BattleBaseController = require "app/module/battle/controller/battle_base_controller"
local BattleControllerPVP = class("BattleControllerPVP", BattleBaseController)
local BattleConst = GConst.BattleConst
local SIDE_ATK = BattleConst.SIDE_ATK
local SIDE_DEF = BattleConst.SIDE_DEF
-- *************各个子模块的战斗需要重写的方法 START*************
function BattleControllerPVP:getBoardConfig()
return {}
end
function BattleControllerPVP:getChapterConfig()
return {}
end
function BattleControllerPVP:getChapterId()
return 0
end
function BattleControllerPVP:getBuffs()
return {}
end
-- 战斗对应的ui
function BattleControllerPVP:getBattleUIPath()
return "app/ui/battle/battle_ui_pvp"
end
-- 战斗结束
function BattleControllerPVP:controllBattleEnd()
end
-- 一共有多少波
function BattleControllerPVP:getMaxWave()
return 1
end
function BattleControllerPVP:findNextDefUnit()
self:enterRoundEnd(true)
end
function BattleControllerPVP:postWaveOver(atkDead, isQuit)
end
function BattleControllerPVP:postFightStart()
end
function BattleControllerPVP:getMaxRoundCount()
return 1
end
-- *************各个子模块的战斗需要重写的方法 END*************
function BattleControllerPVP:ctor()
self.battleData = DataManager.BattlePVPData
end
function BattleControllerPVP:initDefUnits(callback)
local defTeamEntity = self.battleData:getDefTeam()
local count = 0
local totalCount = defTeamEntity:getMembersCount()
local function onloadFinished()
count = count + 1
if count == totalCount then
self.battleUI:refreshAtkHp(defTeamEntity:getHp(), defTeamEntity:getHpPercent())
callback()
end
end
local members = defTeamEntity:getAllMembers()
for k, v in pairs(members) do
local modelId = v:getModelId()
BattleHelper:loadBattleHeroModel(modelId, self.battleUI:getBattleNode(), function(spineObject)
local heroComp = spineObject:addLuaComponent(BattleConst.TYPEOF_LUA_COMP.BATTLE_HERO_COMPONENT)
heroComp:initWithEntity(modelId, v, self)
if v:getIsMainUnit() then
self.defTeam:addUnit(heroComp, true)
else
self.defTeam:addUnit(heroComp)
heroComp:hideOutsideScreen()
end
onloadFinished()
end)
end
if totalCount == 0 then
callback()
end
end
function BattleControllerPVP:onLoadComplete(...)
-- 处理技能
local unlockAllSkill = function(side)
local skillPool = self.battleData:getSkillPool(side)
if skillPool then
for elementType, list in pairs(skillPool) do -- 先遍历一下未解锁的技能
if not self.battleData:isUnlockedSkillElementType(elementType, side) then
local skillEntity = self.battleData:getSkillEntityByElement(elementType, side)
if skillEntity then
local skillId = skillEntity:getUnlockId()
if skillId then
self:dealSelectSkill(skillId, nil, side)
end
end
for _, skillId in ipairs(list) do
self:dealSelectSkill(skillId, nil, side)
end
end
end
self.battleUI:refreshSkill(nil, nil, side)
end
end
unlockAllSkill(SIDE_ATK)
unlockAllSkill(SIDE_DEF)
BattleBaseController.onLoadComplete(self, ...)
end
function BattleControllerPVP:enterBattleStep()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_TEAM_ACTION
self.battleTeamActionList = table.clearOrCreate(self.battleTeamActionList)
local action = function()
if self.curActionSide == SIDE_ATK then
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_ATK_STEP
else
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_DEF_STEP
end
self:exeInstructions(function()
self:enterNextTeamAction()
end, self.curActionSide)
end
self:addTeamActionList(action, 1)
self:enterNextTeamAction()
end
function BattleControllerPVP:enterNextTeamAction()
self.atkTeam:onActionOver()
self.defTeam:onActionOver()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_TEAM_ACTION_OVER
self:hideCombo()
self:hideCounterAttack()
if self:checkTeamIsDead(function() self:enterRoundEnd() end) then
return
end
if not self.battleTeamActionList or not self.battleTeamActionList[1] then
if self.curActionSide == SIDE_DEF then -- 防守方行动结束 回合结束
self:enterRoundEnd()
else
self:setCurActionSide(SIDE_DEF)
self.battleUI:enterShowBoardAni(function()
self:enterElimination()
end)
end
return
end
local action = table.remove(self.battleTeamActionList, 1)
action()
end
function BattleControllerPVP:getSkillElementListRow()
self.skillElementListRow = table.clearOrCreate(self.skillElementListRow)
local min, max = self:getCurActionBoardRowRange()
if self.curActionSide == SIDE_ATK then
for row = max, min, -1 do
table.insert(self.skillElementListRow, row)
end
else
for row = min, max do
table.insert(self.skillElementListRow, row)
end
end
return self.skillElementListRow
end
function BattleControllerPVP:onFillBoardOver(...)
BattleBaseController.onFillBoardOver(self, ...)
--- 遍历
local index = 1
for posId, entity in pairs(self.battleData:getGridEnties()) do
if self:getPosIdInCurActionBoardRowRange(posId) and entity:getSkillId() then
if entity:getSkillSide() ~= self.curActionSide then
local skillMatchType = entity:getSkillMatchType()
if skillMatchType then
local skillEntity = self.battleData:getSkillEntityByElement(skillMatchType, self.curActionSide)
if skillEntity then
entity:setSkilId(skillEntity:getSkillId(), false, self.curActionSide)
self.battleUI:playChangeElementSfx(posId, index)
index = index + 1
end
end
end
end
end
end
function BattleControllerPVP:enterElimination(needDelay)
if self.showSelectSkillSid then
ModuleManager.BattleManager:unscheduleGlobal(self.showSelectSkillSid)
self.showSelectSkillSid = nil
end
if self.battleData:useAddlvCount() then
self:tryShowSelectSkillComp(needDelay)
return
end
self.battleUI:hideAllBoardSfxs()
local curActionUnitComp = self:getCurActionUnitComp()
if curActionUnitComp:getIsLimit() then
if curActionUnitComp:getIsFrozen() then
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ARENA_BATTLE_DESC_4))
elseif curActionUnitComp:getIsLethargy() then
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ARENA_BATTLE_DESC_5))
elseif curActionUnitComp:getIsStun() then
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ARENA_BATTLE_DESC_3))
end
self:enterNextTeamAction()
return
end
-- 检查棋盘
local find, pathList = self:findAttention()
if not find then -- 如果没找到,就要打乱棋盘
self:shuffleBoard(function()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_ELIMINATION
end)
else
self.attentionList = pathList
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_ELIMINATION
end
end
function BattleControllerPVP:enterRoundBegin(...)
local nextWaveRound = (self.waveRoundCount[self.waveIndex] or 0) + 1
if self:getMaxRoundCount() < nextWaveRound then -- 超过最大回合, 直接结算
self.victory = false
self:postWaveOver(false)
self:battleEnd()
return
end
BattleBaseController.enterRoundBegin(self, ...)
self:refreshWave()
end
function BattleControllerPVP:enterRoundEnd()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_END
local defTeam = self.battleData:getDefTeam()
if not defTeam or defTeam:getIsDead() then -- 怪物死了, 直接进入刷新逻辑
self.curWaveMonsterDead = true
-- self.atkTeam:onRoundEnd()
self:enterNextWave()
return
end
local atkTeam = self.battleData:getAtkTeam()
if not atkTeam or atkTeam:getIsDead() then -- 英雄死了, 直接结算
-- self.defTeam:onRoundEnd()
self:enterNextWave()
return
end
-- self.atkTeam:onRoundEnd()
-- self.defTeam:onRoundEnd()
if self:checkTeamIsDead(function() self:enterNextWave() end) then
return
end
self:onRoundEnd()
end
function BattleControllerPVP:setCurActionSide(side)
self.curActionSide = side or SIDE_ATK
if self.curActionSide == SIDE_ATK then
self.atkTeam:onRoundEnd()
else
self.defTeam:onRoundEnd()
end
end
function BattleControllerPVP:refreshWave()
if not self.battleUI then
return
end
self.battleUI:refreshWave(self.waveRoundCount[self.waveIndex] or 0)
end
return BattleControllerPVP