mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-06 01:00:16 +00:00
add end loop event
This commit is contained in:
parent
cfc3d0936f
commit
a1feb2c3e7
7
QSB/DeathSync/EndLoopReason.cs
Normal file
7
QSB/DeathSync/EndLoopReason.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace QSB.DeathSync
|
||||
{
|
||||
public enum EndLoopReason
|
||||
{
|
||||
AllPlayersDead = 0
|
||||
}
|
||||
}
|
36
QSB/DeathSync/Events/EndLoopEvent.cs
Normal file
36
QSB/DeathSync/Events/EndLoopEvent.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -82,5 +82,6 @@
|
||||
public static string QSBPlayerRetrieveProbe = "QSBPlayerRetrieveProbe";
|
||||
public static string QSBLaunchProbe = "QSBLaunchProbe";
|
||||
public static string QSBPlayerLaunchProbe = "QSBPlayerLaunchProbe";
|
||||
public static string QSBEndLoop = "QSBEndLoop";
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
//unsorted
|
||||
ServerTime,
|
||||
StartStatue,
|
||||
EndLoop,
|
||||
|
||||
/*
|
||||
* PLAYER EVENTS
|
||||
|
@ -62,6 +62,7 @@ namespace QSB.Events
|
||||
new LaunchProbeEvent(),
|
||||
new PlayerRetrieveProbeEvent(),
|
||||
new PlayerLaunchProbeEvent(),
|
||||
new EndLoopEvent(),
|
||||
// World Objects
|
||||
new ElevatorEvent(),
|
||||
new GeyserEvent(),
|
||||
|
@ -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" />
|
||||
|
Loading…
Reference in New Issue
Block a user