From 1e6e99de9a2ca62832a0af64255c168d1ca73a3f Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Tue, 23 May 2023 15:05:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=A4=E5=AE=B3=E6=95=B0=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/module/battle/battle_const.lua | 2 ++ .../battle/component/battle_unit_comp.lua | 23 ++++++++++++--- .../battle/controller/battle_controller.lua | 3 +- .../module/battle/helper/battle_helper.lua | 28 ++++++++++++++++++- lua/app/ui/battle/battle_ui.lua | 5 ++++ 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index 53688d46..5cbea929 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -30,6 +30,7 @@ BattleConst.HURT_STATE_CRIT = 1 -- 暴击 BattleConst.EFFECT_COLOR_RED = 1 BattleConst.EFFECT_COLOR_GREEN = 2 BattleConst.EFFECT_COLOR_BLUE = 3 +BattleConst.EFFECT_COLOR_WHILTE = 4 BattleConst.EFFECT_TYPE_MOVE_L = 1 BattleConst.EFFECT_TYPE_MOVE_R = 2 BattleConst.EFFECT_TYPE_CRIT = 3 @@ -193,6 +194,7 @@ BattleConst.EFFECT_TYPE = { BattleConst.SPECIAL_DAMAGE_OR_CURE_TYPE = { ROUND_BEGIN_HEAL = "round_begin_heal", KILL_MAX_ELEMENT_AND_HEAL = "kill_max_element_and_heal", + BE_SUCKED = "be_sucked", } BattleConst.SKILL_RECORD_DATA_NAME = { diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 8297dcb7..284f7ab1 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -1407,11 +1407,26 @@ function BattleUnitComp:takeDamageOrCure(atker, num, effectType, effectStatus, d if effectStatus == HURT_STATE_CRIT then self:showEffectNumber(BattleConst.EFFECT_COLOR_RED, BattleConst.EFFECT_TYPE_CRIT, "c" .. damage, x, y, delayTime) else - if self.side == BattleConst.SIDE_ATK then - self:showEffectNumber(BattleConst.EFFECT_COLOR_RED, BattleConst.EFFECT_TYPE_MOVE_L, damage, x, y, delayTime) + local effectColor = BattleConst.EFFECT_COLOR_RED + local damageStr = damage + local direction = BattleConst.EFFECT_TYPE_MOVE_R + local elementType = BattleHelper:getDamageOrCureType2MatchType(damageOrCureType) + local weekNessValue = self.unitEntity:getWeakness(elementType) + if weekNessValue > 0 then + damageStr = "a" .. damage else - self:showEffectNumber(BattleConst.EFFECT_COLOR_RED, BattleConst.EFFECT_TYPE_MOVE_R, damage, x, y, delayTime) + local decGmgValue = self.unitEntity:getDecDmg(elementType) + if decGmgValue > 0 then + effectColor = BattleConst.EFFECT_COLOR_WHILTE + damageStr = "d" .. damage + end end + + if self.side == BattleConst.SIDE_ATK then + direction = BattleConst.EFFECT_TYPE_MOVE_L + end + + self:showEffectNumber(effectColor, direction, damageStr, x, y, delayTime) end end if effectType == EFFECT_TYPE.DIRECT then @@ -1419,7 +1434,7 @@ function BattleUnitComp:takeDamageOrCure(atker, num, effectType, effectStatus, d atker:takeDamageOrCure(self, num*self.unitEntity:getShieldRebound() // DEFAULT_FACTOR, EFFECT_TYPE.REBOUND, 0, BattleConst.BUFF_NAME.SHIELD_REBOUND_200) end if self.unitEntity:getBeSucked() > 0 then -- 吸血 - atker:takeDamageOrCure(self, -num*self.unitEntity:getBeSucked() // DEFAULT_FACTOR, EFFECT_TYPE.HEAL, 0, BattleConst.ATTR_NAME.BE_SUCKED) + atker:takeDamageOrCure(self, -num*self.unitEntity:getBeSucked() // DEFAULT_FACTOR, EFFECT_TYPE.HEAL, 0, BattleConst.SPECIAL_DAMAGE_OR_CURE_TYPE.BE_SUCKED) end if self.unitEntity:getIsLethargy() then -- 移除昏睡 self:removeBuffByName(BattleConst.BUFF_NAME.LETHARGY) diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 0ff46638..f04962e7 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -297,7 +297,8 @@ function BattleController:prepareFight() self.battleUI:addLoadUICompleteListener(function() BattleHelper:setEffectTextCache(self.battleUI:getBattleNumberRed(), self.battleUI:getBattleNumberGreen(), - self.battleUI:getBattleNumberBlue()) + self.battleUI:getBattleNumberBlue(), + self.battleUI:getBattleNumberWhite()) self:initAtkUnits(onPreloadFinished) self:initDefUnits(onPreloadFinished) self.battleUI:refreshChessBoard(self:getChessBoardBgName()) diff --git a/lua/app/module/battle/helper/battle_helper.lua b/lua/app/module/battle/helper/battle_helper.lua index 6000eb26..81c02b33 100644 --- a/lua/app/module/battle/helper/battle_helper.lua +++ b/lua/app/module/battle/helper/battle_helper.lua @@ -20,6 +20,7 @@ function BattleHelper:init() self.seed = tonumber(tostring(os.time()):reverse():sub(1,6)) self.baseOrder = 0 self.skillSoundPath = {} + self.damageOrCureType2MatchType = {} end function BattleHelper:setBaseOrder(baseOrder) @@ -175,13 +176,14 @@ function BattleHelper:addSpineBoneFollowerGraphic(effectObj) return boneFollower end -function BattleHelper:setEffectTextCache(cache1, cache2, cache3) +function BattleHelper:setEffectTextCache(cache1, cache2, cache3, cache4) if self.effectTextCacheList == nil then self.effectTextCacheList = {} end self.effectTextCacheList[1] = cache1 self.effectTextCacheList[2] = cache2 self.effectTextCacheList[3] = cache3 + self.effectTextCacheList[4] = cache4 end function BattleHelper:getEffectText(parent, colorType) @@ -256,6 +258,30 @@ function BattleHelper:playSkillSound(name, delay) end end +function BattleHelper:getDamageOrCureType2MatchType(damageOrCureType) + if not damageOrCureType then + return GConst.BattleConst.ELEMENT_TYPE.NONE + end + + if not self.damageOrCureType2MatchType[damageOrCureType] then + local elementType = GConst.BattleConst.ELEMENT_TYPE.NONE + if string.match(damageOrCureType, "red") then + elementType = GConst.BattleConst.ELEMENT_TYPE.RED + elseif string.match(damageOrCureType, "yellow") then + elementType = GConst.BattleConst.ELEMENT_TYPE.YELLOW + elseif string.match(damageOrCureType, "green") then + elementType = GConst.BattleConst.ELEMENT_TYPE.GREEN + elseif string.match(damageOrCureType, "blue") then + elementType = GConst.BattleConst.ELEMENT_TYPE.BLUE + elseif string.match(damageOrCureType, "purple") then + elementType = GConst.BattleConst.ELEMENT_TYPE.PURPLE + end + self.damageOrCureType2MatchType[damageOrCureType] = elementType + end + + return self.damageOrCureType2MatchType[damageOrCureType] +end + function BattleHelper:performDurationDelay(delay, func) return BattleScheduler:performWithDelayGlobal(func, delay) end diff --git a/lua/app/ui/battle/battle_ui.lua b/lua/app/ui/battle/battle_ui.lua index 59fb80b7..56d4b535 100644 --- a/lua/app/ui/battle/battle_ui.lua +++ b/lua/app/ui/battle/battle_ui.lua @@ -384,6 +384,7 @@ function BattleUI:initNumberNode() self.battleNumberRed = self.uiMap["battle_ui.cache_node.battle_number_red"] self.battleNumberGreen = self.uiMap["battle_ui.cache_node.battle_number_green"] self.battleNumberBlue = self.uiMap["battle_ui.cache_node.battle_number_blue"] + self.battleNumberWhite = self.uiMap["battle_ui.cache_node.battle_number_white"] end function BattleUI:getNumberNode() @@ -402,6 +403,10 @@ function BattleUI:getBattleNumberBlue() return self.battleNumberBlue end +function BattleUI:getBattleNumberWhite() + return self.battleNumberWhite +end + function BattleUI:initComboNode() self.comboNode = self.uiMap["battle_ui.top_node.combo"] self.comboAnimator = self.comboNode:getComponent(GConst.TYPEOF_UNITY_CLASS.ANIMATOR) From 637264f383e22851c3ca6bcd189cee0d9a69c469 Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Tue, 23 May 2023 16:39:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=A0=BC=E6=8C=A1=E5=8A=A8=E4=BD=9C?= =?UTF-8?q?=E8=A1=A8=E7=8E=B0=E3=80=81=E5=8F=8D=E5=87=BB=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E8=A1=A8=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../localization_global_const.lua | 2 + lua/app/config/strings/cn/global.lua | 3 + lua/app/module/battle/battle_const.lua | 2 + .../battle/component/battle_number_comp.lua | 3 + .../battle/component/battle_unit_comp.lua | 67 +++++++++++++------ .../battle/controller/battle_controller.lua | 12 +++- .../module/battle/helper/battle_helper.lua | 3 +- lua/app/ui/battle/battle_ui.lua | 26 +++++++ 8 files changed, 96 insertions(+), 22 deletions(-) diff --git a/lua/app/config/localization/localization_global_const.lua b/lua/app/config/localization/localization_global_const.lua index ffe9d83a..53cc8b85 100644 --- a/lua/app/config/localization/localization_global_const.lua +++ b/lua/app/config/localization/localization_global_const.lua @@ -1,5 +1,7 @@ local LocalizationGlobalConst = { + COUNTER_ATTACK_DESC = "COUNTER_ATTACK_DESC", + BLOCK_DESC = "BLOCK_DESC", MAIN_BTN_1 = "MAIN_BTN_1", QLT_DESC_1 = "QLT_DESC_1", QLT_DESC_2 = "QLT_DESC_2", diff --git a/lua/app/config/strings/cn/global.lua b/lua/app/config/strings/cn/global.lua index cdbd33d0..d65efab0 100644 --- a/lua/app/config/strings/cn/global.lua +++ b/lua/app/config/strings/cn/global.lua @@ -118,6 +118,9 @@ local localization_global = ["BTN_READ"] = "读取", ["BATTLE_DESC_9"] = "{0}攻击力:{1}", ["BATTLE_DESC_10"] = "已激活效果", + + ["BLOCK_DESC"] = "格挡", + ["COUNTER_ATTACK_DESC"] = "反击", } return localization_global \ No newline at end of file diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index 5cbea929..00d87eac 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -31,6 +31,7 @@ BattleConst.EFFECT_COLOR_RED = 1 BattleConst.EFFECT_COLOR_GREEN = 2 BattleConst.EFFECT_COLOR_BLUE = 3 BattleConst.EFFECT_COLOR_WHILTE = 4 +BattleConst.EFFECT_COLOR_SPECIAL = 5 BattleConst.EFFECT_TYPE_MOVE_L = 1 BattleConst.EFFECT_TYPE_MOVE_R = 2 BattleConst.EFFECT_TYPE_CRIT = 3 @@ -179,6 +180,7 @@ BattleConst.SPINE_ANIMATION_NAME = { DEAD = "death", BORN = "born", OUT = "out", + BLOCK = "block", } BattleConst.EFFECT_TYPE = { diff --git a/lua/app/module/battle/component/battle_number_comp.lua b/lua/app/module/battle/component/battle_number_comp.lua index 6269765c..dd9b9879 100644 --- a/lua/app/module/battle/component/battle_number_comp.lua +++ b/lua/app/module/battle/component/battle_number_comp.lua @@ -5,6 +5,9 @@ function BattleNumberComp:init() local uiMap = self.baseObject:genAllChildren() self.animator = self.baseObject:getComponent(GConst.TYPEOF_UNITY_CLASS.ANIMATOR) self.effectText = uiMap["battle_number.text_number"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT) + if not self.effectText then + self.effectText = uiMap["battle_number.text_number"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO) + end self.time = 0 end diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 284f7ab1..3929c673 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -86,7 +86,7 @@ function BattleUnitComp:_initBase() self.currAttackBlockIndex = 0 -- 多段伤害索引 self.validEffectIdx = {} self.switchTime = 0 - self.isPlayHurt = 0 + self.playIdleSubAniDuration = {} self.attackDurationMap = {} self.attackKeyFrameTimeMap = {} self.shieldBuffList = {} @@ -227,11 +227,6 @@ function BattleUnitComp:stopRunAction() end function BattleUnitComp:playAnimation(name, loop, forceRefresh) - if name == SPINE_ANIMATION_NAME.HIT then - self.isPlayHurt = 1 - else - self.isPlayHurt = 0 - end self.currAnimationName = name self.baseObject:playAnimation(name, loop, forceRefresh) end @@ -651,28 +646,58 @@ function BattleUnitComp:enterIdleState() end function BattleUnitComp:updateIdle(dt) - self:updateHurt(dt) + self:updateIdleSubAni(dt) +end + +function BattleUnitComp:updateIdleSubAni(...) + if not self.currAnimationName then + return + end + if self.currAnimationName == SPINE_ANIMATION_NAME.HIT then + self:updateHurt(...) + elseif self.currAnimationName == SPINE_ANIMATION_NAME.BLOCK then + self:updateBlock(...) + end end function BattleUnitComp:playHurt() - self.hurtTime = 0 - if self.currHitDuration == nil then - self.currHitDuration = self:getAnimationDuration(SPINE_ANIMATION_NAME.HIT) + local name = SPINE_ANIMATION_NAME.HIT + self.playIdleSubAniTime = 0 + if self.playIdleSubAniDuration[name] == nil then + self.playIdleSubAniDuration[name] = self:getAnimationDuration(name) end - self:playAnimation(SPINE_ANIMATION_NAME.HIT, false, false) - + self:playAnimation(name, false, false) end function BattleUnitComp:updateHurt(dt) - if self.isPlayHurt == 0 then - return + self.playIdleSubAniTime = self.playIdleSubAniTime + dt + if self.playIdleSubAniTime >= self.playIdleSubAniDuration[SPINE_ANIMATION_NAME.HIT] then + self:playAnimation(SPINE_ANIMATION_NAME.IDLE, true, false) end - if self.isPlayHurt == 1 then - self.hurtTime = self.hurtTime + dt - if self.hurtTime >= self.currHitDuration then - self:playAnimation(SPINE_ANIMATION_NAME.IDLE, true, false) - self.isPlayHurt = 0 - end +end + +function BattleUnitComp:playBlock() + local name = SPINE_ANIMATION_NAME.BLOCK + self.playIdleSubAniTime = 0 + if self.playIdleSubAniDuration[name] == nil then + self.playIdleSubAniDuration[name] = self:getAnimationDuration(name) + end + self:playAnimation(name, false, false) + + local direction = BattleConst.EFFECT_TYPE_MOVE_R + local x, y = self.baseObject:fastGetLocalPosition() + if self.side == BattleConst.SIDE_ATK then + direction = BattleConst.EFFECT_TYPE_MOVE_L + end + + self:showEffectNumber(BattleConst.EFFECT_COLOR_SPECIAL, direction, I18N:getGlobalText(I18N.GlobalConst.BLOCK_DESC), x, y, 0) +end + + +function BattleUnitComp:updateBlock(dt) + self.playIdleSubAniTime = self.playIdleSubAniTime + dt + if self.playIdleSubAniTime >= self.playIdleSubAniDuration[SPINE_ANIMATION_NAME.BLOCK] then + self:playAnimation(SPINE_ANIMATION_NAME.IDLE, true, false) end end @@ -1210,6 +1235,7 @@ function BattleUnitComp:onSkillTakeEffect(skill, isFinalBlock, validEffectIdx) local block = target.unitEntity:getBlock() if block > 0 then if BattleHelper:random(1, DEFAULT_FACTOR) <= block then -- 格挡成功 + target:playBlock() return end end @@ -1446,6 +1472,7 @@ function BattleUnitComp:takeDamageOrCure(atker, num, effectType, effectStatus, d local counterattack = self.unitEntity:getCounterAttack() if counterattack > DEFAULT_FACTOR or BattleHelper:random(1, DEFAULT_FACTOR) <= counterattack then -- 通过命中概率 self.unitEntity:addCounterAttackCount(1) + self.battleController:showCounterAttack(self.unitEntity:getCounterAttackCount(), self.side) end end end diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index f04962e7..e976f226 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -282,6 +282,14 @@ function BattleController:hideCombo() self.battleUI:hideCombo() end +function BattleController:showCounterAttack(count, side) + self.battleUI:showCounterAttack(count, side) +end + +function BattleController:hideCounterAttack() + self.battleUI:hideCounterAttack() +end + function BattleController:prepareFight() local count = 0 local totalCount = 3 @@ -298,7 +306,8 @@ function BattleController:prepareFight() BattleHelper:setEffectTextCache(self.battleUI:getBattleNumberRed(), self.battleUI:getBattleNumberGreen(), self.battleUI:getBattleNumberBlue(), - self.battleUI:getBattleNumberWhite()) + self.battleUI:getBattleNumberWhite(), + self.battleUI:getBattleNumberSpecial()) self:initAtkUnits(onPreloadFinished) self:initDefUnits(onPreloadFinished) self.battleUI:refreshChessBoard(self:getChessBoardBgName()) @@ -578,6 +587,7 @@ function BattleController:enterNextTeamAction() self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_TEAM_ACTION_OVER self:hideCombo() + self:hideCounterAttack() if self:checkTeamIsDead(function() self:enterRoundEnd() end) then return diff --git a/lua/app/module/battle/helper/battle_helper.lua b/lua/app/module/battle/helper/battle_helper.lua index 81c02b33..99229286 100644 --- a/lua/app/module/battle/helper/battle_helper.lua +++ b/lua/app/module/battle/helper/battle_helper.lua @@ -176,7 +176,7 @@ function BattleHelper:addSpineBoneFollowerGraphic(effectObj) return boneFollower end -function BattleHelper:setEffectTextCache(cache1, cache2, cache3, cache4) +function BattleHelper:setEffectTextCache(cache1, cache2, cache3, cache4, cache5) if self.effectTextCacheList == nil then self.effectTextCacheList = {} end @@ -184,6 +184,7 @@ function BattleHelper:setEffectTextCache(cache1, cache2, cache3, cache4) self.effectTextCacheList[2] = cache2 self.effectTextCacheList[3] = cache3 self.effectTextCacheList[4] = cache4 + self.effectTextCacheList[5] = cache5 end function BattleHelper:getEffectText(parent, colorType) diff --git a/lua/app/ui/battle/battle_ui.lua b/lua/app/ui/battle/battle_ui.lua index 56d4b535..c908cd6a 100644 --- a/lua/app/ui/battle/battle_ui.lua +++ b/lua/app/ui/battle/battle_ui.lua @@ -67,6 +67,7 @@ function BattleUI:_display() self:initSelectSkillNode() self:initCommonSkillDescTips() self:initBossEnterAni() + self:initCounterAttack() end function BattleUI:_addListeners() @@ -385,6 +386,7 @@ function BattleUI:initNumberNode() self.battleNumberGreen = self.uiMap["battle_ui.cache_node.battle_number_green"] self.battleNumberBlue = self.uiMap["battle_ui.cache_node.battle_number_blue"] self.battleNumberWhite = self.uiMap["battle_ui.cache_node.battle_number_white"] + self.battleNumberSpecial = self.uiMap["battle_ui.cache_node.battle_number_special"] end function BattleUI:getNumberNode() @@ -407,6 +409,10 @@ function BattleUI:getBattleNumberWhite() return self.battleNumberWhite end +function BattleUI:getBattleNumberSpecial() + return self.battleNumberSpecial +end + function BattleUI:initComboNode() self.comboNode = self.uiMap["battle_ui.top_node.combo"] self.comboAnimator = self.comboNode:getComponent(GConst.TYPEOF_UNITY_CLASS.ANIMATOR) @@ -521,6 +527,26 @@ function BattleUI:showCombo(count) end end +function BattleUI:initCounterAttack() + self.counterAttackNode = self.uiMap["battle_ui.battle_root.battle_number_node.counter_attack"] + self.counterTx = self.uiMap["battle_ui.battle_root.battle_number_node.counter_attack.text_number"] + self.counterAttackNode:setVisible(false) +end + +function BattleUI:showCounterAttack(count, side) + local x = 280 + if side == GConst.BattleConst.SIDE_ATK then + x = -280 + end + self.counterAttackNode:setAnchoredPositionX(x) + self.counterTx:setText(I18N:getGlobalText(I18N.GlobalConst.COUNTER_ATTACK_DESC) .. "+" .. count) + self.counterAttackNode:setVisible(true) +end + +function BattleUI:hideCounterAttack() + self.counterAttackNode:setVisible(false) +end + function BattleUI:initFxNode() self.fxNode = self.uiMap["battle_ui.battle_root.batttle_fx_node"] end