diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 6d97599b..c91e8feb 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -45,6 +45,10 @@ function BattleUnitComp:getMatchType() return self.unitEntity:getMatchType() end +function BattleUnitComp:setTeam(team) + self.team = team +end + function BattleUnitComp:_initBase() self.isClear = false self.isMove = false @@ -55,8 +59,6 @@ function BattleUnitComp:_initBase() self.switchTime = 0 self.isPlayHurt = 0 self.attackDurationMap = {} - self.buffList = {} - self.sameBuffCount = {} self.shieldBuffList = {} self.activeSkillIndex = nil self.currActiveSkill = nil @@ -124,11 +126,12 @@ end function BattleUnitComp:useSkill(index, count, callback) self.actionOverCallback = callback self.activeSkillIndex = index - self.currActiveSkill = self.unitEntity:getActiveSkill(index) + self.currActiveSkill = self.unitEntity:getAvailableActiveSkill(index) self.normalSkillCount = count + self.unitEntity:getNormalAttackAddCount() if self.currActiveSkill == nil then -- 没有技能就用普攻 if self.normalSkillCount <= 0 then self.actionOverCallback = nil + self.activeSkillIndex = nil callback() return end @@ -148,7 +151,15 @@ function BattleUnitComp:useAllSkills(callback) self.actionOverCallback = callback self.normalSkillCount = self.unitEntity:getNormalSkillCount() + self.unitEntity:getNormalAttackAddCount() 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.normalSkillCount <= 0 then self.actionOverCallback = nil @@ -177,10 +188,8 @@ function BattleUnitComp:useNormalSkill(count, callback) end function BattleUnitComp:addShield(num, buffEffect) - if buffEffect then - table.insert(self.shieldBuffList, buffEffect) - end self.unitEntity:addShield(num) + self.team:addShield(buffEffect) end function BattleUnitComp:changeState(state) @@ -480,7 +489,14 @@ function BattleUnitComp:updateSkillAttack(dt) local currActiveSkill = nil if self.activeSkillIndex then 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 if currActiveSkill == nil then if self.targetX then -- 移动过,准备归位 @@ -633,22 +649,15 @@ function BattleUnitComp:updateNormalAttack(dt) end function BattleUnitComp:addBuff(buffEffect) - table.insert(self.buffList, buffEffect) - self:updateBuffState(buffEffect.buff, 1) + self.team:addBuff(buffEffect) end function BattleUnitComp:updateBuffState(buff, num) - local buffName = buff:getName() - 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 + self.team:updateBuffState(buff, num) end function BattleUnitComp:onSkillTakeEffect(skill) + skill:endSkill() if skill == self.unitEntity:getNormalSkill() then self.battleController:addBattleExp(self.side) end @@ -712,7 +721,12 @@ function BattleUnitComp:takeDamageOrCure(atker, buff, num, effectType, effectSta if num == 0 then return 0 end + local shieldHpBefore = self.unitEntity:getShield() 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() self:showEffectNumber(num, x, y) self.battleController:refreshHp(self.side, self.unitEntity:getHp(), self.unitEntity:getHpPercent()) @@ -743,6 +757,10 @@ function BattleUnitComp:playEnterBattlefield(callback) end end +function BattleUnitComp:onRoundEnd() + self.unitEntity:onRoundEnd() +end + function BattleUnitComp:tick(dt) if self.isClear then return diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index b421ffa9..87b08ef8 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -349,16 +349,19 @@ function BattleController:enterRoundEnd() self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_END local defTeam = self.battleData:getDefTeam() if not defTeam or defTeam:getIsDead() then -- 怪物死了, 直接进入刷新逻辑 + self.atkTeam:onRoundEnd() self:enterNextWave() return end local atkTeam = self.battleData:getAtkTeam() if not atkTeam or atkTeam:getIsDead() then -- 英雄死了, 直接结算 + self.defTeam:onRoundEnd() self:enterNextWave() return end - + self.atkTeam:onRoundEnd() + self.defTeam:onRoundEnd() self:enterRoundBegin() end @@ -1234,7 +1237,6 @@ local function _addCurRoundAttr(self, instruction, callback) end local function _assisting(self, instruction, callback) - Logger.logHighlight("援助攻击") self.atkTeam:useAssistingSkill(instruction.assistingList, callback) end diff --git a/lua/app/module/battle/team/battle_team.lua b/lua/app/module/battle/team/battle_team.lua index 828316e1..8aed626b 100644 --- a/lua/app/module/battle/team/battle_team.lua +++ b/lua/app/module/battle/team/battle_team.lua @@ -1,12 +1,18 @@ +local BattleBuffHandle = require "app/module/battle/helper/battle_buff_handle" + local BattleTeam = class("BattleTeam") function BattleTeam:init(side) self.side = side self.unitList = {} self.unitMap = {} + self.buffList = {} + self.sameBuffCount = {} + self.shieldBuffList = {} end function BattleTeam:addUnit(unit, isMainUnit) + unit:setTeam(self) self.unitMap[unit:getMatchType()] = unit table.insert(self.unitList, unit) if isMainUnit then @@ -96,6 +102,82 @@ function BattleTeam:changeMainUnit(matchType) unit:playSwitchIn() 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) for k, v in ipairs(self.unitList) do v:tick(dt) diff --git a/lua/app/userdata/battle/skill/battle_skill_entity.lua b/lua/app/userdata/battle/skill/battle_skill_entity.lua index b3053a99..a530dc48 100644 --- a/lua/app/userdata/battle/skill/battle_skill_entity.lua +++ b/lua/app/userdata/battle/skill/battle_skill_entity.lua @@ -11,6 +11,12 @@ end function BattleSkillEntity:init() 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() end @@ -25,6 +31,25 @@ function BattleSkillEntity:initSkillEffect() 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() return self.skillInfo.position end diff --git a/lua/app/userdata/battle/team/battle_team_entity.lua b/lua/app/userdata/battle/team/battle_team_entity.lua index 0fb3a5a7..d9bef4c7 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:addShield(num) self.shieldHp = self.shieldHp + num end +function BattleTeamEntity:getShieldHp() + return self.shieldHp +end + function BattleTeamEntity:takeDamageOrCure(num) if self.isDead then return 0 diff --git a/lua/app/userdata/battle/team/battle_unit_entity.lua b/lua/app/userdata/battle/team/battle_unit_entity.lua index a42c2cad..1b24f56a 100644 --- a/lua/app/userdata/battle/team/battle_unit_entity.lua +++ b/lua/app/userdata/battle/team/battle_unit_entity.lua @@ -60,6 +60,18 @@ function BattleUnitEntity:getAssistingSkill() return self.assistingSkill 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) return self.activeSkills[index] end @@ -135,8 +147,18 @@ function BattleUnitEntity:addShield(num) self.team:addShield(num) end +function BattleUnitEntity:getShieldHp() + return self.team:getShieldHp() +end + function BattleUnitEntity:addMaxHp(num) self.team:addMaxHp(num) end +function BattleUnitEntity:onRoundEnd() + for k, v in ipairs(self.activeSkills) do + v:cooldown() + end +end + return BattleUnitEntity \ No newline at end of file