From a6b3df378f2ade0f6ded23638b6f1b145bf78a3b Mon Sep 17 00:00:00 2001 From: chenxi Date: Wed, 19 Apr 2023 22:20:07 +0800 Subject: [PATCH] =?UTF-8?q?buff=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/common/white_res_manager.lua | 14 +-- lua/app/global/global_const.lua | 1 + .../battle/component/battle_unit_comp.lua | 5 + .../battle/controller/battle_controller.lua | 8 ++ lua/app/module/battle/team/battle_team.lua | 25 ++++ lua/app/ui/battle/battle_ui.lua | 112 ++++++++++++++++++ .../battle/skill/battle_buff_entity.lua | 4 + 7 files changed, 158 insertions(+), 11 deletions(-) diff --git a/lua/app/common/white_res_manager.lua b/lua/app/common/white_res_manager.lua index 9eeb5be2..87297896 100644 --- a/lua/app/common/white_res_manager.lua +++ b/lua/app/common/white_res_manager.lua @@ -7,18 +7,10 @@ local GAME_RES_WHITE_LIST = { GConst.ATLAS_PATH.COMMON, -- icon GConst.ATLAS_PATH.ICON_SKILL, + GConst.ATLAS_PATH.ICON_SKILL_ROGUE, GConst.ATLAS_PATH.ICON_ITEM, - GConst.ATLAS_PATH.ICON_EQUIP, - GConst.ATLAS_PATH.ICON_AVATAR, - GConst.ATLAS_PATH.ICON_RUNE, - GConst.ATLAS_PATH.ICON_LEGACY, - -- hero - GConst.SPINE_ASSET_PATH.P0001, - GConst.SPINE_ASSET_PATH.P0002, - GConst.SPINE_ASSET_PATH.P0003, - GConst.SPINE_ASSET_PATH.P0004, - -- 战斗伤害字体 - "assets/arts/fonts/tmpfonts/battle/font_battle_sdf.asset", + GConst.ATLAS_PATH.ICON_HERO, + GConst.ATLAS_PATH.ICON_BUFF, } ---- 预加载游戏资源 diff --git a/lua/app/global/global_const.lua b/lua/app/global/global_const.lua index 79812edc..c2dee294 100644 --- a/lua/app/global/global_const.lua +++ b/lua/app/global/global_const.lua @@ -175,6 +175,7 @@ GConst.ATLAS_PATH = { ICON_SKILL = "assets/arts/atlas/icon/skill.asset", ICON_HERO = "assets/arts/atlas/icon/hero.asset", ICON_SKILL_ROGUE = "assets/arts/atlas/icon/skill_rogue.asset", + ICON_BUFF = "assets/arts/atlas/icon/buff.asset", } GConst.TOUCH_EVENT = { diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 1a38fb52..097dab83 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -477,6 +477,7 @@ function BattleUnitComp:exitDeadState() end function BattleUnitComp:enterDeadState() + self:removeAllBuff() local aniName = SPINE_ANIMATION_NAME.DEAD self.deadTime = self:getAnimationDuration(aniName) + 0.1 self:playAnimation(aniName, false, false) @@ -915,6 +916,10 @@ function BattleUnitComp:updateBuffState(buff, num) self.team:updateBuffState(buff, num) end +function BattleUnitComp:removeAllBuff() + self.team:removeAllBuff() +end + function BattleUnitComp:onSkillTakeEffect(skill) skill:endUse() local effectList = skill:getEffectList() diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index ade02988..20b5adec 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -183,6 +183,14 @@ function BattleController:moveBattlefield(time) self.battleUI:moveBattlefield(time) end +function BattleController:refreshBuff(side, buffList) + self.battleUI:refreshBuff(side, buffList) +end + +function BattleController:clearBuff(side) + self.battleUI:clearBuff(side) +end + function BattleController:prepareFight() local count = 0 local totalCount = 3 diff --git a/lua/app/module/battle/team/battle_team.lua b/lua/app/module/battle/team/battle_team.lua index 276468be..3194ea9b 100644 --- a/lua/app/module/battle/team/battle_team.lua +++ b/lua/app/module/battle/team/battle_team.lua @@ -156,6 +156,7 @@ function BattleTeam:handleShield(reduceShield, unit) return end + local needReedRefreshBuff = false local shieldNum = 0 local currShieldBuff = self.shieldBuffList[1] while currShieldBuff do @@ -170,6 +171,9 @@ function BattleTeam:handleShield(reduceShield, unit) currShieldBuff.result = 0 for k, v in ipairs(self.buffList) do if v == currShieldBuff then + if not needReedRefreshBuff and currShieldBuff.buff:getIcon() then + needReedRefreshBuff = true + end self:updateBuffState(currShieldBuff.buff, -1) BattleBuffHandle.removeBuff(unit, currShieldBuff) currShieldBuff = nil @@ -182,11 +186,31 @@ function BattleTeam:handleShield(reduceShield, unit) end currShieldBuff = self.shieldBuffList[1] end + if needReedRefreshBuff then + self.battleController:refreshBuff(self.side, self.buffList) + end end function BattleTeam:addBuff(buffEffect) table.insert(self.buffList, buffEffect) self:updateBuffState(buffEffect.buff, 1) + if buffEffect.buff:getIcon() then + self.battleController:refreshBuff(self.side, self.buffList) + end +end + +function BattleTeam:removeAllBuff() + local buffEffect = nil + local count = #self.buffList + for i = count, 1, -1 do + buffEffect = self.buffList[i] + if buffEffect then + self:updateBuffState(buffEffect.buff, -1) + table.remove(self.buffList, i) + BattleBuffHandle.removeBuff(self, buffEffect) + end + end + self.battleController:clearBuff(self.side) end function BattleTeam:doBuffWork() @@ -205,6 +229,7 @@ function BattleTeam:doBuffWork() BattleBuffHandle.removeBuff(self.mainUnit, buffEffect) end end + self.battleController:refreshBuff(self.side, self.buffList) end function BattleTeam:updateBuffState(buff, num) diff --git a/lua/app/ui/battle/battle_ui.lua b/lua/app/ui/battle/battle_ui.lua index cd704898..0411e385 100644 --- a/lua/app/ui/battle/battle_ui.lua +++ b/lua/app/ui/battle/battle_ui.lua @@ -34,6 +34,7 @@ function BattleUI:_display() self.boardCacheBox = uiMap["battle_ui.bg_2.board_cache_node.skill_box"] self:initBg() self:initSkill() + self:initBuff() self:initBattlefield() self:initNumberNode() self:initHpNode() @@ -101,6 +102,117 @@ function BattleUI:initSkill() uiMap["battle_ui.bg_2.skill_node"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_HORIZONTAL_OR_VERTICAL_LAYOUT):RefreshLayout() end +function BattleUI:initBuff() + self.atkBuffIconList = { + self.uiMap["battle_ui.top_node.buff_l.buff_1"], + self.uiMap["battle_ui.top_node.buff_l.buff_2"], + self.uiMap["battle_ui.top_node.buff_l.buff_3"], + self.uiMap["battle_ui.top_node.buff_l.buff_4"], + self.uiMap["battle_ui.top_node.buff_l.buff_5"], + } + for k, v in ipairs(self.atkBuffIconList) do + v:setLocalScale(0, 0, 0) + end + self.atkBuffTextList = { + self.uiMap["battle_ui.top_node.buff_l.text_1"], + self.uiMap["battle_ui.top_node.buff_l.text_2"], + self.uiMap["battle_ui.top_node.buff_l.text_3"], + self.uiMap["battle_ui.top_node.buff_l.text_4"], + self.uiMap["battle_ui.top_node.buff_l.text_5"], + } + for k, v in ipairs(self.atkBuffTextList) do + v:setText(GConst.EMPTY_STRING) + end + self.defBuffIconList = { + self.uiMap["battle_ui.top_node.buff_r.buff_1"], + self.uiMap["battle_ui.top_node.buff_r.buff_2"], + self.uiMap["battle_ui.top_node.buff_r.buff_3"], + self.uiMap["battle_ui.top_node.buff_r.buff_4"], + self.uiMap["battle_ui.top_node.buff_r.buff_5"], + } + for k, v in ipairs(self.atkBuffIconList) do + v:setLocalScale(0, 0, 0) + end + self.defBuffTextList = { + self.uiMap["battle_ui.top_node.buff_r.text_1"], + self.uiMap["battle_ui.top_node.buff_r.text_2"], + self.uiMap["battle_ui.top_node.buff_r.text_3"], + self.uiMap["battle_ui.top_node.buff_r.text_4"], + self.uiMap["battle_ui.top_node.buff_r.text_5"], + } + for k, v in ipairs(self.defBuffTextList) do + v:setText(GConst.EMPTY_STRING) + end +end + +function BattleUI:refreshBuff(side, buffList) + if side == GConst.BattleConst.SIDE_ATK then + local buffObj = nil + local count = #buffList + local buffIconCount = #self.atkBuffIconList + local index = 1 + for i = 1, count do + buffObj = buffList[i] + if buffObj and buffObj.buff:getIcon() then + local icon = self.atkBuffIconList[index] + local text = self.atkBuffTextList[index] + icon:setLocalScale(1, 1, 1) + icon:setTexture(GConst.ATLAS_PATH.ICON_BUFF, buffObj.buff:getIcon()) + text:setText(buffObj.round) + index = index + 1 + if index > buffIconCount then + break + end + end + end + for i = index, buffIconCount do + self.atkBuffIconList[i]:setLocalScale(0, 0, 0) + self.atkBuffTextList[i]:setText(GConst.EMPTY_STRING) + end + else + local buffObj = nil + local count = #buffList + local buffIconCount = #self.defBuffIconList + local index = 1 + for i = 1, count do + buffObj = buffList[i] + if buffObj and buffObj.buff:getIcon() then + local icon = self.defBuffIconList[index] + local text = self.defBuffTextList[index] + icon:setLocalScale(1, 1, 1) + icon:setTexture(GConst.ATLAS_PATH.ICON_BUFF, buffObj.buff:getIcon()) + text:setText(buffObj.round) + index = index + 1 + if index > buffIconCount then + break + end + end + end + for i = index, buffIconCount do + self.defBuffIconList[i]:setLocalScale(0, 0, 0) + self.defBuffTextList[i]:setText(GConst.EMPTY_STRING) + end + end +end + +function BattleUI:clearBuff(side) + if side == GConst.BattleConst.SIDE_ATK then + for k, v in ipairs(self.atkBuffIconList) do + v:setLocalScale(0, 0, 0) + end + for k, v in ipairs(self.atkBuffTextList) do + v:setText(GConst.EMPTY_STRING) + end + else + for k, v in ipairs(self.defBuffIconList) do + v:setLocalScale(0, 0, 0) + end + for k, v in ipairs(self.defBuffTextList) do + v:setText(GConst.EMPTY_STRING) + end + end +end + function BattleUI:initBattlefield() self.battleNode = self.uiMap["battle_ui.battle_node"] end diff --git a/lua/app/userdata/battle/skill/battle_buff_entity.lua b/lua/app/userdata/battle/skill/battle_buff_entity.lua index a124cbfd..e6fcc344 100644 --- a/lua/app/userdata/battle/skill/battle_buff_entity.lua +++ b/lua/app/userdata/battle/skill/battle_buff_entity.lua @@ -66,4 +66,8 @@ function BattleBuffEntity:setTargetSide(side) self.targetSide = side end +function BattleBuffEntity:getIcon() + return self.buffInfo.icon +end + return BattleBuffEntity \ No newline at end of file