require("Modules.Battle.Logic.Monster.MonsterSkill.MCondition") MTrigger = {} local this = MTrigger local _TriggerConfig = { [1] = { --1:敌方单位行动前 event = BattleEventName.RoleTurnStart, triggerFunc = function(skill, ...) local args = {...} local role = args[1] return role.camp ~= skill.owner.camp end }, [2] = {--2:敌方单位行动后 event = BattleEventName.RoleTurnEnd, triggerFunc = function(skill, ...) local args = {...} local role = args[1] return role.camp ~= skill.owner.camp end }, [3] = {--3:我方单位行动前 event = BattleEventName.RoleTurnStart, triggerFunc = function(skill, ...) local args = {...} local role = args[1] return role.camp == skill.owner.camp end }, [4] = {--4:我方单位行动后 event = BattleEventName.RoleTurnEnd, triggerFunc = function(skill, ...) local args = {...} local role = args[1] return role.camp == skill.owner.camp end }, [5] = {--5:战前 event = BattleEventName.BattleStart, triggerFunc = function(skill, ...) return true end }, [6] = {--6:奇数回合开始前 event = BattleEventName.BattleRoundStart, triggerFunc = function(skill, ...) local args = {...} local curRound = args[1] return curRound%2 == 1 end }, [7] = {--7:偶数回合开始前 event = BattleEventName.BattleRoundStart, triggerFunc = function(skill, ...) local args = {...} local curRound = args[1] return curRound%2 == 0 end }, [8] = {--8:奇数回合结束后 event = BattleEventName.BattleRoundEnd, triggerFunc = function(skill, ...) local args = {...} local curRound = args[1] return curRound%2 == 1 end }, [9] = {--9:偶数回合结束后 event = BattleEventName.BattleRoundEnd, triggerFunc = function(skill, ...) local args = {...} local curRound = args[1] return curRound%2 == 0 end }, [10] = {--10:回合开始前 event = BattleEventName.BattleRoundStart, triggerFunc = function(skill, ...) return true end }, [11] = {--11:回合结束后 event = BattleEventName.BattleRoundEnd, triggerFunc = function(skill, ...) return true end }, [12] = {--12:我方单位释放技能后 event = BattleEventName.SkillCastEnd, triggerFunc = function(skill, ...) local args = {...} local castSkill = args[1] return castSkill.owner.camp == skill.owner.camp end }, } function MTrigger.Init() this.TriggerList ={} this.InitListener() end -- 初始化事件监听 function this.InitListener() for triggerId, config in pairs(_TriggerConfig) do BattleLogic.Event:AddEvent(config.event, function(...) -- 用于排序 local sortList = {} -- 判断是否有需要触发的技能 local triggerSkill = this.TriggerList[triggerId] if not triggerSkill then return end for _, trigger in ipairs(triggerSkill) do local skill = trigger.skill local condition = trigger.condition -- 判断技能是否可以释放 if skill:canCastSkill() then -- 判断是否符合触发类型条件 if config.triggerFunc(skill, ... ) then -- 检测是否符合子条件 if MCondition.CheckCondition(skill, condition) then -- 加入技能排序对列 table.insert(sortList, skill) end end end end -- 对技能进行排序 table.sort(sortList, function(a, b) -- 同阵营按位置排序 if a.owner.camp == b.owner.camp then return a.owner.position < b.owner.position else -- 不同阵营的根据先手阵营排序 return a.owner.camp == BattleLogic.FirstCamp end end) -- 依次加入技能管理 for _, skill in ipairs(sortList) do SkillManager.AddMonsterSkill(skill) end end) end end -- 技能加入检测 function MTrigger.AddSkill(triggerId, condition, skill) if not this.TriggerList then this.TriggerList = {} end if not this.TriggerList[triggerId] then this.TriggerList[triggerId] = {} end table.insert(this.TriggerList[triggerId], {condition = condition, skill = skill}) end return MTrigger