From 31d46697733f0d210724eb59fdf42ec5b889d50f Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 1 Apr 2022 17:26:58 -0700 Subject: [PATCH] rename --- ...temSyncManager.cs => AlarmTotemManager.cs} | 2 +- .../Messages/SetEnabledMessage.cs | 2 +- .../Messages/SetFaceOpenMessage.cs | 2 +- .../Patches/AlarmTotemPatches.cs | 55 +++++++++++++++++++ .../WorldObjects/QSBAlarmTotem.cs | 4 ++ 5 files changed, 62 insertions(+), 3 deletions(-) rename QSB/EchoesOfTheEye/AlarmTotemSync/{AlarmTotemSyncManager.cs => AlarmTotemManager.cs} (89%) diff --git a/QSB/EchoesOfTheEye/AlarmTotemSync/AlarmTotemSyncManager.cs b/QSB/EchoesOfTheEye/AlarmTotemSync/AlarmTotemManager.cs similarity index 89% rename from QSB/EchoesOfTheEye/AlarmTotemSync/AlarmTotemSyncManager.cs rename to QSB/EchoesOfTheEye/AlarmTotemSync/AlarmTotemManager.cs index 29ababc5..b121d519 100644 --- a/QSB/EchoesOfTheEye/AlarmTotemSync/AlarmTotemSyncManager.cs +++ b/QSB/EchoesOfTheEye/AlarmTotemSync/AlarmTotemManager.cs @@ -5,7 +5,7 @@ using System.Threading; namespace QSB.EchoesOfTheEye.AlarmTotemSync; -public class SarcophagusManager : WorldObjectManager +public class AlarmTotemManager : WorldObjectManager { public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem; public override bool DlcOnly => true; diff --git a/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/SetEnabledMessage.cs b/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/SetEnabledMessage.cs index c8784298..457137d8 100644 --- a/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/SetEnabledMessage.cs +++ b/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/SetEnabledMessage.cs @@ -5,7 +5,7 @@ namespace QSB.EchoesOfTheEye.AlarmTotemSync.Messages; public class SetEnabledMessage : QSBWorldObjectMessage { - public SetEnabledMessage(bool data) : base(data) { } + public SetEnabledMessage(bool enabled) : base(enabled) { } public override void OnReceiveRemote() => WorldObject.SetEnabled(Data); diff --git a/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/SetFaceOpenMessage.cs b/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/SetFaceOpenMessage.cs index 7cc0a6a2..0f120b7e 100644 --- a/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/SetFaceOpenMessage.cs +++ b/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/SetFaceOpenMessage.cs @@ -6,7 +6,7 @@ namespace QSB.EchoesOfTheEye.AlarmTotemSync.Messages; public class SetFaceOpenMessage : QSBWorldObjectMessage { - public SetFaceOpenMessage(bool data) : base(data) { } + public SetFaceOpenMessage(bool open) : base(open) { } public override void OnReceiveRemote() => QSBPatch.RemoteCall(() => WorldObject.AttachedObject.SetFaceOpen(Data)); diff --git a/QSB/EchoesOfTheEye/AlarmTotemSync/Patches/AlarmTotemPatches.cs b/QSB/EchoesOfTheEye/AlarmTotemSync/Patches/AlarmTotemPatches.cs index 1bdded46..9183c7d7 100644 --- a/QSB/EchoesOfTheEye/AlarmTotemSync/Patches/AlarmTotemPatches.cs +++ b/QSB/EchoesOfTheEye/AlarmTotemSync/Patches/AlarmTotemPatches.cs @@ -55,4 +55,59 @@ public class AlarmTotemPatches : QSBPatch .SendMessage(new SetEnabledMessage(false)); } } + + [HarmonyPrefix] + [HarmonyPatch(typeof(AlarmTotem), nameof(AlarmTotem.FixedUpdate))] + private static bool FixedUpdate(AlarmTotem __instance) + { + var isPlayerVisible = __instance._isPlayerVisible; + __instance._isPlayerVisible = __instance.CheckPlayerVisible(); + if (__instance._isPlayerVisible && !isPlayerVisible) + { + Locator.GetAlarmSequenceController().IncreaseAlarmCounter(); + __instance._simTotemMaterials[0] = __instance._simAlarmMaterial; + __instance._simTotemRenderer.sharedMaterials = __instance._simTotemMaterials; + __instance._simVisionConeRenderer.SetColor(__instance._simAlarmColor); + if (__instance._isTutorialTotem) + { + GlobalMessenger.FireEvent("TutorialAlarmTotemTriggered"); + } + } + else if (isPlayerVisible && !__instance._isPlayerVisible) + { + Locator.GetAlarmSequenceController().DecreaseAlarmCounter(); + __instance._simTotemMaterials[0] = __instance._origSimEyeMaterial; + __instance._simTotemRenderer.sharedMaterials = __instance._simTotemMaterials; + __instance._simVisionConeRenderer.SetColor(__instance._simVisionConeRenderer.GetOriginalColor()); + __instance._pulseLightController.FadeTo(0f, 0.5f); + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(AlarmTotem), nameof(AlarmTotem.CheckPlayerVisible))] + private static bool CheckPlayerVisible(AlarmTotem __instance, out bool __result) + { + if (!__instance._isFaceOpen) + { + __result = false; + return false; + } + + var lanternController = Locator.GetDreamWorldController().GetPlayerLantern().GetLanternController(); + var playerLightSensor = Locator.GetPlayerLightSensor(); + if (lanternController.IsHeldByPlayer() && !lanternController.IsConcealed() || playerLightSensor.IsIlluminated()) + { + var position = Locator.GetPlayerCamera().transform.position; + if (__instance.CheckPointInVisionCone(position) && !__instance.CheckLineOccluded(__instance._sightOrigin.position, position)) + { + __result = true; + return false; + } + } + + __result = false; + return false; + } } diff --git a/QSB/EchoesOfTheEye/AlarmTotemSync/WorldObjects/QSBAlarmTotem.cs b/QSB/EchoesOfTheEye/AlarmTotemSync/WorldObjects/QSBAlarmTotem.cs index d64730fc..f96ba536 100644 --- a/QSB/EchoesOfTheEye/AlarmTotemSync/WorldObjects/QSBAlarmTotem.cs +++ b/QSB/EchoesOfTheEye/AlarmTotemSync/WorldObjects/QSBAlarmTotem.cs @@ -1,11 +1,15 @@ using QSB.EchoesOfTheEye.AlarmTotemSync.Messages; using QSB.Messaging; +using QSB.Player; using QSB.WorldSync; +using System.Collections.Generic; namespace QSB.EchoesOfTheEye.AlarmTotemSync.WorldObjects; public class QSBAlarmTotem : WorldObject { + public readonly List VisibleFor = new(); + public override void SendInitialState(uint to) { this.SendMessage(new SetFaceOpenMessage(AttachedObject._isFaceOpen) { To = to });