From 3e4edb0bedfb79c21e44799c55e4d7f5c164adae Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 1 Apr 2022 17:48:01 -0700 Subject: [PATCH] alarm totems: track visible players --- .../Messages/VisibleForMessage.cs | 1 + .../Patches/AlarmTotemPatches.cs | 26 ------------------- .../WorldObjects/QSBAlarmTotem.cs | 25 ++++++++++++++++++ 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/VisibleForMessage.cs b/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/VisibleForMessage.cs index 3047a1e7..f619c5a5 100644 --- a/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/VisibleForMessage.cs +++ b/QSB/EchoesOfTheEye/AlarmTotemSync/Messages/VisibleForMessage.cs @@ -15,5 +15,6 @@ public class VisibleForMessage : QSBWorldObjectMessage { WorldObject.VisibleFor.Clear(); WorldObject.VisibleFor.AddRange(Data); + WorldObject.UpdateVisible(); } } diff --git a/QSB/EchoesOfTheEye/AlarmTotemSync/Patches/AlarmTotemPatches.cs b/QSB/EchoesOfTheEye/AlarmTotemSync/Patches/AlarmTotemPatches.cs index d5e00482..4e3c8d93 100644 --- a/QSB/EchoesOfTheEye/AlarmTotemSync/Patches/AlarmTotemPatches.cs +++ b/QSB/EchoesOfTheEye/AlarmTotemSync/Patches/AlarmTotemPatches.cs @@ -94,30 +94,4 @@ public class AlarmTotemPatches : QSBPatch 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 98aa5b08..79562320 100644 --- a/QSB/EchoesOfTheEye/AlarmTotemSync/WorldObjects/QSBAlarmTotem.cs +++ b/QSB/EchoesOfTheEye/AlarmTotemSync/WorldObjects/QSBAlarmTotem.cs @@ -49,6 +49,31 @@ public class QSBAlarmTotem : WorldObject { VisibleFor.QuickRemove(playerId); } + + UpdateVisible(); + } + + public void UpdateVisible() + { + if (AttachedObject._isPlayerVisible && VisibleFor.Count < 1) + { + Locator.GetAlarmSequenceController().IncreaseAlarmCounter(); + AttachedObject._simTotemMaterials[0] = AttachedObject._simAlarmMaterial; + AttachedObject._simTotemRenderer.sharedMaterials = AttachedObject._simTotemMaterials; + AttachedObject._simVisionConeRenderer.SetColor(AttachedObject._simAlarmColor); + if (AttachedObject._isTutorialTotem) + { + GlobalMessenger.FireEvent("TutorialAlarmTotemTriggered"); + } + } + else if (!AttachedObject._isPlayerVisible && VisibleFor.Count >= 1) + { + Locator.GetAlarmSequenceController().DecreaseAlarmCounter(); + AttachedObject._simTotemMaterials[0] = AttachedObject._origSimEyeMaterial; + AttachedObject._simTotemRenderer.sharedMaterials = AttachedObject._simTotemMaterials; + AttachedObject._simVisionConeRenderer.SetColor(AttachedObject._simVisionConeRenderer.GetOriginalColor()); + AttachedObject._pulseLightController.FadeTo(0f, 0.5f); + } } public void SetEnabled(bool enabled)