From a8d3e443cd24fc15a24ca9abcd53425b65c55f25 Mon Sep 17 00:00:00 2001 From: chenxi Date: Mon, 17 Apr 2023 17:13:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=A2=E4=BA=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/module/battle/battle_const.lua | 4 ++ .../battle/component/battle_unit_comp.lua | 56 +++++++++++++++++++ .../battle/controller/battle_controller.lua | 11 ++-- lua/app/module/battle/team/battle_team.lua | 13 +++++ 4 files changed, 78 insertions(+), 6 deletions(-) diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index 75f2aa63..031d670d 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -60,6 +60,8 @@ BattleConst.UNIT_STATE = { HURT = 4, -- 受伤 DEAD = 5, -- 死亡 ENTER_BATTLEFIELD = 6, -- 进入战场 + SWITCH_IN = 7, -- 入场 + SWITCH_OUT = 8, -- 离场 } BattleConst.MATCH_DMG_ADDITION_NAME = { @@ -95,6 +97,8 @@ BattleConst.SPINE_ANIMATION_NAME = { MOVE = "move", HIT = "suffer", DEAD = "death", + BORN = "born", + OUT = "out", } BattleConst.EFFECT_TYPE = { diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 24d6a473..d9559ac4 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -28,6 +28,15 @@ function BattleUnitComp:playBorn() self:changeState(UNIT_STATE.IDLE) end +function BattleUnitComp:playSwitchIn() + self:changeState(UNIT_STATE.SWITCH_IN) +end + +function BattleUnitComp:playSwitchOut() + self:changeState(UNIT_STATE.SWITCH_OUT) +end + + function BattleUnitComp:getModelId() return self.modelId end @@ -43,6 +52,7 @@ function BattleUnitComp:_initBase() self.attackTime = 0 self.currAttackDuration = 0 self.currAttackKeyTime = 0 + self.switchTime = 0 self.isPlayHurt = 0 self.attackDurationMap = {} self.buffList = {} @@ -160,6 +170,10 @@ function BattleUnitComp:changeState(state) self:exitDeadState() elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then self:exitEnterBattlefieldState() + elseif self.currState == UNIT_STATE.SWITCH_IN then + self:exitSwitchInState() + elseif self.currState == UNIT_STATE.SWITCH_OUT then + self:exitSwitchOutState() end -- 进入目标状态 self.currState = state @@ -175,6 +189,10 @@ function BattleUnitComp:changeState(state) self:enterBornState() elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then self:enterEnterBattlefieldState() + elseif self.currState == UNIT_STATE.SWITCH_IN then + self:enterSwitchInState() + elseif self.currState == UNIT_STATE.SWITCH_OUT then + self:enterSwitchOutState() end return true end @@ -188,6 +206,40 @@ function BattleUnitComp:repeatCurrState() return false end +function BattleUnitComp:updateSwitchInState(dt) + self.switchTime = self.switchTime - dt + if self.switchTime < 0 then + self:changeState(UNIT_STATE.IDLE) + end +end + +function BattleUnitComp:enterSwitchInState() + local aniName = SPINE_ANIMATION_NAME.BORN + self.switchTime = self:getAnimationDuration(aniName) + 0.1 + self:initPosition() + self:playAnimation(aniName, false, true) +end + +function BattleUnitComp:exitSwitchInState() +end + +function BattleUnitComp:updateSwitchOutState(dt) + self.switchTime = self.switchTime - dt + if self.switchTime < 0 then + self:changeState(UNIT_STATE.IDLE) + end +end + +function BattleUnitComp:enterSwitchOutState() + local aniName = SPINE_ANIMATION_NAME.OUT + self.switchTime = self:getAnimationDuration(aniName) + 0.1 + self:playAnimation(aniName, false, true) +end + +function BattleUnitComp:exitSwitchOutState() + self:hideOutsideScreen() +end + function BattleUnitComp:updateDead(dt) self.deadTime = self.deadTime - dt if self.deadTime <= 0 then @@ -620,6 +672,10 @@ function BattleUnitComp:tick(dt) self:updateSkillAttack(dt) elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then self:updateEnterBattlefieldState(dt) + elseif self.currState == UNIT_STATE.SWITCH_IN then + self:updateSwitchInState(dt) + elseif self.currState == UNIT_STATE.SWITCH_OUT then + self:updateSwitchOutState(dt) end end diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 5168ea7b..046037b5 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -106,7 +106,7 @@ function BattleController:onLinkChange() self.battleUI:refreshSkill(elementTypeMap) if mainElementType then - Logger.logHighlight("mainElementType " .. mainElementType) + self.atkTeam:changeMainUnit(mainElementType) end end @@ -1166,12 +1166,10 @@ function BattleController:snapshotBoard() return snapshot end -function BattleController:addBattleExp(side, exp) - if side ~= BattleConst.SIDE_ATK or not self.battleData then +function BattleController:addBattleExp(exp) + if not self.battleData or not exp then return end - - exp = exp or 1 self.battleData:addExp(exp) end @@ -1225,11 +1223,12 @@ local function _addCurRoundAttr(self, instruction, callback) end local function _assisting(self, instruction, callback) - self:addBattleExp(BattleConst.SIDE_ATK, instruction.count) -- 先直接加 + self:addBattleExp(instruction.count) callback() end local function _generalAttack(self, instruction, callback) + self:addBattleExp(instruction.count) -- 先直接加 self.atkTeam:useNormalSkill(instruction.skillMatch, instruction.count, callback) end diff --git a/lua/app/module/battle/team/battle_team.lua b/lua/app/module/battle/team/battle_team.lua index 3afe8c6c..ecd13cc2 100644 --- a/lua/app/module/battle/team/battle_team.lua +++ b/lua/app/module/battle/team/battle_team.lua @@ -62,6 +62,19 @@ function BattleTeam:mainUnitUseAllSkills(callback) self.mainUnit:useAllSkills(callback) end +function BattleTeam:changeMainUnit(matchType) + if self.mainUnit and matchType == self.mainUnit:getMatchType() then + return + end + local unit = self.unitMap[matchType] + if unit == nil then + return + end + self.mainUnit:playSwitchOut() + self.mainUnit = unit + unit:playSwitchIn() +end + function BattleTeam:tick(dt) for k, v in ipairs(self.unitList) do v:tick(dt)