157 lines
5.9 KiB
Plaintext
157 lines
5.9 KiB
Plaintext
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
|
||
self.Player = self.Character.Player
|
||
self.TriggerSlot = 0
|
||
self.WearingSlot = 0
|
||
self.TriggerTime = 0
|
||
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
|
||
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: 行为名称列表,符文可以修改
|
||
-- 返回值: true表示可以执行,false表示跳过
|
||
return false
|
||
end
|
||
|
||
-- 执行事件
|
||
function Rune:Execute(index: number, AttributesData: table?, BehaviorNameList: table?)
|
||
-- index: 当前符文在列表中的位置
|
||
-- AttributesData: 属性数据,符文可以修改
|
||
-- BehaviorNameList: 行为名称列表,符文可以修改
|
||
-- 返回值: 下一个要执行的index,或者nil表示继续下一个
|
||
|
||
-- 记录执行前的状态
|
||
local attributesBefore = Utils:DeepCopyTable(AttributesData or {})
|
||
local behaviorListBefore = Utils:DeepCopyTable(BehaviorNameList or {})
|
||
|
||
-- 使用PlayerAI的专用方法
|
||
local beginNextIndex = self.PlayerAI:TriggerAllRunesExcept(self, "OnTriggerBeginEvent", index, AttributesData, BehaviorNameList)
|
||
if type(beginNextIndex) == "number" then
|
||
self:RecordExecution(index, attributesBefore, AttributesData, behaviorListBefore, BehaviorNameList, beginNextIndex)
|
||
return beginNextIndex
|
||
end
|
||
|
||
-- 执行自己的逻辑
|
||
local nextIndex = self:OnExecute(index, AttributesData, BehaviorNameList)
|
||
if type(nextIndex) == "number" then
|
||
self.PlayerAI:TriggerAllRunesExcept(self, "OnTriggerEndEvent", index, AttributesData, BehaviorNameList)
|
||
self:RecordExecution(index, attributesBefore, AttributesData, behaviorListBefore, BehaviorNameList, nextIndex)
|
||
return nextIndex
|
||
end
|
||
|
||
local endNextIndex = self.PlayerAI:TriggerAllRunesExcept(self, "OnTriggerEndEvent", index, AttributesData, BehaviorNameList)
|
||
if type(endNextIndex) == "number" then
|
||
self:RecordExecution(index, attributesBefore, AttributesData, behaviorListBefore, BehaviorNameList, endNextIndex)
|
||
return endNextIndex
|
||
end
|
||
|
||
self.TriggerTime = self.TriggerTime + 1
|
||
self:RecordExecution(index, attributesBefore, AttributesData, behaviorListBefore, BehaviorNameList, nextIndex)
|
||
|
||
return nextIndex
|
||
end
|
||
|
||
-- 子类可以重写这个方法
|
||
function Rune:OnExecute(index: number, AttributesData: table?, BehaviorNameList: table?)
|
||
-- index: 当前符文在列表中的位置
|
||
-- AttributesData: 属性数据,符文可以修改
|
||
-- BehaviorNameList: 行为名称列表,符文可以修改
|
||
-- 返回值: 下一个要执行的index,或者nil表示继续下一个
|
||
return nil
|
||
end
|
||
|
||
-- 销毁
|
||
function Rune:OnDestroy()
|
||
self.executionRecords = nil
|
||
self = nil
|
||
end
|
||
|
||
return Rune |