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

View File

@ -81,10 +81,19 @@ function BattleTeam:useSkill(matchType, count, callback)
if unit:getIsLimit() then
return callback()
end
local lastMainUnit = self.mainUnit
self.mainUnit = unit
unit:beforeAttack()
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
function BattleTeam:useAssistingSkill(assistingList, callback)