battle team

This commit is contained in:
chenxi 2023-04-17 00:09:48 +08:00
parent 210be03aa4
commit 2f0e60fb5a
6 changed files with 122 additions and 47 deletions

View File

@ -32,6 +32,10 @@ function BattleUnitComp:getModelId()
return self.modelId
end
function BattleUnitComp:getMatchType()
return self.unitEntity:getMatchType()
end
function BattleUnitComp:_initBase()
self.isClear = false
self.isMove = false

View File

@ -1,5 +1,6 @@
local BattleHelper = require "app/module/battle/helper/battle_helper"
local BattleScheduler = require "app/module/battle/helper/battle_scheduler"
local BattleTeam = require "app/module/battle/team/battle_team"
local BattleController = class("BattleController")
@ -130,19 +131,24 @@ function BattleController:init(params)
self.maxWaveIndex = self:getMaxWave()
self.victory = false
self.roundStep = BattleConst.BATTLE_ROUND_STEP.WAIT_BEGIN
self.atkUnits = {}
self.defUnits = {}
self.allUnits = {}
self.effectTexts = {}
self.instructions = {}
self.time = 0
self.battleData:init()
BattleScheduler:init()
BattleHelper:init()
self:initBattleTeam()
self:initOther()
self:prepareFight()
end
function BattleController:initBattleTeam()
self.atkTeam = BattleTeam:create()
self.atkTeam:init(BattleConst.SIDE_ATK)
self.defTeam = BattleTeam:create()
self.defTeam:init(BattleConst.SIDE_DEF)
end
function BattleController:prepareFight()
local count = 0
local totalCount = 3
@ -164,25 +170,26 @@ function BattleController:prepareFight()
end
function BattleController:initAtkUnits(callback)
local atkTeam = self.battleData:getAtkTeam()
local atkTeamEntity = self.battleData:getAtkTeam()
local count = 0
local totalCount = atkTeam:getMembersCount()
local totalCount = atkTeamEntity:getMembersCount()
local function onloadFinished()
count = count + 1
if count == totalCount then
self.battleUI:refreshAtkHp(atkTeam:getHp(), atkTeam:getHpPercent())
self.battleUI:refreshAtkHp(atkTeamEntity:getHp(), atkTeamEntity:getHpPercent())
callback()
end
end
local members = atkTeam:getAllMembers()
local members = atkTeamEntity: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)
self.atkUnits[v:getMatchType()] = heroComp
table.insert(self.allUnits, heroComp)
if not v:getIsMainUnit() then
if v:getIsMainUnit() then
self.atkTeam:addUnit(heroComp, true)
else
self.atkTeam:addUnit(heroComp)
heroComp:hideOutsideScreen()
end
onloadFinished()
@ -203,9 +210,9 @@ end
function BattleController:getOtherSideMainUnit(side)
if side == BattleConst.SIDE_ATK then
return self.defMainUnit
return self.defTeam:getMainUnit()
else
return self.atkMainUnit
return self.atkTeam:getMainUnit()
end
end
@ -305,7 +312,7 @@ end
function BattleController:enterDefStep()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_DEF_STEP
self.defMainUnit:useAllSkills(function()
self.defTeam:mainUnitUseAllSkills(function()
self:enterDefStepOver()
end)
end
@ -1168,9 +1175,8 @@ function BattleController:_tick(dt)
return
end
self.time = self.time + dt
for k, v in ipairs(self.allUnits) do
v:tick(dt)
end
self.atkTeam:tick(dt)
self.defTeam:tick(dt)
local count = #self.effectTexts
for i = count, 1, -1 do
self.effectTexts[i]:tick(dt)
@ -1218,23 +1224,12 @@ local function _assisting(self, instruction, callback)
end
local function _generalAttack(self, instruction, callback)
local hero = self.atkUnits[instruction.skillMatch]
if hero == nil then
return callback()
end
self.atkMainUnit = hero
hero:useNormalSkill(instruction.count, callback)
self.atkTeam:useNormalSkill(instruction.skillMatch, instruction.count, callback)
end
local function _playSkill(self, instruction, callback)
local hero = self.atkUnits[instruction.skillMatch]
if hero == nil then
return callback()
self.atkTeam:useSkill(instruction.skillMatch, callback)
end
self.atkMainUnit = hero
hero:useSkill(1, callback)
end
BattleController._doInstruction = {
[BattleConst.INSTRUCTION_NAME.ADD_CUR_ROUND_ATTR] = _addCurRoundAttr,

View File

@ -24,9 +24,7 @@ function BattleControllerStage:initDefUnits(callback)
BattleHelper:loadBattleHeroModel(modelId, self.battleUI:getBattleNode(), function(spineObject)
local monsterComp = spineObject:addLuaComponent(GConst.BattleConst.TYPEOF_LUA_COMP.BATTLE_MONSTER_COMPONENT)
monsterComp:initWithEntity(modelId, unitEntity, self)
self.defUnits[unitEntity:getMatchType()] = monsterComp
table.insert(self.allUnits, monsterComp)
self.defMainUnit = monsterComp
self.defTeam:addUnit(monsterComp, true)
self.battleUI:refreshDefHp(unitEntity:getHp(), unitEntity:getHpPercent())
callback()
end)
@ -37,22 +35,11 @@ function BattleControllerStage:_stageGenerateNextMonster()
local unitEntity = DataManager.BattleData:addMonster(config.monster[self.waveIndex], true)
local modelId = unitEntity:getModelId()
BattleHelper:loadBattleHeroModel(modelId, self.battleUI:getBattleNode(), function(spineObject)
if self.defMainUnit then
for k, v in ipairs(self.allUnits) do
if v == self.defMainUnit then
table.remove(self.allUnits, k)
break
end
end
self.defMainUnit:recycle()
end
self.defTeam:removeAllUnits()
local monsterComp = spineObject:addLuaComponent(GConst.BattleConst.TYPEOF_LUA_COMP.BATTLE_MONSTER_COMPONENT)
monsterComp:initWithEntity(modelId, unitEntity, self)
self.defUnits[unitEntity:getMatchType()] = monsterComp
table.insert(self.allUnits, monsterComp)
self.defMainUnit = monsterComp
self.defMainUnit:playEnterBattlefield(function()
self.defTeam:addUnit(monsterComp, true)
monsterComp:playEnterBattlefield(function()
self:enterNextWave()
self:enterRefreshBoard()
end)
@ -107,7 +94,7 @@ function BattleControllerStage:getNotInvolvedSkills()
end
function BattleControllerStage:findNextDefUnit()
self.defMainUnit:playDead(function()
self.defTeam:getMainUnit():playDead(function()
self:_stageGenerateNextMonster()
end)
end

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3401612032d992f43a88efbb82ff9ca7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,71 @@
local BattleTeam = class("BattleTeam")
function BattleTeam:init(side)
self.side = side
self.unitList = {}
self.unitMap = {}
end
function BattleTeam:addUnit(unit, isMainUnit)
self.unitMap[unit:getMatchType()] = unit
table.insert(self.unitList, unit)
if isMainUnit then
self.mainUnit = unit
end
end
function BattleTeam:getMainUnit()
return self.mainUnit
end
function BattleTeam:removeAllUnits()
for k, v in pairs(self.unitMap) do
self.unitMap[k] = nil
end
local count = #self.unitList
for i = 1, count do
self.unitList[i]:recycle()
table.remove(self.unitList)
end
self.mainUnit = nil
end
function BattleTeam:useNormalSkill(matchType, count, callback)
local unit = nil
if matchType == nil then
unit = self.unitList[1]
else
unit = self.unitMap[matchType]
end
if unit == nil then
return callback()
end
self.mainUnit = unit
unit:useNormalSkill(count, callback)
end
function BattleTeam:useSkill(matchType, callback)
local unit = nil
if matchType == nil then
unit = self.unitList[1]
else
unit = self.unitMap[matchType]
end
if unit == nil then
return callback()
end
self.mainUnit = unit
unit:useSkill(1, callback)
end
function BattleTeam:mainUnitUseAllSkills()
self.mainUnit:useAllSkills()
end
function BattleTeam:tick(dt)
for k, v in ipairs(self.unitList) do
v:tick(dt)
end
end
return BattleTeam

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 39135bd7b51505c4d873a1f99917dc5d
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}