换人逻辑

This commit is contained in:
chenxi 2023-04-17 17:13:24 +08:00
parent 2d3991fcbd
commit a8d3e443cd
4 changed files with 78 additions and 6 deletions

View File

@ -60,6 +60,8 @@ BattleConst.UNIT_STATE = {
HURT = 4, -- 受伤 HURT = 4, -- 受伤
DEAD = 5, -- 死亡 DEAD = 5, -- 死亡
ENTER_BATTLEFIELD = 6, -- 进入战场 ENTER_BATTLEFIELD = 6, -- 进入战场
SWITCH_IN = 7, -- 入场
SWITCH_OUT = 8, -- 离场
} }
BattleConst.MATCH_DMG_ADDITION_NAME = { BattleConst.MATCH_DMG_ADDITION_NAME = {
@ -95,6 +97,8 @@ BattleConst.SPINE_ANIMATION_NAME = {
MOVE = "move", MOVE = "move",
HIT = "suffer", HIT = "suffer",
DEAD = "death", DEAD = "death",
BORN = "born",
OUT = "out",
} }
BattleConst.EFFECT_TYPE = { BattleConst.EFFECT_TYPE = {

View File

@ -28,6 +28,15 @@ function BattleUnitComp:playBorn()
self:changeState(UNIT_STATE.IDLE) self:changeState(UNIT_STATE.IDLE)
end end
function BattleUnitComp:playSwitchIn()
self:changeState(UNIT_STATE.SWITCH_IN)
end
function BattleUnitComp:playSwitchOut()
self:changeState(UNIT_STATE.SWITCH_OUT)
end
function BattleUnitComp:getModelId() function BattleUnitComp:getModelId()
return self.modelId return self.modelId
end end
@ -43,6 +52,7 @@ function BattleUnitComp:_initBase()
self.attackTime = 0 self.attackTime = 0
self.currAttackDuration = 0 self.currAttackDuration = 0
self.currAttackKeyTime = 0 self.currAttackKeyTime = 0
self.switchTime = 0
self.isPlayHurt = 0 self.isPlayHurt = 0
self.attackDurationMap = {} self.attackDurationMap = {}
self.buffList = {} self.buffList = {}
@ -160,6 +170,10 @@ function BattleUnitComp:changeState(state)
self:exitDeadState() self:exitDeadState()
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
self:exitEnterBattlefieldState() self:exitEnterBattlefieldState()
elseif self.currState == UNIT_STATE.SWITCH_IN then
self:exitSwitchInState()
elseif self.currState == UNIT_STATE.SWITCH_OUT then
self:exitSwitchOutState()
end end
-- 进入目标状态 -- 进入目标状态
self.currState = state self.currState = state
@ -175,6 +189,10 @@ function BattleUnitComp:changeState(state)
self:enterBornState() self:enterBornState()
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
self:enterEnterBattlefieldState() self:enterEnterBattlefieldState()
elseif self.currState == UNIT_STATE.SWITCH_IN then
self:enterSwitchInState()
elseif self.currState == UNIT_STATE.SWITCH_OUT then
self:enterSwitchOutState()
end end
return true return true
end end
@ -188,6 +206,40 @@ function BattleUnitComp:repeatCurrState()
return false return false
end end
function BattleUnitComp:updateSwitchInState(dt)
self.switchTime = self.switchTime - dt
if self.switchTime < 0 then
self:changeState(UNIT_STATE.IDLE)
end
end
function BattleUnitComp:enterSwitchInState()
local aniName = SPINE_ANIMATION_NAME.BORN
self.switchTime = self:getAnimationDuration(aniName) + 0.1
self:initPosition()
self:playAnimation(aniName, false, true)
end
function BattleUnitComp:exitSwitchInState()
end
function BattleUnitComp:updateSwitchOutState(dt)
self.switchTime = self.switchTime - dt
if self.switchTime < 0 then
self:changeState(UNIT_STATE.IDLE)
end
end
function BattleUnitComp:enterSwitchOutState()
local aniName = SPINE_ANIMATION_NAME.OUT
self.switchTime = self:getAnimationDuration(aniName) + 0.1
self:playAnimation(aniName, false, true)
end
function BattleUnitComp:exitSwitchOutState()
self:hideOutsideScreen()
end
function BattleUnitComp:updateDead(dt) function BattleUnitComp:updateDead(dt)
self.deadTime = self.deadTime - dt self.deadTime = self.deadTime - dt
if self.deadTime <= 0 then if self.deadTime <= 0 then
@ -620,6 +672,10 @@ function BattleUnitComp:tick(dt)
self:updateSkillAttack(dt) self:updateSkillAttack(dt)
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
self:updateEnterBattlefieldState(dt) self:updateEnterBattlefieldState(dt)
elseif self.currState == UNIT_STATE.SWITCH_IN then
self:updateSwitchInState(dt)
elseif self.currState == UNIT_STATE.SWITCH_OUT then
self:updateSwitchOutState(dt)
end end
end end

View File

@ -106,7 +106,7 @@ function BattleController:onLinkChange()
self.battleUI:refreshSkill(elementTypeMap) self.battleUI:refreshSkill(elementTypeMap)
if mainElementType then if mainElementType then
Logger.logHighlight("mainElementType " .. mainElementType) self.atkTeam:changeMainUnit(mainElementType)
end end
end end
@ -1166,12 +1166,10 @@ function BattleController:snapshotBoard()
return snapshot return snapshot
end end
function BattleController:addBattleExp(side, exp) function BattleController:addBattleExp(exp)
if side ~= BattleConst.SIDE_ATK or not self.battleData then if not self.battleData or not exp then
return return
end end
exp = exp or 1
self.battleData:addExp(exp) self.battleData:addExp(exp)
end end
@ -1225,11 +1223,12 @@ local function _addCurRoundAttr(self, instruction, callback)
end end
local function _assisting(self, instruction, callback) local function _assisting(self, instruction, callback)
self:addBattleExp(BattleConst.SIDE_ATK, instruction.count) -- 先直接加 self:addBattleExp(instruction.count)
callback() callback()
end end
local function _generalAttack(self, instruction, callback) local function _generalAttack(self, instruction, callback)
self:addBattleExp(instruction.count) -- 先直接加
self.atkTeam:useNormalSkill(instruction.skillMatch, instruction.count, callback) self.atkTeam:useNormalSkill(instruction.skillMatch, instruction.count, callback)
end end

View File

@ -62,6 +62,19 @@ function BattleTeam:mainUnitUseAllSkills(callback)
self.mainUnit:useAllSkills(callback) self.mainUnit:useAllSkills(callback)
end end
function BattleTeam:changeMainUnit(matchType)
if self.mainUnit and matchType == self.mainUnit:getMatchType() then
return
end
local unit = self.unitMap[matchType]
if unit == nil then
return
end
self.mainUnit:playSwitchOut()
self.mainUnit = unit
unit:playSwitchIn()
end
function BattleTeam:tick(dt) function BattleTeam:tick(dt)
for k, v in ipairs(self.unitList) do for k, v in ipairs(self.unitList) do
v:tick(dt) v:tick(dt)