diff --git a/lua/app/module/battle/controller/battle_base_controller.lua b/lua/app/module/battle/controller/battle_base_controller.lua index e11bd70d..7e016964 100644 --- a/lua/app/module/battle/controller/battle_base_controller.lua +++ b/lua/app/module/battle/controller/battle_base_controller.lua @@ -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 BattleBuffHandle = require "app/module/battle/helper/battle_buff_handle" 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 BattleConst = GConst.BattleConst local BUFF_NAME_TO_ATTR = BattleConst.BUFF_NAME_TO_ATTR @@ -245,13 +246,18 @@ function BattleBaseController:onLinkChange() local sequence = self.battleData:getGridSequence() local mainElementType - + local dmgSkillId for index, info in ipairs(sequence) do local entity = self.battleData:getGridEntity(info.posId) if not mainElementType then local skillId = entity:getSkillId() - if not skillId then + if not skillId and not mainElementType then mainElementType = entity:getElementType() + end + if skillId and not dmgSkillId then + dmgSkillId = skillId + end + if mainElementType and dmgSkillId then break end end @@ -298,8 +304,10 @@ function BattleBaseController:onLinkChange() end end + local dmgElementTypeMap if not self:getCurActionUnitComp():getActiveSkillLimit() then local aniSequence, influenceElementType, lineCount, elementTypeMap, linkElementType, effectGridMap, randomPosList = self:calculateCurElimination(true) + dmgElementTypeMap = elementTypeMap if randomPosList then for _, posId in ipairs(randomPosList) do local gridEntity = self.battleData:getGridEntity(posId) @@ -317,6 +325,23 @@ function BattleBaseController:onLinkChange() if mainElementType then self:getSideTeam(self.curActionSide):changeMainUnit(mainElementType) 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 function BattleBaseController:getInitBoard() @@ -724,6 +749,18 @@ function BattleBaseController:getCurActionUnitComp() return self:getCurActionTeam():getMainUnit() 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) side = side or self.curActionSide local isAtkAction = side == SIDE_ATK @@ -1176,6 +1213,14 @@ function BattleBaseController:clearGridSequence() end 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() local sequence = self.battleData:getGridSequence() local count = #sequence @@ -3025,4 +3070,17 @@ BattleBaseController._doInstruction = { [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 \ No newline at end of file diff --git a/lua/app/module/battle/helper/battle_formula.lua b/lua/app/module/battle/helper/battle_formula.lua index 815be78c..de66c004 100644 --- a/lua/app/module/battle/helper/battle_formula.lua +++ b/lua/app/module/battle/helper/battle_formula.lua @@ -14,6 +14,37 @@ function BattleFormula:getDamageOrCureResult(unitComp, buff, targetUnitComp) return 0 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 = { -- ((攻击)*技能倍率*(1+(攻击者元素伤害增加+所有伤害增加)(攻击者)- (攻击者元素伤害降低+所有伤害降低) +(受到元素伤害增加+受到所有伤害增加(受击)-受到元素伤害降低-受到所有伤害降低(受击) + 主动技能增伤) + 固定值) *暴击伤害*(1-最终造成伤害降低%+最终造成伤害增加%) [1] = function(unitComp, buff, targetUnit) diff --git a/lua/app/ui/battle/battle_base_ui.lua b/lua/app/ui/battle/battle_base_ui.lua index c0125803..a9883038 100644 --- a/lua/app/ui/battle/battle_base_ui.lua +++ b/lua/app/ui/battle/battle_base_ui.lua @@ -1081,6 +1081,16 @@ function BattleBaseUI:refreshDefHp(num, percent) 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) side = side or SIDE_ATK if not self.skillNodeCells or not self.skillNodeCells[side] then