From f839dc3b57abb0085d013b7aa3d6cd3e07f39301 Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Tue, 5 Sep 2023 17:14:49 +0800 Subject: [PATCH] =?UTF-8?q?buff=E6=95=B0=E5=80=BC=E4=B8=8A=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/component/battle_unit_comp.lua | 10 ++++ lua/app/module/battle/team/battle_team.lua | 56 +++++++++++++++++++ .../battle/skill/battle_buff_entity.lua | 4 ++ 3 files changed, 70 insertions(+) diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index caa0de46..b0e3ff3f 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -1352,6 +1352,10 @@ function BattleUnitComp:addBuff(buffEffect, conditionResult) return self.team:addBuff(buffEffect) end +function BattleUnitComp:judgeBuffEffectEffectNumOverflow(buffEntity) + return self.team:judgeBuffEffectEffectNumOverflow(buffEntity) +end + function BattleUnitComp:getBuffCountByName(buffName) return self.team:getBuffCountByName(buffName) end @@ -1553,6 +1557,9 @@ function BattleUnitComp:takeEffect(buff, target, conditionResult) buffEffect.target = target buffEffect.sender = self buffEffect = target:addBuff(buffEffect, conditionResult) + if not buffEffect then -- 添加buff失败 + return + end end if buffEffect and buffEffect.result then return @@ -1584,6 +1591,9 @@ function BattleUnitComp:reTakeEffectByBuffEffect(buffEffect) if round > 0 then buffEffect.result = nil buffEffect = target:addBuff(buffEffect) + if not buffEffect then -- 添加buff失败 + return + end end if buffEffect and buffEffect.result then return diff --git a/lua/app/module/battle/team/battle_team.lua b/lua/app/module/battle/team/battle_team.lua index 70fbf3cc..9c53a9fa 100644 --- a/lua/app/module/battle/team/battle_team.lua +++ b/lua/app/module/battle/team/battle_team.lua @@ -11,6 +11,7 @@ function BattleTeam:init(side, battleController) self.unitMap = {} self.buffList = {} self.sameBuffCount = {} + self.sameBuffEffectNum = {} -- 相同的buff参数,用于判定buff数值上限 self.shieldBuffList = {} self.loopFxMap = {} self.comboCount = 0 @@ -265,9 +266,14 @@ function BattleTeam:handleShield(reduceShield, unit) if needReedRefreshBuff then self.battleController:refreshBuff(self.side, self.buffList) end + self:calSameBuffEffectNum() end function BattleTeam:addBuff(buffEffect) + if not self:judgeBuffEffectEffectNumOverflow(buffEffect.buff) then + return + end + local stack = buffEffect.buff:getStack() local needRecycle if not stack or stack == BattleConst.BUFF_STACK_TYPE.CANT_ADD then @@ -337,6 +343,7 @@ function BattleTeam:addBuff(buffEffect) self.battleController:refreshBuff(self.side, self.buffList) end + self:calSameBuffEffectNum() return needRecycle end @@ -364,6 +371,7 @@ function BattleTeam:removeAllBuff() end self.battleController:clearBuff(self.side) + self:calSameBuffEffectNum() end function BattleTeam:putCacheBuff(buffEffect) @@ -402,6 +410,8 @@ function BattleTeam:putCacheBuffByDecr(buffDecr) if needRefresh then self.battleController:refreshBuff(self.side, self.buffList) end + + self:calSameBuffEffectNum() end function BattleTeam:popCacheBuffByDecr(buffDecr) @@ -426,6 +436,48 @@ function BattleTeam:popCacheBuffByDecr(buffDecr) if needRefresh then self.battleController:refreshBuff(self.side, self.buffList) end + + self:calSameBuffEffectNum() +end + +function BattleTeam:calSameBuffEffectNum() + if not self.buffList then + return + end + self.sameBuffEffectNum = table.clearOrCreate(self.sameBuffEffectNum) + for _, buffEffect in ipairs(self.buffList) do + local buffEntity = buffEffect.buff + if buffEntity then + local buffName = buffEntity:getName() + local buffNum = buffEntity:getEffectNum() + if buffName and buffNum then + self.sameBuffEffectNum[buffName] = (self.sameBuffEffectNum[buffName] or 0) + buffNum + end + end + end +end + +function BattleTeam:judgeBuffEffectEffectNumOverflow(buffEntity) + if not buffEntity then + return true + end + local limitNum = buffEntity:getLimitParameter() + if not limitNum then + return true + end + + local buffName = buffEntity:getName() + local buffNum = buffEntity:getEffectNum() + local curNum = self.sameBuffEffectNum[buffName] or 0 + local remainNum = limitNum - curNum + if remainNum <= 0 then -- 已经超出上限了,直接返回失败 + return false + end + + if buffNum > remainNum then + buffEntity:setEffectNum(remainNum) + end + return true end function BattleTeam:doBuffWork() @@ -473,6 +525,8 @@ function BattleTeam:doBuffWork() end end self.battleController:refreshBuff(self.side, self.buffList) + + self:calSameBuffEffectNum() end -- 比如复活类,需要最后触发buff @@ -514,6 +568,7 @@ function BattleTeam:doFinalBuffWork() if refreshUI then self.battleController:refreshBuff(self.side, self.buffList) end + self:calSameBuffEffectNum() end function BattleTeam:removeBuffByName(buffName) @@ -531,6 +586,7 @@ function BattleTeam:removeBuffByName(buffName) end end self.battleController:refreshBuff(self.side, self.buffList) + self:calSameBuffEffectNum() end function BattleTeam:updateBuffState(buff, num) diff --git a/lua/app/userdata/battle/skill/battle_buff_entity.lua b/lua/app/userdata/battle/skill/battle_buff_entity.lua index d10ccc53..d7dc0e62 100644 --- a/lua/app/userdata/battle/skill/battle_buff_entity.lua +++ b/lua/app/userdata/battle/skill/battle_buff_entity.lua @@ -141,6 +141,10 @@ function BattleBuffEntity:needShowName() return self.buffInfo.show_name end +function BattleBuffEntity:getLimitParameter() + return self.buffInfo.limit_parameter +end + function BattleBuffEntity:isCantRemove() return self.cantRemove end