最后一次攻击判断死亡

This commit is contained in:
chenxi 2023-04-19 18:39:46 +08:00
parent 1f86476cb0
commit 8a334afbff
3 changed files with 49 additions and 8 deletions

View File

@ -236,7 +236,13 @@ function BattleUnitComp:getAnimationKeyFrameTime(animationName)
return time return time
end end
function BattleUnitComp:getIsCentralizedAttack()
return self.centralizedAttack
end
function BattleUnitComp:beforeAttack() function BattleUnitComp:beforeAttack()
self.centralizedAttack = true
self.battleController:setIsPauseHpProgress(true)
self:checkPassiveEvent(PASSIVE_EVENT.ON_UNI_ATTACK_START, self) self:checkPassiveEvent(PASSIVE_EVENT.ON_UNI_ATTACK_START, self)
end end
@ -279,18 +285,21 @@ function BattleUnitComp:useSkill(index, count, callback)
self.actionOverCallback = nil self.actionOverCallback = nil
self.activeSkillIndex = nil self.activeSkillIndex = nil
self.battleController:setIsPauseHpProgress(false) self.battleController:setIsPauseHpProgress(false)
self.centralizedAttack = false
callback() callback()
return return
end end
if not self:changeState(UNIT_STATE.NORMAL_ATTACK) then if not self:changeState(UNIT_STATE.NORMAL_ATTACK) then
self.actionOverCallback = nil self.actionOverCallback = nil
self.battleController:setIsPauseHpProgress(false) self.battleController:setIsPauseHpProgress(false)
self.centralizedAttack = false
callback() callback()
end end
else else
if not self:changeState(UNIT_STATE.SKILL_ATTACK) then if not self:changeState(UNIT_STATE.SKILL_ATTACK) then
self.actionOverCallback = nil self.actionOverCallback = nil
self.battleController:setIsPauseHpProgress(false) self.battleController:setIsPauseHpProgress(false)
self.centralizedAttack = false
callback() callback()
end end
end end
@ -313,18 +322,21 @@ function BattleUnitComp:useAllSkills(callback)
if self.normalSkillCount <= 0 then if self.normalSkillCount <= 0 then
self.actionOverCallback = nil self.actionOverCallback = nil
self.battleController:setIsPauseHpProgress(false) self.battleController:setIsPauseHpProgress(false)
self.centralizedAttack = false
callback() callback()
return return
end end
if not self:changeState(UNIT_STATE.NORMAL_ATTACK) then if not self:changeState(UNIT_STATE.NORMAL_ATTACK) then
self.actionOverCallback = nil self.actionOverCallback = nil
self.battleController:setIsPauseHpProgress(false) self.battleController:setIsPauseHpProgress(false)
self.centralizedAttack = false
callback() callback()
end end
else else
if not self:changeState(UNIT_STATE.SKILL_ATTACK) then if not self:changeState(UNIT_STATE.SKILL_ATTACK) then
self.actionOverCallback = nil self.actionOverCallback = nil
self.battleController:setIsPauseHpProgress(false) self.battleController:setIsPauseHpProgress(false)
self.centralizedAttack = false
callback() callback()
end end
end end
@ -336,6 +348,7 @@ function BattleUnitComp:useNormalSkill(count, callback)
if not self:changeState(UNIT_STATE.NORMAL_ATTACK) then if not self:changeState(UNIT_STATE.NORMAL_ATTACK) then
self.actionOverCallback = nil self.actionOverCallback = nil
self.battleController:setIsPauseHpProgress(false) self.battleController:setIsPauseHpProgress(false)
self.centralizedAttack = false
callback() callback()
end end
end end
@ -701,14 +714,21 @@ function BattleUnitComp:updateSkillAttack(dt)
if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用 if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用
self.currAttackKeyTime = 0 self.currAttackKeyTime = 0
if self.normalSkillCount > 0 then if self.normalSkillCount > 0 then
if self.normalSkillCount == 1 and self.currActiveSkill == nil then -- 最后一次攻击
self.centralizedAttack = false
end
local skill = self.unitEntity:getNormalSkill() local skill = self.unitEntity:getNormalSkill()
self:onSkillTakeEffect(skill) self:onSkillTakeEffect(skill)
if self.normalSkillCount == 1 and self.currActiveSkill == nil then -- 最后一次攻击 if self.normalSkillCount == 1 and self.currActiveSkill == nil then -- 最后一次攻击
self.battleController:setIsPauseHpProgress(false) self.battleController:setIsPauseHpProgress(false)
end end
else else
local isHaveNextAttack = self:getIsHaveNextAvailableActiveSkill()
if not isHaveNextAttack then
self.centralizedAttack = false
end
self:onSkillTakeEffect(self.currActiveSkill) self:onSkillTakeEffect(self.currActiveSkill)
if not self:getIsHaveNextAvailableActiveSkill() then if not isHaveNextAttack then
self.battleController:setIsPauseHpProgress(false) self.battleController:setIsPauseHpProgress(false)
end end
end end
@ -868,6 +888,9 @@ function BattleUnitComp:updateNormalAttack(dt)
else else
if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用 if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用
self.currAttackKeyTime = 0 self.currAttackKeyTime = 0
if self.normalSkillCount == 1 then -- 如果是最后一次攻击,那么敌人受到这次攻击可以开始嗝屁了
self.centralizedAttack = false
end
local skill = self.unitEntity:getNormalSkill() local skill = self.unitEntity:getNormalSkill()
self:onSkillTakeEffect(skill) self:onSkillTakeEffect(skill)
if self.normalSkillCount == 1 then -- 如果是最后一次攻击,那么可以开始跑血条了 if self.normalSkillCount == 1 then -- 如果是最后一次攻击,那么可以开始跑血条了
@ -966,6 +989,12 @@ function BattleUnitComp:removeEffect(buff, target)
end end
function BattleUnitComp:takeDamageOrCure(atker, buff, num, effectType, effectStatus) function BattleUnitComp:takeDamageOrCure(atker, buff, num, effectType, effectStatus)
if self:getIsClear() then
return 0
end
if self.currState == UNIT_STATE.DEAD then
return 0
end
if num == 0 then if num == 0 then
return 0 return 0
end end
@ -986,9 +1015,16 @@ function BattleUnitComp:takeDamageOrCure(atker, buff, num, effectType, effectSta
local hp = self.unitEntity:getHp() local hp = self.unitEntity:getHp()
local hpPercent = self.unitEntity:getHpPercent() local hpPercent = self.unitEntity:getHpPercent()
self.battleController:refreshHp(self.side, hp, hpPercent) self.battleController:refreshHp(self.side, hp, hpPercent)
if atker:getIsCentralizedAttack() then
if self.currState == UNIT_STATE.IDLE then if self.currState == UNIT_STATE.IDLE then
self:playHurt() self:playHurt()
end
else
if self.unitEntity:getIsDead() then
self:changeState(UNIT_STATE.DEAD)
elseif self.currState == UNIT_STATE.IDLE then
self:playHurt()
end
end end
if hp > 0 then if hp > 0 then
self:checkPassiveEvent(PASSIVE_EVENT.HP_LOWER_THAN, atker, hpPercent) self:checkPassiveEvent(PASSIVE_EVENT.HP_LOWER_THAN, atker, hpPercent)
@ -1001,7 +1037,11 @@ end
function BattleUnitComp:playDead(callback) function BattleUnitComp:playDead(callback)
self.deadOverCallback = callback self.deadOverCallback = callback
if not self:changeState(UNIT_STATE.DEAD) then if self:getIsClear() then
self.deadOverCallback = nil
return callback()
end
if self.currState ~= UNIT_STATE.DEAD and not self:changeState(UNIT_STATE.DEAD) then
self.deadOverCallback = nil self.deadOverCallback = nil
callback() callback()
end end

View File

@ -58,7 +58,6 @@ function BattleTeam:useNormalSkill(matchType, count, callback)
return callback() return callback()
end end
self.mainUnit = unit self.mainUnit = unit
self.battleController:setIsPauseHpProgress(true)
unit:beforeAttack() unit:beforeAttack()
unit:resetBeforeAttack() unit:resetBeforeAttack()
unit:useNormalSkill(count, callback) unit:useNormalSkill(count, callback)
@ -78,7 +77,6 @@ function BattleTeam:useSkill(matchType, count, callback)
return callback() return callback()
end end
self.mainUnit = unit self.mainUnit = unit
self.battleController:setIsPauseHpProgress(true)
unit:beforeAttack() unit:beforeAttack()
unit:resetBeforeAttack() unit:resetBeforeAttack()
unit:useSkill(1, count, callback) unit:useSkill(1, count, callback)
@ -121,7 +119,6 @@ function BattleTeam:mainUnitUseAllSkills(callback)
if self.mainUnit:getIsLimit() then if self.mainUnit:getIsLimit() then
return callback() return callback()
end end
self.battleController:setIsPauseHpProgress(true)
self.mainUnit:beforeAttack() self.mainUnit:beforeAttack()
self.mainUnit:resetBeforeAttack() self.mainUnit:resetBeforeAttack()
self.mainUnit:useAllSkills(callback) self.mainUnit:useAllSkills(callback)

View File

@ -249,6 +249,10 @@ function BattleUnitEntity:getExp()
return self.unitData.exp return self.unitData.exp
end end
function BattleUnitEntity:getIsDead()
return self.team:getIsDead()
end
function BattleUnitEntity:addSkillExtraUseTimes(skillId, count) function BattleUnitEntity:addSkillExtraUseTimes(skillId, count)
if self.skillExtraUseTimes == nil then if self.skillExtraUseTimes == nil then
self.skillExtraUseTimes = {} self.skillExtraUseTimes = {}