diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index 359d0332..9834052f 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -189,17 +189,36 @@ BattleConst.EFFECT_TYPE = { COUNTERATTACK = 301, -- 反击 } +---- 特殊的伤害类型,其余都是buffname +BattleConst.SPECIAL_DAMAGE_OR_CURE_TYPE = { + ROUND_BEGIN_HEAL = "round_begin_heal", + KILL_MAX_ELEMENT_AND_HEAL = "kill_max_element_and_heal", +} + BattleConst.SKILL_RECORD_DATA_NAME = { HP_LOWER_THAN = 1 } +BattleConst.SKILL_CONDITION_TYPE = { + STATE = "state", -- 状态 + ATTR = "attr", -- 属性 +} + +BattleConst.SKILL_CONDITION_REL_TYPE = { + AND = 1, + OR = 2, +} + BattleConst.PASSIVE_EVENT = { ON_UNIT_PREPARE_OVER = 2, -- 新单位出场时 ON_UNI_ATTACK_START = 3, -- 攻击开始前 HP_LOWER_THAN = 4, -- 血量低于X% USE_NORMAL_SKILL = 5, -- 使用普攻 ACTIVE_SKILL_HIT = 6, -- 主动技能命中 - ON_DEAD = 7, -- 死亡时 + ON_NORAML_SKILL_OVER = 7, -- 普攻结束后 + ON_DEAD_BY_BURN = 8, -- 有敌人死于灼烧伤害时触发 + ON_DEAD_BY_SKILL = 9, -- 有敌人死于技能时触发 + ON_DEAD = 10, -- 死亡时 } local BUFF_NAME = { diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index cf49f334..99234f41 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -2,6 +2,7 @@ local BattleConst = require "app/module/battle/battle_const" local BattleHelper = require "app/module/battle/helper/battle_helper" local BattleBuffHandle = require "app/module/battle/helper/battle_buff_handle" local BATTLE_BOARD_SKILL_HANDLE = require "app/module/battle/skill/battle_board_skill_handle" +local BATTLE_SKILL_CONDITION_HANDLE = require "app/module/battle/helper/battle_skill_condition_handle" local BattlePassive = require "app/module/battle/helper/battle_passive" local BattleUnitComp = class("BattleUnitComp", LuaComponent) @@ -335,6 +336,7 @@ function BattleUnitComp:useSkill(index, count, callback) end if count <= 0 then self.normalSkillCount = 0 + self:checkPassiveEvent(PASSIVE_EVENT.ON_NORAML_SKILL_OVER, self) else self.normalSkillCount = count + self.unitEntity:getNormalAttackAddCount() end @@ -693,7 +695,7 @@ function BattleUnitComp:updateRecoverHpWaveState(dt) if healNum < 0 then -- 治疗效果不能为负数 healNum = 0 end - self:takeDamageOrCure(self, healNum, EFFECT_TYPE.HEAL, 0) + self:takeDamageOrCure(self, healNum, EFFECT_TYPE.HEAL, 0, BattleConst.SPECIAL_DAMAGE_OR_CURE_TYPE.ROUND_BEGIN_HEAL) if self.recoverHpCount <= 0 then if self.finishRecoverHpCallback then local callback = self.finishRecoverHpCallback @@ -854,6 +856,7 @@ function BattleUnitComp:updateSkillAttack(dt) self.currActiveSkill:startUse() self:doNextSkillAttack() end + self:checkPassiveEvent(PASSIVE_EVENT.ON_NORAML_SKILL_OVER, self) else -- 继续普攻 self:doNextNormalAttack() end @@ -880,6 +883,11 @@ function BattleUnitComp:updateSkillAttack(dt) else self:onAttackOver() end + + local target = self.battleController:getOtherSideMainUnit(self.side) + if target and target.unitEntity:getIsDead() then + self:checkPassiveEvent(PASSIVE_EVENT.ON_DEAD_BY_SKILL, self) + end return else self.currActiveSkill = currActiveSkill @@ -889,9 +897,6 @@ function BattleUnitComp:updateSkillAttack(dt) else if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用 if self.normalSkillCount > 0 then - if self.normalSkillCount == 1 and self.currActiveSkill == nil then -- 最后一次攻击 - self.team:setCentralizedAttack(false) - end local skill = self.unitEntity:getNormalSkill() if skill then local attackName = skill:getSkillAttackName() @@ -899,8 +904,13 @@ function BattleUnitComp:updateSkillAttack(dt) else self.currAttackKeyTime = 0 end + local isFinalBlock = self.currAttackKeyTime <= 0 + + if self.normalSkillCount == 1 and self.currActiveSkill == nil and isFinalBlock then -- 最后一次攻击 + self.team:setCentralizedAttack(false) + end self:onSkillTakeEffect(skill, self.currAttackKeyTime <= 0, self.validEffectIdx) - if self.normalSkillCount == 1 and self.currActiveSkill == nil then -- 最后一次攻击 + if self.normalSkillCount == 1 and self.currActiveSkill == nil and isFinalBlock then -- 最后一次攻击 self.battleController:setIsPauseHpProgress(false) end else @@ -1103,6 +1113,7 @@ function BattleUnitComp:updateNormalAttack(dt) else self:onAttackOver() end + self:checkPassiveEvent(PASSIVE_EVENT.ON_NORAML_SKILL_OVER, self) return else -- 继续攻击 self:doNextNormalAttack() @@ -1140,6 +1151,10 @@ function BattleUnitComp:addBuff(buffEffect) return self.team:addBuff(buffEffect) end +function BattleUnitComp:getBuffCountByName(buffName) + return self.team:getBuffCountByName(buffName) +end + function BattleUnitComp:updateBuffState(buff, num) self.team:updateBuffState(buff, num) end @@ -1204,8 +1219,10 @@ function BattleUnitComp:onSkillTakeEffect(skill, isFinalBlock, validEffectIdx) local succ = false for k, effect in ipairs(effectList) do if k >= validEffectIdx[1] and k <= validEffectIdx[2] then - if self:takeEffect(effect, target) then - succ = true + if self:judgeSkillEffectCondition(skill, k) then + if self:takeEffect(effect, target) then + succ = true + end end end end @@ -1235,6 +1252,17 @@ function BattleUnitComp:onSkillTakeEffect(skill, isFinalBlock, validEffectIdx) end end +function BattleUnitComp:judgeSkillEffectCondition(skill, index) + if not skill then + return true + end + + local buffConditions = skill:getBuffCondition(index) + local conditionRel = skill:getBuffConditionRel(index) + + return BATTLE_SKILL_CONDITION_HANDLE.judgeSkillEffectCondition(buffConditions, conditionRel, self.battleController) +end + function BattleUnitComp:takeEffect(buff, target) local ratio = buff:getRatio() if ratio < DEFAULT_FACTOR then @@ -1330,7 +1358,7 @@ function BattleUnitComp:removeEffect(buff, target) end end -function BattleUnitComp:takeDamageOrCure(atker, num, effectType, effectStatus) +function BattleUnitComp:takeDamageOrCure(atker, num, effectType, effectStatus, damageOrCureType) if self:getIsClear() then return 0 end @@ -1388,16 +1416,16 @@ function BattleUnitComp:takeDamageOrCure(atker, num, effectType, effectStatus) end if effectType == EFFECT_TYPE.DIRECT then if hp > 0 and self.unitEntity:getShieldRebound() then -- 伤害反弹 - atker:takeDamageOrCure(self, num*self.unitEntity:getShieldRebound() // DEFAULT_FACTOR, EFFECT_TYPE.REBOUND, 0) + 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) + atker:takeDamageOrCure(self, -num*self.unitEntity:getBeSucked() // DEFAULT_FACTOR, EFFECT_TYPE.HEAL, 0, BattleConst.ATTR_NAME.BE_SUCKED) end if self.unitEntity:getIsLethargy() then -- 移除昏睡 self:removeBuffByName(BattleConst.BUFF_NAME.LETHARGY) end if self.unitEntity:getThorns() > 0 then -- 反伤 - atker:takeDamageOrCure(self, num*self.unitEntity:getThorns() // DEFAULT_FACTOR, EFFECT_TYPE.REBOUND, 0) + atker:takeDamageOrCure(self, num*self.unitEntity:getThorns() // DEFAULT_FACTOR, EFFECT_TYPE.REBOUND, 0, BattleConst.BUFF_NAME.THORNS) end if self.unitEntity:getCounterAttack() > 0 then -- 触发反击 local counterattack = self.unitEntity:getCounterAttack() @@ -1418,10 +1446,15 @@ function BattleUnitComp:takeDamageOrCure(atker, num, effectType, effectStatus) else if self.unitEntity:getIsDead() then self:changeState(UNIT_STATE.DEAD) + if damageOrCureType == BattleConst.BUFF_NAME.BURN then + local target = self.battleController:getOtherSideMainUnit(self.side) + target:checkPassiveEvent(BattleConst.PASSIVE_EVENT.ON_DEAD_BY_BURN, target) + end elseif damage < 0 and self.currState == UNIT_STATE.IDLE then self:playHurt() end end + if hp > 0 then self.team:checkPassiveEvent(PASSIVE_EVENT.HP_LOWER_THAN, atker, hpPercent) else diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 89407f12..0394cd29 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -2620,7 +2620,7 @@ local function _generalAttack(self, instruction, callback) end local function _playSkill(self, instruction, callback) - self.atkTeam:useSkill(instruction.skillMatch, instruction.count, #self.instructions == 0, callback) + self.atkTeam:useSkill(instruction.skillMatch, instruction.count, #self.instructions == 0, BattleConst.EFFECT_TYPE.DIRECT, callback) end BattleController._doInstruction = { diff --git a/lua/app/module/battle/helper/battle_buff_handle.lua b/lua/app/module/battle/helper/battle_buff_handle.lua index d59f4d39..f063ca9c 100644 --- a/lua/app/module/battle/helper/battle_buff_handle.lua +++ b/lua/app/module/battle/helper/battle_buff_handle.lua @@ -18,7 +18,7 @@ local function _doDotWork(unitComp, buffEffect, buff) else damage = -damage end - unitComp:takeDamageOrCure(buffEffect.sender, damage, EFFECT_TYPE.DOT, hurtStatus) + unitComp:takeDamageOrCure(buffEffect.sender, damage, EFFECT_TYPE.DOT, hurtStatus, buff:getName()) end local function _doHotWork(unitComp, buffEffect, buff) @@ -26,7 +26,7 @@ local function _doHotWork(unitComp, buffEffect, buff) if cure < 0 then -- 加血不能是负数 cure = 0 end - unitComp:takeDamageOrCure(buffEffect.sender, cure, EFFECT_TYPE.HOT, hurtStatus) + unitComp:takeDamageOrCure(buffEffect.sender, cure, EFFECT_TYPE.HOT, hurtStatus, buff:getName()) end function BattleBuffHandle.doBuffWork(unitComp, buffEffect) @@ -92,7 +92,7 @@ local function _takeEffectDirectHurt(unitComp, buff, target, buffEffect) else damage = -damage end - target:takeDamageOrCure(unitComp, damage, EFFECT_TYPE.DIRECT, hurtStatus) + target:takeDamageOrCure(unitComp, damage, EFFECT_TYPE.DIRECT, hurtStatus, buff:getName()) return damage end @@ -105,7 +105,7 @@ local function _takeEffectDirectCure(unitComp, buff, target, buffEffect) if cure < 0 then -- 加血不能是负数 cure = 0 end - target:takeDamageOrCure(unitComp, cure, EFFECT_TYPE.HEAL, hurtStatus) + target:takeDamageOrCure(unitComp, cure, EFFECT_TYPE.HEAL, hurtStatus, buff:getName()) return cure end diff --git a/lua/app/module/battle/helper/battle_buff_special.lua b/lua/app/module/battle/helper/battle_buff_special.lua index 43232ce5..64967a97 100644 --- a/lua/app/module/battle/helper/battle_buff_special.lua +++ b/lua/app/module/battle/helper/battle_buff_special.lua @@ -43,7 +43,7 @@ local function _bleedWork(unitComp, buffEffect, buff) else damage = -damage end - unitComp:takeDamageOrCure(buffEffect.sender, damage, EFFECT_TYPE.DOT, hurtStatus) + unitComp:takeDamageOrCure(buffEffect.sender, damage, EFFECT_TYPE.DOT, hurtStatus, buff:getName()) return 1 end diff --git a/lua/app/module/battle/helper/battle_passive.lua b/lua/app/module/battle/helper/battle_passive.lua index a023ba49..278879b4 100644 --- a/lua/app/module/battle/helper/battle_passive.lua +++ b/lua/app/module/battle/helper/battle_passive.lua @@ -49,6 +49,18 @@ local function _checkActiveSkillHit(unitComp, skill, targetComp) return 1 end +local function _checkOnNormalSkillOver(unitComp, skill, targetComp) + return 1 +end + +local function _checkOnDeadByBurn(unitComp, skill, targetComp) + return 1 +end + +local function _checkOnDeadBySkill(unitComp, skill, targetComp) + return 1 +end + local function _checkOnDead(unitComp, skill, targetComp) return 1 end @@ -59,6 +71,9 @@ BattlePassive.checkTrigger = { [PASSIVE_EVENT.HP_LOWER_THAN] = _checkhpLowerThan, [PASSIVE_EVENT.USE_NORMAL_SKILL] = _checkUseNormalSkill, [PASSIVE_EVENT.ACTIVE_SKILL_HIT] = _checkActiveSkillHit, + [PASSIVE_EVENT.ON_NORAML_SKILL_OVER] = _checkOnNormalSkillOver, + [PASSIVE_EVENT.ON_DEAD_BY_BURN] = _checkOnDeadByBurn, + [PASSIVE_EVENT.ON_DEAD_BY_SKILL] = _checkOnDeadBySkill, [PASSIVE_EVENT.ON_DEAD] = _checkOnDead, } diff --git a/lua/app/module/battle/helper/battle_skill_condition_handle.lua b/lua/app/module/battle/helper/battle_skill_condition_handle.lua new file mode 100644 index 00000000..09244fff --- /dev/null +++ b/lua/app/module/battle/helper/battle_skill_condition_handle.lua @@ -0,0 +1,84 @@ +local BattleConst = require "app/module/battle/battle_const" + +local BattleSkillConditionHandle = {} + +local SKILL_CONDITION_REL_TYPE = BattleConst.SKILL_CONDITION_REL_TYPE +local SKILL_CONDITION_TYPE = BattleConst.SKILL_CONDITION_TYPE +local DEFAULT_FACTOR = BattleConst.DEFAULT_FACTOR + +local function _judgeTargetState(buffCondition, conditionRel, target, battleController) + local num = target:getBuffCountByName(buffCondition.attr) + if num > 0 then -- 拥有这个buff + return true + end + return false +end + +local function _judgeTargetAttr(buffCondition, conditionRel, target, battleController) + local attrNum = 0 + if buffCondition.attr == "hpp" then + attrNum = target.unitEntity:getHpPercent() * DEFAULT_FACTOR + else + attrNum = target.unitEntity:getAttrValue(buffCondition.attr) + end + return BattleSkillConditionHandle._strOperatorOverloading(buffCondition.op, attrNum, buffCondition.v) +end + +BattleSkillConditionHandle._judgeSkillEffectCondition = { + [SKILL_CONDITION_TYPE.STATE] = _judgeTargetState, + [SKILL_CONDITION_TYPE.ATTR] = _judgeTargetAttr, +} + +BattleSkillConditionHandle._strOperatorOverloading = function(opStr, value1, value2) + if opStr == "<" then + return value1 < value2 + elseif opStr == "<=" then + return value1 <= value2 + elseif opStr == "=" then + return value1 == value2 + elseif opStr == ">" then + return value1 > value2 + elseif opStr == ">=" then + return value1 >= value2 + elseif opStr == "!=" then + return value1 ~= value2 + end + + return false +end + +function BattleSkillConditionHandle.judgeSkillEffectCondition(buffConditions, conditionRel, battleController) + if not buffConditions or not conditionRel then + return true + end + + local passConditionCount = 0 + for _, condition in ipairs(buffConditions) do + local func = BattleSkillConditionHandle._judgeSkillEffectCondition[condition.type] + if func then + local target + if condition.side == BattleConst.SIDE_ATK then + target = battleController.atkTeam:getMainUnit() + else + target = battleController.defTeam:getMainUnit() + end + if func(condition, conditionRel, target, battleController) then + passConditionCount = passConditionCount + 1 + end + end + end + + if conditionRel == SKILL_CONDITION_REL_TYPE.AND then + if passConditionCount >= #buffConditions then + return true + end + elseif conditionRel == SKILL_CONDITION_REL_TYPE.OR then + if passConditionCount > 0 then + return true + end + end + + return false +end + +return BattleSkillConditionHandle \ No newline at end of file diff --git a/lua/app/module/battle/helper/battle_skill_condition_handle.lua.meta b/lua/app/module/battle/helper/battle_skill_condition_handle.lua.meta new file mode 100644 index 00000000..220d8dd0 --- /dev/null +++ b/lua/app/module/battle/helper/battle_skill_condition_handle.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 9858e4faf8623ec4983583f58ea463ba +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/module/battle/skill/battle_board_skill_handle.lua b/lua/app/module/battle/skill/battle_board_skill_handle.lua index 8aece41f..ba82316c 100644 --- a/lua/app/module/battle/skill/battle_board_skill_handle.lua +++ b/lua/app/module/battle/skill/battle_board_skill_handle.lua @@ -252,7 +252,7 @@ local function _takeKillMaxElementAndHeal(atkUnitComp, skillEntity, battleContro local list = elementMap[maxElement] local heal = count * effectNum * atkUnitComp.unitEntity:getAtk() // GConst.BattleConst.DEFAULT_FACTOR - atkUnitComp:takeDamageOrCure(atkUnitComp, heal, BattleConst.EFFECT_TYPE.HEAL, 0) + atkUnitComp:takeDamageOrCure(atkUnitComp, heal, BattleConst.EFFECT_TYPE.HEAL, 0, BattleConst.SPECIAL_DAMAGE_OR_CURE_TYPE.KILL_MAX_ELEMENT_AND_HEAL) battleController:killGrids(list) end diff --git a/lua/app/module/battle/team/battle_team.lua b/lua/app/module/battle/team/battle_team.lua index 7b56959e..6c887cf6 100644 --- a/lua/app/module/battle/team/battle_team.lua +++ b/lua/app/module/battle/team/battle_team.lua @@ -78,7 +78,7 @@ function BattleTeam:useNormalSkill(matchType, count, isFinalAction, effectType, unit:useNormalSkill(count, effectType, callback) end -function BattleTeam:useSkill(matchType, count, isFinalAction, callback) +function BattleTeam:useSkill(matchType, count, isFinalAction, effectType, callback) self.isFinalAction = isFinalAction local unit = nil if matchType == nil then @@ -94,7 +94,7 @@ function BattleTeam:useSkill(matchType, count, isFinalAction, callback) end local lastMainUnit = self.mainUnit self.mainUnit = unit - unit:beforeAttack() + unit:beforeAttack(effectType) unit:resetBeforeAttack() if unit:useSkill(1, count, callback) then if lastMainUnit and lastMainUnit ~= unit then @@ -480,6 +480,10 @@ function BattleTeam:updateBuffState(buff, num) end end +function BattleTeam:getBuffCountByName(buffName) + return self.sameBuffCount[buffName] or 0 +end + function BattleTeam:getLoopFxResCount(res) return self.loopFxMap[res] or 0 end diff --git a/lua/app/userdata/battle/skill/battle_skill_entity.lua b/lua/app/userdata/battle/skill/battle_skill_entity.lua index eebb0d86..b83c7a05 100644 --- a/lua/app/userdata/battle/skill/battle_skill_entity.lua +++ b/lua/app/userdata/battle/skill/battle_skill_entity.lua @@ -199,6 +199,25 @@ function BattleSkillEntity:getEffectBlockTime() return self.blockTime end +function BattleSkillEntity:getBuffCondition(index) + if not self.skillInfo.buff_condition then + return + end + return self.skillInfo.buff_condition[index] +end + +function BattleSkillEntity:getBuffConditionRel(index) + if not self.skillInfo.condition_rel then + return + end + for _, info in ipairs(self.skillInfo.condition_rel) do + if info[1] == index then + return info[2] + end + end + return self.skillInfo.condition_rel[index] +end + function BattleSkillEntity:getTargetType() return self.skillInfo.obj end diff --git a/lua/app/userdata/battle/team/battle_team_entity.lua b/lua/app/userdata/battle/team/battle_team_entity.lua index 5cda5537..08bbccb1 100644 --- a/lua/app/userdata/battle/team/battle_team_entity.lua +++ b/lua/app/userdata/battle/team/battle_team_entity.lua @@ -305,6 +305,10 @@ function BattleTeamEntity:getSkillHurt() return self.attr.skill_hurt or 0 end +function BattleTeamEntity:getAttrValue(attrName) + return self.attr[attrName] or 0 +end + function BattleTeamEntity:takeDamageOrCure(num) if self.isDead then return 0 diff --git a/lua/app/userdata/battle/team/battle_unit_entity.lua b/lua/app/userdata/battle/team/battle_unit_entity.lua index c7f308a4..e84bf21e 100644 --- a/lua/app/userdata/battle/team/battle_unit_entity.lua +++ b/lua/app/userdata/battle/team/battle_unit_entity.lua @@ -394,6 +394,10 @@ function BattleUnitEntity:getIsDead() return self.team:getIsDead() end +function BattleUnitEntity:getAttrValue(attr) + return self.team:getAttrValue(attr) +end + function BattleUnitEntity:addSkillExtraUseTimes(skillId, count) if self.skillExtraUseTimes == nil then self.skillExtraUseTimes = {}