129 lines
3.7 KiB
Plaintext
Raw Normal View History

2025-07-07 23:52:31 +08:00
local Behaviour = {}
Behaviour.__index = Behaviour
2025-07-12 05:06:14 +08:00
--> Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
--> Events
local RE_PerformanceEvent = ReplicatedStorage:FindFirstChild("Events"):FindFirstChild("RE_PerformanceEvent")
local RE_CleanPlayerPerformance = ReplicatedStorage:FindFirstChild("Events"):FindFirstChild("RE_CleanPlayerPerformance")
2025-07-07 23:52:31 +08:00
--> Dependencies
2025-07-12 05:06:14 +08:00
local TypeList = require(ServerStorage.Base.TypeList)
local Communicate = require(ServerStorage.Modules.Tools.Communicate)
2025-07-07 23:52:31 +08:00
--------------------------------------------------------------------------------
-- 刷新时,重新载入,暂时不考虑性能
-- 初始化内容
2025-07-12 05:06:14 +08:00
function Behaviour:Init(PlayerAI, Character: TypeList.Character, ScriptName: string)
2025-07-07 23:52:31 +08:00
local self = {}
2025-07-09 02:01:45 +08:00
self.PlayerAI = PlayerAI
2025-07-07 23:52:31 +08:00
self.Character = Character
self.CheckData = nil
self.ExeTask = nil
2025-07-12 05:06:14 +08:00
self.UniqueIdList = {}
self.ScriptName = ScriptName
self.Cooldown = 0
self.OrgCooldown = 0
self.CooldownTask = nil
2025-07-07 23:52:31 +08:00
local Humanoid = self.Character.Humanoid
-- 监听属性变化
self.ConAttribtueChanged = Humanoid.AttributeChanged:Connect(function(attributeKey: string, attributeValue: any)
-- 以后这里要是有其他状态也可以加打断
if attributeKey == "Died" and attributeValue == true then
self:OnDied()
end
end)
return self
end
-- 执行检查(主要重写部分) return 优先级, 执行数据
function Behaviour:Check(CheckInfo: table)
-- 返回优先级,执行数据
return -1, self.CheckData
end
-- 具体执行内容(主要重写部分)
function Behaviour:Execute()
end
2025-07-12 05:06:14 +08:00
-- 启动冷却时间清除计时
function Behaviour:StartCooldownTask()
self.Cooldown = self.OrgCooldown
self.CooldownTask = task.spawn(function()
task.wait(self.OrgCooldown)
self.Cooldown = 0
end)
end
function Behaviour:SendPerformanceEvent(...)
Communicate:SendToClient(RE_PerformanceEvent, ...)
end
2025-07-07 23:52:31 +08:00
-- 检查当前状态是否可执行
function Behaviour:CheckStat()
2025-07-09 23:59:56 +08:00
if not self.Character then return true end
2025-07-07 23:52:31 +08:00
-- 死亡检查
2025-07-09 23:59:56 +08:00
if self.Character:GetState("Died") then return true end
2025-07-07 23:52:31 +08:00
2025-07-12 05:06:14 +08:00
-- 冷却中检查
if self.Cooldown > 0 then return true end
2025-07-07 23:52:31 +08:00
-- 执行状态中检查
2025-07-09 02:01:45 +08:00
local ExecutingState = self.PlayerAI.ExecutingState
2025-07-07 23:52:31 +08:00
-- 其他内容执行中就false
2025-07-09 23:59:56 +08:00
if ExecutingState == true then return true end
return false
2025-07-07 23:52:31 +08:00
end
-- 改变当前执行状态标记
function Behaviour:ChangeExecutingState(State: boolean)
if not self.Character then warn("Behaviour Character not found") return end
2025-07-09 23:59:56 +08:00
self.PlayerAI.ExecutingState = State
2025-07-07 23:52:31 +08:00
end
-- 销毁
function Behaviour:Destroy()
2025-07-12 05:06:14 +08:00
-- 清除客户端对应行为表现
for _, UniqueId in self.UniqueIdList do
self:SendPerformanceEvent("Destroy", self.Player, self.ScriptName, true, {UniqueId = UniqueId})
end
if self.CooldownTask then
task.cancel(self.CooldownTask)
self.CooldownTask = nil
end
if self.ExeTask then
task.cancel(self.ExeTask)
self.ExeTask = nil
end
-- 清除数据
self.UniqueIdList = {}
2025-07-07 23:52:31 +08:00
if self.ConAttribtueChanged then
self.ConAttribtueChanged:Disconnect()
self.ConAttribtueChanged = nil
end
if self.LoopTask then
task.cancel(self.LoopTask)
self.LoopTask = nil
end
2025-07-12 05:06:14 +08:00
for _, UniqueId in self.UniqueIdList do
self.PlayerAI:RemoveBehaviourUniqueId(UniqueId)
end
self.UniqueIdList = {}
2025-07-07 23:52:31 +08:00
self = nil
end
-- 死亡时,主要打断当前执行状态
function Behaviour:OnDied()
if self.ExeTask then
task.cancel(self.ExeTask)
self.ExeTask = nil
end
end
return Behaviour