48 lines
1.7 KiB
Lua
48 lines
1.7 KiB
Lua
|
local EventAction_PlayerExit = {
|
|||
|
PlayerKey = 0;
|
|||
|
EndEvent = -1;
|
|||
|
}
|
|||
|
|
|||
|
-- 触发器激活时,将执行Action的Execute
|
|||
|
function EventAction_PlayerExit:Execute(...)
|
|||
|
if not UGCGameSystem.IsServer() then return end
|
|||
|
UGCGameSystem.SendPlayerSettlement(self.PlayerKey);
|
|||
|
|
|||
|
local PlayerState = UGCGameSystem.GetPlayerStateByPlayerKey(self.PlayerKey)
|
|||
|
local PlayerPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey)
|
|||
|
|
|||
|
if PlayerPawn then
|
|||
|
PlayerPawn:K2_DestroyActor()
|
|||
|
else
|
|||
|
UGCLogSystem.LogError("[EventAction_PlayerExit_Execute] PlayerPawn is nil")
|
|||
|
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
|
|||
|
local HasNotControlled = false
|
|||
|
for k, Pawn in pairs(AllPawn) do
|
|||
|
if not Pawn:IsControlled() then
|
|||
|
Pawn:K2_DestroyActor()
|
|||
|
HasNotControlled = true
|
|||
|
end
|
|||
|
end
|
|||
|
if HasNotControlled == false then UGCLogSystem.LogError("[EventAction_PlayerExit_Execute] HasNotControlled is false") end
|
|||
|
end
|
|||
|
|
|||
|
if UGCGameSystem.GameState and PlayerState then
|
|||
|
UGCLogSystem.Log("[EventAction_PlayerExit_Execute] PlayerName = "..PlayerState.PlayerName)
|
|||
|
local PlayerData = UGCGameSystem.GameState.PlayerPersonalInfos[self.PlayerKey]
|
|||
|
if PlayerData ~= nil then
|
|||
|
PlayerData.IsOffline = true
|
|||
|
end
|
|||
|
|
|||
|
local PlayerNum = #UGCGameSystem.GetAllPlayerState()
|
|||
|
if PlayerNum == 0 then
|
|||
|
UGCGameSystem.GameState.GameEndTimeStamp = UGCSystemLibrary.GetGameTime()
|
|||
|
-- UGCGameSystem.SendModeCustomEvent("GameEnd")
|
|||
|
UGCEventSystem.SendEvent(self.EndEvent)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--UGCEventSystem.SendEvent(EventEnum.PlayerExit, self.PlayerKey)
|
|||
|
return true
|
|||
|
end
|
|||
|
|
|||
|
return EventAction_PlayerExit
|