battle team
This commit is contained in:
parent
210be03aa4
commit
2f0e60fb5a
@ -32,6 +32,10 @@ function BattleUnitComp:getModelId()
|
|||||||
return self.modelId
|
return self.modelId
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleUnitComp:getMatchType()
|
||||||
|
return self.unitEntity:getMatchType()
|
||||||
|
end
|
||||||
|
|
||||||
function BattleUnitComp:_initBase()
|
function BattleUnitComp:_initBase()
|
||||||
self.isClear = false
|
self.isClear = false
|
||||||
self.isMove = false
|
self.isMove = false
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
local BattleHelper = require "app/module/battle/helper/battle_helper"
|
local BattleHelper = require "app/module/battle/helper/battle_helper"
|
||||||
local BattleScheduler = require "app/module/battle/helper/battle_scheduler"
|
local BattleScheduler = require "app/module/battle/helper/battle_scheduler"
|
||||||
|
local BattleTeam = require "app/module/battle/team/battle_team"
|
||||||
|
|
||||||
local BattleController = class("BattleController")
|
local BattleController = class("BattleController")
|
||||||
|
|
||||||
@ -130,19 +131,24 @@ function BattleController:init(params)
|
|||||||
self.maxWaveIndex = self:getMaxWave()
|
self.maxWaveIndex = self:getMaxWave()
|
||||||
self.victory = false
|
self.victory = false
|
||||||
self.roundStep = BattleConst.BATTLE_ROUND_STEP.WAIT_BEGIN
|
self.roundStep = BattleConst.BATTLE_ROUND_STEP.WAIT_BEGIN
|
||||||
self.atkUnits = {}
|
|
||||||
self.defUnits = {}
|
|
||||||
self.allUnits = {}
|
|
||||||
self.effectTexts = {}
|
self.effectTexts = {}
|
||||||
self.instructions = {}
|
self.instructions = {}
|
||||||
self.time = 0
|
self.time = 0
|
||||||
self.battleData:init()
|
self.battleData:init()
|
||||||
BattleScheduler:init()
|
BattleScheduler:init()
|
||||||
BattleHelper:init()
|
BattleHelper:init()
|
||||||
|
self:initBattleTeam()
|
||||||
self:initOther()
|
self:initOther()
|
||||||
self:prepareFight()
|
self:prepareFight()
|
||||||
end
|
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()
|
function BattleController:prepareFight()
|
||||||
local count = 0
|
local count = 0
|
||||||
local totalCount = 3
|
local totalCount = 3
|
||||||
@ -164,25 +170,26 @@ function BattleController:prepareFight()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function BattleController:initAtkUnits(callback)
|
function BattleController:initAtkUnits(callback)
|
||||||
local atkTeam = self.battleData:getAtkTeam()
|
local atkTeamEntity = self.battleData:getAtkTeam()
|
||||||
local count = 0
|
local count = 0
|
||||||
local totalCount = atkTeam:getMembersCount()
|
local totalCount = atkTeamEntity:getMembersCount()
|
||||||
local function onloadFinished()
|
local function onloadFinished()
|
||||||
count = count + 1
|
count = count + 1
|
||||||
if count == totalCount then
|
if count == totalCount then
|
||||||
self.battleUI:refreshAtkHp(atkTeam:getHp(), atkTeam:getHpPercent())
|
self.battleUI:refreshAtkHp(atkTeamEntity:getHp(), atkTeamEntity:getHpPercent())
|
||||||
callback()
|
callback()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local members = atkTeam:getAllMembers()
|
local members = atkTeamEntity:getAllMembers()
|
||||||
for k, v in pairs(members) do
|
for k, v in pairs(members) do
|
||||||
local modelId = v:getModelId()
|
local modelId = v:getModelId()
|
||||||
BattleHelper:loadBattleHeroModel(modelId, self.battleUI:getBattleNode(), function(spineObject)
|
BattleHelper:loadBattleHeroModel(modelId, self.battleUI:getBattleNode(), function(spineObject)
|
||||||
local heroComp = spineObject:addLuaComponent(BattleConst.TYPEOF_LUA_COMP.BATTLE_HERO_COMPONENT)
|
local heroComp = spineObject:addLuaComponent(BattleConst.TYPEOF_LUA_COMP.BATTLE_HERO_COMPONENT)
|
||||||
heroComp:initWithEntity(modelId, v, self)
|
heroComp:initWithEntity(modelId, v, self)
|
||||||
self.atkUnits[v:getMatchType()] = heroComp
|
if v:getIsMainUnit() then
|
||||||
table.insert(self.allUnits, heroComp)
|
self.atkTeam:addUnit(heroComp, true)
|
||||||
if not v:getIsMainUnit() then
|
else
|
||||||
|
self.atkTeam:addUnit(heroComp)
|
||||||
heroComp:hideOutsideScreen()
|
heroComp:hideOutsideScreen()
|
||||||
end
|
end
|
||||||
onloadFinished()
|
onloadFinished()
|
||||||
@ -203,9 +210,9 @@ end
|
|||||||
|
|
||||||
function BattleController:getOtherSideMainUnit(side)
|
function BattleController:getOtherSideMainUnit(side)
|
||||||
if side == BattleConst.SIDE_ATK then
|
if side == BattleConst.SIDE_ATK then
|
||||||
return self.defMainUnit
|
return self.defTeam:getMainUnit()
|
||||||
else
|
else
|
||||||
return self.atkMainUnit
|
return self.atkTeam:getMainUnit()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -305,7 +312,7 @@ end
|
|||||||
function BattleController:enterDefStep()
|
function BattleController:enterDefStep()
|
||||||
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_DEF_STEP
|
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_DEF_STEP
|
||||||
|
|
||||||
self.defMainUnit:useAllSkills(function()
|
self.defTeam:mainUnitUseAllSkills(function()
|
||||||
self:enterDefStepOver()
|
self:enterDefStepOver()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@ -1168,9 +1175,8 @@ function BattleController:_tick(dt)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.time = self.time + dt
|
self.time = self.time + dt
|
||||||
for k, v in ipairs(self.allUnits) do
|
self.atkTeam:tick(dt)
|
||||||
v:tick(dt)
|
self.defTeam:tick(dt)
|
||||||
end
|
|
||||||
local count = #self.effectTexts
|
local count = #self.effectTexts
|
||||||
for i = count, 1, -1 do
|
for i = count, 1, -1 do
|
||||||
self.effectTexts[i]:tick(dt)
|
self.effectTexts[i]:tick(dt)
|
||||||
@ -1218,24 +1224,13 @@ local function _assisting(self, instruction, callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function _generalAttack(self, instruction, callback)
|
local function _generalAttack(self, instruction, callback)
|
||||||
local hero = self.atkUnits[instruction.skillMatch]
|
self.atkTeam:useNormalSkill(instruction.skillMatch, instruction.count, callback)
|
||||||
if hero == nil then
|
|
||||||
return callback()
|
|
||||||
end
|
|
||||||
self.atkMainUnit = hero
|
|
||||||
hero:useNormalSkill(instruction.count, callback)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function _playSkill(self, instruction, callback)
|
local function _playSkill(self, instruction, callback)
|
||||||
local hero = self.atkUnits[instruction.skillMatch]
|
self.atkTeam:useSkill(instruction.skillMatch, callback)
|
||||||
if hero == nil then
|
|
||||||
return callback()
|
|
||||||
end
|
|
||||||
self.atkMainUnit = hero
|
|
||||||
hero:useSkill(1, callback)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
BattleController._doInstruction = {
|
BattleController._doInstruction = {
|
||||||
[BattleConst.INSTRUCTION_NAME.ADD_CUR_ROUND_ATTR] = _addCurRoundAttr,
|
[BattleConst.INSTRUCTION_NAME.ADD_CUR_ROUND_ATTR] = _addCurRoundAttr,
|
||||||
[BattleConst.INSTRUCTION_NAME.ASSISTING] = _assisting,
|
[BattleConst.INSTRUCTION_NAME.ASSISTING] = _assisting,
|
||||||
|
|||||||
@ -24,9 +24,7 @@ function BattleControllerStage:initDefUnits(callback)
|
|||||||
BattleHelper:loadBattleHeroModel(modelId, self.battleUI:getBattleNode(), function(spineObject)
|
BattleHelper:loadBattleHeroModel(modelId, self.battleUI:getBattleNode(), function(spineObject)
|
||||||
local monsterComp = spineObject:addLuaComponent(GConst.BattleConst.TYPEOF_LUA_COMP.BATTLE_MONSTER_COMPONENT)
|
local monsterComp = spineObject:addLuaComponent(GConst.BattleConst.TYPEOF_LUA_COMP.BATTLE_MONSTER_COMPONENT)
|
||||||
monsterComp:initWithEntity(modelId, unitEntity, self)
|
monsterComp:initWithEntity(modelId, unitEntity, self)
|
||||||
self.defUnits[unitEntity:getMatchType()] = monsterComp
|
self.defTeam:addUnit(monsterComp, true)
|
||||||
table.insert(self.allUnits, monsterComp)
|
|
||||||
self.defMainUnit = monsterComp
|
|
||||||
self.battleUI:refreshDefHp(unitEntity:getHp(), unitEntity:getHpPercent())
|
self.battleUI:refreshDefHp(unitEntity:getHp(), unitEntity:getHpPercent())
|
||||||
callback()
|
callback()
|
||||||
end)
|
end)
|
||||||
@ -37,22 +35,11 @@ function BattleControllerStage:_stageGenerateNextMonster()
|
|||||||
local unitEntity = DataManager.BattleData:addMonster(config.monster[self.waveIndex], true)
|
local unitEntity = DataManager.BattleData:addMonster(config.monster[self.waveIndex], true)
|
||||||
local modelId = unitEntity:getModelId()
|
local modelId = unitEntity:getModelId()
|
||||||
BattleHelper:loadBattleHeroModel(modelId, self.battleUI:getBattleNode(), function(spineObject)
|
BattleHelper:loadBattleHeroModel(modelId, self.battleUI:getBattleNode(), function(spineObject)
|
||||||
if self.defMainUnit then
|
self.defTeam:removeAllUnits()
|
||||||
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
|
|
||||||
|
|
||||||
local monsterComp = spineObject:addLuaComponent(GConst.BattleConst.TYPEOF_LUA_COMP.BATTLE_MONSTER_COMPONENT)
|
local monsterComp = spineObject:addLuaComponent(GConst.BattleConst.TYPEOF_LUA_COMP.BATTLE_MONSTER_COMPONENT)
|
||||||
monsterComp:initWithEntity(modelId, unitEntity, self)
|
monsterComp:initWithEntity(modelId, unitEntity, self)
|
||||||
self.defUnits[unitEntity:getMatchType()] = monsterComp
|
self.defTeam:addUnit(monsterComp, true)
|
||||||
table.insert(self.allUnits, monsterComp)
|
monsterComp:playEnterBattlefield(function()
|
||||||
self.defMainUnit = monsterComp
|
|
||||||
self.defMainUnit:playEnterBattlefield(function()
|
|
||||||
self:enterNextWave()
|
self:enterNextWave()
|
||||||
self:enterRefreshBoard()
|
self:enterRefreshBoard()
|
||||||
end)
|
end)
|
||||||
@ -107,7 +94,7 @@ function BattleControllerStage:getNotInvolvedSkills()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function BattleControllerStage:findNextDefUnit()
|
function BattleControllerStage:findNextDefUnit()
|
||||||
self.defMainUnit:playDead(function()
|
self.defTeam:getMainUnit():playDead(function()
|
||||||
self:_stageGenerateNextMonster()
|
self:_stageGenerateNextMonster()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
8
lua/app/module/battle/team.meta
Normal file
8
lua/app/module/battle/team.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3401612032d992f43a88efbb82ff9ca7
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
71
lua/app/module/battle/team/battle_team.lua
Normal file
71
lua/app/module/battle/team/battle_team.lua
Normal 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
|
||||||
10
lua/app/module/battle/team/battle_team.lua.meta
Normal file
10
lua/app/module/battle/team/battle_team.lua.meta
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 39135bd7b51505c4d873a1f99917dc5d
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}
|
||||||
Loading…
x
Reference in New Issue
Block a user