diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index 8fcf179b..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", @@ -129,6 +136,7 @@ BattleConst.PASSIVE_EVENT = { ON_UNIT_PREPARE_OVER = 2, -- 新单位出场时 ON_UNI_ATTACK_START = 3, -- 攻击开始前 HP_LOWER_THAN = 4, -- 血量低于X% + USE_NORMAL_SKILL = 5, -- 使用普攻 } local BUFF_NAME = { diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 73c692d5..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 @@ -812,9 +832,6 @@ end function BattleUnitComp:onSkillTakeEffect(skill) skill:endUse() - if self.side == GConst.BattleConst.SIDE_ATK and skill == self.unitEntity:getNormalSkill() then - self.battleController:addBattleExp(self.side) - end local effectList = skill:getEffectList() if effectList == nil then return @@ -825,6 +842,14 @@ function BattleUnitComp:onSkillTakeEffect(skill) target = self else target = self.battleController:getOtherSideMainUnit(self.side) + if skill:getIsNormalType() then -- 普攻要计算一下格挡 + local block = target.unitEntity:getBlock() + if block > 0 then + if BattleHelper:random(1, DEFAULT_FACTOR) <= block then -- 格挡成功 + return + end + end + end end local succ = false @@ -833,6 +858,9 @@ function BattleUnitComp:onSkillTakeEffect(skill) succ = true end end + if succ and skill:getIsNormalType() then -- 普攻攻击成功的话 + self:checkPassiveEvent(PASSIVE_EVENT.USE_NORMAL_SKILL, target) + end end function BattleUnitComp:takeEffect(buff, target) @@ -887,7 +915,13 @@ function BattleUnitComp:takeDamageOrCure(atker, buff, num, effectType, effectSta return 0 end local shieldHpBefore = self.unitEntity:getShieldHp() - self.unitEntity:takeDamageOrCure(num) + local hpRealReduce = self.unitEntity:takeDamageOrCure(num) + if hpRealReduce < 0 and self.side == BattleConst.SIDE_DEF then -- 实际掉血了 + local exp = self.unitEntity:getExp() + if exp > 0 then + self.battleController:addBattleExp(math.floor(exp/self.unitEntity:getMaxHp()*-hpRealReduce)) + end + end local shieldHpDiff = self.unitEntity:getShieldHp() - shieldHpBefore if shieldHpDiff < 0 then -- 说明护盾减少了 self:handleShield(shieldHpDiff, self) diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index c4fdcf50..32e96cb1 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 -- 怪物死了, 直接进入刷新逻辑 @@ -1402,6 +1421,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/helper/battle_passive.lua b/lua/app/module/battle/helper/battle_passive.lua index 4c24d36c..12beb35e 100644 --- a/lua/app/module/battle/helper/battle_passive.lua +++ b/lua/app/module/battle/helper/battle_passive.lua @@ -41,10 +41,15 @@ local function _checkhpLowerThan(unitComp, skill, targetComp, hpPercent) return 0 end +local function _checkUseNormalSkill(unitComp, skill, targetComp) + return 1 +end + BattlePassive.checkTrigger = { [PASSIVE_EVENT.ON_UNIT_PREPARE_OVER] = _checkOnUnitPrepareOver, [PASSIVE_EVENT.ON_UNI_ATTACK_START] = _checkOnUniAttackStart, [PASSIVE_EVENT.HP_LOWER_THAN] = _checkhpLowerThan, + [PASSIVE_EVENT.USE_NORMAL_SKILL] = _checkUseNormalSkill, } return BattlePassive \ No newline at end of file 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 815feb5f..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 = {} @@ -416,6 +480,7 @@ function BattleData:addMonster(monsterId, newTeam) normalSkillCount = monsterInfo.hurt_num, assistingSkill = nil, isBoss = monsterInfo.is_boss, + exp = monsterInfo.monster_exp or 0, 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 db387a03..b3e06231 100644 --- a/lua/app/userdata/battle/skill/battle_skill_entity.lua +++ b/lua/app/userdata/battle/skill/battle_skill_entity.lua @@ -1,4 +1,5 @@ local BattleBuffEntity = require "app/userdata/battle/skill/battle_buff_entity" +local BattleConst = require "app/module/battle/battle_const" local BattleSkillEntity = class("BattleSkillEntity", BaseData) @@ -104,7 +105,11 @@ function BattleSkillEntity:getSkillid() end function BattleSkillEntity:getIsPassiveType() - return self.skillType == GConst.BattleConst.SKILL_TYPE_PASSIVE + return self.skillType == BattleConst.SKILL_TYPE_PASSIVE +end + +function BattleSkillEntity:getIsNormalType() + return self.skillType == BattleConst.SKILL_TYPE_NORMAL end function BattleSkillEntity:changeSkillId(skillId) diff --git a/lua/app/userdata/battle/team/battle_team_entity.lua b/lua/app/userdata/battle/team/battle_team_entity.lua index 00672b56..d66aca23 100644 --- a/lua/app/userdata/battle/team/battle_team_entity.lua +++ b/lua/app/userdata/battle/team/battle_team_entity.lua @@ -129,6 +129,10 @@ function BattleTeamEntity:getHp() return self.attr.hp end +function BattleTeamEntity:getMaxHp() + return self.attr.max_hp +end + function BattleTeamEntity:getHpPercent() return self.attr.hp / self.attr.max_hp end @@ -191,6 +195,10 @@ function BattleTeamEntity:getShieldHp() return self.shieldHp end +function BattleTeamEntity:getBlock() + return self.attr.block or 0 +end + function BattleTeamEntity:takeDamageOrCure(num) if self.isDead then return 0 @@ -212,7 +220,7 @@ function BattleTeamEntity:takeDamageOrCure(num) hurtEventNum = num else -- 满血了 -- 这是加血 - hurtEventNum = 0 + hurtEventNum = self.attr.max_hp - hpBefore self.attr.hp = self.attr.max_hp end return hurtEventNum diff --git a/lua/app/userdata/battle/team/battle_unit_entity.lua b/lua/app/userdata/battle/team/battle_unit_entity.lua index 657fb9be..24d2ae3f 100644 --- a/lua/app/userdata/battle/team/battle_unit_entity.lua +++ b/lua/app/userdata/battle/team/battle_unit_entity.lua @@ -177,6 +177,10 @@ function BattleUnitEntity:getHp() return self.team:getHp() end +function BattleUnitEntity:getMaxHp() + return self.team:getMaxHp() +end + function BattleUnitEntity:getHpPercent() return self.team:getHpPercent() end @@ -233,6 +237,14 @@ function BattleUnitEntity:addMaxHp(num) self.team:addMaxHp(num) end +function BattleUnitEntity:getBlock() + return self.team:getBlock() +end + +function BattleUnitEntity:getExp() + return self.unitData.exp +end + function BattleUnitEntity:addSkillExtraUseTimes(skillId, count) if self.skillExtraUseTimes == nil then self.skillExtraUseTimes = {}