From b311395f108c6f25ac41ab8a380af4a8a2e6b7d3 Mon Sep 17 00:00:00 2001 From: chenxi Date: Sun, 16 Apr 2023 22:59:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=AA=E7=89=A9=E6=8A=80=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/module/battle/battle_const.lua | 2 +- .../battle/component/battle_unit_comp.lua | 138 +++++++++++++++++- .../battle/controller/battle_controller.lua | 5 +- lua/app/userdata/battle/battle_data.lua | 2 +- .../battle/skill/battle_skill_entity.lua | 5 + .../battle/team/battle_unit_entity.lua | 4 + 6 files changed, 145 insertions(+), 11 deletions(-) diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index 8f33472d..ce9f78e7 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -56,7 +56,7 @@ BattleConst.UNIT_STATE = { INIT = 0, -- 初始化 IDLE = 1, -- 待机 NORMAL_ATTACK = 2, -- 普通攻击 - SKILL = 3, -- 技能 + SKILL_ATTACK = 3, -- 技能攻击 HURT = 4, -- 受伤 DEAD = 5, -- 死亡 ENTER_BATTLEFIELD = 6, -- 进入战场 diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 4436d937..3ac23cb6 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -44,6 +44,9 @@ function BattleUnitComp:_initBase() self.buffList = {} self.sameBuffCount = {} self.shieldBuffList = {} + self.activeSkillIndex = 1 + self.currActiveSkill = nil + self.targetX = nil self.currState = UNIT_STATE.INIT end @@ -86,6 +89,21 @@ function BattleUnitComp:getAnimationDuration(aniName) return duration or 0 end +function BattleUnitComp:useAllSkills(callback) + self.actionOverCallback = callback + self.activeSkillIndex = 1 + self.currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex) + if self.currActiveSkill == nil then + self.actionOverCallback = nil + callback() + return + end + if not self:changeState(UNIT_STATE.SKILL_ATTACK) then + self.actionOverCallback = nil + callback() + end +end + function BattleUnitComp:useNormalSkill(count, callback) self.baseObject:getTransform():SetAsLastSibling() self.actionOverCallback = callback @@ -117,8 +135,8 @@ function BattleUnitComp:changeState(state) self:exitIdleState() elseif self.currState == UNIT_STATE.NORMAL_ATTACK then self:exitNormalAttackState() - elseif self.currState == UNIT_STATE.SKILL then - self:exitSkillState() + elseif self.currState == UNIT_STATE.SKILL_ATTACK then + self:exitSkillAttackState() elseif self.currState == UNIT_STATE.DEAD then self:exitDeadState() elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then @@ -130,8 +148,8 @@ function BattleUnitComp:changeState(state) self:enterIdleState() elseif state == UNIT_STATE.NORMAL_ATTACK then self:enterNormalAttackState() - elseif state == UNIT_STATE.SKILL then - self:enterSkillState() + elseif state == UNIT_STATE.SKILL_ATTACK then + self:enterSkillAttackState() elseif state == UNIT_STATE.DEAD then self:enterDeadState() elseif self.currState == UNIT_STATE.BORN then @@ -145,7 +163,7 @@ end function BattleUnitComp:repeatCurrState() if self.currState == UNIT_STATE.NORMAL_ATTACK then return true - elseif self.currState == UNIT_STATE.SKILL then + elseif self.currState == UNIT_STATE.SKILL_ATTACK then return true end return false @@ -240,6 +258,112 @@ function BattleUnitComp:updateHurt(dt) end end +function BattleUnitComp:enterSkillAttackState() + self.attackOver = false + self.attackTime = 0 + self.currAttackKeyTime = 0.3 + self.targetX = nil + if self.currActiveSkill: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.UNIT_FRONT_POS_X + self.moveDirection = 1 + else + self.targetX = -BattleConst.UNIT_FRONT_POS_X + self.moveDirection = -1 + end + else + self.isMove = false + self.attackTime = 0 + local attackName = self.currActiveSkill:getSkillAttackName() + self.currAttackDuration = self:getAnimationDuration(attackName) + self:playAnimation(attackName, false, false) + end +end + +function BattleUnitComp:exitSkillAttackState() +end + +function BattleUnitComp:updateSkillAttack(dt) + if self.isMove then + local addX = dt*BattleConst.MOVE_SPEED*self.moveDirection + self.positionX = self.positionX + addX + 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 -- 归位后该进行下一次攻击了 + self.activeSkillIndex = self.activeSkillIndex + 1 + self.currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex) + 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 -- 到位置该攻击了 + self.attackTime = 0 + local attackName = self.currActiveSkill:getSkillAttackName() + self.currAttackDuration = self:getAnimationDuration(attackName) + self:playAnimation(attackName, false, false) + end + end + self.baseObject:setLocalPosition(self.positionX, 0, 0) + return + end + self.attackTime = self.attackTime + dt + if self.attackTime >= self.currAttackDuration then + self.attackOver = true + self.activeSkillIndex = self.activeSkillIndex + 1 + local currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex) + 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 + else + self:changeState(UNIT_STATE.IDLE) + local callback = self.actionOverCallback + self.actionOverCallback = nil + if callback then + callback() + end + 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) + end + else + if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用 + self.currAttackKeyTime = 0 + self:onSkillTakeEffect(self.currActiveSkill) + end + end +end + function BattleUnitComp:enterNormalAttackState() self.attackOver = false self.attackTime = 0 @@ -463,8 +587,8 @@ function BattleUnitComp:tick(dt) end if self.currState == UNIT_STATE.NORMAL_ATTACK then self:updateNormalAttack(dt) - elseif self.currState == UNIT_STATE.SKILL then - self:updateSkill(dt) + elseif self.currState == UNIT_STATE.SKILL_ATTACK then + self:updateSkillAttack(dt) elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then self:updateEnterBattlefieldState(dt) end diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 3de59786..0e1f319d 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -305,8 +305,9 @@ end function BattleController:enterDefStep() self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_DEF_STEP - -- defTodo - self:enterDefStepOver() + self.defMainUnit:useAllSkills(function() + self:enterDefStepOver() + end) end function BattleController:enterDefStepOver() diff --git a/lua/app/userdata/battle/battle_data.lua b/lua/app/userdata/battle/battle_data.lua index d0b3e7c4..30735319 100644 --- a/lua/app/userdata/battle/battle_data.lua +++ b/lua/app/userdata/battle/battle_data.lua @@ -375,7 +375,7 @@ function BattleData:initHeroData() modelId = heroEntity:getModelId(), matchType = matchType, normalSkill = heroEntity:getHurtSkill(), - activeSkill = {activeSkill}, + activeSkills = {activeSkill}, attr = { hp = hp, max_hp = hp, diff --git a/lua/app/userdata/battle/skill/battle_skill_entity.lua b/lua/app/userdata/battle/skill/battle_skill_entity.lua index 175d7027..d39bb444 100644 --- a/lua/app/userdata/battle/skill/battle_skill_entity.lua +++ b/lua/app/userdata/battle/skill/battle_skill_entity.lua @@ -44,6 +44,11 @@ function BattleSkillEntity:getRandomNormalAttackName() return self.normalSkillNameList[self.normalSkillNameIndex] end +function BattleSkillEntity:getSkillAttackName() + -- return self.skillInfo.name_act + return "atk1" +end + function BattleSkillEntity:getEffectList() return self.effectList end diff --git a/lua/app/userdata/battle/team/battle_unit_entity.lua b/lua/app/userdata/battle/team/battle_unit_entity.lua index b3810b9e..76c4f730 100644 --- a/lua/app/userdata/battle/team/battle_unit_entity.lua +++ b/lua/app/userdata/battle/team/battle_unit_entity.lua @@ -53,6 +53,10 @@ function BattleUnitEntity:getNormalSkill() return self.normalSkill end +function BattleUnitEntity:getActiveSkill(index) + return self.activeSkills[index] +end + function BattleUnitEntity:takeDamageOrCure(num) return self.team:takeDamageOrCure(num) end