diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index 4051846c..0272071b 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -38,6 +38,13 @@ BattleConst.BATTLE_ROUND_STEP = { ON_END = 10, -- 回合结束 } +BattleConst.TIME_SCALE = { + LEVEL_0 = 0, + LEVEL_1 = 1, + LEVEL_2 = 1.5, + LEVEL_3 = 2, +} + -- 为方便存储,这里使用字符串 BattleConst.BATTLE_TYPE = { STAGE = "1", diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index aa433ead..95a2425e 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -67,6 +67,7 @@ function BattleUnitComp:_initBase() self.currActiveSkill = nil self.targetX = nil self.assistingDmgAddition = 0 + self.attackCount = 0 self.currState = UNIT_STATE.INIT end @@ -88,6 +89,10 @@ function BattleUnitComp:prepare() self:checkPassiveEvent(PASSIVE_EVENT.HP_LOWER_THAN, nil, self.unitEntity:getHpPercent()) end +function BattleUnitComp:resetBeforeAttack() + self.attackCount = 0 +end + function BattleUnitComp:initPassiveSkills() local pasSkills = self.unitEntity:getPassiveSkills() if pasSkills and #pasSkills > 0 then @@ -503,6 +508,7 @@ function BattleUnitComp:enterAssistingAttackState() self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) + self:attackAndSpeedUp() self:initPosition() end @@ -564,6 +570,7 @@ function BattleUnitComp:enterSkillAttackState() self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) + self:attackAndSpeedUp() end end @@ -695,12 +702,22 @@ function BattleUnitComp:onAttackOver() end end +function BattleUnitComp:attackAndSpeedUp() + self.attackCount = self.attackCount + 1 + if self.attackCount == 3 then + DataManager.BattleData:addTimeSpeed() + elseif self.attackCount == 5 then + DataManager.BattleData:addTimeSpeed() + end +end + function BattleUnitComp:doNextSkillAttack() self.attackTime = 0 local attackName = self.currActiveSkill:getSkillAttackName() self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) + self:attackAndSpeedUp() end function BattleUnitComp:doNextNormalAttack() @@ -710,6 +727,7 @@ function BattleUnitComp:doNextNormalAttack() self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) + self:attackAndSpeedUp() end function BattleUnitComp:doNextAttack() @@ -725,6 +743,7 @@ function BattleUnitComp:doNextAttack() self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) + self:attackAndSpeedUp() else -- 归位 self:moveBackToInitPosition() end @@ -753,6 +772,7 @@ function BattleUnitComp:enterNormalAttackState() self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) + self:attackAndSpeedUp() end end diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 9c5974c8..4072ee45 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -148,11 +148,23 @@ function BattleController:init(params) BattleScheduler:init() BattleHelper:init() BattlePassive:init() + self:setTimeScale(DataManager.BattleData:getTimeScale()) + self:bindData() self:initBattleTeam() self:initOther() self:prepareFight() end +function BattleController:bindData() + DataManager.BattleData:bind("timeSpeed", ModuleManager.BattleManager, function() + self:setTimeScale(DataManager.BattleData:getTimeScale()) + end, false) +end + +function BattleController:unBindAll() + DataManager.BattleData:unBind("timeSpeed", ModuleManager.BattleManager) +end + function BattleController:initBattleTeam() self.atkTeam = BattleTeam:create() self.atkTeam:init(BattleConst.SIDE_ATK, self) @@ -245,6 +257,12 @@ function BattleController:battleStart() self:enterNextWave() end +function BattleController:setTimeScale(timeScale) + GFunc.setDOTweenTimeScale(GConst.DOTWEEN_IDS.BATTLE, timeScale) + BattleScheduler:setTimeScale(timeScale) + BattleHelper:setTimeScale(timeScale) +end + ---- start 回合步骤 function BattleController:enterNextWave() @@ -366,6 +384,7 @@ function BattleController:enterRefreshBoard() end function BattleController:enterRoundEnd() + DataManager.BattleData:resetTimeSpeed() self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_END local defTeam = self.battleData:getDefTeam() if not defTeam or defTeam:getIsDead() then -- 怪物死了, 直接进入刷新逻辑 @@ -1299,6 +1318,8 @@ function BattleController:clear() BattleScheduler:clear() BattleHelper:clear() BattlePassive:clear() + self:unBindAll() + DataManager.BattleData:resetTimeSpeed() end function BattleController:endBattleAndExit() diff --git a/lua/app/module/battle/helper/battle_helper.lua b/lua/app/module/battle/helper/battle_helper.lua index 67423cbd..34f847b5 100644 --- a/lua/app/module/battle/helper/battle_helper.lua +++ b/lua/app/module/battle/helper/battle_helper.lua @@ -12,6 +12,19 @@ function BattleHelper:init() self.seed = tonumber(tostring(os.time()):reverse():sub(1,6)) end +function BattleHelper:setTimeScale(timeScale) + if self.effectMap then + for k, effect in pairs(self.effectMap) do + effect:setTimeScale(timeScale) + end + end + if self.characterMap then + for k, character in pairs(self.characterMap) do + character:setTimeScale(timeScale) + end + end +end + function BattleHelper:random(min, max) self.seed = (self.seed*9301 + 49297)%233280 return min + self.seed*(max - min + 1)//233280 @@ -25,12 +38,16 @@ function BattleHelper:loadBattleHeroModel(id, parent, callback) if self.characterMap then self.characterMap[spineObject:getInstanceID()] = spineObject end + local timeScale = DataManager.BattleData:getTimeScale() + spineObject:setTimeScale(timeScale) callback(spineObject) else SpineManager:loadHeroAsync(id, parent, function(spineObject) spineObject:setDefaultMix(0) if self.characterMap then self.characterMap[spineObject:getInstanceID()] = spineObject + local timeScale = DataManager.BattleData:getTimeScale() + spineObject:setTimeScale(timeScale) callback(spineObject) end end) diff --git a/lua/app/module/battle/team/battle_team.lua b/lua/app/module/battle/team/battle_team.lua index cdefdc35..6a9aef06 100644 --- a/lua/app/module/battle/team/battle_team.lua +++ b/lua/app/module/battle/team/battle_team.lua @@ -56,6 +56,7 @@ function BattleTeam:useNormalSkill(matchType, count, callback) self.mainUnit = unit self.battleController:setIsPauseHpProgress(true) unit:beforeAttack() + unit:resetBeforeAttack() unit:useNormalSkill(count, callback) end @@ -72,6 +73,7 @@ function BattleTeam:useSkill(matchType, count, callback) self.mainUnit = unit self.battleController:setIsPauseHpProgress(true) unit:beforeAttack() + unit:resetBeforeAttack() unit:useSkill(1, count, callback) end @@ -89,6 +91,7 @@ function BattleTeam:useAssistingSkill(assistingList, callback) for _, v in ipairs(assistingList) do local unit = self.unitMap[v.skillMatch] if unit then + unit:resetBeforeAttack() unit:useAssistingSkill(v.count, finish) else finish() @@ -99,6 +102,7 @@ end function BattleTeam:mainUnitUseAllSkills(callback) self.battleController:setIsPauseHpProgress(true) self.mainUnit:beforeAttack() + self.mainUnit:resetBeforeAttack() self.mainUnit:useAllSkills(callback) end diff --git a/lua/app/userdata/battle/battle_data.lua b/lua/app/userdata/battle/battle_data.lua index db0c30da..8adacf26 100644 --- a/lua/app/userdata/battle/battle_data.lua +++ b/lua/app/userdata/battle/battle_data.lua @@ -17,6 +17,8 @@ function BattleData:init() self.curBattleExp = 0 self.needBattleExp = self:getLvNeedExp() self.addLvCount = 0 + self.timeScale = BattleConst.TIME_SCALE.LEVEL_1 + self.data.timeSpeed = 1 self.data.lvDirty = false BattleSkillEntity.sid = 0 self.atkTeam = self:initTeam(BattleConst.SIDE_ATK) @@ -24,6 +26,68 @@ function BattleData:init() self:initRogueSkills() end +function BattleData:getTimeScale() + return self.timeScale +end + +function BattleData:pauseBattle() + self.cacheSpeed = self.data.timeSpeed + self:setTimeSpeed(0) +end + +function BattleData:resumeBattle() + if self.cacheSpeed == nil then + return + end + if self.data.timeSpeed ~= 0 then + return + end + self:setTimeSpeed(self.cacheSpeed or 1) +end + +function BattleData:resetTimeSpeed() + if self.cacheSpeed then -- 目前处于暂停状态 + self.cacheSpeed = 1 + return + end + if self.data.timeSpeed <= 1 then + return + end + self:setTimeSpeed(1) +end + +function BattleData:addTimeSpeed() + if self.data.timeSpeed >= 3 then + return + end + if self.cacheSpeed then -- 目前处于暂停状态 + if self.cacheSpeed < 3 then + self.cacheSpeed = self.cacheSpeed + 1 + end + return + end + local timeSpeed = self.data.timeSpeed + 1 + self:setTimeSpeed(timeSpeed) +end + +function BattleData:setTimeSpeed(timeSpeed) + if timeSpeed == self.data.timeSpeed then + return + end + if timeSpeed == 0 then + self.timeScale = 0 + elseif timeSpeed == 1 then + self.timeScale = BattleConst.TIME_SCALE.LEVEL_1 + elseif timeSpeed == 2 then + self.timeScale = BattleConst.TIME_SCALE.LEVEL_2 + elseif timeSpeed == 3 then + self.timeScale = BattleConst.TIME_SCALE.LEVEL_3 + else + self.timeScale = BattleConst.TIME_SCALE.LEVEL_1 + end + self.data.timeSpeed = timeSpeed +end + function BattleData:initRogueSkills() self.skillPool = {} self.skillMap = {}