2022-03-27 13:32:10 -07:00

58 lines
1.2 KiB
C#

using HarmonyLib;
using QSB.EchoesOfTheEye.DreamRafts.Messages;
using QSB.EchoesOfTheEye.DreamRafts.WorldObjects;
using QSB.Messaging;
using QSB.Patches;
using QSB.WorldSync;
using System.Linq;
namespace QSB.EchoesOfTheEye.DreamRafts.Patches;
public class DreamRaftPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPrefix]
[HarmonyPatch(typeof(DreamRaftProjector), nameof(DreamRaftProjector.SpawnRaft))]
private static void SpawnRaft(DreamRaftProjector __instance,
bool lit)
{
if (Remote)
{
return;
}
if (!QSBWorldSync.AllObjectsReady)
{
return;
}
__instance.GetWorldObject<QSBDreamRaftProjector>()
.SendMessage(new SpawnRaftMessage());
}
[HarmonyPrefix]
[HarmonyPatch(typeof(DreamRaftProjection), nameof(DreamRaftProjection.OnCandleLitStateChanged))]
private static bool OnCandleLitStateChanged(DreamRaftProjection __instance)
{
if (!__instance._visible)
{
return false;
}
if (__instance._candles.Any(x => x.IsLit()))
{
return false;
}
__instance.SetVisible(false);
if (!Remote && QSBWorldSync.AllObjectsReady)
{
__instance.GetWorldObject<QSBDreamRaftProjection>()
.SendMessage(new ExtinguishMessage());
}
return false;
}
}