dream rafts: just sync RespawnRaft

This commit is contained in:
JohnCorby 2022-03-29 14:40:54 -07:00
parent 78acdf3ec6
commit 3197120313
6 changed files with 16 additions and 59 deletions

View File

@ -16,6 +16,5 @@ public class DreamRaftManager : WorldObjectManager
QSBWorldSync.Init<QSBSealRaft, SealRaftController>();
QSBWorldSync.Init<QSBDreamRaftProjector, DreamRaftProjector>();
QSBWorldSync.Init<QSBDreamRaftProjection, DreamRaftProjection>();
}
}

View File

@ -1,11 +0,0 @@
using QSB.EchoesOfTheEye.DreamRafts.WorldObjects;
using QSB.Messaging;
using QSB.Patches;
namespace QSB.EchoesOfTheEye.DreamRafts.Messages;
public class ExtinguishMessage : QSBWorldObjectMessage<QSBDreamRaftProjection>
{
public override void OnReceiveRemote() =>
QSBPatch.RemoteCall(() => WorldObject.AttachedObject.SetVisible(false));
}

View File

@ -4,7 +4,7 @@ using QSB.Patches;
namespace QSB.EchoesOfTheEye.DreamRafts.Messages;
public class SpawnRaftMessage : QSBWorldObjectMessage<QSBDreamRaftProjector>
public class RespawnRaftMessage : QSBWorldObjectMessage<QSBDreamRaftProjector>
{
public override void OnReceiveRemote() =>
QSBPatch.RemoteCall(WorldObject.AttachedObject.RespawnRaft);

View File

@ -4,7 +4,6 @@ using QSB.EchoesOfTheEye.DreamRafts.WorldObjects;
using QSB.Messaging;
using QSB.Patches;
using QSB.WorldSync;
using System.Linq;
namespace QSB.EchoesOfTheEye.DreamRafts.Patches;
@ -13,8 +12,8 @@ public class DreamRaftPatches : QSBPatch
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPrefix]
[HarmonyPatch(typeof(DreamRaftProjector), nameof(DreamRaftProjector.SpawnRaft))]
private static void SpawnRaft(DreamRaftProjector __instance)
[HarmonyPatch(typeof(DreamRaftProjector), nameof(DreamRaftProjector.RespawnRaft))]
private static void RespawnRaft(DreamRaftProjector __instance)
{
if (Remote)
{
@ -27,42 +26,28 @@ public class DreamRaftPatches : QSBPatch
}
__instance.GetWorldObject<QSBDreamRaftProjector>()
.SendMessage(new SpawnRaftMessage());
.SendMessage(new RespawnRaftMessage());
}
/// <summary>
/// make the projectors invisible,
/// but don't change the lit state
/// or sync anything.
/// </summary>
[HarmonyPrefix]
[HarmonyPatch(typeof(DreamRaftProjection), nameof(DreamRaftProjection.OnCandleLitStateChanged))]
private static bool OnCandleLitStateChanged(DreamRaftProjection __instance)
[HarmonyPatch(typeof(DreamRaftProjector), nameof(DreamRaftProjector.ExtinguishImmediately))]
private static bool ExtinguishImmediately(DreamRaftProjector __instance)
{
if (!__instance._visible)
if (!__instance._lit)
{
return false;
}
if (__instance._candles.Any(x => x.IsLit()))
foreach (var projection in __instance._projections)
{
return false;
}
__instance.SetVisible(false);
if (!Remote && QSBWorldSync.AllObjectsReady)
{
__instance.GetWorldObject<QSBDreamRaftProjection>()
.SendMessage(new ExtinguishMessage());
projection.SetVisibleImmediate(false, true);
}
return false;
}
/// <summary>
/// this only happens when
/// 1) you leave the dream world
/// 2) the raft goes thru a warp volume when ur not riding it
///
/// we ignore both of these
/// </summary>
[HarmonyPrefix]
[HarmonyPatch(typeof(DreamRaftProjector), nameof(DreamRaftProjector.ExtinguishImmediately))]
private static bool ExtinguishImmediately(DreamRaftProjector __instance) =>
false;
}

View File

@ -1,8 +0,0 @@
using QSB.WorldSync;
namespace QSB.EchoesOfTheEye.DreamRafts.WorldObjects;
public class QSBDreamRaftProjection : WorldObject<DreamRaftProjection>
{
public override void SendInitialState(uint to) { }
}

View File

@ -1,16 +1,8 @@
using QSB.EchoesOfTheEye.DreamRafts.Messages;
using QSB.Messaging;
using QSB.WorldSync;
using QSB.WorldSync;
namespace QSB.EchoesOfTheEye.DreamRafts.WorldObjects;
public class QSBDreamRaftProjector : WorldObject<DreamRaftProjector>
{
public override void SendInitialState(uint to)
{
if (AttachedObject._lit)
{
this.SendMessage(new SpawnRaftMessage { To = to });
}
}
public override void SendInitialState(uint to) { }
}