切波次

This commit is contained in:
chenxi 2023-04-16 22:23:34 +08:00
parent f291195ccd
commit fc44d4dc8f
6 changed files with 118 additions and 21 deletions

View File

@ -53,12 +53,13 @@ BattleConst.SKILL_MOVE_TYPE = {
} }
BattleConst.UNIT_STATE = { BattleConst.UNIT_STATE = {
INIT = 0, INIT = 0, -- 初始化
IDLE = 1, -- 待机 IDLE = 1, -- 待机
NORMAL_ATTACK = 2, -- 普通攻击 NORMAL_ATTACK = 2, -- 普通攻击
SKILL = 3, -- 技能 SKILL = 3, -- 技能
HURT = 4, -- 受伤 HURT = 4, -- 受伤
DEAD = 5, -- 死亡 DEAD = 5, -- 死亡
ENTER_BATTLEFIELD = 6, -- 进入战场
} }
BattleConst.MATCH_DMG_ADDITION_NAME = { BattleConst.MATCH_DMG_ADDITION_NAME = {

View File

@ -28,6 +28,10 @@ function BattleUnitComp:playBorn()
self:changeState(UNIT_STATE.IDLE) self:changeState(UNIT_STATE.IDLE)
end end
function BattleUnitComp:getModelId()
return self.modelId
end
function BattleUnitComp:_initBase() function BattleUnitComp:_initBase()
self.isClear = false self.isClear = false
self.isMove = false self.isMove = false
@ -117,6 +121,8 @@ function BattleUnitComp:changeState(state)
self:exitSkillState() self:exitSkillState()
elseif self.currState == UNIT_STATE.DEAD then elseif self.currState == UNIT_STATE.DEAD then
self:exitDeadState() self:exitDeadState()
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
self:exitEnterBattlefieldState()
end end
-- 进入目标状态 -- 进入目标状态
self.currState = state self.currState = state
@ -130,19 +136,17 @@ function BattleUnitComp:changeState(state)
self:enterDeadState() self:enterDeadState()
elseif self.currState == UNIT_STATE.BORN then elseif self.currState == UNIT_STATE.BORN then
self:enterBornState() self:enterBornState()
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
self:enterEnterBattlefieldState()
end end
return true return true
end end
function BattleUnitComp:repeatCurrState() function BattleUnitComp:repeatCurrState()
if self.currState == UNIT_STATE.IDLE then if self.currState == UNIT_STATE.NORMAL_ATTACK then
return false
elseif self.currState == UNIT_STATE.NORMAL_ATTACK then
return true return true
elseif self.currState == UNIT_STATE.SKILL then elseif self.currState == UNIT_STATE.SKILL then
return true return true
elseif self.currState == UNIT_STATE.DEAD then
return false
end end
return false return false
end end
@ -168,6 +172,41 @@ function BattleUnitComp:enterDeadState()
self:playAnimation(aniName, false, false) self:playAnimation(aniName, false, false)
end end
function BattleUnitComp:updateEnterBattlefieldState(dt)
if self.isMove then
local addX = dt*BattleConst.MOVE_SPEED*self.moveDirection
self.positionX = self.positionX + addX
if (self.moveDirection > 0 and self.positionX >= self.targetX) or (self.moveDirection < 0 and self.positionX <= self.targetX) then
self.isMove = false
self.positionX = self.targetX
self:changeState(UNIT_STATE.IDLE)
end
self.baseObject:setLocalPosition(self.positionX, 0, 0)
end
end
function BattleUnitComp:exitEnterBattlefieldState()
local callback = self.finishEnterBattlefieldCallback
self.finishEnterBattlefieldCallback = nil
if callback then
callback()
end
end
function BattleUnitComp:enterEnterBattlefieldState()
self:hideOutsideScreen()
self.isMove = true
self:playAnimation(SPINE_ANIMATION_NAME.MOVE, true, false)
self.positionX = self.baseObject:fastGetLocalPosition()
if self.side == BattleConst.SIDE_ATK then
self.targetX = -BattleConst.INIT_POS_X
self.moveDirection = 1
else
self.targetX = BattleConst.INIT_POS_X
self.moveDirection = -1
end
end
function BattleUnitComp:exitIdleState() function BattleUnitComp:exitIdleState()
end end
@ -376,10 +415,6 @@ function BattleUnitComp:takeDamageOrCure(atker, buff, num, effectType, effectSta
return 0 return 0
end end
self.unitEntity:takeDamageOrCure(num) self.unitEntity:takeDamageOrCure(num)
if self.currState == UNIT_STATE.INIT or
self.currState == UNIT_STATE.IDLE then
self:playHurt()
end
local x, y, z = self.baseObject:fastGetLocalPosition() local x, y, z = self.baseObject:fastGetLocalPosition()
self:showEffectNumber(num, x, y) self:showEffectNumber(num, x, y)
self.battleController:refreshHp(self.side, self.unitEntity:getHp(), self.unitEntity:getHpPercent()) self.battleController:refreshHp(self.side, self.unitEntity:getHp(), self.unitEntity:getHpPercent())
@ -405,6 +440,15 @@ function BattleUnitComp:playDead(callback)
end end
end end
function BattleUnitComp:playEnterBattlefield(callback)
self.finishEnterBattlefieldCallback = callback
self:hideOutsideScreen()
if not self:changeState(UNIT_STATE.ENTER_BATTLEFIELD) then
self.finishEnterBattlefieldCallback = nil
callback()
end
end
function BattleUnitComp:tick(dt) function BattleUnitComp:tick(dt)
if self.isClear then if self.isClear then
return return
@ -421,6 +465,8 @@ function BattleUnitComp:tick(dt)
self:updateNormalAttack(dt) self:updateNormalAttack(dt)
elseif self.currState == UNIT_STATE.SKILL then elseif self.currState == UNIT_STATE.SKILL then
self:updateSkill(dt) self:updateSkill(dt)
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
self:updateEnterBattlefieldState(dt)
end end
end end
@ -435,4 +481,8 @@ function BattleUnitComp:clear()
self.isClear = true self.isClear = true
end end
function BattleUnitComp:recycle()
BattleHelper:recycleBattleHeroModel(self.modelId, self.baseObject)
end
return BattleUnitComp return BattleUnitComp

View File

@ -54,6 +54,7 @@ function BattleController:initDefUnits(callback)
end end
function BattleController:findNextDefUnit() function BattleController:findNextDefUnit()
self:enterRefreshBoard()
end end
function BattleController:tick(dt) function BattleController:tick(dt)
@ -287,7 +288,7 @@ function BattleController:enterAtkStepOver()
if self.waveIndex >= self.maxWaveIndex then if self.waveIndex >= self.maxWaveIndex then
self:enterRoundEnd() self:enterRoundEnd()
else else
self:enterRefreshBoard() self:findNextDefUnit()
end end
return return
end end
@ -322,7 +323,7 @@ function BattleController:enterDefStepOver()
if self.waveIndex >= self.maxWaveIndex then if self.waveIndex >= self.maxWaveIndex then
self:enterRoundEnd() self:enterRoundEnd()
else else
self:enterRefreshBoard() self:findNextDefUnit()
end end
return return
end end

View File

@ -32,6 +32,34 @@ function BattleControllerStage:initDefUnits(callback)
end) end)
end end
function BattleControllerStage:_stageGenerateNextMonster()
local config = ConfigManager:getConfig("chapter")[self.chapterId]
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
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:enterNextWave()
self:enterRefreshBoard()
end)
self.battleUI:refreshDefHp(unitEntity:getHp(), unitEntity:getHpPercent())
end)
end
function BattleControllerStage:getInitBoard() function BattleControllerStage:getInitBoard()
if not self.boradList then if not self.boradList then
self.boradList = {} self.boradList = {}
@ -79,7 +107,9 @@ function BattleControllerStage:getNotInvolvedSkills()
end end
function BattleControllerStage:findNextDefUnit() function BattleControllerStage:findNextDefUnit()
self.defMainUnit:playDead(function()
self:_stageGenerateNextMonster()
end)
end end
function BattleControllerStage:controllBattleEnd() function BattleControllerStage:controllBattleEnd()

View File

@ -398,7 +398,7 @@ function BattleData:initHeroData()
return data return data
end end
function BattleData:addMonster(monsterId) function BattleData:addMonster(monsterId, newTeam)
local monsterInfo = ConfigManager:getConfig("monster")[monsterId] local monsterInfo = ConfigManager:getConfig("monster")[monsterId]
local hp = monsterInfo.hp // DEFAULT_FACTOR local hp = monsterInfo.hp // DEFAULT_FACTOR
local atk = monsterInfo.atk // DEFAULT_FACTOR local atk = monsterInfo.atk // DEFAULT_FACTOR
@ -419,6 +419,9 @@ function BattleData:addMonster(monsterId)
atk_purple = 0, atk_purple = 0,
} }
} }
if newTeam then
self.defTeam:init(BattleConst.SIDE_DEF)
end
return self.defTeam:addUnit(unitData) return self.defTeam:addUnit(unitData)
end end

View File

@ -19,8 +19,20 @@ end
function BattleTeamEntity:init(side, data) function BattleTeamEntity:init(side, data)
self.side = side self.side = side
if self.baseAttr then
for k, v in pairs(self.baseAttr) do
self.baseAttr[k] = 0
end
else
self.baseAttr = {} self.baseAttr = {}
end
if self.attr then
for k, v in pairs(self.attr) do
self.attr[k] = 0
end
else
self.attr = {} self.attr = {}
end
self.isDead = false self.isDead = false
self.stunCount = 0 self.stunCount = 0
self.limitAll = 0 self.limitAll = 0