quantum-space-buddies/QSB/Player/Messages/PlayerInformationMessage.cs

89 lines
2.5 KiB
C#
Raw Normal View History

using Mirror;
using OWML.Common;
2021-12-22 17:38:08 -08:00
using QSB.ClientServerStateSync;
using QSB.Messaging;
2021-12-22 17:38:08 -08:00
using QSB.Utility;
2022-03-02 19:46:33 -08:00
namespace QSB.Player.Messages;
public class PlayerInformationMessage : QSBMessage
{
2022-03-02 19:46:33 -08:00
private string PlayerName;
private bool IsReady;
private bool FlashlightActive;
private bool SuitedUp;
2022-04-16 10:08:59 +01:00
private bool LocalProbeLauncherEquipped;
2022-03-02 19:46:33 -08:00
private bool SignalscopeEquipped;
private bool TranslatorEquipped;
private bool ProbeActive;
private ClientState ClientState;
2021-12-22 17:38:08 -08:00
2022-03-02 19:46:33 -08:00
public PlayerInformationMessage()
{
var player = QSBPlayerManager.LocalPlayer;
PlayerName = player.Name;
IsReady = player.IsReady;
FlashlightActive = player.FlashlightActive;
SuitedUp = player.SuitedUp;
2022-04-16 10:08:59 +01:00
LocalProbeLauncherEquipped = player.LocalProbeLauncherEquipped;
2022-03-02 19:46:33 -08:00
SignalscopeEquipped = player.SignalscopeEquipped;
TranslatorEquipped = player.TranslatorEquipped;
ProbeActive = player.ProbeActive;
ClientState = player.State;
}
2021-12-22 17:38:08 -08:00
2022-03-02 19:46:33 -08:00
public override void Serialize(NetworkWriter writer)
{
base.Serialize(writer);
writer.Write(PlayerName);
writer.Write(IsReady);
writer.Write(FlashlightActive);
writer.Write(SuitedUp);
2022-04-16 10:08:59 +01:00
writer.Write(LocalProbeLauncherEquipped);
2022-03-02 19:46:33 -08:00
writer.Write(SignalscopeEquipped);
writer.Write(TranslatorEquipped);
writer.Write(ProbeActive);
writer.Write(ClientState);
}
2022-03-02 19:46:33 -08:00
public override void Deserialize(NetworkReader reader)
{
base.Deserialize(reader);
PlayerName = reader.ReadString();
IsReady = reader.Read<bool>();
FlashlightActive = reader.Read<bool>();
SuitedUp = reader.Read<bool>();
2022-04-16 10:08:59 +01:00
LocalProbeLauncherEquipped = reader.Read<bool>();
2022-03-02 19:46:33 -08:00
SignalscopeEquipped = reader.Read<bool>();
TranslatorEquipped = reader.Read<bool>();
ProbeActive = reader.Read<bool>();
ClientState = reader.Read<ClientState>();
}
2022-03-02 19:46:33 -08:00
public override void OnReceiveRemote()
{
RequestStateResyncMessage._waitingForEvent = false;
if (QSBPlayerManager.PlayerExists(From))
{
2022-03-02 19:46:33 -08:00
var player = QSBPlayerManager.GetPlayer(From);
player.Name = PlayerName;
player.IsReady = IsReady;
player.FlashlightActive = FlashlightActive;
player.SuitedUp = SuitedUp;
2022-04-16 10:08:59 +01:00
player.LocalProbeLauncherEquipped = LocalProbeLauncherEquipped;
2022-03-02 19:46:33 -08:00
player.SignalscopeEquipped = SignalscopeEquipped;
player.TranslatorEquipped = TranslatorEquipped;
player.ProbeActive = ProbeActive;
if (QSBPlayerManager.LocalPlayer.IsReady && player.IsReady)
{
2022-03-02 19:46:33 -08:00
player.UpdateObjectsFromStates();
}
2022-03-02 19:46:33 -08:00
player.State = ClientState;
}
else
{
DebugLog.ToConsole($"Warning - got player information message about player that doesnt exist!", MessageType.Warning);
2021-12-22 17:38:08 -08:00
}
2020-12-02 21:23:01 +00:00
}
}