From f7b2b736f8d21431b4d597fd9f24675382c30354 Mon Sep 17 00:00:00 2001 From: chenxi Date: Wed, 19 Apr 2023 16:27:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E5=9C=BA=E8=A1=A8=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/component/battle_unit_comp.lua | 62 ++++++++++++++----- .../controller/battle_controller_stage.lua | 18 ++++-- lua/app/module/battle/team/battle_team.lua | 19 ++++++ .../battle/team/battle_team_entity.lua | 4 ++ .../battle/team/battle_unit_entity.lua | 4 ++ 5 files changed, 89 insertions(+), 18 deletions(-) diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 622c4e8e..d2f18301 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -47,6 +47,10 @@ function BattleUnitComp:getMatchType() return self.unitEntity:getMatchType() end +function BattleUnitComp:getIsBoss() + return self.unitEntity:getIsBoss() +end + function BattleUnitComp:setTeam(team) self.team = team end @@ -188,6 +192,14 @@ function BattleUnitComp:hideOutsideScreen() end end +function BattleUnitComp:playRunAction() + self:playAnimation(SPINE_ANIMATION_NAME.MOVE, true) +end + +function BattleUnitComp:stopRunAction() + self:playAnimation(SPINE_ANIMATION_NAME.IDLE, true) +end + function BattleUnitComp:playAnimation(name, loop, forceRefresh) if name == SPINE_ANIMATION_NAME.HIT then self.isPlayHurt = 1 @@ -457,6 +469,11 @@ function BattleUnitComp:updateEnterBattlefieldState(dt) self:changeState(UNIT_STATE.IDLE) end self.baseObject:setLocalPosition(self.positionX, 0, 0) + else + self.waitTime = self.waitTime - dt + if self.waitTime < 0 then + self:changeState(UNIT_STATE.IDLE) + end end end @@ -469,16 +486,19 @@ function BattleUnitComp:exitEnterBattlefieldState() end function BattleUnitComp:enterEnterBattlefieldState() - self:hideOutsideScreen() - self.isMove = true - self:playAnimation(SPINE_ANIMATION_NAME.BORN, true, false) - self.positionX = self.baseObject:fastGetLocalPosition() - if self.side == BattleConst.SIDE_ATK then - self.targetX = -BattleConst.INIT_POS_X - self.moveDirection = 1 + if self.isMove then + self:playAnimation(SPINE_ANIMATION_NAME.IDLE, 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.targetX = BattleConst.INIT_POS_X - self.moveDirection = -1 + self:playAnimation(SPINE_ANIMATION_NAME.BORN, false, false) + self.waitTime = self:getAnimationDuration(SPINE_ANIMATION_NAME.BORN) end end @@ -982,12 +1002,26 @@ function BattleUnitComp:playDead(callback) end end -function BattleUnitComp:playEnterBattlefield(callback) +function BattleUnitComp:playEnterBattlefield(isBoss, callback) self.finishEnterBattlefieldCallback = callback - self:hideOutsideScreen() - if not self:changeState(UNIT_STATE.ENTER_BATTLEFIELD) then - self.finishEnterBattlefieldCallback = nil - callback() + if isBoss then + self.isMove = true + self:hideOutsideScreen() + if not self:changeState(UNIT_STATE.ENTER_BATTLEFIELD) then + self.finishEnterBattlefieldCallback = nil + self.isMove = false + self:initPosition() + self:changeState(UNIT_STATE.IDLE) + callback() + end + else + self.isMove = false + self:initPosition() + if not self:changeState(UNIT_STATE.ENTER_BATTLEFIELD) then + self.finishEnterBattlefieldCallback = nil + self:changeState(UNIT_STATE.IDLE) + callback() + end end end diff --git a/lua/app/module/battle/controller/battle_controller_stage.lua b/lua/app/module/battle/controller/battle_controller_stage.lua index 61f6bc1b..6545b657 100644 --- a/lua/app/module/battle/controller/battle_controller_stage.lua +++ b/lua/app/module/battle/controller/battle_controller_stage.lua @@ -31,6 +31,7 @@ function BattleControllerStage:initDefUnits(callback) end function BattleControllerStage:_stageGenerateNextMonster() + local isBoss = self.defTeam:getIsBoss() local config = ConfigManager:getConfig("chapter")[self.chapterId] local unitEntity = DataManager.BattleData:addMonster(config.monster[self.waveIndex], true) local modelId = unitEntity:getModelId() @@ -39,11 +40,20 @@ function BattleControllerStage:_stageGenerateNextMonster() local monsterComp = spineObject:addLuaComponent(GConst.BattleConst.TYPEOF_LUA_COMP.BATTLE_MONSTER_COMPONENT) monsterComp:initWithEntity(modelId, unitEntity, self) self.defTeam:addUnit(monsterComp, true) - monsterComp:playEnterBattlefield(function() - self:enterNextWave() - self:enterRefreshBoard() - end) self.battleUI:refreshDefHp(unitEntity:getHp(), unitEntity:getHpPercent()) + if isBoss then -- 如果是boss就跑过去 + self.atkTeam:playRunAction() + monsterComp:playEnterBattlefield(true, function() + self.atkTeam:stopRunAction() + self:enterNextWave() + self:enterRefreshBoard() + end) + else + monsterComp:playEnterBattlefield(false, function() + self:enterNextWave() + self:enterRefreshBoard() + end) + end end) end diff --git a/lua/app/module/battle/team/battle_team.lua b/lua/app/module/battle/team/battle_team.lua index 7271c321..a0dacaa4 100644 --- a/lua/app/module/battle/team/battle_team.lua +++ b/lua/app/module/battle/team/battle_team.lua @@ -202,6 +202,25 @@ function BattleTeam:getUnitComp() return self.unitMap end +function BattleTeam:getIsBoss() + if self.mainUnit == nil then + return false + end + return self.mainUnit:getIsBoss() +end + +function BattleTeam:playRunAction() + if self.mainUnit then + self.mainUnit:playRunAction() + end +end + +function BattleTeam:stopRunAction() + if self.mainUnit then + self.mainUnit:stopRunAction() + end +end + function BattleTeam:tick(dt) for k, v in ipairs(self.unitList) do v:tick(dt) diff --git a/lua/app/userdata/battle/team/battle_team_entity.lua b/lua/app/userdata/battle/team/battle_team_entity.lua index d66aca23..7c03fedb 100644 --- a/lua/app/userdata/battle/team/battle_team_entity.lua +++ b/lua/app/userdata/battle/team/battle_team_entity.lua @@ -187,6 +187,10 @@ function BattleTeamEntity:removeLimit(name) self.limitAll = self.limitAll - 1 end +function BattleTeamEntity:getIsLimit() + return self.limitAll > 0 +end + function BattleTeamEntity:addShield(num) self.shieldHp = self.shieldHp + num end diff --git a/lua/app/userdata/battle/team/battle_unit_entity.lua b/lua/app/userdata/battle/team/battle_unit_entity.lua index 7ec7cc68..bd606824 100644 --- a/lua/app/userdata/battle/team/battle_unit_entity.lua +++ b/lua/app/userdata/battle/team/battle_unit_entity.lua @@ -225,6 +225,10 @@ function BattleUnitEntity:removeLimit(name) self.team:removeLimit(name) end +function BattleUnitEntity:getIsLimit() + return self.team:getIsLimit() +end + function BattleUnitEntity:addShield(num) self.team:addShield(num) end