处理护盾以及buff

This commit is contained in:
chenxi 2023-04-18 11:04:27 +08:00
parent 74cffb310d
commit 3bc1b7b07a
6 changed files with 173 additions and 20 deletions

View File

@ -45,6 +45,10 @@ function BattleUnitComp:getMatchType()
return self.unitEntity:getMatchType() return self.unitEntity:getMatchType()
end end
function BattleUnitComp:setTeam(team)
self.team = team
end
function BattleUnitComp:_initBase() function BattleUnitComp:_initBase()
self.isClear = false self.isClear = false
self.isMove = false self.isMove = false
@ -55,8 +59,6 @@ function BattleUnitComp:_initBase()
self.switchTime = 0 self.switchTime = 0
self.isPlayHurt = 0 self.isPlayHurt = 0
self.attackDurationMap = {} self.attackDurationMap = {}
self.buffList = {}
self.sameBuffCount = {}
self.shieldBuffList = {} self.shieldBuffList = {}
self.activeSkillIndex = nil self.activeSkillIndex = nil
self.currActiveSkill = nil self.currActiveSkill = nil
@ -124,11 +126,12 @@ end
function BattleUnitComp:useSkill(index, count, callback) function BattleUnitComp:useSkill(index, count, callback)
self.actionOverCallback = callback self.actionOverCallback = callback
self.activeSkillIndex = index self.activeSkillIndex = index
self.currActiveSkill = self.unitEntity:getActiveSkill(index) self.currActiveSkill = self.unitEntity:getAvailableActiveSkill(index)
self.normalSkillCount = count + self.unitEntity:getNormalAttackAddCount() self.normalSkillCount = count + self.unitEntity:getNormalAttackAddCount()
if self.currActiveSkill == nil then -- 没有技能就用普攻 if self.currActiveSkill == nil then -- 没有技能就用普攻
if self.normalSkillCount <= 0 then if self.normalSkillCount <= 0 then
self.actionOverCallback = nil self.actionOverCallback = nil
self.activeSkillIndex = nil
callback() callback()
return return
end end
@ -148,7 +151,15 @@ function BattleUnitComp:useAllSkills(callback)
self.actionOverCallback = callback self.actionOverCallback = callback
self.normalSkillCount = self.unitEntity:getNormalSkillCount() + self.unitEntity:getNormalAttackAddCount() self.normalSkillCount = self.unitEntity:getNormalSkillCount() + self.unitEntity:getNormalAttackAddCount()
self.activeSkillIndex = 1 self.activeSkillIndex = 1
self.currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex) self.currActiveSkill = nil
local activeSkillCount = self.unitEntity:getActiveSkillCount()
while self.activeSkillIndex <= activeSkillCount do
self.currActiveSkill = self.unitEntity:getAvailableActiveSkill(self.activeSkillIndex)
if self.currActiveSkill then
break
end
self.activeSkillIndex = self.activeSkillIndex + 1
end
if self.currActiveSkill == nil then -- 没有技能就用普攻 if self.currActiveSkill == nil then -- 没有技能就用普攻
if self.normalSkillCount <= 0 then if self.normalSkillCount <= 0 then
self.actionOverCallback = nil self.actionOverCallback = nil
@ -177,10 +188,8 @@ function BattleUnitComp:useNormalSkill(count, callback)
end end
function BattleUnitComp:addShield(num, buffEffect) function BattleUnitComp:addShield(num, buffEffect)
if buffEffect then
table.insert(self.shieldBuffList, buffEffect)
end
self.unitEntity:addShield(num) self.unitEntity:addShield(num)
self.team:addShield(buffEffect)
end end
function BattleUnitComp:changeState(state) function BattleUnitComp:changeState(state)
@ -480,7 +489,14 @@ function BattleUnitComp:updateSkillAttack(dt)
local currActiveSkill = nil local currActiveSkill = nil
if self.activeSkillIndex then if self.activeSkillIndex then
self.activeSkillIndex = self.activeSkillIndex + 1 self.activeSkillIndex = self.activeSkillIndex + 1
currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex) local activeSkillCount = self.unitEntity:getActiveSkillCount()
while self.activeSkillIndex <= activeSkillCount do
currActiveSkill = self.unitEntity:getAvailableActiveSkill(self.activeSkillIndex)
if currActiveSkill then
break
end
self.activeSkillIndex = self.activeSkillIndex + 1
end
end end
if currActiveSkill == nil then if currActiveSkill == nil then
if self.targetX then -- 移动过,准备归位 if self.targetX then -- 移动过,准备归位
@ -633,22 +649,15 @@ function BattleUnitComp:updateNormalAttack(dt)
end end
function BattleUnitComp:addBuff(buffEffect) function BattleUnitComp:addBuff(buffEffect)
table.insert(self.buffList, buffEffect) self.team:addBuff(buffEffect)
self:updateBuffState(buffEffect.buff, 1)
end end
function BattleUnitComp:updateBuffState(buff, num) function BattleUnitComp:updateBuffState(buff, num)
local buffName = buff:getName() self.team:updateBuffState(buff, num)
local buffNum = (self.sameBuffCount[buffName] or 0) + num
self.sameBuffCount[buffName] = buffNum
-- if buffNum > 0 and buffNum == num then
-- self:showBuffFx(buffName, buff:getBuffFxId())
-- elseif buffNum <= 0 then
-- self:hideBuffFx(buffName)
-- end
end end
function BattleUnitComp:onSkillTakeEffect(skill) function BattleUnitComp:onSkillTakeEffect(skill)
skill:endSkill()
if skill == self.unitEntity:getNormalSkill() then if skill == self.unitEntity:getNormalSkill() then
self.battleController:addBattleExp(self.side) self.battleController:addBattleExp(self.side)
end end
@ -712,7 +721,12 @@ function BattleUnitComp:takeDamageOrCure(atker, buff, num, effectType, effectSta
if num == 0 then if num == 0 then
return 0 return 0
end end
local shieldHpBefore = self.unitEntity:getShield()
self.unitEntity:takeDamageOrCure(num) self.unitEntity:takeDamageOrCure(num)
local shieldHpDiff = self.unitEntity:getShield() - shieldHpBefore
if shieldHpDiff < 0 then -- 说明护盾减少了
self:handleShield(shieldHpDiff, self)
end
local x, y, z = self.baseObject:fastGetLocalPosition() local x, y, z = self.baseObject:fastGetLocalPosition()
self:showEffectNumber(num, x, y) self:showEffectNumber(num, x, y)
self.battleController:refreshHp(self.side, self.unitEntity:getHp(), self.unitEntity:getHpPercent()) self.battleController:refreshHp(self.side, self.unitEntity:getHp(), self.unitEntity:getHpPercent())
@ -743,6 +757,10 @@ function BattleUnitComp:playEnterBattlefield(callback)
end end
end end
function BattleUnitComp:onRoundEnd()
self.unitEntity:onRoundEnd()
end
function BattleUnitComp:tick(dt) function BattleUnitComp:tick(dt)
if self.isClear then if self.isClear then
return return

View File

@ -349,16 +349,19 @@ function BattleController:enterRoundEnd()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_END self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_END
local defTeam = self.battleData:getDefTeam() local defTeam = self.battleData:getDefTeam()
if not defTeam or defTeam:getIsDead() then -- 怪物死了, 直接进入刷新逻辑 if not defTeam or defTeam:getIsDead() then -- 怪物死了, 直接进入刷新逻辑
self.atkTeam:onRoundEnd()
self:enterNextWave() self:enterNextWave()
return return
end end
local atkTeam = self.battleData:getAtkTeam() local atkTeam = self.battleData:getAtkTeam()
if not atkTeam or atkTeam:getIsDead() then -- 英雄死了, 直接结算 if not atkTeam or atkTeam:getIsDead() then -- 英雄死了, 直接结算
self.defTeam:onRoundEnd()
self:enterNextWave() self:enterNextWave()
return return
end end
self.atkTeam:onRoundEnd()
self.defTeam:onRoundEnd()
self:enterRoundBegin() self:enterRoundBegin()
end end
@ -1234,7 +1237,6 @@ local function _addCurRoundAttr(self, instruction, callback)
end end
local function _assisting(self, instruction, callback) local function _assisting(self, instruction, callback)
Logger.logHighlight("援助攻击")
self.atkTeam:useAssistingSkill(instruction.assistingList, callback) self.atkTeam:useAssistingSkill(instruction.assistingList, callback)
end end

View File

@ -1,12 +1,18 @@
local BattleBuffHandle = require "app/module/battle/helper/battle_buff_handle"
local BattleTeam = class("BattleTeam") local BattleTeam = class("BattleTeam")
function BattleTeam:init(side) function BattleTeam:init(side)
self.side = side self.side = side
self.unitList = {} self.unitList = {}
self.unitMap = {} self.unitMap = {}
self.buffList = {}
self.sameBuffCount = {}
self.shieldBuffList = {}
end end
function BattleTeam:addUnit(unit, isMainUnit) function BattleTeam:addUnit(unit, isMainUnit)
unit:setTeam(self)
self.unitMap[unit:getMatchType()] = unit self.unitMap[unit:getMatchType()] = unit
table.insert(self.unitList, unit) table.insert(self.unitList, unit)
if isMainUnit then if isMainUnit then
@ -96,6 +102,82 @@ function BattleTeam:changeMainUnit(matchType)
unit:playSwitchIn() unit:playSwitchIn()
end end
-- 回合结束的时候要结算buff和技能
function BattleTeam:onRoundEnd()
for k, v in ipairs(self.unitList) do
v:onRoundEnd()
end
self:doBuffWork()
end
function BattleTeam:addShield(buffEffect)
if buffEffect then
table.insert(self.shieldBuffList, buffEffect)
end
end
function BattleTeam:handleShield(reduceShield, unit)
if #self.shieldBuffList <= 0 then
return
end
local shieldNum = 0
local currShieldBuff = self.shieldBuffList[1]
while currShieldBuff do
reduceShield = reduceShield + currShieldBuff.effectResult
if reduceShield > 0 then
shieldNum = shieldNum + reduceShield - currShieldBuff.effectResult
currShieldBuff.effectResult = reduceShield
reduceShield = 0
break
else
shieldNum = shieldNum - currShieldBuff.effectResult
currShieldBuff.effectResult = 0
for k, v in ipairs(self.buffList) do
if v == currShieldBuff then
self:updateBuffState(currShieldBuff.buff, -1)
BattleBuffHandle.removeBuff(unit, currShieldBuff)
currShieldBuff = nil
break
end
end
if currShieldBuff then
table.remove(self.shieldBuffList, 1)
end
end
currShieldBuff = self.shieldBuffList[1]
end
end
function BattleTeam:addBuff(buffEffect)
table.insert(self.buffList, buffEffect)
self:updateBuffState(buffEffect.buff, 1)
end
function BattleTeam:doBuffWork()
local count = #self.buffList
if count <= 0 then
return
end
local buffEffect = nil
for i = count, 1, -1 do
buffEffect = self.buffList[i]
buffEffect.round = buffEffect.round - 1
BattleBuffHandle.doBuffWork(self.mainUnit, buffEffect)
if buffEffect.round <= 0 then
self:updateBuffState(buffEffect.buff, -1)
table.remove(self.buffList, i)
BattleBuffHandle.removeBuff(self.mainUnit, buffEffect)
end
end
end
function BattleTeam:updateBuffState(buff, num)
local buffName = buff:getName()
local buffNum = (self.sameBuffCount[buffName] or 0) + num
self.sameBuffCount[buffName] = buffNum
end
function BattleTeam:tick(dt) function BattleTeam:tick(dt)
for k, v in ipairs(self.unitList) do for k, v in ipairs(self.unitList) do
v:tick(dt) v:tick(dt)

View File

@ -11,6 +11,12 @@ end
function BattleSkillEntity:init() function BattleSkillEntity:init()
self.skillInfo = ConfigManager:getConfig("skill")[self.skillId] self.skillInfo = ConfigManager:getConfig("skill")[self.skillId]
self.coolingRounds = self.skillInfo.cd or 0
if self.skillInfo.cd_start then -- 开场就进入cd
self.cd = self.skillInfo.cd_start
else
self.cd = 0
end
self:initSkillEffect() self:initSkillEffect()
end end
@ -25,6 +31,25 @@ function BattleSkillEntity:initSkillEffect()
end end
end end
function BattleSkillEntity:cooldown(round)
if self.cd > 0 then
self.cd = self.cd - (round or 1)
if self.cd < 0 then
self.cd = 0
end
end
end
-- 技能是否可用
function BattleSkillEntity:getIsAvailable()
return self.cd == 0
end
-- 技能完全释放完毕
function BattleSkillEntity:endSkill()
self.cd = self.coolingRounds
end
function BattleSkillEntity:getMoveType() function BattleSkillEntity:getMoveType()
return self.skillInfo.position return self.skillInfo.position
end end

View File

@ -187,6 +187,10 @@ function BattleTeamEntity:addShield(num)
self.shieldHp = self.shieldHp + num self.shieldHp = self.shieldHp + num
end end
function BattleTeamEntity:getShieldHp()
return self.shieldHp
end
function BattleTeamEntity:takeDamageOrCure(num) function BattleTeamEntity:takeDamageOrCure(num)
if self.isDead then if self.isDead then
return 0 return 0

View File

@ -60,6 +60,18 @@ function BattleUnitEntity:getAssistingSkill()
return self.assistingSkill return self.assistingSkill
end end
function BattleUnitEntity:getActiveSkillCount()
return #self.activeSkills
end
function BattleUnitEntity:getAvailableActiveSkill(index)
local skill = self.activeSkills[index]
if skill:getIsAvailable() then
return skill
end
return nil
end
function BattleUnitEntity:getActiveSkill(index) function BattleUnitEntity:getActiveSkill(index)
return self.activeSkills[index] return self.activeSkills[index]
end end
@ -135,8 +147,18 @@ function BattleUnitEntity:addShield(num)
self.team:addShield(num) self.team:addShield(num)
end end
function BattleUnitEntity:getShieldHp()
return self.team:getShieldHp()
end
function BattleUnitEntity:addMaxHp(num) function BattleUnitEntity:addMaxHp(num)
self.team:addMaxHp(num) self.team:addMaxHp(num)
end end
function BattleUnitEntity:onRoundEnd()
for k, v in ipairs(self.activeSkills) do
v:cooldown()
end
end
return BattleUnitEntity return BattleUnitEntity