战斗血条优化

This commit is contained in:
xiekaidong 2023-08-02 20:34:25 +08:00
parent 2018d556bb
commit 24d90bfd1c
3 changed files with 101 additions and 2 deletions

View File

@ -11,6 +11,7 @@ local BATTLE_INSTRUCTIONS_HELPER = require "app/module/battle/helper/battle_inst
local BattleBoardTouchHelper = require "app/module/battle/helper/battle_board_touch_helper" local BattleBoardTouchHelper = require "app/module/battle/helper/battle_board_touch_helper"
local BattleBuffHandle = require "app/module/battle/helper/battle_buff_handle" local BattleBuffHandle = require "app/module/battle/helper/battle_buff_handle"
local BATTLE_SNAPSHOT_HELPER = require "app/module/battle/helper/battle_snapshot_helper" local BATTLE_SNAPSHOT_HELPER = require "app/module/battle/helper/battle_snapshot_helper"
local BattleFormula = require "app/module/battle/helper/battle_formula"
local BattleBaseController = class("BattleBaseController") local BattleBaseController = class("BattleBaseController")
local BattleConst = GConst.BattleConst local BattleConst = GConst.BattleConst
local BUFF_NAME_TO_ATTR = BattleConst.BUFF_NAME_TO_ATTR local BUFF_NAME_TO_ATTR = BattleConst.BUFF_NAME_TO_ATTR
@ -245,13 +246,18 @@ function BattleBaseController:onLinkChange()
local sequence = self.battleData:getGridSequence() local sequence = self.battleData:getGridSequence()
local mainElementType local mainElementType
local dmgSkillId
for index, info in ipairs(sequence) do for index, info in ipairs(sequence) do
local entity = self.battleData:getGridEntity(info.posId) local entity = self.battleData:getGridEntity(info.posId)
if not mainElementType then if not mainElementType then
local skillId = entity:getSkillId() local skillId = entity:getSkillId()
if not skillId then if not skillId and not mainElementType then
mainElementType = entity:getElementType() mainElementType = entity:getElementType()
end
if skillId and not dmgSkillId then
dmgSkillId = skillId
end
if mainElementType and dmgSkillId then
break break
end end
end end
@ -298,8 +304,10 @@ function BattleBaseController:onLinkChange()
end end
end end
local dmgElementTypeMap
if not self:getCurActionUnitComp():getActiveSkillLimit() then if not self:getCurActionUnitComp():getActiveSkillLimit() then
local aniSequence, influenceElementType, lineCount, elementTypeMap, linkElementType, effectGridMap, randomPosList = self:calculateCurElimination(true) local aniSequence, influenceElementType, lineCount, elementTypeMap, linkElementType, effectGridMap, randomPosList = self:calculateCurElimination(true)
dmgElementTypeMap = elementTypeMap
if randomPosList then if randomPosList then
for _, posId in ipairs(randomPosList) do for _, posId in ipairs(randomPosList) do
local gridEntity = self.battleData:getGridEntity(posId) local gridEntity = self.battleData:getGridEntity(posId)
@ -317,6 +325,23 @@ function BattleBaseController:onLinkChange()
if mainElementType then if mainElementType then
self:getSideTeam(self.curActionSide):changeMainUnit(mainElementType) self:getSideTeam(self.curActionSide):changeMainUnit(mainElementType)
end end
local elementTypeCount = 0
for element, count in pairs(dmgElementTypeMap) do
elementTypeCount = elementTypeCount + count
end
local dmg = self:calExpectedInjury(mainElementType, elementTypeCount, dmgSkillId)
Logger.logHighlight(dmg)
local defMainUnitcomp = self:getCurOtherActionUnitComp()
if defMainUnitcomp then
local hp = defMainUnitcomp.unitEntity:getHp()
local hpPercent = (hp - dmg) / defMainUnitcomp.unitEntity:getMaxHp()
if self.curActionSide == SIDE_ATK then
self.battleUI:setDefHp(hp, hpPercent)
else
self.battleUI:setAtkHp(hp, hpPercent)
end
end
end end
function BattleBaseController:getInitBoard() function BattleBaseController:getInitBoard()
@ -724,6 +749,18 @@ function BattleBaseController:getCurActionUnitComp()
return self:getCurActionTeam():getMainUnit() return self:getCurActionTeam():getMainUnit()
end end
function BattleBaseController:getCurOtherActionUnitComp()
local side = self:getCurActionOtherSide()
if not side then
return
end
local team = self:getCurActionTeam(side)
if not team then
return
end
return team:getMainUnit()
end
function BattleBaseController:getCurActionBoardRowRange(side) function BattleBaseController:getCurActionBoardRowRange(side)
side = side or self.curActionSide side = side or self.curActionSide
local isAtkAction = side == SIDE_ATK local isAtkAction = side == SIDE_ATK
@ -1176,6 +1213,14 @@ function BattleBaseController:clearGridSequence()
end end
function BattleBaseController:onLinkOver() function BattleBaseController:onLinkOver()
local hp = self.atkTeam:getMainUnit().unitEntity:getHp()
local hpPercent = self.atkTeam:getMainUnit().unitEntity:getMaxHp()
self.battleUI:setAtkHp(hp, hpPercent)
local hp = self.defTeam:getMainUnit().unitEntity:getHp()
local hpPercent = self.defTeam:getMainUnit().unitEntity:getMaxHp()
self.battleUI:setDefHp(hp, hpPercent)
self.battleUI:hideAllSfxLine() self.battleUI:hideAllSfxLine()
local sequence = self.battleData:getGridSequence() local sequence = self.battleData:getGridSequence()
local count = #sequence local count = #sequence
@ -3025,4 +3070,17 @@ BattleBaseController._doInstruction = {
[BattleConst.INSTRUCTION_NAME.PLAY_SKILL] = _playSkill, [BattleConst.INSTRUCTION_NAME.PLAY_SKILL] = _playSkill,
} }
function BattleBaseController:calExpectedInjury(mainElementType, count, skillId)
local atkCompMap = self:getCurActionTeam():getUnitComp()
if not atkCompMap then
return 0
end
local atkUnitComp = atkCompMap[mainElementType]
if not atkUnitComp then
return 0
end
local dmg = BattleFormula:getExpectedDamageResult(atkUnitComp, count, self:getCurOtherActionUnitComp(), skillId, atkCompMap)
return dmg
end
return BattleBaseController return BattleBaseController

View File

@ -14,6 +14,37 @@ function BattleFormula:getDamageOrCureResult(unitComp, buff, targetUnitComp)
return 0 return 0
end end
function BattleFormula:getExpectedDamageResult(unitComp, count, targetUnitComp, skillId, atkCompMap)
-- (元素个数*攻击者攻击力+链接技能的伤害) * 受击者伤害减免
-- 普攻
local result = unitComp.unitEntity:getAtk() * count
local atkMatchType = unitComp.unitEntity:getMatchType()
local coefficient = math.max(DEFAULT_FACTOR - targetUnitComp.unitEntity:getDecDmg(atkMatchType), 0)
result = result * coefficient // DEFAULT_FACTOR
-- 技能
if skillId and atkCompMap then
local skillConfig = ConfigManager:getConfig("skill")[skillId]
if skillConfig and skillConfig.effect and skillConfig.position then
local matchType = skillConfig.position
if atkCompMap[matchType] then
local atk = atkCompMap[matchType].unitEntity:getAtk()
local dmg = 0
for _, effect in ipairs(skillConfig.effect) do
local buffConfig = ConfigManager:getConfigWithOtherKey("buff", effect.type)
if buffConfig and buffConfig.formula == 1 then -- 伤害公式
dmg = dmg + effect.num * atk
end
end
local coefficient = math.max(DEFAULT_FACTOR - targetUnitComp.unitEntity:getDecDmg(atkMatchType), 0)
result = result + (dmg * coefficient // DEFAULT_FACTOR)
end
end
end
-- 最终伤害
result = result * (DEFAULT_FACTOR - unitComp.unitEntity:getEndDmgDecAll() + unitComp.unitEntity:getEndDmgAddtionAll()) // DEFAULT_FACTOR
return result
end
BattleFormula.calculateFormula = { BattleFormula.calculateFormula = {
-- ((攻击)*技能倍率*(1+(攻击者元素伤害增加+所有伤害增加)(攻击者)- (攻击者元素伤害降低+所有伤害降低) +(受到元素伤害增加+受到所有伤害增加(受击)-受到元素伤害降低-受到所有伤害降低(受击) + 主动技能增伤) + 固定值) *暴击伤害*(1-最终造成伤害降低%+最终造成伤害增加%) -- ((攻击)*技能倍率*(1+(攻击者元素伤害增加+所有伤害增加)(攻击者)- (攻击者元素伤害降低+所有伤害降低) +(受到元素伤害增加+受到所有伤害增加(受击)-受到元素伤害降低-受到所有伤害降低(受击) + 主动技能增伤) + 固定值) *暴击伤害*(1-最终造成伤害降低%+最终造成伤害增加%)
[1] = function(unitComp, buff, targetUnit) [1] = function(unitComp, buff, targetUnit)

View File

@ -1081,6 +1081,16 @@ function BattleBaseUI:refreshDefHp(num, percent)
end end
end end
function BattleBaseUI:setAtkHp(num, percent)
self.hpTextLeft:setText(GFunc.num2Str(num))
self.hpProgressLeft.value = percent
end
function BattleBaseUI:setDefHp(num, percent)
self.hpTextRight:setText(GFunc.num2Str(num))
self.hpProgressRight.value = percent
end
function BattleBaseUI:refreshSkill(elementMap, showSfx, side) function BattleBaseUI:refreshSkill(elementMap, showSfx, side)
side = side or SIDE_ATK side = side or SIDE_ATK
if not self.skillNodeCells or not self.skillNodeCells[side] then if not self.skillNodeCells or not self.skillNodeCells[side] then