切波次

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 = {
INIT = 0,
INIT = 0, -- 初始化
IDLE = 1, -- 待机
NORMAL_ATTACK = 2, -- 普通攻击
SKILL = 3, -- 技能
HURT = 4, -- 受伤
DEAD = 5, -- 死亡
ENTER_BATTLEFIELD = 6, -- 进入战场
}
BattleConst.MATCH_DMG_ADDITION_NAME = {

View File

@ -28,6 +28,10 @@ function BattleUnitComp:playBorn()
self:changeState(UNIT_STATE.IDLE)
end
function BattleUnitComp:getModelId()
return self.modelId
end
function BattleUnitComp:_initBase()
self.isClear = false
self.isMove = false
@ -117,6 +121,8 @@ function BattleUnitComp:changeState(state)
self:exitSkillState()
elseif self.currState == UNIT_STATE.DEAD then
self:exitDeadState()
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
self:exitEnterBattlefieldState()
end
-- 进入目标状态
self.currState = state
@ -130,19 +136,17 @@ function BattleUnitComp:changeState(state)
self:enterDeadState()
elseif self.currState == UNIT_STATE.BORN then
self:enterBornState()
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
self:enterEnterBattlefieldState()
end
return true
end
function BattleUnitComp:repeatCurrState()
if self.currState == UNIT_STATE.IDLE then
return false
elseif self.currState == UNIT_STATE.NORMAL_ATTACK then
if self.currState == UNIT_STATE.NORMAL_ATTACK then
return true
elseif self.currState == UNIT_STATE.SKILL then
return true
elseif self.currState == UNIT_STATE.DEAD then
return false
end
return false
end
@ -168,6 +172,41 @@ function BattleUnitComp:enterDeadState()
self:playAnimation(aniName, false, false)
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()
end
@ -376,10 +415,6 @@ function BattleUnitComp:takeDamageOrCure(atker, buff, num, effectType, effectSta
return 0
end
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()
self:showEffectNumber(num, x, y)
self.battleController:refreshHp(self.side, self.unitEntity:getHp(), self.unitEntity:getHpPercent())
@ -405,6 +440,15 @@ function BattleUnitComp:playDead(callback)
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)
if self.isClear then
return
@ -421,6 +465,8 @@ function BattleUnitComp:tick(dt)
self:updateNormalAttack(dt)
elseif self.currState == UNIT_STATE.SKILL then
self:updateSkill(dt)
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
self:updateEnterBattlefieldState(dt)
end
end
@ -435,4 +481,8 @@ function BattleUnitComp:clear()
self.isClear = true
end
function BattleUnitComp:recycle()
BattleHelper:recycleBattleHeroModel(self.modelId, self.baseObject)
end
return BattleUnitComp

View File

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

View File

@ -32,6 +32,34 @@ function BattleControllerStage:initDefUnits(callback)
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()
if not self.boradList then
self.boradList = {}
@ -79,7 +107,9 @@ function BattleControllerStage:getNotInvolvedSkills()
end
function BattleControllerStage:findNextDefUnit()
self.defMainUnit:playDead(function()
self:_stageGenerateNextMonster()
end)
end
function BattleControllerStage:controllBattleEnd()

View File

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

View File

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