92 lines
4.3 KiB
Lua
92 lines
4.3 KiB
Lua
CheckLogicManager = CheckLogicManager or {}
|
||
|
||
-- Setting ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||
-- 此帧数会存在微小误差,可忽略不计
|
||
CheckLogicManager.FPS = 1
|
||
|
||
CheckLogicManager.ECheckLogicType = {
|
||
PlayerWeapon = 1;
|
||
FloorItemHandle = 2;
|
||
}
|
||
|
||
-- 核心列表,此列表不包含的类型不进行检测。 表示检测对应函数的时间间隔
|
||
CheckLogicManager.CheckLogicInfo = {
|
||
[CheckLogicManager.ECheckLogicType.FloorItemHandle] = { IntervalTime = 4., Server = true, Client = false};
|
||
[CheckLogicManager.ECheckLogicType.PlayerWeapon] = { IntervalTime = 2., Server = true, Client = false};
|
||
}
|
||
|
||
-- 检测函数,此列表不包含的函数也将不执行。可后续赋值,结构为 {Func, Obj},也可以在此manager后面写
|
||
CheckLogicManager.CheckLogicFunc = {}
|
||
|
||
-- Setting End --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||
|
||
|
||
-- Func ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||
--- 激活函数
|
||
function CheckLogicManager.ActiveCheck()
|
||
if CheckLogicManager.CheckHandle == nil then
|
||
CheckLogicManager.CheckHandle = UGCEventSystem.SetTimerLoop(UGCGameSystem.GameState, CheckLogicManager.Check, CheckLogicManager.FPS)
|
||
end
|
||
end
|
||
--- 暂停函数
|
||
function CheckLogicManager.StopCheck()
|
||
if CheckLogicManager.CheckHandle then
|
||
UGCEventSystem.StopTimer(CheckLogicManager.CheckHandle)
|
||
CheckLogicManager.CheckHandle = nil
|
||
end
|
||
end
|
||
|
||
|
||
CheckLogicManager.LastCheckTime = {}
|
||
--- Loop函数 每秒判断一次是否Check
|
||
function CheckLogicManager.Check()
|
||
local NowTime = UGCSystemLibrary.GetGameTime()
|
||
for i, CheckInfo in pairs(CheckLogicManager.CheckLogicInfo) do
|
||
-- 判断双端是否符合执行
|
||
if (UGCGameSystem.IsServer() and CheckInfo.Server) or (not UGCGameSystem.IsServer() and CheckInfo.Client)then
|
||
local CheckIntervalTime = CheckInfo.IntervalTime
|
||
-- 检验初始化
|
||
if CheckLogicManager.LastCheckTime[i] == nil then
|
||
CheckLogicManager.LastCheckTime[i] = NowTime
|
||
end
|
||
-- 判断时间间隔是否满足
|
||
if CheckIntervalTime <= NowTime - CheckLogicManager.LastCheckTime[i] then
|
||
CheckLogicManager.LastCheckTime[i] = NowTime
|
||
local LogicFuncInfo = CheckLogicManager.CheckLogicFunc[i]
|
||
-- 判断函数是否已填充
|
||
if LogicFuncInfo then
|
||
if LogicFuncInfo.Obj then
|
||
LogicFuncInfo.Func(LogicFuncInfo.Obj)
|
||
else
|
||
LogicFuncInfo.Func()
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
-- Func End -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||
|
||
|
||
-- Check Func ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||
|
||
--- 清除掉落物函数
|
||
CheckLogicManager.CheckLogicFunc[CheckLogicManager.ECheckLogicType.FloorItemHandle] = {
|
||
Func = function()
|
||
-- 清除掉落物,忽略生成物
|
||
UGCSystemLibrary.RemoveActorFromClassName("PickUpWrapperActor")
|
||
-- UGCLogSystem.Log("[FloorItemHandle_Func] Finish")
|
||
end, Obj = nil
|
||
}
|
||
|
||
-- 校验玩家的武器和配件
|
||
CheckLogicManager.CheckLogicFunc[CheckLogicManager.ECheckLogicType.PlayerWeapon] = {
|
||
Func = function()
|
||
local AllPC = UGCGameSystem.GetAllPlayerController()
|
||
for i, v in pairs(AllPC) do
|
||
UGCGameSystem.GameState:CheckWeaponAndParts(v.PlayerKey)
|
||
end
|
||
end, Obj = nil
|
||
}
|
||
-- Check Func End ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |