From 32cba5ced223ffe2626f9ef184599496410ad412 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 28 May 2022 13:57:32 -0700 Subject: [PATCH] messages --- .../Messages/PlayerIlluminatedByMessage.cs | 28 ++++++++++++++++ .../PlayerIlluminatingLanternsMessage.cs | 32 +++++++++++++++++++ .../Messages/PlayerSetIlluminatedMessage.cs | 13 ++++++++ QSB/Player/PlayerInfoParts/Body.cs | 2 +- .../Local/LocalPlayerCreation.cs | 2 +- .../Remote/RemotePlayerCreation.cs | 2 +- 6 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerIlluminatedByMessage.cs create mode 100644 QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerIlluminatingLanternsMessage.cs create mode 100644 QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerSetIlluminatedMessage.cs diff --git a/QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerIlluminatedByMessage.cs b/QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerIlluminatedByMessage.cs new file mode 100644 index 00000000..a86b0cba --- /dev/null +++ b/QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerIlluminatedByMessage.cs @@ -0,0 +1,28 @@ +using QSB.Messaging; +using QSB.Player; +using System.Linq; + +namespace QSB.EchoesOfTheEye.LightSensorSync.Messages; + +/// +/// always sent by host +/// +internal class PlayerIlluminatedByMessage : QSBMessage<(uint playerId, uint[] illuminatedBy)> +{ + public PlayerIlluminatedByMessage(uint playerId, uint[] illuminatedBy) : base((playerId, illuminatedBy)) { } + + public override void OnReceiveRemote() + { + var qsbPlayerLightSensor = QSBPlayerManager.GetPlayer(Data.playerId).QSBPlayerLightSensor; + + foreach (var added in Data.illuminatedBy.Except(qsbPlayerLightSensor._illuminatedBy)) + { + qsbPlayerLightSensor.SetIlluminated(added, true); + } + + foreach (var removed in qsbPlayerLightSensor._illuminatedBy.Except(Data.illuminatedBy)) + { + qsbPlayerLightSensor.SetIlluminated(removed, false); + } + } +} diff --git a/QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerIlluminatingLanternsMessage.cs b/QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerIlluminatingLanternsMessage.cs new file mode 100644 index 00000000..6e6a7d5a --- /dev/null +++ b/QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerIlluminatingLanternsMessage.cs @@ -0,0 +1,32 @@ +using QSB.EchoesOfTheEye.DreamLantern.WorldObjects; +using QSB.Messaging; +using QSB.Player; +using QSB.WorldSync; +using System.Collections.Generic; +using System.Linq; + +namespace QSB.EchoesOfTheEye.LightSensorSync.Messages; + +internal class PlayerIlluminatingLanternsMessage : QSBMessage<(uint playerId, int[] lanterns)> +{ + public PlayerIlluminatingLanternsMessage(uint playerId, IEnumerable lanterns) : + base(( + playerId, + lanterns.Select(x => x.GetWorldObject().ObjectId).ToArray() + )) { } + + public override void OnReceiveRemote() + { + var lightSensor = (SingleLightSensor)QSBPlayerManager.GetPlayer(Data.playerId).LightSensor; + + if (lightSensor.enabled) + { + // sensor is enabled, so this will already be synced + return; + } + + lightSensor._illuminatingDreamLanternList.Clear(); + lightSensor._illuminatingDreamLanternList.AddRange( + Data.lanterns.Select(x => x.GetWorldObject().AttachedObject)); + } +} diff --git a/QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerSetIlluminatedMessage.cs b/QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerSetIlluminatedMessage.cs new file mode 100644 index 00000000..acd6abfe --- /dev/null +++ b/QSB/EchoesOfTheEye/LightSensorSync/Messages/PlayerSetIlluminatedMessage.cs @@ -0,0 +1,13 @@ +using QSB.Messaging; +using QSB.Player; + +namespace QSB.EchoesOfTheEye.LightSensorSync.Messages; + +internal class PlayerSetIlluminatedMessage : QSBMessage<(uint playerId, bool illuminated)> +{ + public PlayerSetIlluminatedMessage(uint playerId, bool illuminated) : base((playerId, illuminated)) { } + public override void OnReceiveLocal() => OnReceiveRemote(); + + public override void OnReceiveRemote() => + QSBPlayerManager.GetPlayer(Data.playerId).QSBPlayerLightSensor.SetIlluminated(From, Data.illuminated); +} diff --git a/QSB/Player/PlayerInfoParts/Body.cs b/QSB/Player/PlayerInfoParts/Body.cs index 5805f0cf..7bfba9a8 100644 --- a/QSB/Player/PlayerInfoParts/Body.cs +++ b/QSB/Player/PlayerInfoParts/Body.cs @@ -74,7 +74,7 @@ public partial class PlayerInfo } } - public QSBPlayerLightSensor PlayerLightSensor; + public QSBPlayerLightSensor QSBPlayerLightSensor; public Vector3 Velocity { diff --git a/QSB/PlayerBodySetup/Local/LocalPlayerCreation.cs b/QSB/PlayerBodySetup/Local/LocalPlayerCreation.cs index 2f8397ad..512755ed 100644 --- a/QSB/PlayerBodySetup/Local/LocalPlayerCreation.cs +++ b/QSB/PlayerBodySetup/Local/LocalPlayerCreation.cs @@ -38,7 +38,7 @@ public static class LocalPlayerCreation player.CameraBody = cameraBody.gameObject; visibleCameraRoot = cameraBody; - player.PlayerLightSensor = player.LightSensor.gameObject.GetAddComponent(); + player.QSBPlayerLightSensor = player.LightSensor.gameObject.GetAddComponent(); PlayerToolsManager.InitLocal(); diff --git a/QSB/PlayerBodySetup/Remote/RemotePlayerCreation.cs b/QSB/PlayerBodySetup/Remote/RemotePlayerCreation.cs index bfef26cb..6c238a82 100644 --- a/QSB/PlayerBodySetup/Remote/RemotePlayerCreation.cs +++ b/QSB/PlayerBodySetup/Remote/RemotePlayerCreation.cs @@ -77,7 +77,7 @@ public static class RemotePlayerCreation player.CameraBody = REMOTE_PlayerCamera; visibleCameraRoot = REMOTE_PlayerCamera.transform; - player.PlayerLightSensor = player.LightSensor.gameObject.GetAddComponent(); + player.QSBPlayerLightSensor = player.LightSensor.gameObject.GetAddComponent(); PlayerToolsManager.InitRemote(player);