2025-08-14 17:01:07 +08:00
|
|
|
|
local Rune = {}
|
|
|
|
|
Rune.__index = Rune
|
|
|
|
|
|
|
|
|
|
--> Services
|
|
|
|
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
|
|
|
local ServerStorage = game:GetService("ServerStorage")
|
|
|
|
|
|
|
|
|
|
--> Dependencies
|
|
|
|
|
local TypeList = require(ServerStorage.Base.TypeList)
|
|
|
|
|
local Utils = require(ReplicatedStorage.Tools.Utils)
|
|
|
|
|
|
|
|
|
|
function Rune:Init(PlayerAI: Player, Character: TypeList.Character, ScriptName: string)
|
|
|
|
|
local self = {}
|
|
|
|
|
setmetatable(self, Rune)
|
|
|
|
|
self.PlayerAI = PlayerAI
|
|
|
|
|
self.Character = Character
|
|
|
|
|
self.ScriptName = ScriptName
|
2025-08-20 19:29:16 +08:00
|
|
|
|
self.Player = self.Character.Player
|
2025-08-14 17:01:07 +08:00
|
|
|
|
self.TriggerSlot = 0
|
|
|
|
|
self.WearingSlot = 0
|
|
|
|
|
self.TriggerTime = 0
|
2025-08-20 19:29:16 +08:00
|
|
|
|
self.executionRecords = {}
|
|
|
|
|
self.isRecording = false -- 记录开关
|
|
|
|
|
return self
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 开始记录
|
|
|
|
|
function Rune:StartRecording()
|
|
|
|
|
self.isRecording = true
|
|
|
|
|
self.executionRecords = {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 停止记录
|
|
|
|
|
function Rune:StopRecording()
|
|
|
|
|
self.isRecording = false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 记录执行信息
|
|
|
|
|
function Rune:RecordExecution(index: number, attributesBefore: table?, attributesAfter: table?, behaviorListBefore: table?, behaviorListAfter: table?, nextIndex: number?)
|
|
|
|
|
if not self.isRecording then return end
|
|
|
|
|
|
|
|
|
|
table.insert(self.executionRecords, {
|
|
|
|
|
runeName = self.ScriptName,
|
|
|
|
|
runeUniqueId = self.TriggerSlot,
|
|
|
|
|
index = index,
|
|
|
|
|
timestamp = tick(),
|
|
|
|
|
action = "Execute",
|
|
|
|
|
attributesBefore = attributesBefore or {},
|
|
|
|
|
attributesAfter = attributesAfter or {},
|
|
|
|
|
behaviorListBefore = behaviorListBefore or {},
|
|
|
|
|
behaviorListAfter = behaviorListAfter or {},
|
|
|
|
|
nextIndex = nextIndex
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 获取执行记录
|
|
|
|
|
function Rune:GetExecutionRecords()
|
|
|
|
|
return self.executionRecords
|
2025-08-14 17:01:07 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 触发最开始事件
|
|
|
|
|
function Rune:OnStartEvent(runeName: string, triggerSlot: number, AttributesData: table?, BehaviorNameList: table?)
|
|
|
|
|
-- runeName: 符文名称
|
|
|
|
|
-- triggerSlot: 触发槽位
|
|
|
|
|
-- AttributesData: 属性数据,符文可以修改
|
|
|
|
|
-- BehaviorNameList: 行为名称列表,符文可以修改
|
|
|
|
|
-- 返回值: 可以返回下一个index来控制流程,或者nil表示不干预
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 卡牌触发前事件
|
|
|
|
|
function Rune:OnTriggerBeginEvent(index: number, AttributesData: table?, BehaviorNameList: table?)
|
|
|
|
|
-- index: 当前符文在列表中的位置
|
|
|
|
|
-- AttributesData: 属性数据,符文可以修改
|
|
|
|
|
-- BehaviorNameList: 行为名称列表,符文可以修改
|
|
|
|
|
-- 返回值: 可以返回下一个index来控制流程,或者nil表示不干预
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 卡牌触发后事件
|
|
|
|
|
function Rune:OnTriggerEndEvent(index: number, AttributesData: table?, BehaviorNameList: table?)
|
|
|
|
|
-- index: 当前符文在列表中的位置
|
|
|
|
|
-- AttributesData: 属性数据,符文可以修改
|
|
|
|
|
-- BehaviorNameList: 行为名称列表,符文可以修改
|
|
|
|
|
-- 返回值: 可以返回下一个index来控制流程,或者nil表示不干预
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 触发结束事件
|
|
|
|
|
function Rune:OnEndEvent(runeName: string, triggerSlot: number, AttributesData: table?, BehaviorNameList: table?)
|
|
|
|
|
-- runeName: 符文名称
|
|
|
|
|
-- triggerSlot: 触发槽位
|
|
|
|
|
-- AttributesData: 属性数据,符文可以修改
|
|
|
|
|
-- BehaviorNameList: 行为名称列表,符文可以修改
|
|
|
|
|
-- 返回值: 可以返回下一个index来控制流程,或者nil表示不干预
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 检查事件
|
|
|
|
|
function Rune:Check(index: number, AttributesData: table?, BehaviorNameList: table?)
|
|
|
|
|
-- index: 当前符文在列表中的位置
|
|
|
|
|
-- AttributesData: 属性数据,符文可以修改
|
|
|
|
|
-- BehaviorNameList: 行为名称列表,符文可以修改
|
2025-08-20 19:29:16 +08:00
|
|
|
|
-- 返回值: true表示可以执行,false表示跳过
|
|
|
|
|
return false
|
2025-08-14 17:01:07 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 执行事件
|
|
|
|
|
function Rune:Execute(index: number, AttributesData: table?, BehaviorNameList: table?)
|
2025-08-20 19:29:16 +08:00
|
|
|
|
-- index: 当前符文在列表中的位置
|
|
|
|
|
-- AttributesData: 属性数据,符文可以修改
|
|
|
|
|
-- BehaviorNameList: 行为名称列表,符文可以修改
|
|
|
|
|
-- 返回值: 下一个要执行的index,或者nil表示继续下一个
|
|
|
|
|
|
|
|
|
|
-- 记录执行前的状态
|
|
|
|
|
local attributesBefore = Utils:DeepCopyTable(AttributesData or {})
|
|
|
|
|
local behaviorListBefore = Utils:DeepCopyTable(BehaviorNameList or {})
|
|
|
|
|
|
|
|
|
|
-- 使用PlayerAI的专用方法
|
2025-08-14 17:01:07 +08:00
|
|
|
|
local beginNextIndex = self.PlayerAI:TriggerAllRunesExcept(self, "OnTriggerBeginEvent", index, AttributesData, BehaviorNameList)
|
|
|
|
|
if type(beginNextIndex) == "number" then
|
2025-08-20 19:29:16 +08:00
|
|
|
|
self:RecordExecution(index, attributesBefore, AttributesData, behaviorListBefore, BehaviorNameList, beginNextIndex)
|
2025-08-14 17:01:07 +08:00
|
|
|
|
return beginNextIndex
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 执行自己的逻辑
|
|
|
|
|
local nextIndex = self:OnExecute(index, AttributesData, BehaviorNameList)
|
|
|
|
|
if type(nextIndex) == "number" then
|
|
|
|
|
self.PlayerAI:TriggerAllRunesExcept(self, "OnTriggerEndEvent", index, AttributesData, BehaviorNameList)
|
2025-08-20 19:29:16 +08:00
|
|
|
|
self:RecordExecution(index, attributesBefore, AttributesData, behaviorListBefore, BehaviorNameList, nextIndex)
|
2025-08-14 17:01:07 +08:00
|
|
|
|
return nextIndex
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local endNextIndex = self.PlayerAI:TriggerAllRunesExcept(self, "OnTriggerEndEvent", index, AttributesData, BehaviorNameList)
|
|
|
|
|
if type(endNextIndex) == "number" then
|
2025-08-20 19:29:16 +08:00
|
|
|
|
self:RecordExecution(index, attributesBefore, AttributesData, behaviorListBefore, BehaviorNameList, endNextIndex)
|
2025-08-14 17:01:07 +08:00
|
|
|
|
return endNextIndex
|
|
|
|
|
end
|
2025-08-20 19:29:16 +08:00
|
|
|
|
|
2025-08-14 17:01:07 +08:00
|
|
|
|
self.TriggerTime = self.TriggerTime + 1
|
2025-08-20 19:29:16 +08:00
|
|
|
|
self:RecordExecution(index, attributesBefore, AttributesData, behaviorListBefore, BehaviorNameList, nextIndex)
|
|
|
|
|
|
|
|
|
|
return nextIndex
|
2025-08-14 17:01:07 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 子类可以重写这个方法
|
|
|
|
|
function Rune:OnExecute(index: number, AttributesData: table?, BehaviorNameList: table?)
|
|
|
|
|
-- index: 当前符文在列表中的位置
|
|
|
|
|
-- AttributesData: 属性数据,符文可以修改
|
|
|
|
|
-- BehaviorNameList: 行为名称列表,符文可以修改
|
|
|
|
|
-- 返回值: 下一个要执行的index,或者nil表示继续下一个
|
2025-08-20 19:29:16 +08:00
|
|
|
|
return nil
|
2025-08-14 17:01:07 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 销毁
|
|
|
|
|
function Rune:OnDestroy()
|
2025-08-20 19:29:16 +08:00
|
|
|
|
self.executionRecords = nil
|
2025-08-14 17:01:07 +08:00
|
|
|
|
self = nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return Rune
|