2020-10-29 16:36:10 +08:00
require ( " Modules.Battle.Logic.Monster.MonsterSkill.MCondition " )
MTrigger = { }
local this = MTrigger
2021-11-23 14:17:57 +08:00
-- 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 and castSkill.owner.job==2 and (castSkill.type==BattleSkillType.DeadSkill or castSkill.type==BattleSkillType.Extra or castSkill.type==BattleSkillType.Special)
-- end
-- },
-- }
2020-10-29 16:36:10 +08:00
local _TriggerConfig = {
2021-11-23 14:17:57 +08:00
[ BattleEventName.RoleTurnStart ] = {
[ 1 ] = function ( skill , ... ) --1: 敌方单位行动前
2020-10-29 16:36:10 +08:00
local args = { ... }
local role = args [ 1 ]
return role.camp ~= skill.owner . camp
2021-11-23 14:17:57 +08:00
end ,
[ 3 ] = function ( skill , ... ) --3: 我方单位行动前
2020-10-29 16:36:10 +08:00
local args = { ... }
local role = args [ 1 ]
2021-11-23 14:17:57 +08:00
return role.camp == skill.owner . camp
2020-10-29 16:36:10 +08:00
end
} ,
2021-11-23 14:17:57 +08:00
[ BattleEventName.RoleTurnEnd ] = {
[ 2 ] = function ( skill , ... ) --2: 敌方单位行动后
2020-10-29 16:36:10 +08:00
local args = { ... }
local role = args [ 1 ]
2021-11-23 14:17:57 +08:00
return role.camp ~= skill.owner . camp
end ,
[ 4 ] = function ( skill , ... ) --4: 我方单位行动后
2020-10-29 16:36:10 +08:00
local args = { ... }
local role = args [ 1 ]
return role.camp == skill.owner . camp
2021-12-07 18:37:27 +08:00
end ,
[ 13 ] = function ( skill , ... ) --13:敌方攻击最高单位行动后
local args = { ... }
local caster = args [ 1 ]
local cam = skill.owner . camp
if caster.camp == cam then
return false
end
local list = RoleManager.Query ( function ( v ) return v.camp ~= cam end )
if list and # list > 0 then
BattleUtil.SortByProp ( list , RoleDataName.Attack , 0 )
if caster == list [ 1 ] then
return true
end
end
return false
2020-10-29 16:36:10 +08:00
end
} ,
2021-11-23 14:17:57 +08:00
[ BattleEventName.BattleStart ] = {
[ 5 ] = function ( skill , ... ) --5: 战前
2020-10-29 16:36:10 +08:00
return true
end
} ,
2021-11-23 14:17:57 +08:00
[ BattleEventName.BattleRoundStart ] = {
[ 6 ] = function ( skill , ... ) --6: 奇数回合开始前
2020-10-29 16:36:10 +08:00
local args = { ... }
local curRound = args [ 1 ]
return curRound % 2 == 1
2021-11-23 14:17:57 +08:00
end ,
[ 7 ] = function ( skill , ... ) --7: 偶数回合开始前
2020-10-29 16:36:10 +08:00
local args = { ... }
local curRound = args [ 1 ]
return curRound % 2 == 0
2021-11-23 14:17:57 +08:00
end ,
[ 10 ] = function ( skill , ... ) --10: 回合开始前
return true
2020-10-29 16:36:10 +08:00
end
} ,
2021-11-23 14:17:57 +08:00
[ BattleEventName.BattleRoundEnd ] = {
[ 8 ] = function ( skill , ... ) --8: 奇数回合结束后
2020-10-29 16:36:10 +08:00
local args = { ... }
local curRound = args [ 1 ]
return curRound % 2 == 1
2021-11-23 14:17:57 +08:00
end ,
[ 9 ] = function ( skill , ... ) --9: 偶数回合结束后
2020-10-29 16:36:10 +08:00
local args = { ... }
local curRound = args [ 1 ]
return curRound % 2 == 0
2021-11-23 14:17:57 +08:00
end ,
[ 11 ] = function ( skill , ... ) --11: 回合结束后
2020-10-29 16:36:10 +08:00
return true
end
} ,
2021-11-23 14:17:57 +08:00
[ BattleEventName.SkillCastEnd ] = {
[ 12 ] = function ( skill , ... ) --12: 我方单位释放技能后
2020-10-29 16:36:10 +08:00
local args = { ... }
local castSkill = args [ 1 ]
2021-01-14 17:18:41 +08:00
return castSkill.owner . camp == skill.owner . camp and castSkill.owner . job == 2 and ( castSkill.type == BattleSkillType.DeadSkill or castSkill.type == BattleSkillType.Extra or castSkill.type == BattleSkillType.Special )
2021-12-07 18:37:27 +08:00
end ,
[ 14 ] = function ( skill , ... ) --14:我方金乌释放技能后
local args = { ... }
local castSkill = args [ 1 ]
return castSkill.owner . camp == skill.owner . camp and castSkill.owner . type == BattleUnitType.Monster and castSkill.owner . uid == 20008
end ,
2020-10-29 16:36:10 +08:00
} ,
2022-03-11 17:13:54 +08:00
[ BattleEventName.RoleIsVanish ] = {
[ 15 ] = function ( skill , ... )
local args = { ... }
local role = RoleManager.GetDeadRole ( skill.owner . camp )
if role and role : IsRealDead ( ) and not BattleUtil.CheckIsNoDead ( role ) then
return true
end
return false
end ,
} ,
2020-10-29 16:36:10 +08:00
}
function MTrigger . Init ( )
this.TriggerList = { }
this.InitListener ( )
end
-- 初始化事件监听
function this . InitListener ( )
2021-10-22 16:59:08 +08:00
--每次初始化时间监听前 清除下缓存数据
MCondition.ClearCache ( )
2021-11-23 14:17:57 +08:00
for event , list in pairs ( _TriggerConfig ) do
BattleLogic.Event : AddEvent ( event , function ( ... )
-- 用于排序
local firstList = { }
2020-11-04 14:38:54 +08:00
-- 用于排序
local sortList = { }
2021-11-23 14:17:57 +08:00
for triggerId , triggerFunc in pairs ( list ) do
-- 判断是否有需要触发的技能
local triggerSkill = this.TriggerList [ triggerId ]
if triggerSkill then
for _ , trigger in ipairs ( triggerSkill ) do
local skill = trigger.skill
local condition = trigger.condition
-- 判断技能是否可以释放
if skill : canCastSkill ( ) then
-- 判断是否符合触发类型条件
if triggerFunc ( skill , ... ) then
-- 检测是否符合子条件
if MCondition.CheckCondition ( skill , condition ) then
-- 加入技能排序对列
if skill.owner . position == 100 then
table.insert ( firstList , skill )
else
table.insert ( sortList , skill )
end
end
end
2020-10-29 16:36:10 +08:00
end
2021-11-23 14:17:57 +08:00
end
2020-10-29 16:36:10 +08:00
end
end
2020-11-04 14:38:54 +08:00
-- 对技能进行排序
2021-11-23 14:17:57 +08:00
table.sort ( firstList , function ( a , b )
-- 同阵营按位置排序
if a.owner . camp == b.owner . camp then
2022-03-11 17:13:54 +08:00
if a.owner . position == b.owner . position then
return a.id < b.id
else
return a.owner . position < b.owner . position
end
2021-11-23 14:17:57 +08:00
else
-- 不同阵营的根据先手阵营排序
return a.owner . camp == BattleLogic.FirstCamp
end
end )
-- 对技能进行排序
2020-11-04 14:38:54 +08:00
table.sort ( sortList , function ( a , b )
-- 同阵营按位置排序
if a.owner . camp == b.owner . camp then
2022-03-11 17:13:54 +08:00
if a.owner . position == b.owner . position then
return a.id < b.id
else
return a.owner . position < b.owner . position
end
2020-11-04 14:38:54 +08:00
else
-- 不同阵营的根据先手阵营排序
return a.owner . camp == BattleLogic.FirstCamp
end
end )
-- 依次加入技能管理
2021-11-23 14:17:57 +08:00
for _ , skill in ipairs ( firstList ) do
SkillManager.AddMonsterSkill ( skill )
end
2020-11-04 14:38:54 +08:00
for _ , skill in ipairs ( sortList ) do
SkillManager.AddMonsterSkill ( skill )
end
2020-10-29 16:36:10 +08:00
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
2021-10-22 16:59:08 +08:00
table.insert ( this.TriggerList [ triggerId ] , { condition = condition , skill = skill , trigger = triggerId } )
2020-10-29 16:36:10 +08:00
end
return MTrigger