alarm totems: track visible players

This commit is contained in:
JohnCorby 2022-04-01 17:48:01 -07:00
parent 3829211711
commit 3e4edb0bed
3 changed files with 26 additions and 26 deletions

View File

@ -15,5 +15,6 @@ public class VisibleForMessage : QSBWorldObjectMessage<QSBAlarmTotem, List<uint>
{
WorldObject.VisibleFor.Clear();
WorldObject.VisibleFor.AddRange(Data);
WorldObject.UpdateVisible();
}
}

View File

@ -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;
}
}

View File

@ -49,6 +49,31 @@ public class QSBAlarmTotem : WorldObject<AlarmTotem>
{
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)