quantum-space-buddies/QSB/EchoesOfTheEye/DreamRafts/Patches/DreamRaftPatches.cs

87 lines
2.4 KiB
C#
Raw Permalink Normal View History

2022-03-26 02:47:35 +00:00
using HarmonyLib;
using QSB.EchoesOfTheEye.DreamCandles.Patches;
2022-03-29 21:44:50 +00:00
using QSB.EchoesOfTheEye.DreamObjectProjectors.WorldObject;
2022-03-26 02:47:35 +00:00
using QSB.EchoesOfTheEye.DreamRafts.Messages;
using QSB.EchoesOfTheEye.DreamRafts.WorldObjects;
2022-03-26 02:47:35 +00:00
using QSB.Messaging;
2023-05-08 18:30:59 +00:00
using QSB.OwnershipSync;
2022-03-26 02:47:35 +00:00
using QSB.Patches;
using QSB.WorldSync;
2022-03-12 00:39:53 +00:00
namespace QSB.EchoesOfTheEye.DreamRafts.Patches;
public class DreamRaftPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
2022-03-26 02:47:35 +00:00
[HarmonyPrefix]
2022-03-29 21:40:54 +00:00
[HarmonyPatch(typeof(DreamRaftProjector), nameof(DreamRaftProjector.RespawnRaft))]
private static void RespawnRaft_Prefix(DreamRaftProjector __instance)
2022-03-26 02:47:35 +00:00
{
if (Remote)
{
return;
}
if (!QSBWorldSync.AllObjectsReady)
{
return;
}
2022-03-29 21:44:50 +00:00
__instance.GetWorldObject<QSBDreamObjectProjector>()
2022-03-29 21:40:54 +00:00
.SendMessage(new RespawnRaftMessage());
// since respawning extinguishes all the candles, but we already have the above message
DreamCandlePatches.DontSendMessage = true;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(DreamRaftProjector), nameof(DreamRaftProjector.RespawnRaft))]
private static void RespawnRaft_Postfix(DreamRaftProjector __instance)
{
if (Remote)
{
return;
}
if (!QSBWorldSync.AllObjectsReady)
{
return;
}
DreamCandlePatches.DontSendMessage = false;
}
2022-03-29 21:40:54 +00:00
/// <summary>
/// this is only called when:
/// - you exit the dream world
/// - the raft goes thru the warp volume with you not on it
///
/// this is to suspend the raft so it doesn't fall endlessly.
/// however, it's okay if it does that,
/// and we don't want it to extinguish with other players on it.
2022-10-07 00:26:50 +00:00
///
/// BUG: this breaks when going thru the volume as a non auth player sometimes. oh well.
/// TODO: use in-raft-volume trigger volume instead. just copy from the ringworld rafts. use this for fake sectors as well
2022-03-29 21:40:54 +00:00
/// </summary>
[HarmonyPrefix]
[HarmonyPatch(typeof(DreamWorldController), nameof(DreamWorldController.ExtinguishDreamRaft))]
private static bool ExtinguishDreamRaft(DreamWorldController __instance)
{
if (!QSBWorldSync.AllObjectsReady)
{
return true;
}
if (__instance._lastUsedRaftProjector)
{
// still release ownership over the raft tho
__instance._lastUsedRaftProjector
._dreamRaftProjection.GetComponent<DreamRaftController>().GetWorldObject<QSBDreamRaft>()
2023-05-08 18:41:43 +00:00
.NetworkBehaviour.netIdentity.UpdateOwnerQueue(OwnerQueueAction.Remove);
}
return false;
}
2022-03-12 00:39:53 +00:00
}