mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-17 01:13:05 +00:00
QSBDreamLantern
This commit is contained in:
parent
362b9afc39
commit
df43552ed2
@ -1,7 +0,0 @@
|
||||
namespace QSB.EchoesOfTheEye.DreamLantern;
|
||||
|
||||
public enum DreamLanternActionType
|
||||
{
|
||||
FOCUS,
|
||||
CONCEAL
|
||||
}
|
15
QSB/EchoesOfTheEye/DreamLantern/DreamLanternManager.cs
Normal file
15
QSB/EchoesOfTheEye/DreamLantern/DreamLanternManager.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using QSB.EchoesOfTheEye.DreamLantern.WorldObjects;
|
||||
using QSB.WorldSync;
|
||||
using System.Threading;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.DreamLantern;
|
||||
|
||||
public class DreamLanternManager : WorldObjectManager
|
||||
{
|
||||
public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem;
|
||||
public override bool DlcOnly => true;
|
||||
|
||||
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) =>
|
||||
QSBWorldSync.Init<QSBDreamLantern, DreamLanternController>();
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
using QSB.ItemSync.WorldObjects.Items;
|
||||
using QSB.Messaging;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.DreamLantern.Messages;
|
||||
|
||||
internal class DreamLanternStateMessage : QSBMessage<(DreamLanternActionType Type, bool BoolValue, float FloatValue)>
|
||||
{
|
||||
public DreamLanternStateMessage(DreamLanternActionType actionType, bool boolValue = false, float floatValue = 0f)
|
||||
: base((actionType, boolValue, floatValue)) { }
|
||||
|
||||
public override void OnReceiveRemote()
|
||||
{
|
||||
var heldItem = QSBPlayerManager.GetPlayer(From).HeldItem;
|
||||
|
||||
if (heldItem is not QSBDreamLanternItem lantern)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Got DreamLanternStateMessage from player {From}, but they are not holding a QSBDreamLanternItem!", OWML.Common.MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var controller = lantern.AttachedObject._lanternController;
|
||||
|
||||
switch (Data.Type)
|
||||
{
|
||||
case DreamLanternActionType.CONCEAL:
|
||||
DebugLog.DebugWrite($"CONCEAL {lantern.AttachedObject.name}");
|
||||
controller.SetConcealed(Data.BoolValue);
|
||||
break;
|
||||
case DreamLanternActionType.FOCUS:
|
||||
controller.SetFocus(Data.FloatValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using QSB.EchoesOfTheEye.DreamLantern.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
using QSB.Patches;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.DreamLantern.Messages;
|
||||
|
||||
internal class SetConcealedMessage : QSBWorldObjectMessage<QSBDreamLantern, bool>
|
||||
{
|
||||
public SetConcealedMessage(bool concealed) : base(concealed) { }
|
||||
|
||||
public override void OnReceiveRemote()
|
||||
=> QSBPatch.RemoteCall(() => WorldObject.AttachedObject.SetConcealed(Data));
|
||||
}
|
13
QSB/EchoesOfTheEye/DreamLantern/Messages/SetFocusMessage.cs
Normal file
13
QSB/EchoesOfTheEye/DreamLantern/Messages/SetFocusMessage.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using QSB.EchoesOfTheEye.DreamLantern.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
using QSB.Patches;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.DreamLantern.Messages;
|
||||
|
||||
internal class SetFocusMessage : QSBWorldObjectMessage<QSBDreamLantern, float>
|
||||
{
|
||||
public SetFocusMessage(float focus) : base(focus) { }
|
||||
|
||||
public override void OnReceiveRemote()
|
||||
=> QSBPatch.RemoteCall(() => WorldObject.AttachedObject.SetFocus(Data));
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
using QSB.ItemSync.WorldObjects.Items;
|
||||
using QSB.EchoesOfTheEye.DreamLantern.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
using QSB.Patches;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.DreamLantern.Messages;
|
||||
|
||||
internal class DreamLanternLitMessage : QSBWorldObjectMessage<QSBDreamLanternItem, bool>
|
||||
internal class SetLitMessage : QSBWorldObjectMessage<QSBDreamLantern, bool>
|
||||
{
|
||||
public DreamLanternLitMessage(bool lit) : base(lit) { }
|
||||
public SetLitMessage(bool lit) : base(lit) { }
|
||||
|
||||
public override void OnReceiveRemote()
|
||||
=> QSBPatch.RemoteCall(() => WorldObject.AttachedObject.SetLit(Data));
|
13
QSB/EchoesOfTheEye/DreamLantern/Messages/SetRangeMessage.cs
Normal file
13
QSB/EchoesOfTheEye/DreamLantern/Messages/SetRangeMessage.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using QSB.EchoesOfTheEye.DreamLantern.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
using QSB.Patches;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.DreamLantern.Messages;
|
||||
|
||||
internal class SetRangeMessage : QSBWorldObjectMessage<QSBDreamLantern, (float minRange, float maxRange)>
|
||||
{
|
||||
public SetRangeMessage(float minRange, float maxRange) : base((minRange, maxRange)) { }
|
||||
|
||||
public override void OnReceiveRemote()
|
||||
=> QSBPatch.RemoteCall(() => WorldObject.AttachedObject.SetRange(Data.minRange, Data.maxRange));
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using QSB.EchoesOfTheEye.DreamLantern.Messages;
|
||||
using QSB.ItemSync.WorldObjects.Items;
|
||||
using QSB.EchoesOfTheEye.DreamLantern.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
using QSB.Patches;
|
||||
using QSB.WorldSync;
|
||||
@ -13,73 +13,15 @@ internal class DreamLanternPatches : QSBPatch
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(DreamLanternItem), nameof(DreamLanternItem.Update))]
|
||||
public static bool UpdateReplacement(DreamLanternItem __instance)
|
||||
{
|
||||
var isHoldingItem = Locator.GetToolModeSwapper().IsInToolMode(ToolMode.Item);
|
||||
|
||||
__instance._wasFocusing = __instance._focusing;
|
||||
__instance._focusing = OWInput.IsPressed(InputLibrary.toolActionPrimary, InputMode.Character) && Time.time > __instance._forceUnfocusTime + 1f && isHoldingItem;
|
||||
|
||||
var concealActionPressed = OWInput.IsPressed(InputLibrary.toolActionSecondary, InputMode.Character) && isHoldingItem;
|
||||
if (concealActionPressed && !__instance._lanternController.IsConcealed())
|
||||
{
|
||||
Locator.GetPlayerAudioController().OnArtifactConceal();
|
||||
__instance._lanternController.SetConcealed(true);
|
||||
new DreamLanternStateMessage(DreamLanternActionType.CONCEAL, true).Send();
|
||||
}
|
||||
else if (!concealActionPressed && __instance._lanternController.IsConcealed())
|
||||
{
|
||||
Locator.GetPlayerAudioController().OnArtifactUnconceal();
|
||||
__instance._lanternController.SetConcealed(false);
|
||||
new DreamLanternStateMessage(DreamLanternActionType.CONCEAL).Send();
|
||||
}
|
||||
|
||||
if (__instance._focusing != __instance._wasFocusing)
|
||||
{
|
||||
if (__instance._focusing)
|
||||
{
|
||||
Locator.GetPlayerAudioController().OnArtifactFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
Locator.GetPlayerAudioController().OnArtifactUnfocus();
|
||||
}
|
||||
}
|
||||
|
||||
__instance.UpdateFocus();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(DreamLanternController), nameof(DreamLanternController.MoveTowardFocus))]
|
||||
public static bool UpdateFocusReplacement(DreamLanternController __instance, float targetFocus, float rate)
|
||||
{
|
||||
var value = Mathf.MoveTowards(__instance._focus, targetFocus, rate * Time.deltaTime);
|
||||
|
||||
if (__instance._focus == value)
|
||||
{
|
||||
__instance.SetFocus(value);
|
||||
return false;
|
||||
}
|
||||
|
||||
__instance.SetFocus(value);
|
||||
new DreamLanternStateMessage(DreamLanternActionType.FOCUS, floatValue: value).Send();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(DreamLanternItem), nameof(DreamLanternItem.SetLit))]
|
||||
public static void SetLit(DreamLanternItem __instance, bool lit)
|
||||
[HarmonyPatch(typeof(DreamLanternController), nameof(DreamLanternController.SetLit))]
|
||||
public static void SetLit(DreamLanternController __instance, bool lit)
|
||||
{
|
||||
if (Remote)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (__instance._lanternController.IsLit() == lit)
|
||||
if (__instance._lit == lit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -89,6 +31,73 @@ internal class DreamLanternPatches : QSBPatch
|
||||
return;
|
||||
}
|
||||
|
||||
__instance.GetWorldObject<QSBDreamLanternItem>().SendMessage(new DreamLanternLitMessage(lit));
|
||||
__instance.GetWorldObject<QSBDreamLantern>().SendMessage(new SetLitMessage(lit));
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(DreamLanternController), nameof(DreamLanternController.SetConcealed))]
|
||||
public static void SetConcealed(DreamLanternController __instance, bool concealed)
|
||||
{
|
||||
if (Remote)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (__instance._concealed == concealed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!QSBWorldSync.AllObjectsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
__instance.GetWorldObject<QSBDreamLantern>().SendMessage(new SetConcealedMessage(concealed));
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(DreamLanternController), nameof(DreamLanternController.SetFocus))]
|
||||
public static void SetFocus(DreamLanternController __instance, float focus)
|
||||
{
|
||||
if (Remote)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
focus = Mathf.Clamp01(focus);
|
||||
if (OWMath.ApproxEquals(__instance._focus, focus))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!QSBWorldSync.AllObjectsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
__instance.GetWorldObject<QSBDreamLantern>().SendMessage(new SetFocusMessage(focus));
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(DreamLanternController), nameof(DreamLanternController.SetRange))]
|
||||
public static void SetRange(DreamLanternController __instance, float minRange, float maxRange)
|
||||
{
|
||||
if (Remote)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (OWMath.ApproxEquals(__instance._minRange, minRange) && OWMath.ApproxEquals(__instance._maxRange, maxRange))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!QSBWorldSync.AllObjectsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
__instance.GetWorldObject<QSBDreamLantern>().SendMessage(new SetRangeMessage(minRange, maxRange));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
using QSB.EchoesOfTheEye.DreamLantern.Messages;
|
||||
using QSB.Messaging;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.DreamLantern.WorldObjects;
|
||||
|
||||
public class QSBDreamLantern : WorldObject<DreamLanternController>
|
||||
{
|
||||
public override void SendInitialState(uint to)
|
||||
{
|
||||
this.SendMessage(new SetLitMessage(AttachedObject._lit) { To = to });
|
||||
this.SendMessage(new SetConcealedMessage(AttachedObject._concealed) { To = to });
|
||||
this.SendMessage(new SetFocusMessage(AttachedObject._focus) { To = to });
|
||||
this.SendMessage(new SetRangeMessage(AttachedObject._minRange, AttachedObject._maxRange) { To = to });
|
||||
}
|
||||
}
|
@ -1,17 +1,3 @@
|
||||
using QSB.EchoesOfTheEye.DreamLantern.Messages;
|
||||
using QSB.Messaging;
|
||||
namespace QSB.ItemSync.WorldObjects.Items;
|
||||
|
||||
namespace QSB.ItemSync.WorldObjects.Items;
|
||||
|
||||
public class QSBDreamLanternItem : QSBItem<DreamLanternItem>
|
||||
{
|
||||
public override void SendInitialState(uint to)
|
||||
{
|
||||
base.SendInitialState(to);
|
||||
|
||||
if (AttachedObject._lanternController != null)
|
||||
{
|
||||
this.SendMessage(new DreamLanternLitMessage(AttachedObject._lanternController.IsLit()) { To = to });
|
||||
}
|
||||
}
|
||||
}
|
||||
public class QSBDreamLanternItem : QSBItem<DreamLanternItem> { }
|
||||
|
Loading…
Reference in New Issue
Block a user