护盾伤害

This commit is contained in:
chenxi 2023-04-24 15:37:04 +08:00
parent fd3f4df034
commit 802a3670e2
5 changed files with 77 additions and 14 deletions

View File

@ -28,6 +28,7 @@ BattleConst.MOVE_SPEED_ENTER = 500 -- 战斗单位入场时的移动速
BattleConst.HURT_STATE_CRIT = 1 -- 暴击
BattleConst.EFFECT_COLOR_RED = 1
BattleConst.EFFECT_COLOR_GREEN = 2
BattleConst.EFFECT_COLOR_BLUE = 3
BattleConst.EFFECT_TYPE_MOVE_L = 1
BattleConst.EFFECT_TYPE_MOVE_R = 2
BattleConst.EFFECT_TYPE_CRIT = 3
@ -40,6 +41,7 @@ BattleConst.UNLOCK_SKILL_ROGUE_TYPE = 6
BattleConst.RECOVER_HP_COUNT = 3
BattleConst.RECOVER_HP_INTERVAL = 0.2
BattleConst.RECOVER_HP_PERCENT = 333
BattleConst.EFFECT_NUMBER_DELAY = 0.2
BattleConst.BATTLE_ROUND_STEP = {
WAIT_BEGIN = 0, -- 等待开始

View File

@ -1151,20 +1151,33 @@ function BattleUnitComp:takeDamageOrCure(atker, num, effectType, effectStatus)
local hp = self.unitEntity:getHp()
local x, y = self.baseObject:fastGetLocalPosition()
if num < 0 then -- 伤害
if effectStatus == HURT_STATE_CRIT then
self:showEffectNumber(BattleConst.EFFECT_COLOR_RED, BattleConst.EFFECT_TYPE_CRIT, "c" .. num, x, y)
else
local delayTime = 0
local damage = num
if shieldHpDiff < 0 then
damage = damage - shieldHpDiff
delayTime = BattleConst.EFFECT_NUMBER_DELAY
if self.side == BattleConst.SIDE_ATK then
self:showEffectNumber(BattleConst.EFFECT_COLOR_RED, BattleConst.EFFECT_TYPE_MOVE_L, num, x, y)
self:showEffectNumber(BattleConst.EFFECT_COLOR_BLUE, BattleConst.EFFECT_TYPE_MOVE_L, shieldHpDiff, x, y, 0)
else
self:showEffectNumber(BattleConst.EFFECT_COLOR_RED, BattleConst.EFFECT_TYPE_MOVE_R, num, x, y)
self:showEffectNumber(BattleConst.EFFECT_COLOR_BLUE, BattleConst.EFFECT_TYPE_MOVE_R, shieldHpDiff, x, y, 0)
end
end
if damage < 0 then
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)
else
self:showEffectNumber(BattleConst.EFFECT_COLOR_RED, BattleConst.EFFECT_TYPE_MOVE_R, damage, x, y, delayTime)
end
end
end
if hp > 0 and self.unitEntity:getShieldRebound() then -- 伤害反弹
atker:takeDamageOrCure(self, num*self.unitEntity:getShieldRebound() // DEFAULT_FACTOR, EFFECT_TYPE.DIRECT, 0)
end
elseif num > 0 then -- 治疗
self:showEffectNumber(BattleConst.EFFECT_COLOR_GREEN, BattleConst.EFFECT_TYPE_BUFF, "+" .. num, x, y)
self:showEffectNumber(BattleConst.EFFECT_COLOR_GREEN, BattleConst.EFFECT_TYPE_BUFF, "+" .. num, x, y, 0)
end
local hpPercent = self.unitEntity:getHpPercent()
self.battleController:refreshHp(self.side, hp, hpPercent)
@ -1184,9 +1197,9 @@ function BattleUnitComp:takeDamageOrCure(atker, num, effectType, effectStatus)
end
end
function BattleUnitComp:showEffectNumber(colorType, effectType, num, x, y)
function BattleUnitComp:showEffectNumber(colorType, effectType, num, x, y, delayTime)
local addY = BattleConst.MIN_NODE_HEIGHT[self.unitEntity:getBody()] or BattleConst.MIN_NODE_HEIGHT_DEFAULT
self.battleController:showEffectNumber(colorType, effectType, num, x, y + addY)
self.battleController:showEffectNumber(colorType, effectType, num, x, y + addY, delayTime)
end
function BattleUnitComp:playDead(callback)

View File

@ -174,6 +174,8 @@ function BattleController:init(params)
self.roundStep = BattleConst.BATTLE_ROUND_STEP.WAIT_BEGIN
self.effectTexts = {}
self.instructions = {}
self.delayEffectTextList = {}
self.delayEffectTextCount = 0
self.time = 0
self.battleData:init()
BattleScheduler:init()
@ -250,7 +252,8 @@ function BattleController:prepareFight()
self.battleUI:setController(self)
self.battleUI:addLoadUICompleteListener(function()
BattleHelper:setEffectTextCache(self.battleUI:getBattleNumberRed(),
self.battleUI:getBattleNumberGreen())
self.battleUI:getBattleNumberGreen(),
self.battleUI:getBattleNumberBlue())
self:initAtkUnits(onPreloadFinished)
self:initDefUnits(onPreloadFinished)
end)
@ -1887,6 +1890,7 @@ function BattleController:_tick(dt)
table.remove(self.effectTexts, i)
end
end
self:checkDelayEffectText(dt)
self:tick(dt)
end
@ -1925,10 +1929,48 @@ function BattleController:endBattleAndExit()
ModuleManager.BattleManager:exitBattle()
end
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)
function BattleController:checkDelayEffectText(dt)
if self.delayEffectTextCount <= 0 then
return
end
for i = self.delayEffectTextCount, 1, -1 do
local delayEffectText = self.delayEffectTextList[i]
delayEffectText.time = delayEffectText.time - dt
if delayEffectText.time <= 0 then
local effectTextComp = BattleHelper:getEffectText(self.battleUI:getNumberNode(), delayEffectText.colorType)
effectTextComp:showEffectNumber(delayEffectText.effectType, delayEffectText.num, delayEffectText.x, delayEffectText.y)
table.insert(self.effectTexts, effectTextComp)
local tailDelayEffectText = self.delayEffectTextList[self.delayEffectTextCount]
delayEffectText.colorType = tailDelayEffectText.colorType
delayEffectText.effectType = tailDelayEffectText.effectType
delayEffectText.num = tailDelayEffectText.num
delayEffectText.x = tailDelayEffectText.x
delayEffectText.y = tailDelayEffectText.y
delayEffectText.time = tailDelayEffectText.time
self.delayEffectTextCount = self.delayEffectTextCount - 1
end
end
end
function BattleController:showEffectNumber(colorType, effectType, num, x, y, delayTime)
if delayTime > 0 then
self.delayEffectTextCount = self.delayEffectTextCount + 1
local obj = self.delayEffectTextList[self.delayEffectTextCount]
if obj == nil then
obj = {}
self.delayEffectTextList[self.delayEffectTextCount] = obj
end
obj.colorType = colorType
obj.effectType = effectType
obj.num = num
obj.x = x
obj.y = y
obj.time = delayTime
else
local effectTextComp = BattleHelper:getEffectText(self.battleUI:getNumberNode(), colorType)
effectTextComp:showEffectNumber(effectType, num, x, y)
table.insert(self.effectTexts, effectTextComp)
end
end
function BattleController:getFxNode()

View File

@ -168,12 +168,13 @@ function BattleHelper:addSpineBoneFollowerGraphic(effectObj)
return boneFollower
end
function BattleHelper:setEffectTextCache(cache1, cache2)
function BattleHelper:setEffectTextCache(cache1, cache2, cache3)
if self.effectTextCacheList == nil then
self.effectTextCacheList = {}
end
self.effectTextCacheList[1] = cache1
self.effectTextCacheList[2] = cache2
self.effectTextCacheList[3] = cache3
end
function BattleHelper:getEffectText(parent, colorType)

View File

@ -352,6 +352,7 @@ function BattleUI:initNumberNode()
self.battleNumberNode = self.uiMap["battle_ui.battle_root.battle_number_node"]
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"]
end
function BattleUI:getNumberNode()
@ -366,6 +367,10 @@ function BattleUI:getBattleNumberGreen()
return self.battleNumberGreen
end
function BattleUI:getBattleNumberBlue()
return self.battleNumberBlue
end
function BattleUI:initFxNode()
self.fxNode = self.uiMap["battle_ui.battle_root.batttle_fx_node"]
end