mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
PlayerRespawnMessage
This commit is contained in:
parent
54810251cd
commit
a7c7544314
@ -65,7 +65,6 @@
|
||||
public const string QSBComponentDamaged = nameof(QSBComponentDamaged);
|
||||
public const string QSBComponentRepaired = nameof(QSBComponentRepaired);
|
||||
public const string QSBComponentRepairTick = nameof(QSBComponentRepairTick);
|
||||
public const string QSBPlayerRespawn = nameof(QSBPlayerRespawn);
|
||||
public const string QSBProbeEvent = nameof(QSBProbeEvent);
|
||||
public const string QSBProbeStartRetrieve = nameof(QSBProbeStartRetrieve);
|
||||
public const string QSBRetrieveProbe = nameof(QSBRetrieveProbe);
|
||||
|
@ -1,39 +0,0 @@
|
||||
using QSB.ClientServerStateSync;
|
||||
using QSB.Events;
|
||||
using QSB.Messaging;
|
||||
using QSB.Player;
|
||||
|
||||
namespace QSB.RespawnSync.Events
|
||||
{
|
||||
internal class PlayerRespawnEvent : QSBEvent<PlayerMessage>
|
||||
{
|
||||
public override bool RequireWorldObjectsReady => false;
|
||||
|
||||
public override void SetupListener()
|
||||
=> GlobalMessenger<uint>.AddListener(EventNames.QSBPlayerRespawn, Handler);
|
||||
|
||||
public override void CloseListener()
|
||||
=> GlobalMessenger<uint>.RemoveListener(EventNames.QSBPlayerRespawn, Handler);
|
||||
|
||||
private void Handler(uint playerId) => SendEvent(CreateMessage(playerId));
|
||||
|
||||
private PlayerMessage CreateMessage(uint playerId) => new()
|
||||
{
|
||||
AboutId = playerId
|
||||
};
|
||||
|
||||
public override void OnReceiveLocal(bool server, PlayerMessage message)
|
||||
=> OnReceiveRemote(server, message);
|
||||
|
||||
public override void OnReceiveRemote(bool server, PlayerMessage message)
|
||||
{
|
||||
if (message.AboutId == LocalPlayerId)
|
||||
{
|
||||
RespawnManager.Instance.Respawn();
|
||||
ClientStateManager.Instance.OnRespawn();
|
||||
}
|
||||
|
||||
RespawnManager.Instance.OnPlayerRespawn(QSBPlayerManager.GetPlayer(message.AboutId));
|
||||
}
|
||||
}
|
||||
}
|
41
QSB/RespawnSync/Events/PlayerRespawnMessage.cs
Normal file
41
QSB/RespawnSync/Events/PlayerRespawnMessage.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using QSB.ClientServerStateSync;
|
||||
using QSB.Messaging;
|
||||
using QSB.Player;
|
||||
using QuantumUNET.Transport;
|
||||
|
||||
namespace QSB.RespawnSync.Events
|
||||
{
|
||||
internal class PlayerRespawnMessage : QSBMessage
|
||||
{
|
||||
private uint PlayerId;
|
||||
|
||||
public PlayerRespawnMessage(uint playerId) => PlayerId = playerId;
|
||||
|
||||
public PlayerRespawnMessage() { }
|
||||
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(PlayerId);
|
||||
}
|
||||
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
PlayerId = reader.ReadUInt32();
|
||||
}
|
||||
|
||||
public override void OnReceiveLocal() => OnReceiveRemote();
|
||||
|
||||
public override void OnReceiveRemote()
|
||||
{
|
||||
if (PlayerId == QSBPlayerManager.LocalPlayerId)
|
||||
{
|
||||
RespawnManager.Instance.Respawn();
|
||||
ClientStateManager.Instance.OnRespawn();
|
||||
}
|
||||
|
||||
RespawnManager.Instance.OnPlayerRespawn(QSBPlayerManager.GetPlayer(PlayerId));
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,8 @@ using QSB.Player.TransformSync;
|
||||
using QSB.Utility;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QSB.Messaging;
|
||||
using QSB.RespawnSync.Events;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
@ -174,7 +176,7 @@ namespace QSB.RespawnSync
|
||||
public void RespawnSomePlayer()
|
||||
{
|
||||
var playerToRespawn = _playersPendingRespawn.First();
|
||||
QSBEventManager.FireEvent(EventNames.QSBPlayerRespawn, playerToRespawn.PlayerId);
|
||||
new PlayerRespawnMessage(playerToRespawn.PlayerId).Send();
|
||||
}
|
||||
|
||||
private void UpdateRespawnNotification()
|
||||
|
Loading…
Reference in New Issue
Block a user