This commit is contained in:
xiekaidong 2023-04-24 11:21:32 +08:00
commit d5803e07df
2 changed files with 71 additions and 16 deletions

View File

@ -27,6 +27,7 @@ function BattleUnitComp:initPosition()
self.body:setLocalScaleX(-1) self.body:setLocalScaleX(-1)
self.direction = -1 self.direction = -1
end end
self.isOutside = false
end end
function BattleUnitComp:playBorn() function BattleUnitComp:playBorn()
@ -42,7 +43,6 @@ function BattleUnitComp:playSwitchOut()
self:changeState(UNIT_STATE.SWITCH_OUT) self:changeState(UNIT_STATE.SWITCH_OUT)
end end
function BattleUnitComp:getModelId() function BattleUnitComp:getModelId()
return self.modelId return self.modelId
end end
@ -82,6 +82,7 @@ function BattleUnitComp:_initBase()
self.assistingDmgAddition = 0 self.assistingDmgAddition = 0
self.attackCount = 0 self.attackCount = 0
self.currState = UNIT_STATE.INIT self.currState = UNIT_STATE.INIT
self.isOutside = false
end end
function BattleUnitComp:initWithEntity(modelId, entity, battleController, target) function BattleUnitComp:initWithEntity(modelId, entity, battleController, target)
@ -199,6 +200,7 @@ function BattleUnitComp:hideOutsideScreen()
else else
self.baseObject:setLocalPosition(GConst.UI_SCREEN_WIDTH/2 + BattleConst.UNIT_BODY_WIDTH, 0, 0) self.baseObject:setLocalPosition(GConst.UI_SCREEN_WIDTH/2 + BattleConst.UNIT_BODY_WIDTH, 0, 0)
end end
self.isOutside = true
end end
function BattleUnitComp:playRunAction() function BattleUnitComp:playRunAction()
@ -288,30 +290,46 @@ function BattleUnitComp:useSkill(index, count, callback)
self.actionOverCallback = callback self.actionOverCallback = callback
self.activeSkillIndex = index self.activeSkillIndex = index
self.currActiveSkill = self.unitEntity:getAvailableActiveSkill(index) self.currActiveSkill = self.unitEntity:getAvailableActiveSkill(index)
self.normalSkillCount = count + self.unitEntity:getNormalAttackAddCount() if count <= 0 then
self.normalSkillCount = 0
else
self.normalSkillCount = count + self.unitEntity:getNormalAttackAddCount()
end
if self.currActiveSkill == nil then -- 没有技能就用普攻 if self.currActiveSkill == nil then -- 没有技能就用普攻
self.activeSkillIndex = nil
if self.normalSkillCount <= 0 then if self.normalSkillCount <= 0 then
self.actionOverCallback = nil self.actionOverCallback = nil
self.activeSkillIndex = nil
self.battleController:setIsPauseHpProgress(false) self.battleController:setIsPauseHpProgress(false)
self.team:setCentralizedAttack(false) self.team:setCentralizedAttack(false)
callback() callback()
return return false
end end
if not self:changeState(UNIT_STATE.NORMAL_ATTACK) then if self.isOutside then
self.actionOverCallback = nil self:playSwitchIn()
self.battleController:setIsPauseHpProgress(false) else
self.team:setCentralizedAttack(false) if not self:changeState(UNIT_STATE.NORMAL_ATTACK) then
callback() self.actionOverCallback = nil
self.battleController:setIsPauseHpProgress(false)
self.team:setCentralizedAttack(false)
callback()
return false
end
end end
else else
if not self:changeState(UNIT_STATE.SKILL_ATTACK) then if self.isOutside then
self.actionOverCallback = nil self:playSwitchIn()
self.battleController:setIsPauseHpProgress(false) else
self.team:setCentralizedAttack(false) if not self:changeState(UNIT_STATE.SKILL_ATTACK) then
callback() self.actionOverCallback = nil
self.activeSkillIndex = nil
self.battleController:setIsPauseHpProgress(false)
self.team:setCentralizedAttack(false)
callback()
return false
end
end end
end end
return true
end end
function BattleUnitComp:useAllSkills(callback) function BattleUnitComp:useAllSkills(callback)
@ -449,7 +467,35 @@ end
function BattleUnitComp:updateSwitchInState(dt) function BattleUnitComp:updateSwitchInState(dt)
self.switchTime = self.switchTime - dt self.switchTime = self.switchTime - dt
if self.switchTime < 0 then if self.switchTime < 0 then
self:changeState(UNIT_STATE.IDLE) if self.actionOverCallback then
if self.currActiveSkill then
if not self:changeState(UNIT_STATE.SKILL_ATTACK) then
local callback = self.actionOverCallback
self.actionOverCallback = nil
self.activeSkillIndex = nil
self.battleController:setIsPauseHpProgress(false)
self.team:setCentralizedAttack(false)
callback()
end
elseif self.normalSkillCount > 0 then
if not self:changeState(UNIT_STATE.NORMAL_ATTACK) then
local callback = self.actionOverCallback
self.actionOverCallback = nil
self.battleController:setIsPauseHpProgress(false)
self.team:setCentralizedAttack(false)
callback()
end
else
self:changeState(UNIT_STATE.IDLE)
local callback = self.actionOverCallback
self.actionOverCallback = nil
self.battleController:setIsPauseHpProgress(false)
self.team:setCentralizedAttack(false)
callback()
end
else
self:changeState(UNIT_STATE.IDLE)
end
end end
end end

View File

@ -81,10 +81,19 @@ function BattleTeam:useSkill(matchType, count, callback)
if unit:getIsLimit() then if unit:getIsLimit() then
return callback() return callback()
end end
local lastMainUnit = self.mainUnit
self.mainUnit = unit self.mainUnit = unit
unit:beforeAttack() unit:beforeAttack()
unit:resetBeforeAttack() unit:resetBeforeAttack()
unit:useSkill(1, count, callback) if unit:useSkill(1, count, callback) then
if lastMainUnit and lastMainUnit ~= unit then
lastMainUnit:playSwitchOut()
end
else
if lastMainUnit and lastMainUnit ~= unit then
self.mainUnit = lastMainUnit
end
end
end end
function BattleTeam:useAssistingSkill(assistingList, callback) function BattleTeam:useAssistingSkill(assistingList, callback)