108 lines
4.0 KiB
Plaintext
108 lines
4.0 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 Communicate = require(ServerStorage.Modules.Tools.Communicate)
|
|||
|
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.TriggerSlot = 0
|
|||
|
self.WearingSlot = 0
|
|||
|
self.TriggerTime = 0
|
|||
|
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: 行为名称列表,符文可以修改
|
|||
|
return false -- 默认返回false,表示不可以执行
|
|||
|
end
|
|||
|
|
|||
|
-- 执行事件
|
|||
|
function Rune:Execute(index: number, AttributesData: table?, BehaviorNameList: table?)
|
|||
|
-- 使用PlayerAI的专用方法,性能更好
|
|||
|
local beginNextIndex = self.PlayerAI:TriggerAllRunesExcept(self, "OnTriggerBeginEvent", index, AttributesData, BehaviorNameList)
|
|||
|
if type(beginNextIndex) == "number" then
|
|||
|
return beginNextIndex
|
|||
|
end
|
|||
|
|
|||
|
-- 执行自己的逻辑
|
|||
|
local nextIndex = self:OnExecute(index, AttributesData, BehaviorNameList)
|
|||
|
if type(nextIndex) == "number" then
|
|||
|
self.PlayerAI:TriggerAllRunesExcept(self, "OnTriggerEndEvent", index, AttributesData, BehaviorNameList)
|
|||
|
return nextIndex
|
|||
|
end
|
|||
|
|
|||
|
local endNextIndex = self.PlayerAI:TriggerAllRunesExcept(self, "OnTriggerEndEvent", index, AttributesData, BehaviorNameList)
|
|||
|
if type(endNextIndex) == "number" then
|
|||
|
return endNextIndex
|
|||
|
end
|
|||
|
self.TriggerTime = self.TriggerTime + 1
|
|||
|
return nextIndex -- 返回下一个要执行的index
|
|||
|
end
|
|||
|
|
|||
|
-- 子类可以重写这个方法
|
|||
|
function Rune:OnExecute(index: number, AttributesData: table?, BehaviorNameList: table?)
|
|||
|
-- 默认实现,子类可以重写
|
|||
|
-- index: 当前符文在列表中的位置
|
|||
|
-- AttributesData: 属性数据,符文可以修改
|
|||
|
-- BehaviorNameList: 行为名称列表,符文可以修改
|
|||
|
-- 返回值: 下一个要执行的index,或者nil表示继续下一个
|
|||
|
return nil -- 默认继续下一个符文
|
|||
|
end
|
|||
|
|
|||
|
-- 销毁
|
|||
|
function Rune:OnDestroy()
|
|||
|
self = nil
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
return Rune
|