mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-21 18:40:03 +00:00
use player light sensor messages
This commit is contained in:
parent
a6e1ed359a
commit
766cb2584e
@ -1,7 +1,12 @@
|
||||
using HarmonyLib;
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.Messages;
|
||||
using QSB.Messaging;
|
||||
using QSB.Patches;
|
||||
using QSB.Player;
|
||||
using QSB.Tools.FlashlightTool;
|
||||
using QSB.Tools.ProbeTool;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
/*
|
||||
@ -11,11 +16,58 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.LightSensorSync.Patches;
|
||||
|
||||
/// <summary>
|
||||
/// remote player light sensors are disabled, so these will only run for the local player light sensor
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(SingleLightSensor))]
|
||||
internal class PlayerLightSensorPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
/// <summary>
|
||||
/// to prevent allocating a new list every frame
|
||||
/// </summary>
|
||||
private static readonly List<DreamLanternController> _illuminatingDreamLanternList = new();
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(SingleLightSensor.ManagedFixedUpdate))]
|
||||
private static bool ManagedFixedUpdate(SingleLightSensor __instance)
|
||||
{
|
||||
if (!LightSensorManager.IsPlayerLightSensor(__instance))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (__instance._fixedUpdateFrameDelayCount > 0)
|
||||
{
|
||||
__instance._fixedUpdateFrameDelayCount--;
|
||||
return false;
|
||||
}
|
||||
var illuminated = __instance._illuminated;
|
||||
if (__instance._illuminatingDreamLanternList != null)
|
||||
{
|
||||
_illuminatingDreamLanternList.Clear();
|
||||
_illuminatingDreamLanternList.AddRange(__instance._illuminatingDreamLanternList);
|
||||
}
|
||||
__instance.UpdateIllumination();
|
||||
if (!illuminated && __instance._illuminated)
|
||||
{
|
||||
__instance.OnDetectLight.Invoke();
|
||||
new PlayerSetIlluminatedMessage(QSBPlayerManager.LocalPlayerId, true).Send();
|
||||
}
|
||||
else if (illuminated && !__instance._illuminated)
|
||||
{
|
||||
__instance.OnDetectDarkness.Invoke();
|
||||
new PlayerSetIlluminatedMessage(QSBPlayerManager.LocalPlayerId, false).Send();
|
||||
}
|
||||
if (__instance._illuminatingDreamLanternList != null &&
|
||||
!__instance._illuminatingDreamLanternList.SequenceEqual(_illuminatingDreamLanternList))
|
||||
{
|
||||
new PlayerIlluminatingLanternsMessage(QSBPlayerManager.LocalPlayerId, __instance._illuminatingDreamLanternList).Send();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(SingleLightSensor.UpdateIllumination))]
|
||||
private static bool UpdateIllumination(SingleLightSensor __instance)
|
||||
|
Loading…
x
Reference in New Issue
Block a user