add end loop event

This commit is contained in:
Mister_Nebula 2021-07-31 09:44:56 +01:00
parent cfc3d0936f
commit a1feb2c3e7
7 changed files with 59 additions and 1 deletions

View File

@ -0,0 +1,7 @@
namespace QSB.DeathSync
{
public enum EndLoopReason
{
AllPlayersDead = 0
}
}

View File

@ -0,0 +1,36 @@
using QSB.Events;
using QSB.Messaging;
using QSB.Utility;
namespace QSB.DeathSync.Events
{
class EndLoopEvent : QSBEvent<EnumMessage<EndLoopReason>>
{
public override EventType Type => EventType.EndLoop;
public override void SetupListener() => GlobalMessenger<EndLoopReason>.AddListener(EventNames.QSBEndLoop, Handler);
public override void CloseListener() => GlobalMessenger<EndLoopReason>.RemoveListener(EventNames.QSBEndLoop, Handler);
private void Handler(EndLoopReason type) => SendEvent(CreateMessage(type));
private EnumMessage<EndLoopReason> CreateMessage(EndLoopReason type) => new EnumMessage<EndLoopReason>
{
AboutId = LocalPlayerId,
EnumValue = type
};
public override void OnReceiveLocal(bool server, EnumMessage<EndLoopReason> message)
=> OnReceiveRemote(server, message);
public override void OnReceiveRemote(bool server, EnumMessage<EndLoopReason> message)
{
switch (message.EnumValue)
{
case EndLoopReason.AllPlayersDead:
DebugLog.DebugWrite($"all players dead");
Locator.GetDeathManager().KillPlayer(DeathType.TimeLoop);
break;
}
}
}
}

View File

@ -1,5 +1,7 @@
using OWML.Common;
using OWML.Utils;
using QSB.Events;
using QSB.Player;
using QSB.Player.TransformSync;
using QSB.Utility;
using System.Linq;
@ -46,13 +48,21 @@ namespace QSB.DeathSync
public void ResetPlayer()
{
DebugLog.DebugWrite($"Trying to reset player.");
DebugLog.DebugWrite($"RESET PLAYER");
if (_playerSpawnPoint == null)
{
DebugLog.ToConsole("Warning - _playerSpawnPoint is null!", MessageType.Warning);
Init();
}
var deadPlayersCount = QSBPlayerManager.PlayerList.Count(x => x.IsDead);
if (deadPlayersCount == QSBPlayerManager.PlayerList.Count)
{
QSBEventManager.FireEvent(EventNames.QSBEndLoop, EndLoopReason.AllPlayersDead);
return;
}
RespawnManager.Instance.TriggerRespawnMap();
var inSpace = PlayerTransformSync.LocalInstance.SectorSync.SectorList.Count == 0;

View File

@ -82,5 +82,6 @@
public static string QSBPlayerRetrieveProbe = "QSBPlayerRetrieveProbe";
public static string QSBLaunchProbe = "QSBLaunchProbe";
public static string QSBPlayerLaunchProbe = "QSBPlayerLaunchProbe";
public static string QSBEndLoop = "QSBEndLoop";
}
}

View File

@ -5,6 +5,7 @@
//unsorted
ServerTime,
StartStatue,
EndLoop,
/*
* PLAYER EVENTS

View File

@ -62,6 +62,7 @@ namespace QSB.Events
new LaunchProbeEvent(),
new PlayerRetrieveProbeEvent(),
new PlayerLaunchProbeEvent(),
new EndLoopEvent(),
// World Objects
new ElevatorEvent(),
new GeyserEvent(),

View File

@ -141,6 +141,8 @@
<Compile Include="ConversationSync\Events\ConversationStartEndMessage.cs" />
<Compile Include="ConversationSync\ConversationType.cs" />
<Compile Include="ConversationSync\ConversationManager.cs" />
<Compile Include="DeathSync\EndLoopReason.cs" />
<Compile Include="DeathSync\Events\EndLoopEvent.cs" />
<Compile Include="DeathSync\Events\PlayerRespawnEvent.cs" />
<Compile Include="DeathSync\Patches\MapPatches.cs" />
<Compile Include="DeathSync\Events\PlayerDeathMessage.cs" />