普攻和技能

This commit is contained in:
chenxi 2023-04-17 20:20:07 +08:00
parent 602983faee
commit ebf0d93d30
2 changed files with 142 additions and 135 deletions

View File

@ -182,7 +182,7 @@ local skill = {
["icon"]=10, ["icon"]=10,
["battle_icon"]=1, ["battle_icon"]=1,
["skill_position"]=1, ["skill_position"]=1,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[220011]={ [220011]={
["energy"]=10, ["energy"]=10,
@ -203,7 +203,7 @@ local skill = {
}, },
["obj"]=2, ["obj"]=2,
["skill_position"]=1, ["skill_position"]=1,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[220012]={ [220012]={
["energy"]=10, ["energy"]=10,
@ -244,7 +244,7 @@ local skill = {
} }
}, },
["skill_position"]=1, ["skill_position"]=1,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[420011]={ [420011]={
["energy"]=10, ["energy"]=10,
@ -260,7 +260,7 @@ local skill = {
["icon"]=30, ["icon"]=30,
["battle_icon"]=3, ["battle_icon"]=3,
["skill_position"]=2, ["skill_position"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[520011]={ [520011]={
["energy"]=10, ["energy"]=10,
@ -281,7 +281,7 @@ local skill = {
}, },
["obj"]=1, ["obj"]=1,
["skill_position"]=2, ["skill_position"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[120011]={ [120011]={
["energy"]=10, ["energy"]=10,
@ -301,7 +301,7 @@ local skill = {
["icon"]=50, ["icon"]=50,
["battle_icon"]=5, ["battle_icon"]=5,
["skill_position"]=2, ["skill_position"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[330011]={ [330011]={
["energy"]=10, ["energy"]=10,
@ -322,7 +322,7 @@ local skill = {
}, },
["obj"]=1, ["obj"]=1,
["skill_position"]=2, ["skill_position"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[230011]={ [230011]={
["energy"]=10, ["energy"]=10,
@ -466,7 +466,7 @@ local skill = {
} }
}, },
["skill_position"]=1, ["skill_position"]=1,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[430012]={ [430012]={
["energy"]=10, ["energy"]=10,
@ -510,7 +510,7 @@ local skill = {
} }
}, },
["skill_position"]=1, ["skill_position"]=1,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000000]={ [1000000]={
["effect_type"]=1, ["effect_type"]=1,
@ -555,7 +555,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=3, ["cd"]=3,
["cd_start"]=3, ["cd_start"]=3,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000003]={ [1000003]={
["effect_type"]=1, ["effect_type"]=1,
@ -572,7 +572,7 @@ local skill = {
["skill_position"]=1, ["skill_position"]=1,
["cd"]=4, ["cd"]=4,
["cd_start"]=4, ["cd_start"]=4,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000004]={ [1000004]={
["effect_type"]=1, ["effect_type"]=1,
@ -589,7 +589,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=2, ["cd"]=2,
["cd_start"]=2, ["cd_start"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000005]={ [1000005]={
["effect_type"]=2, ["effect_type"]=2,
@ -625,7 +625,7 @@ local skill = {
["skill_position"]=1, ["skill_position"]=1,
["cd"]=3, ["cd"]=3,
["cd_start"]=3, ["cd_start"]=3,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000007]={ [1000007]={
["effect_type"]=2, ["effect_type"]=2,
@ -651,7 +651,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=2, ["cd"]=2,
["cd_start"]=2, ["cd_start"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000009]={ [1000009]={
["effect_type"]=2, ["effect_type"]=2,
@ -683,7 +683,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=2, ["cd"]=2,
["cd_start"]=2, ["cd_start"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000011]={ [1000011]={
["effect_type"]=1, ["effect_type"]=1,
@ -700,7 +700,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=2, ["cd"]=2,
["cd_start"]=2, ["cd_start"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000012]={ [1000012]={
["effect_type"]=2, ["effect_type"]=2,
@ -731,7 +731,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=3, ["cd"]=3,
["cd_start"]=3, ["cd_start"]=3,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000014]={ [1000014]={
["effect_type"]=2, ["effect_type"]=2,
@ -757,7 +757,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=2, ["cd"]=2,
["cd_start"]=2, ["cd_start"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000016]={ [1000016]={
["skill_type"]=3, ["skill_type"]=3,
@ -769,7 +769,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=2, ["cd"]=2,
["cd_start"]=2, ["cd_start"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000017]={ [1000017]={
["effect_type"]=2, ["effect_type"]=2,
@ -816,7 +816,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=3, ["cd"]=3,
["cd_start"]=3, ["cd_start"]=3,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000020]={ [1000020]={
["effect_type"]=2, ["effect_type"]=2,
@ -842,7 +842,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=2, ["cd"]=2,
["cd_start"]=2, ["cd_start"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000022]={ [1000022]={
["effect_type"]=2, ["effect_type"]=2,
@ -870,7 +870,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=3, ["cd"]=3,
["cd_start"]=3, ["cd_start"]=3,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000024]={ [1000024]={
["skill_type"]=3, ["skill_type"]=3,
@ -882,7 +882,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=3, ["cd"]=3,
["cd_start"]=3, ["cd_start"]=3,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000025]={ [1000025]={
["effect_type"]=2, ["effect_type"]=2,
@ -913,7 +913,7 @@ local skill = {
["skill_position"]=2, ["skill_position"]=2,
["cd"]=2, ["cd"]=2,
["cd_start"]=2, ["cd_start"]=2,
["name_act"]="skill_01" ["name_act"]="skill01"
}, },
[1000027]={ [1000027]={
["effect_type"]=2, ["effect_type"]=2,

View File

@ -105,18 +105,25 @@ end
function BattleUnitComp:useSkill(index, count, callback) function BattleUnitComp:useSkill(index, count, callback)
self.actionOverCallback = callback self.actionOverCallback = callback
self.normalSkillCount = count + self.unitEntity:getNormalAttackAddCount() self.activeSkillIndex = index
self.activeSkillIndex = nil
self.currActiveSkill = self.unitEntity:getActiveSkill(index) self.currActiveSkill = self.unitEntity:getActiveSkill(index)
if self.currActiveSkill == nil and self.normalSkillCount <= 0 then self.normalSkillCount = count + self.unitEntity:getNormalAttackAddCount()
if self.currActiveSkill == nil then -- 没有技能就用普攻
if self.normalSkillCount <= 0 then
self.actionOverCallback = nil self.actionOverCallback = nil
callback() callback()
return return
end end
if not self:changeState(UNIT_STATE.NORMAL_ATTACK) then
self.actionOverCallback = nil
callback()
end
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
callback() callback()
end end
end
end end
function BattleUnitComp:useAllSkills(callback) function BattleUnitComp:useAllSkills(callback)
@ -125,6 +132,11 @@ function BattleUnitComp:useAllSkills(callback)
self.activeSkillIndex = 1 self.activeSkillIndex = 1
self.currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex) self.currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex)
if self.currActiveSkill == nil then -- 没有技能就用普攻 if self.currActiveSkill == nil then -- 没有技能就用普攻
if self.normalSkillCount <= 0 then
self.actionOverCallback = nil
callback()
return
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
callback() callback()
@ -337,7 +349,13 @@ function BattleUnitComp:enterSkillAttackState()
self.attackTime = 0 self.attackTime = 0
self.currAttackKeyTime = 0.3 self.currAttackKeyTime = 0.3
self.targetX = nil self.targetX = nil
if self.currActiveSkill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then local skill
if self.normalSkillCount > 0 then
skill = self.unitEntity:getNormalSkill()
else
skill = self.currActiveSkill
end
if skill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then
self.isMove = true self.isMove = true
self:playAnimation(BattleConst.SPINE_ANIMATION_NAME.MOVE, true, false) self:playAnimation(BattleConst.SPINE_ANIMATION_NAME.MOVE, true, false)
self.positionX = self.baseObject:fastGetLocalPosition() self.positionX = self.baseObject:fastGetLocalPosition()
@ -351,7 +369,12 @@ function BattleUnitComp:enterSkillAttackState()
else else
self.isMove = false self.isMove = false
self.attackTime = 0 self.attackTime = 0
local attackName = self.currActiveSkill:getSkillAttackName() local attackName
if self.normalSkillCount > 0 then
attackName = skill:getRandomNormalAttackName()
else
attackName = skill:getSkillAttackName()
end
self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false) self:playAnimation(attackName, false, false)
end end
@ -367,41 +390,10 @@ function BattleUnitComp:updateSkillAttack(dt)
if (self.moveDirection > 0 and self.positionX >= self.targetX) or (self.moveDirection < 0 and self.positionX <= self.targetX) then if (self.moveDirection > 0 and self.positionX >= self.targetX) or (self.moveDirection < 0 and self.positionX <= self.targetX) then
self.isMove = false self.isMove = false
self.positionX = self.targetX self.positionX = self.targetX
if self.attackOver then -- 归位后该进行下一次攻击了 if self.attackOver then -- 归位后该下一步了
if self.activeSkillIndex then self:onAttackOver()
self.activeSkillIndex = self.activeSkillIndex + 1
self.currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex)
else
self.currActiveSkill = nil
end
if self.currActiveSkill == nil then
self:changeState(UNIT_STATE.IDLE)
local callback = self.actionOverCallback
self.actionOverCallback = nil
if callback then
callback()
end
return
else
if not self:changeState(UNIT_STATE.SKILL_ATTACK) then
local callback = self.actionOverCallback
self.actionOverCallback = nil
callback()
return
end
end
else -- 到位置该攻击了 else -- 到位置该攻击了
self.attackTime = 0 self:doNextAttack()
self.currAttackKeyTime = 0.3
local attackName = nil
if self.normalSkillCount > 0 then
local skill = self.unitEntity:getNormalSkill()
attackName = skill:getRandomNormalAttackName()
else
attackName = self.currActiveSkill:getSkillAttackName()
end
self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false)
end end
end end
self.baseObject:setLocalPosition(self.positionX, 0, 0) self.baseObject:setLocalPosition(self.positionX, 0, 0)
@ -412,8 +404,21 @@ function BattleUnitComp:updateSkillAttack(dt)
self.attackOver = true self.attackOver = true
if self.normalSkillCount > 0 then if self.normalSkillCount > 0 then
self.normalSkillCount = self.normalSkillCount - 1 self.normalSkillCount = self.normalSkillCount - 1
end
if self.normalSkillCount <= 0 then if self.normalSkillCount <= 0 then
if self.currActiveSkill == nil then
if self.targetX then -- 移动过,准备归位
self:moveBackToInitPosition()
else
self:onAttackOver()
end
return
else
self:doNextSkillAttack()
end
else -- 继续普攻
self:doNextNormalAttack()
end
else
local currActiveSkill = nil local currActiveSkill = nil
if self.activeSkillIndex then if self.activeSkillIndex then
self.activeSkillIndex = self.activeSkillIndex + 1 self.activeSkillIndex = self.activeSkillIndex + 1
@ -421,40 +426,15 @@ function BattleUnitComp:updateSkillAttack(dt)
end end
if currActiveSkill == nil then if currActiveSkill == nil then
if self.targetX then -- 移动过,准备归位 if self.targetX then -- 移动过,准备归位
self.isMove = true self:moveBackToInitPosition()
self:playAnimation(BattleConst.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 else
self.targetX = BattleConst.INIT_POS_X self:onAttackOver()
self.moveDirection = 1
end
else
self:changeState(UNIT_STATE.IDLE)
local callback = self.actionOverCallback
self.actionOverCallback = nil
if callback then
callback()
end
end end
return return
else else
self.currActiveSkill = currActiveSkill self.currActiveSkill = currActiveSkill
self.attackTime = 0 self:doNextSkillAttack()
self.currAttackKeyTime = 0.3
local attackName = self.currActiveSkill:getSkillAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false)
end end
else -- 继续攻击
self.attackTime = 0
self.currAttackKeyTime = 0.3
local skill = self.unitEntity:getNormalSkill()
local attackName = skill:getRandomNormalAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false)
end end
else else
if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用 if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用
@ -469,10 +449,66 @@ function BattleUnitComp:updateSkillAttack(dt)
end end
end end
function BattleUnitComp:moveBackToInitPosition()
self.isMove = true
self:playAnimation(BattleConst.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:onAttackOver()
self:changeState(UNIT_STATE.IDLE)
local callback = self.actionOverCallback
self.actionOverCallback = nil
if callback then
callback()
end
end
function BattleUnitComp:doNextSkillAttack()
self.attackTime = 0
self.currAttackKeyTime = 0.3
local attackName = self.currActiveSkill:getSkillAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false)
end
function BattleUnitComp:doNextNormalAttack()
self.attackTime = 0
self.currAttackKeyTime = 0.3
local skill = self.unitEntity:getNormalSkill()
local attackName = skill:getRandomNormalAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false)
end
function BattleUnitComp:doNextAttack()
self.attackTime = 0
self.currAttackKeyTime = 0.3
local attackName = nil
if self.normalSkillCount > 0 then
local skill = self.unitEntity:getNormalSkill()
attackName = skill:getRandomNormalAttackName()
elseif self.currActiveSkill then
attackName = self.currActiveSkill:getSkillAttackName()
end
if attackName then
self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false)
else -- 归位
self:moveBackToInitPosition()
end
end
function BattleUnitComp:enterNormalAttackState() function BattleUnitComp:enterNormalAttackState()
self.attackOver = false self.attackOver = false
self.attackTime = 0 self.attackTime = 0
self.currAttackKeyTime = 0.3 self.currAttackKeyTime = 0.3
local skill = self.unitEntity:getNormalSkill() local skill = self.unitEntity:getNormalSkill()
if skill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then if skill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then
@ -506,19 +542,9 @@ function BattleUnitComp:updateNormalAttack(dt)
self.isMove = false self.isMove = false
self.positionX = self.targetX self.positionX = self.targetX
if self.attackOver then -- 归位后该下一步了 if self.attackOver then -- 归位后该下一步了
self:changeState(UNIT_STATE.IDLE) self:onAttackOver()
local callback = self.actionOverCallback
self.actionOverCallback = nil
if callback then
callback()
end
else -- 到位置该攻击了 else -- 到位置该攻击了
self.attackTime = 0 self:doNextNormalAttack()
self.currAttackKeyTime = 0.3
local skill = self.unitEntity:getNormalSkill()
local attackName = skill:getRandomNormalAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false)
end end
end end
self.baseObject:setLocalPosition(self.positionX, 0, 0) self.baseObject:setLocalPosition(self.positionX, 0, 0)
@ -531,32 +557,13 @@ function BattleUnitComp:updateNormalAttack(dt)
if self.normalSkillCount <= 0 then if self.normalSkillCount <= 0 then
local skill = self.unitEntity:getNormalSkill() local skill = self.unitEntity:getNormalSkill()
if skill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then if skill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then
self.isMove = true self:moveBackToInitPosition()
self:playAnimation(BattleConst.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 else
self.targetX = BattleConst.INIT_POS_X self:onAttackOver()
self.moveDirection = 1
end
else
self:changeState(UNIT_STATE.IDLE)
local callback = self.actionOverCallback
self.actionOverCallback = nil
if callback then
callback()
end
end end
return return
else -- 继续攻击 else -- 继续攻击
self.attackTime = 0 self:doNextNormalAttack()
self.currAttackKeyTime = 0.3
local skill = self.unitEntity:getNormalSkill()
local attackName = skill:getRandomNormalAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false)
end end
else else
if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用 if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用