mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-19 12:40:56 +00:00
do _startIlluminated checks in worldobject and not in Start
This commit is contained in:
parent
b1810c413e
commit
0efd04fd70
@ -6,6 +6,7 @@ using QSB.Patches;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
/*
|
||||
* For those who come here,
|
||||
@ -19,6 +20,52 @@ internal class LightSensorPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(SingleLightSensor.Start))]
|
||||
private static bool Start(SingleLightSensor __instance)
|
||||
{
|
||||
if (__instance._lightDetector != null)
|
||||
{
|
||||
__instance._lightSources = new List<ILightSource>();
|
||||
__instance._lightSourceMask = LightSourceType.VOLUME_ONLY;
|
||||
if (__instance._detectFlashlight)
|
||||
{
|
||||
__instance._lightSourceMask |= LightSourceType.FLASHLIGHT;
|
||||
}
|
||||
|
||||
if (__instance._detectProbe)
|
||||
{
|
||||
__instance._lightSourceMask |= LightSourceType.PROBE;
|
||||
}
|
||||
|
||||
if (__instance._detectDreamLanterns)
|
||||
{
|
||||
__instance._lightSourceMask |= LightSourceType.DREAM_LANTERN;
|
||||
}
|
||||
|
||||
if (__instance._detectSimpleLanterns)
|
||||
{
|
||||
__instance._lightSourceMask |= LightSourceType.SIMPLE_LANTERN;
|
||||
}
|
||||
|
||||
__instance._lightDetector.OnLightVolumeEnter += __instance.OnLightSourceEnter;
|
||||
__instance._lightDetector.OnLightVolumeExit += __instance.OnLightSourceExit;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("LightSensor has no LightSourceDetector", __instance);
|
||||
}
|
||||
|
||||
if (__instance._sector != null)
|
||||
{
|
||||
__instance.enabled = false;
|
||||
__instance._lightDetector.GetShape().enabled = false;
|
||||
// dont do _startIlluminated stuff here since its done in the worldobject
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(SingleLightSensor.OnSectorOccupantsUpdated))]
|
||||
private static bool OnSectorOccupantsUpdated(SingleLightSensor __instance)
|
||||
|
@ -35,14 +35,13 @@ public class QSBPlayerLightSensor : MonoBehaviour
|
||||
RequestInitialStatesMessage.SendInitialState += SendInitialState;
|
||||
QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
|
||||
|
||||
// normally done in Start, but world objects arent ready by that point
|
||||
if (_lightSensor._sector != null)
|
||||
{
|
||||
if (_lightSensor._startIlluminated)
|
||||
{
|
||||
_locallyIlluminated = true;
|
||||
// do it manually so as not to invoke OnDetectLight, since that's handled by Start
|
||||
// BUG? should add all players to the list, not just local
|
||||
_illuminatedBy.SafeAdd(PlayerId);
|
||||
new PlayerSetIlluminatedMessage(PlayerId, true).Send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,15 +36,14 @@ internal class QSBLightSensor : WorldObject<SingleLightSensor>
|
||||
{
|
||||
QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
|
||||
|
||||
// normally done in Start, but world objects arent ready by that point
|
||||
if (AttachedObject._sector != null)
|
||||
{
|
||||
if (AttachedObject._startIlluminated)
|
||||
{
|
||||
_locallyIlluminated = true;
|
||||
OnDetectLocalLight?.Invoke();
|
||||
// do it manually so as not to invoke OnDetectLight, since that's handled by Start
|
||||
// BUG? should add all players to the list, not just local
|
||||
_illuminatedBy.SafeAdd(QSBPlayerManager.LocalPlayerId);
|
||||
this.SendMessage(new SetIlluminatedMessage(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user