SetIlluminatedMessage

This commit is contained in:
JohnCorby 2022-08-16 16:02:22 -07:00
parent aaee2ded3a
commit 99e7ff986c
3 changed files with 27 additions and 7 deletions

View File

@ -14,12 +14,6 @@ internal class IlluminatingLanternsMessage : QSBWorldObjectMessage<QSBLightSenso
public override void OnReceiveRemote()
{
if (WorldObject.AttachedObject.enabled)
{
// sensor is enabled, so this will already be synced
return;
}
WorldObject.AttachedObject._illuminatingDreamLanternList.Clear();
WorldObject.AttachedObject._illuminatingDreamLanternList.AddRange(
Data.Select(x => x.GetWorldObject<QSBDreamLantern>().AttachedObject));

View File

@ -0,0 +1,22 @@
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
using QSB.Messaging;
namespace QSB.EchoesOfTheEye.LightSensorSync.Messages;
internal class SetIlluminatedMessage : QSBWorldObjectMessage<QSBLightSensor, bool>
{
public SetIlluminatedMessage(bool illuminated) : base(illuminated) { }
public override void OnReceiveRemote()
{
WorldObject.AttachedObject._illuminated = Data;
if (Data)
{
WorldObject.AttachedObject.OnDetectLight.Invoke();
}
else
{
WorldObject.AttachedObject.OnDetectDarkness.Invoke();
}
}
}

View File

@ -1,6 +1,8 @@
using HarmonyLib;
using QSB.AuthoritySync;
using QSB.EchoesOfTheEye.LightSensorSync.Messages;
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
using QSB.Messaging;
using QSB.Patches;
using QSB.Player;
using QSB.Utility;
@ -112,16 +114,18 @@ internal class LightSensorPatches : QSBPatch
if (!illuminated && __instance._illuminated)
{
__instance.OnDetectLight.Invoke();
qsbLightSensor.SendMessage(new SetIlluminatedMessage(true));
return false;
}
if (illuminated && !__instance._illuminated)
{
__instance.OnDetectDarkness.Invoke();
qsbLightSensor.SendMessage(new SetIlluminatedMessage(false));
}
if (__instance._illuminatingDreamLanternList != null &&
!__instance._illuminatingDreamLanternList.SequenceEqual(_illuminatingDreamLanternList))
{
// todo send a message about it
qsbLightSensor.SendMessage(new IlluminatingLanternsMessage(__instance._illuminatingDreamLanternList));
}
}
if (!locallyIlluminated && qsbLightSensor._locallyIlluminated)