83 lines
2.4 KiB
Plaintext
83 lines
2.4 KiB
Plaintext
|
local Behaviour = {}
|
|||
|
Behaviour.__index = Behaviour
|
|||
|
|
|||
|
--> Dependencies
|
|||
|
local TypeList = require(script.Parent.TypeList)
|
|||
|
|
|||
|
--------------------------------------------------------------------------------
|
|||
|
|
|||
|
-- 刷新时,重新载入,暂时不考虑性能
|
|||
|
|
|||
|
-- 初始化内容
|
|||
|
function Behaviour:Init(Character: TypeList.Character)
|
|||
|
local self = {}
|
|||
|
self.Character = Character
|
|||
|
self.CheckData = nil
|
|||
|
self.ExeTask = nil
|
|||
|
|
|||
|
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
|
|||
|
|
|||
|
-- 检查当前状态是否可执行
|
|||
|
function Behaviour:CheckStat()
|
|||
|
if not self.Character then warn("Behaviour Character not found") return false end
|
|||
|
-- 死亡检查
|
|||
|
if self.Character:GetState("Died") then return false end
|
|||
|
|
|||
|
-- 执行状态中检查
|
|||
|
local FightingFolder = self.Character:FindFirstChild("Fighting")
|
|||
|
local ExecutingState = FightingFolder:FindFirstChild("ExecutingState")
|
|||
|
-- 其他内容执行中,就false
|
|||
|
if ExecutingState.Value == true then return false end
|
|||
|
return true
|
|||
|
end
|
|||
|
|
|||
|
-- 改变当前执行状态标记
|
|||
|
function Behaviour:ChangeExecutingState(State: boolean)
|
|||
|
if not self.Character then warn("Behaviour Character not found") return end
|
|||
|
local FightingFolder = self.Character:FindFirstChild("Fighting")
|
|||
|
local ExecutingState = FightingFolder:FindFirstChild("ExecutingState")
|
|||
|
ExecutingState.Value = State
|
|||
|
end
|
|||
|
|
|||
|
-- 销毁
|
|||
|
function Behaviour:Destroy()
|
|||
|
if self.ConAttribtueChanged then
|
|||
|
self.ConAttribtueChanged:Disconnect()
|
|||
|
self.ConAttribtueChanged = nil
|
|||
|
end
|
|||
|
if self.LoopTask then
|
|||
|
task.cancel(self.LoopTask)
|
|||
|
self.LoopTask = nil
|
|||
|
end
|
|||
|
self = nil
|
|||
|
end
|
|||
|
|
|||
|
-- 死亡时,主要打断当前执行状态
|
|||
|
function Behaviour:OnDied()
|
|||
|
if self.ExeTask then
|
|||
|
task.cancel(self.ExeTask)
|
|||
|
self.ExeTask = nil
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
return Behaviour
|