From ebf0d93d306fad476f126fa84e95179ab35c65c5 Mon Sep 17 00:00:00 2001 From: chenxi Date: Mon, 17 Apr 2023 20:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=99=AE=E6=94=BB=E5=92=8C=E6=8A=80=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/config/skill.lua | 48 ++-- .../battle/component/battle_unit_comp.lua | 229 +++++++++--------- 2 files changed, 142 insertions(+), 135 deletions(-) diff --git a/lua/app/config/skill.lua b/lua/app/config/skill.lua index 3f6f1e84..96a9a779 100644 --- a/lua/app/config/skill.lua +++ b/lua/app/config/skill.lua @@ -182,7 +182,7 @@ local skill = { ["icon"]=10, ["battle_icon"]=1, ["skill_position"]=1, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [220011]={ ["energy"]=10, @@ -203,7 +203,7 @@ local skill = { }, ["obj"]=2, ["skill_position"]=1, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [220012]={ ["energy"]=10, @@ -244,7 +244,7 @@ local skill = { } }, ["skill_position"]=1, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [420011]={ ["energy"]=10, @@ -260,7 +260,7 @@ local skill = { ["icon"]=30, ["battle_icon"]=3, ["skill_position"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [520011]={ ["energy"]=10, @@ -281,7 +281,7 @@ local skill = { }, ["obj"]=1, ["skill_position"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [120011]={ ["energy"]=10, @@ -301,7 +301,7 @@ local skill = { ["icon"]=50, ["battle_icon"]=5, ["skill_position"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [330011]={ ["energy"]=10, @@ -322,7 +322,7 @@ local skill = { }, ["obj"]=1, ["skill_position"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [230011]={ ["energy"]=10, @@ -466,7 +466,7 @@ local skill = { } }, ["skill_position"]=1, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [430012]={ ["energy"]=10, @@ -510,7 +510,7 @@ local skill = { } }, ["skill_position"]=1, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000000]={ ["effect_type"]=1, @@ -555,7 +555,7 @@ local skill = { ["skill_position"]=2, ["cd"]=3, ["cd_start"]=3, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000003]={ ["effect_type"]=1, @@ -572,7 +572,7 @@ local skill = { ["skill_position"]=1, ["cd"]=4, ["cd_start"]=4, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000004]={ ["effect_type"]=1, @@ -589,7 +589,7 @@ local skill = { ["skill_position"]=2, ["cd"]=2, ["cd_start"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000005]={ ["effect_type"]=2, @@ -625,7 +625,7 @@ local skill = { ["skill_position"]=1, ["cd"]=3, ["cd_start"]=3, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000007]={ ["effect_type"]=2, @@ -651,7 +651,7 @@ local skill = { ["skill_position"]=2, ["cd"]=2, ["cd_start"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000009]={ ["effect_type"]=2, @@ -683,7 +683,7 @@ local skill = { ["skill_position"]=2, ["cd"]=2, ["cd_start"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000011]={ ["effect_type"]=1, @@ -700,7 +700,7 @@ local skill = { ["skill_position"]=2, ["cd"]=2, ["cd_start"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000012]={ ["effect_type"]=2, @@ -731,7 +731,7 @@ local skill = { ["skill_position"]=2, ["cd"]=3, ["cd_start"]=3, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000014]={ ["effect_type"]=2, @@ -757,7 +757,7 @@ local skill = { ["skill_position"]=2, ["cd"]=2, ["cd_start"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000016]={ ["skill_type"]=3, @@ -769,7 +769,7 @@ local skill = { ["skill_position"]=2, ["cd"]=2, ["cd_start"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000017]={ ["effect_type"]=2, @@ -816,7 +816,7 @@ local skill = { ["skill_position"]=2, ["cd"]=3, ["cd_start"]=3, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000020]={ ["effect_type"]=2, @@ -842,7 +842,7 @@ local skill = { ["skill_position"]=2, ["cd"]=2, ["cd_start"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000022]={ ["effect_type"]=2, @@ -870,7 +870,7 @@ local skill = { ["skill_position"]=2, ["cd"]=3, ["cd_start"]=3, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000024]={ ["skill_type"]=3, @@ -882,7 +882,7 @@ local skill = { ["skill_position"]=2, ["cd"]=3, ["cd_start"]=3, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000025]={ ["effect_type"]=2, @@ -913,7 +913,7 @@ local skill = { ["skill_position"]=2, ["cd"]=2, ["cd_start"]=2, - ["name_act"]="skill_01" + ["name_act"]="skill01" }, [1000027]={ ["effect_type"]=2, diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 3d7dd79f..200fb639 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -105,17 +105,24 @@ end function BattleUnitComp:useSkill(index, count, callback) self.actionOverCallback = callback - self.normalSkillCount = count + self.unitEntity:getNormalAttackAddCount() - self.activeSkillIndex = nil + self.activeSkillIndex = index self.currActiveSkill = self.unitEntity:getActiveSkill(index) - if self.currActiveSkill == nil and self.normalSkillCount <= 0 then - self.actionOverCallback = nil - callback() - return - end - if not self:changeState(UNIT_STATE.SKILL_ATTACK) then - self.actionOverCallback = nil - callback() + self.normalSkillCount = count + self.unitEntity:getNormalAttackAddCount() + 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 + self.actionOverCallback = nil + callback() + end + else + if not self:changeState(UNIT_STATE.SKILL_ATTACK) then + self.actionOverCallback = nil + callback() + end end end @@ -125,6 +132,11 @@ function BattleUnitComp:useAllSkills(callback) self.activeSkillIndex = 1 self.currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex) 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 self.actionOverCallback = nil callback() @@ -337,7 +349,13 @@ function BattleUnitComp:enterSkillAttackState() self.attackTime = 0 self.currAttackKeyTime = 0.3 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:playAnimation(BattleConst.SPINE_ANIMATION_NAME.MOVE, true, false) self.positionX = self.baseObject:fastGetLocalPosition() @@ -351,7 +369,12 @@ function BattleUnitComp:enterSkillAttackState() else self.isMove = false 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:playAnimation(attackName, false, false) 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 self.isMove = false self.positionX = self.targetX - if self.attackOver then -- 归位后该进行下一次攻击了 - if self.activeSkillIndex then - 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 + if self.attackOver then -- 归位后该下一步了 + self:onAttackOver() else -- 到位置该攻击了 - self.attackTime = 0 - 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) + self:doNextAttack() end end self.baseObject:setLocalPosition(self.positionX, 0, 0) @@ -412,8 +404,21 @@ function BattleUnitComp:updateSkillAttack(dt) self.attackOver = true if self.normalSkillCount > 0 then 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 if self.activeSkillIndex then self.activeSkillIndex = self.activeSkillIndex + 1 @@ -421,40 +426,15 @@ function BattleUnitComp:updateSkillAttack(dt) end if currActiveSkill == nil then if self.targetX then -- 移动过,准备归位 - 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 + self:moveBackToInitPosition() else - self:changeState(UNIT_STATE.IDLE) - local callback = self.actionOverCallback - self.actionOverCallback = nil - if callback then - callback() - end + self:onAttackOver() end return else self.currActiveSkill = currActiveSkill - self.attackTime = 0 - self.currAttackKeyTime = 0.3 - local attackName = self.currActiveSkill:getSkillAttackName() - self.currAttackDuration = self:getAnimationDuration(attackName) - self:playAnimation(attackName, false, false) + self:doNextSkillAttack() 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 else if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用 @@ -469,10 +449,66 @@ function BattleUnitComp:updateSkillAttack(dt) 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() self.attackOver = false self.attackTime = 0 - self.currAttackKeyTime = 0.3 local skill = self.unitEntity:getNormalSkill() if skill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then @@ -506,19 +542,9 @@ function BattleUnitComp:updateNormalAttack(dt) self.isMove = false self.positionX = self.targetX if self.attackOver then -- 归位后该下一步了 - self:changeState(UNIT_STATE.IDLE) - local callback = self.actionOverCallback - self.actionOverCallback = nil - if callback then - callback() - end + self:onAttackOver() 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) + self:doNextNormalAttack() end end self.baseObject:setLocalPosition(self.positionX, 0, 0) @@ -531,32 +557,13 @@ function BattleUnitComp:updateNormalAttack(dt) if self.normalSkillCount <= 0 then local skill = self.unitEntity:getNormalSkill() if skill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then - 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 + self:moveBackToInitPosition() else - self:changeState(UNIT_STATE.IDLE) - local callback = self.actionOverCallback - self.actionOverCallback = nil - if callback then - callback() - end + self:onAttackOver() end return 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) + self:doNextNormalAttack() end else if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用