This commit is contained in:
Mister_Nebula 2022-04-01 19:08:10 +01:00
commit 583fcec7bb
14 changed files with 258 additions and 27 deletions

View File

@ -0,0 +1,15 @@
using Cysharp.Threading.Tasks;
using QSB.EchoesOfTheEye.AlarmTotemSync.WorldObjects;
using QSB.WorldSync;
using System.Threading;
namespace QSB.EchoesOfTheEye.AlarmTotemSync;
public class SarcophagusManager : WorldObjectManager
{
public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem;
public override bool DlcOnly => true;
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) =>
QSBWorldSync.Init<QSBAlarmTotem, AlarmTotem>();
}

View File

@ -0,0 +1,12 @@
using QSB.EchoesOfTheEye.AlarmTotemSync.WorldObjects;
using QSB.Messaging;
namespace QSB.EchoesOfTheEye.AlarmTotemSync.Messages;
public class SetEnabledMessage : QSBWorldObjectMessage<QSBAlarmTotem, bool>
{
public SetEnabledMessage(bool data) : base(data) { }
public override void OnReceiveRemote() =>
WorldObject.SetEnabled(Data);
}

View File

@ -0,0 +1,13 @@
using QSB.EchoesOfTheEye.AlarmTotemSync.WorldObjects;
using QSB.Messaging;
using QSB.Patches;
namespace QSB.EchoesOfTheEye.AlarmTotemSync.Messages;
public class SetFaceOpenMessage : QSBWorldObjectMessage<QSBAlarmTotem, bool>
{
public SetFaceOpenMessage(bool data) : base(data) { }
public override void OnReceiveRemote() =>
QSBPatch.RemoteCall(() => WorldObject.AttachedObject.SetFaceOpen(Data));
}

View File

@ -0,0 +1,36 @@
using HarmonyLib;
using QSB.EchoesOfTheEye.AlarmTotemSync.Messages;
using QSB.EchoesOfTheEye.AlarmTotemSync.WorldObjects;
using QSB.Messaging;
using QSB.Patches;
using QSB.WorldSync;
namespace QSB.EchoesOfTheEye.AlarmTotemSync.Patches;
public class AlarmTotemPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPrefix]
[HarmonyPatch(typeof(AlarmTotem), nameof(AlarmTotem.SetFaceOpen))]
private static void SetFaceOpen(AlarmTotem __instance, bool open)
{
if (Remote)
{
return;
}
if (__instance._isFaceOpen == open)
{
return;
}
if (!QSBWorldSync.AllObjectsReady)
{
return;
}
__instance.GetWorldObject<QSBAlarmTotem>()
.SendMessage(new SetFaceOpenMessage(open));
}
}

View File

@ -0,0 +1,45 @@
using QSB.EchoesOfTheEye.AlarmTotemSync.Messages;
using QSB.Messaging;
using QSB.WorldSync;
namespace QSB.EchoesOfTheEye.AlarmTotemSync.WorldObjects;
public class QSBAlarmTotem : WorldObject<AlarmTotem>
{
public override void SendInitialState(uint to)
{
this.SendMessage(new SetFaceOpenMessage(AttachedObject._isFaceOpen) { To = to });
this.SendMessage(new SetEnabledMessage(AttachedObject.enabled) { To = to });
}
public void SetEnabled(bool enabled)
{
if (AttachedObject.enabled == enabled)
{
return;
}
if (!enabled &&
AttachedObject._sector &&
AttachedObject._sector.ContainsOccupant(DynamicOccupant.Player))
{
// local player is in sector, do not disable
return;
}
AttachedObject.enabled = enabled;
if (!enabled)
{
AttachedObject._pulseLightController.SetIntensity(0f);
AttachedObject._simTotemMaterials[0] = AttachedObject._origSimEyeMaterial;
AttachedObject._simTotemRenderer.sharedMaterials = AttachedObject._simTotemMaterials;
AttachedObject._simVisionConeRenderer.SetColor(AttachedObject._simVisionConeRenderer.GetOriginalColor());
if (AttachedObject._isPlayerVisible)
{
AttachedObject._isPlayerVisible = false;
Locator.GetAlarmSequenceController().DecreaseAlarmCounter();
}
}
}
}

View File

@ -5,11 +5,6 @@ using QSB.Messaging;
using QSB.Patches;
using QSB.Player;
using QSB.WorldSync;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace QSB.EchoesOfTheEye.DreamLantern.Patches;
@ -42,9 +37,9 @@ internal class DreamLanternPatches : QSBPatch
var isHoldingItem = Locator.GetToolModeSwapper().IsInToolMode(ToolMode.Item);
__instance._wasFocusing = __instance._focusing;
__instance._focusing = OWInput.IsPressed(InputLibrary.toolActionPrimary, InputMode.Character, 0f) && Time.time > __instance._forceUnfocusTime + 1f && isHoldingItem;
__instance._focusing = OWInput.IsPressed(InputLibrary.toolActionPrimary, InputMode.Character) && Time.time > __instance._forceUnfocusTime + 1f && isHoldingItem;
var concealActionPressed = OWInput.IsPressed(InputLibrary.toolActionSecondary, InputMode.Character, 0f) && isHoldingItem;
var concealActionPressed = OWInput.IsPressed(InputLibrary.toolActionSecondary, InputMode.Character) && isHoldingItem;
if (concealActionPressed && !__instance._lanternController.IsConcealed())
{
Locator.GetPlayerAudioController().OnArtifactConceal();
@ -55,7 +50,7 @@ internal class DreamLanternPatches : QSBPatch
{
Locator.GetPlayerAudioController().OnArtifactUnconceal();
__instance._lanternController.SetConcealed(false);
new DreamLanternStateMessage(DreamLanternActionType.CONCEAL, false).Send();
new DreamLanternStateMessage(DreamLanternActionType.CONCEAL).Send();
}
if (__instance._focusing != __instance._wasFocusing)
@ -102,6 +97,16 @@ internal class DreamLanternPatches : QSBPatch
return;
}
if (__instance._lanternController.IsLit() == lit)
{
return;
}
if (!QSBWorldSync.AllObjectsReady)
{
return;
}
__instance.GetWorldObject<QSBDreamLanternItem>().SendMessage(new DreamLanternLitMessage(lit));
}
}

View File

@ -1,12 +1,10 @@
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
using QSB.Messaging;
using QSB.Patches;
namespace QSB.EchoesOfTheEye.LightSensorSync.Messages;
internal class SetEnabledMessage : QSBWorldObjectMessage<QSBLightSensor, bool>
{
public SetEnabledMessage(bool data) : base(data) { }
public override void OnReceiveRemote() =>
QSBPatch.RemoteCall(WorldObject.AttachedObject.OnSectorOccupantsUpdated, Data);
public override void OnReceiveRemote() => WorldObject.SetEnabled(Data);
}

View File

@ -19,31 +19,26 @@ internal class LightSensorPatches : QSBPatch
[HarmonyPatch(nameof(SingleLightSensor.OnSectorOccupantsUpdated))]
private static bool OnSectorOccupantsUpdated(SingleLightSensor __instance)
{
var enable = !Remote
? __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)
: (bool)RemoteData;
if (enable && !__instance.enabled)
if (!QSBWorldSync.AllObjectsReady)
{
return true;
}
var flag = __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe);
if (flag && !__instance.enabled)
{
__instance.enabled = true;
if (!Remote && QSBWorldSync.AllObjectsReady)
{
__instance.GetWorldObject<QSBLightSensor>().SendMessage(new SetEnabledMessage(true));
}
__instance.GetWorldObject<QSBLightSensor>().SendMessage(new SetEnabledMessage(true));
__instance._lightDetector.GetShape().enabled = true;
if (__instance._preserveStateWhileDisabled)
{
__instance._fixedUpdateFrameDelayCount = 10;
}
}
else if (!enable && __instance.enabled)
else if (!flag && __instance.enabled)
{
__instance.enabled = false;
if (!Remote && QSBWorldSync.AllObjectsReady)
{
__instance.GetWorldObject<QSBLightSensor>().SendMessage(new SetEnabledMessage(false));
}
__instance.GetWorldObject<QSBLightSensor>().SendMessage(new SetEnabledMessage(false));
__instance._lightDetector.GetShape().enabled = false;
if (!__instance._preserveStateWhileDisabled)
{

View File

@ -14,4 +14,38 @@ internal class QSBLightSensor : WorldObject<SingleLightSensor>
public override void SendInitialState(uint to) =>
this.SendMessage(new SetEnabledMessage(AttachedObject.enabled) { To = to });
public void SetEnabled(bool enabled)
{
if (enabled && !AttachedObject.enabled)
{
AttachedObject.enabled = true;
AttachedObject._lightDetector.GetShape().enabled = true;
if (AttachedObject._preserveStateWhileDisabled)
{
AttachedObject._fixedUpdateFrameDelayCount = 10;
}
}
else if (!enabled && AttachedObject.enabled)
{
if (AttachedObject._sector &&
AttachedObject._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe))
{
// local player is in sector, do not disable
return;
}
AttachedObject.enabled = false;
AttachedObject._lightDetector.GetShape().enabled = false;
if (!AttachedObject._preserveStateWhileDisabled)
{
if (AttachedObject._illuminated)
{
AttachedObject.OnDetectDarkness.Invoke();
}
AttachedObject._illuminated = false;
}
}
}
}

View File

@ -0,0 +1,11 @@
using QSB.EchoesOfTheEye.Sarcophagus.WorldObjects;
using QSB.Messaging;
using QSB.Patches;
namespace QSB.EchoesOfTheEye.Sarcophagus.Messages;
public class OpenMessage : QSBWorldObjectMessage<QSBSarcophagus>
{
public override void OnReceiveRemote() =>
QSBPatch.RemoteCall(WorldObject.AttachedObject.OnPressInteract);
}

View File

@ -0,0 +1,36 @@
using HarmonyLib;
using QSB.EchoesOfTheEye.Sarcophagus.Messages;
using QSB.EchoesOfTheEye.Sarcophagus.WorldObjects;
using QSB.Messaging;
using QSB.Patches;
using QSB.WorldSync;
namespace QSB.EchoesOfTheEye.Sarcophagus.Patches;
public class SarcophagusPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPrefix]
[HarmonyPatch(typeof(SarcophagusController), nameof(SarcophagusController.OnPressInteract))]
private static void OnPressInteract(SarcophagusController __instance)
{
if (Remote)
{
return;
}
if (__instance._isOpen)
{
return;
}
if (!QSBWorldSync.AllObjectsReady)
{
return;
}
__instance.GetWorldObject<QSBSarcophagus>()
.SendMessage(new OpenMessage());
}
}

View File

@ -0,0 +1,15 @@
using Cysharp.Threading.Tasks;
using QSB.EchoesOfTheEye.Sarcophagus.WorldObjects;
using QSB.WorldSync;
using System.Threading;
namespace QSB.EchoesOfTheEye.Sarcophagus;
public class SarcophagusManager : WorldObjectManager
{
public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem;
public override bool DlcOnly => true;
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) =>
QSBWorldSync.Init<QSBSarcophagus, SarcophagusController>();
}

View File

@ -0,0 +1,16 @@
using QSB.EchoesOfTheEye.Sarcophagus.Messages;
using QSB.Messaging;
using QSB.WorldSync;
namespace QSB.EchoesOfTheEye.Sarcophagus.WorldObjects;
public class QSBSarcophagus : WorldObject<SarcophagusController>
{
public override void SendInitialState(uint to)
{
if (AttachedObject._isOpen)
{
this.SendMessage(new OpenMessage());
}
}
}

View File

@ -231,7 +231,7 @@ public static class QSBWorldSync
if (!worldObjects.Any(x => x is TWorldObject))
{
DebugLog.ToConsole($"Error - WorldObjectsToUnityObjects does not contain \"{unityObject.name}\"! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error);
DebugLog.ToConsole($"Error - UnityObjectsToWorldObjects does not contain \"{unityObject.name}\"! TWorldObject:{typeof(TWorldObject).Name}, TUnityObject:{unityObject.GetType().Name}, Stacktrace:\r\n{Environment.StackTrace}", MessageType.Error);
return default;
}