diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index 9c51963a..683388d6 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -25,6 +25,18 @@ BattleConst.UNIT_FRONT_DISTANCE = 50 BattleConst.MOVE_SPEED = 2000 -- 战斗单位攻击时的移动速度 BattleConst.MOVE_SPEED_ENTER = 500 -- 战斗单位入场时的移动速度 BattleConst.HURT_STATE_CRIT = 1 -- 暴击 +BattleConst.EFFECT_COLOR_WHITE = 1 +BattleConst.EFFECT_COLOR_RED = 2 +BattleConst.EFFECT_COLOR_YELLOW = 3 +BattleConst.EFFECT_COLOR_GREEN = 4 +BattleConst.EFFECT_TYPE_MOVE_L = 1 +BattleConst.EFFECT_TYPE_MOVE_R = 2 +BattleConst.EFFECT_TYPE_CRIT = 3 +BattleConst.EFFECT_TYPE_BUFF = 4 +BattleConst.ANIMATOR_HASH_NAME_NUMBER_MOVE_L = -526518883 +BattleConst.ANIMATOR_HASH_NAME_NUMBER_MOVE_R = 445827326 +BattleConst.ANIMATOR_HASH_NAME_NUMBER_CRIT = -1734531349 +BattleConst.ANIMATOR_HASH_NAME_NUMBER_BUFF = 1364146828 BattleConst.BATTLE_ROUND_STEP = { WAIT_BEGIN = 0, -- 等待开始 diff --git a/lua/app/module/battle/component/battle_number_comp.lua b/lua/app/module/battle/component/battle_number_comp.lua index 50c635b5..6269765c 100644 --- a/lua/app/module/battle/component/battle_number_comp.lua +++ b/lua/app/module/battle/component/battle_number_comp.lua @@ -1,3 +1,4 @@ +local BattleConst = require "app/module/battle/battle_const" local BattleNumberComp = class("BattleNumberComp", LuaComponent) function BattleNumberComp:init() @@ -7,10 +8,19 @@ function BattleNumberComp:init() self.time = 0 end -function BattleNumberComp:showEffectNumber(num, x, y) +function BattleNumberComp:showEffectNumber(effectType, num, x, y) self.effectText.text = tostring(num) self.baseObject:setLocalPosition(x, y, 0) - self.animator:Play("battle_number_move", -1, 0) + + if effectType == BattleConst.EFFECT_TYPE_MOVE_L then + self.animator:Play(BattleConst.ANIMATOR_HASH_NAME_NUMBER_MOVE_L, -1, 0) + elseif effectType == BattleConst.EFFECT_TYPE_MOVE_R then + self.animator:Play(BattleConst.ANIMATOR_HASH_NAME_NUMBER_MOVE_R, -1, 0) + elseif effectType == BattleConst.EFFECT_TYPE_CRIT then + self.animator:Play(BattleConst.ANIMATOR_HASH_NAME_NUMBER_CRIT, -1, 0) + else + self.animator:Play(BattleConst.ANIMATOR_HASH_NAME_NUMBER_BUFF, -1, 0) + end self.time = 1.367 end @@ -20,6 +30,14 @@ function BattleNumberComp:setEnabled(enabled) self.animator.enabled = enabled end +function BattleNumberComp:setColorType(colorType) + self.colorType = colorType +end + +function BattleNumberComp:getColorType() + return self.colorType +end + function BattleNumberComp:getDuration() return self.time end diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 512345cd..8c4334b2 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -10,6 +10,8 @@ local SIDE_ATK = BattleConst.SIDE_ATK local SPINE_ANIMATION_NAME = BattleConst.SPINE_ANIMATION_NAME local DEFAULT_FACTOR = BattleConst.DEFAULT_FACTOR local PASSIVE_EVENT = BattleConst.PASSIVE_EVENT +local HURT_STATE_CRIT = BattleConst.HURT_STATE_CRIT +local EFFECT_TYPE = BattleConst.EFFECT_TYPE function BattleUnitComp:ctor() end @@ -1022,8 +1024,29 @@ function BattleUnitComp:takeDamageOrCure(atker, buff, num, effectType, effectSta if shieldHpDiff < 0 then -- 说明护盾减少了 self:handleShield(shieldHpDiff, self) end - local x, y, z = self.baseObject:fastGetLocalPosition() - self:showEffectNumber(num, x, y) + local x, y = self.baseObject:fastGetLocalPosition() + if effectStatus == HURT_STATE_CRIT then + self:showEffectNumber(BattleConst.EFFECT_COLOR_YELLOW, BattleConst.EFFECT_TYPE_CRIT, num, x, y) + else + if num < 0 then -- 伤害 + if effectType == EFFECT_TYPE.DOT then + if self.side == BattleConst.SIDE_ATK then + self:showEffectNumber(BattleConst.EFFECT_COLOR_GREEN, BattleConst.EFFECT_TYPE_MOVE_L, num, x, y) + else + self:showEffectNumber(BattleConst.EFFECT_COLOR_GREEN, BattleConst.EFFECT_TYPE_MOVE_R, num, x, y) + end + else + if self.side == BattleConst.SIDE_ATK then + self:showEffectNumber(BattleConst.EFFECT_COLOR_RED, BattleConst.EFFECT_TYPE_MOVE_L, num, x, y) + else + self:showEffectNumber(BattleConst.EFFECT_COLOR_WHITE, BattleConst.EFFECT_TYPE_MOVE_R, num, x, y) + end + end + elseif num > 0 then -- 治疗 + self:showEffectNumber(BattleConst.EFFECT_COLOR_GREEN, BattleConst.EFFECT_TYPE_BUFF, "+" .. num, x, y) + end + end + local hp = self.unitEntity:getHp() local hpPercent = self.unitEntity:getHpPercent() self.battleController:refreshHp(self.side, hp, hpPercent) @@ -1043,8 +1066,8 @@ function BattleUnitComp:takeDamageOrCure(atker, buff, num, effectType, effectSta end end -function BattleUnitComp:showEffectNumber(num, x, y) - self.battleController:showEffectNumber(num, x, y) +function BattleUnitComp:showEffectNumber(colorType, effectType, num, x, y) + self.battleController:showEffectNumber(colorType, effectType, num, x, y) end function BattleUnitComp:playDead(callback) diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 71b285df..25f597c6 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -242,7 +242,10 @@ function BattleController:prepareFight() self.battleUI = UIManager:showUI(self:getBattleUIPath()) self.battleUI:setController(self) self.battleUI:addLoadUICompleteListener(function() - BattleHelper:setEffectTextCache(self.battleUI:getBattleNumber()) + BattleHelper:setEffectTextCache(self.battleUI:getBattleNumber(), + self.battleUI:getBattleNumberRed(), + self.battleUI:getBattleNumberYellow(), + self.battleUI:getBattleNumberGreen()) self:initAtkUnits(onPreloadFinished) self:initDefUnits(onPreloadFinished) end) @@ -1578,9 +1581,9 @@ function BattleController:endBattleAndExit() ModuleManager.BattleManager:exitBattle() end -function BattleController:showEffectNumber(num, x, y) - local effectTextComp = BattleHelper:getEffectText(self.battleUI:getNumberNode()) - effectTextComp:showEffectNumber(num, x, y) +function BattleController:showEffectNumber(colorType, effectType, num, x, y) + local effectTextComp = BattleHelper:getEffectText(self.battleUI:getNumberNode(), colorType) + effectTextComp:showEffectNumber(effectType, num, x, y) table.insert(self.effectTexts, effectTextComp) end diff --git a/lua/app/module/battle/helper/battle_helper.lua b/lua/app/module/battle/helper/battle_helper.lua index 55d50e02..6f50de12 100644 --- a/lua/app/module/battle/helper/battle_helper.lua +++ b/lua/app/module/battle/helper/battle_helper.lua @@ -79,23 +79,31 @@ function BattleHelper:recycleBattleHeroModel(modelId, character) end end -function BattleHelper:setEffectTextCache(effectTextCache) - self.effectTextCache = effectTextCache +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) - if #self.battleEffectTextPool <= 0 then - local prefab = CS.UnityEngine.Object.Instantiate(self.effectTextCache:getGameObject()) +function BattleHelper:getEffectText(parent, colorType) + local pool = self.battleEffectTextPool[colorType] + if #pool <= 0 then + local prefab = CS.UnityEngine.Object.Instantiate(self.effectTextCacheList[colorType]:getGameObject()) local prefabObject = UIPrefabObject:create() - prefabObject:initWithPrefab(self.effectTextCache:getAssetPath(), prefab) + prefabObject:initWithPrefab(GConst.EMPTY_STRING, prefab) prefabObject:initPrefabHelper() prefabObject:getTransform():SetAsLastSibling() prefabObject:setParent(parent, false) local comp = prefabObject:addLuaComponent(GConst.BattleConst.TYPEOF_LUA_COMP.BATTLE_NUMBER_COMPONENT) + comp:setColorType(colorType) comp:setEnabled(true) return comp else - local effectComp = table.remove(self.battleEffectTextPool) + local effectComp = table.remove(pool) effectComp:setEnabled(true) effectComp.baseObject:getTransform():SetAsLastSibling() self.battleEffectTextMap[effectComp.baseObject:getInstanceID()] = effectComp @@ -108,7 +116,9 @@ function BattleHelper:recycleEffectText(comp) return end comp:setEnabled(false) - table.insert(self.battleEffectTextPool, comp) + local colorType = comp:getColorType() + local pool = self.battleEffectTextPool[colorType] + table.insert(pool, comp) if self.battleEffectTextMap then self.battleEffectTextMap[comp.baseObject:getInstanceID()] = nil end diff --git a/lua/app/ui/battle/battle_ui.lua b/lua/app/ui/battle/battle_ui.lua index 27d709b9..49398848 100644 --- a/lua/app/ui/battle/battle_ui.lua +++ b/lua/app/ui/battle/battle_ui.lua @@ -329,7 +329,10 @@ end function BattleUI:initNumberNode() self.battleNumberNode = self.uiMap["battle_ui.battle_number_node"] - self.battleNumber = self.uiMap["battle_ui.battle_number_node.battle_number"] + self.battleNumber = self.uiMap["battle_ui.cache_node.battle_number"] + self.battleNumberRed = self.uiMap["battle_ui.cache_node.battle_number_red"] + self.battleNumberGreen = self.uiMap["battle_ui.cache_node.battle_number_green"] + self.battleNumberYellow = self.uiMap["battle_ui.cache_node.battle_number_yellow"] end function BattleUI:getNumberNode() @@ -340,6 +343,18 @@ function BattleUI:getBattleNumber() return self.battleNumber end +function BattleUI:getBattleNumberRed() + return self.battleNumberRed +end + +function BattleUI:getBattleNumberGreen() + return self.battleNumberGreen +end + +function BattleUI:getBattleNumberYellow() + return self.battleNumberYellow +end + function BattleUI:initHpNode() self.hpProgressLeft = self.uiMap["battle_ui.top_node.bg_l.atk_slider_green"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER) self.hpProgressRight = self.uiMap["battle_ui.top_node.bg_r.def_slider_red"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)