diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index eb3316cd..dd8e4a9c 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -183,6 +183,7 @@ BattleConst.EFFECT_TYPE = { HEAL = 101, HOT = 102, REBOUND = 201, -- 反弹 + COUNTERATTACK = 301, -- 反击 } BattleConst.SKILL_RECORD_DATA_NAME = { @@ -250,6 +251,7 @@ local BUFF_NAME = { UNDEAD = "undead", THORNS = "thorns", FIRST_HAND = "first_hand", + COUNTER_ATTACK = "counterattack", } BattleConst.BUFF_NAME = BUFF_NAME @@ -298,6 +300,7 @@ local ATTR_NAME = { UNDEAD = "undead", THORNS = "thorns", FIRST_HAND = "first_hand", + COUNTER_ATTACK = "counterattack", } BattleConst.ATTR_NAME = ATTR_NAME @@ -339,6 +342,7 @@ BattleConst.BUFF_NAME_TO_ATTR = { [BUFF_NAME.CURSE] = {ATTR_NAME.BE_DMG_TO_HEAL, false}, [BUFF_NAME.THORNS] = {ATTR_NAME.THORNS, false}, [BUFF_NAME.FIRST_HAND] = {ATTR_NAME.FIRST_HAND, false}, + [BUFF_NAME.COUNTER_ATTACK] = {ATTR_NAME.COUNTER_ATTACK, false}, } ---- 格子类型 diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 03090246..81d65120 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -253,10 +253,12 @@ function BattleUnitComp:getIsCentralizedAttack() return self.team:getCentralizedAttack() end -function BattleUnitComp:beforeAttack() +function BattleUnitComp:beforeAttack(effectType) self.team:setCentralizedAttack(true) self.battleController:setIsPauseHpProgress(true) - self:checkPassiveEvent(PASSIVE_EVENT.ON_UNI_ATTACK_START, self) + if effectType == BattleConst.EFFECT_TYPE.DIRECT then + self:checkPassiveEvent(PASSIVE_EVENT.ON_UNI_ATTACK_START, self) + end end function BattleUnitComp:useAssistingSkill(count, delay, callback) @@ -374,9 +376,12 @@ function BattleUnitComp:useAllSkills(callback) end end -function BattleUnitComp:useNormalSkill(count, callback) +function BattleUnitComp:useNormalSkill(count, effectType, callback) self.actionOverCallback = callback - self.normalSkillCount = count + self.unitEntity:getNormalAttackAddCount() + self.normalSkillCount = count + if effectType == BattleConst.EFFECT_TYPE.DIRECT then + self.normalSkillCount = self.normalSkillCount + self.unitEntity:getNormalAttackAddCount() + end if not self:changeState(UNIT_STATE.NORMAL_ATTACK) then self.actionOverCallback = nil self.battleController:setIsPauseHpProgress(false) @@ -1264,6 +1269,12 @@ function BattleUnitComp:takeDamageOrCure(atker, num, effectType, effectStatus) if self.unitEntity:getThorns() > 0 then -- 反伤 atker:takeDamageOrCure(self, num*self.unitEntity:getThorns() // DEFAULT_FACTOR, EFFECT_TYPE.REBOUND, 0) end + if self.unitEntity:getCounterAttack() > 0 then -- 触发反击 + local counterattack = self.unitEntity:getCounterAttack() + if counterattack > DEFAULT_FACTOR or BattleHelper:random(1, DEFAULT_FACTOR) <= counterattack then -- 通过命中概率 + self.unitEntity:addCounterAttackCount(1) + end + end end elseif num > 0 then -- 治疗 self:showEffectNumber(BattleConst.EFFECT_COLOR_GREEN, BattleConst.EFFECT_TYPE_BUFF, "+" .. num, x, y, 0) diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 2ebcb4b7..5d4f2503 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -548,17 +548,29 @@ function BattleController:enterBattleStep() end if self.battleData:getAtkTeam():getFirstHand() < self.battleData:getDefTeam():getFirstHand() then - table.insert(self.battleTeamActionList, defAction) - table.insert(self.battleTeamActionList, atkAction) + self:addTeamActionList(defAction, 1) + self:addTeamActionList(atkAction, 2) else - table.insert(self.battleTeamActionList, atkAction) - table.insert(self.battleTeamActionList, defAction) + self:addTeamActionList(atkAction, 1) + self:addTeamActionList(defAction, 2) end self:enterNextTeamAction() end +function BattleController:addTeamActionList(func, index) + if not self.battleTeamActionList then + self.battleTeamActionList = {} + end + + index = index or 1 + table.insert(self.battleTeamActionList, index, func) +end + function BattleController:enterNextTeamAction() + self.atkTeam:onActionOver() + self.defTeam:onActionOver() + self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_TEAM_ACTION_OVER self:hideCombo() @@ -580,6 +592,7 @@ function BattleController:enterNextTeamAction() return end + Logger.logHighlight(self.battleTeamActionList[1] == nil) if not self.battleTeamActionList or not self.battleTeamActionList[1] then self:enterRefreshBoard() return @@ -2275,7 +2288,7 @@ local function _assisting(self, instruction, callback) end local function _generalAttack(self, instruction, callback) - self.atkTeam:useNormalSkill(instruction.skillMatch, instruction.count, #self.instructions == 0, callback) + self.atkTeam:useNormalSkill(instruction.skillMatch, instruction.count, #self.instructions == 0, BattleConst.EFFECT_TYPE.DIRECT, callback) end local function _playSkill(self, instruction, callback) diff --git a/lua/app/module/battle/team/battle_team.lua b/lua/app/module/battle/team/battle_team.lua index 75381829..740275b7 100644 --- a/lua/app/module/battle/team/battle_team.lua +++ b/lua/app/module/battle/team/battle_team.lua @@ -57,7 +57,7 @@ function BattleTeam:removeAllUnits() self.mainUnit = nil end -function BattleTeam:useNormalSkill(matchType, count, isFinalAction, callback) +function BattleTeam:useNormalSkill(matchType, count, isFinalAction, effectType, callback) self.isFinalAction = isFinalAction local unit = nil if matchType == nil then @@ -72,9 +72,9 @@ function BattleTeam:useNormalSkill(matchType, count, isFinalAction, callback) return callback() end self.mainUnit = unit - unit:beforeAttack() + unit:beforeAttack(effectType) unit:resetBeforeAttack() - unit:useNormalSkill(count, callback) + unit:useNormalSkill(count, effectType, callback) end function BattleTeam:useSkill(matchType, count, isFinalAction, callback) @@ -444,6 +444,27 @@ function BattleTeam:addCombo() self.battleController:showCombo(self.comboCount) end +function BattleTeam:onActionOver() + -- 处理反击 + local counterAttackCount = self:getMainUnit().unitEntity:getCounterAttackCount() + if counterAttackCount <= 0 then + return + end + self:getMainUnit().unitEntity:clearCounterAttackCount() + + local teamAction = function() + self.battleController.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_ATK_STEP + self.battleController.curTeam = self.battleController.atkTeam + ---- 普攻 + local skillMatch = self:getMainUnit().unitEntity:getMatchType() + self:useNormalSkill(skillMatch, counterAttackCount, true, BattleConst.EFFECT_TYPE.COUNTERATTACK, function() + self.battleController:enterNextTeamAction() + end) + end + self.battleController:addTeamActionList(teamAction, 1) + self.comboCount = 0 +end + function BattleTeam:tick(dt) for k, v in ipairs(self.unitList) do v:tick(dt) diff --git a/lua/app/userdata/battle/team/battle_team_entity.lua b/lua/app/userdata/battle/team/battle_team_entity.lua index cbed277b..86b8058c 100644 --- a/lua/app/userdata/battle/team/battle_team_entity.lua +++ b/lua/app/userdata/battle/team/battle_team_entity.lua @@ -16,6 +16,7 @@ local ATTR_NAME = BattleConst.ATTR_NAME function BattleTeamEntity:ctor() self.members = {} self.membersCount = 0 + self.counterAttackCount = 0 -- 反击次数 end function BattleTeamEntity:init(side, data) @@ -264,6 +265,10 @@ function BattleTeamEntity:getBlock() return self.attr.block or 0 end +function BattleTeamEntity:getCounterAttack() + return self.attr.counterattack or 0 +end + function BattleTeamEntity:takeDamageOrCure(num) if self.isDead then return 0 @@ -306,6 +311,19 @@ function BattleTeamEntity:handleShield(damageNum) end end +function BattleTeamEntity:getCounterAttackCount() + return self.counterAttackCount or 0 +end + +function BattleTeamEntity:addCounterAttackCount(count) + count = count or 1 + self.counterAttackCount = self.counterAttackCount + count +end + +function BattleTeamEntity:clearCounterAttackCount() + self.counterAttackCount = 0 +end + function BattleTeamEntity:getRecordData(name) if self.recordData == nil then self.recordData = {} diff --git a/lua/app/userdata/battle/team/battle_unit_entity.lua b/lua/app/userdata/battle/team/battle_unit_entity.lua index f3411ffa..d9f321da 100644 --- a/lua/app/userdata/battle/team/battle_unit_entity.lua +++ b/lua/app/userdata/battle/team/battle_unit_entity.lua @@ -314,6 +314,10 @@ function BattleUnitEntity:getFirstHand() return self.team:getFirstHand() end +function BattleUnitEntity:getCounterAttack() + return self.team:getCounterAttack() +end + function BattleUnitEntity:addLimit(name, buffEffect) self.team:addLimit(name, buffEffect) end @@ -376,6 +380,18 @@ function BattleUnitEntity:getSkillExtraUseTimes(skillId) return self.skillExtraUseTimes[skillId] or 0 end +function BattleUnitEntity:addCounterAttackCount(count) + self.team:addCounterAttackCount(count) +end + +function BattleUnitEntity:getCounterAttackCount() + return self.team:getCounterAttackCount() +end + +function BattleUnitEntity:clearCounterAttackCount() + self.team:clearCounterAttackCount() +end + function BattleUnitEntity:getTeamRecordData(name) return self.team:getRecordData(name) end