quantum-space-buddies/QSB/EchoesOfTheEye/DreamWorld/Messages/ExitDreamWorldMessage.cs
2023-07-28 19:30:57 +01:00

58 lines
1.2 KiB
C#

using QSB.EchoesOfTheEye.Ghosts.WorldObjects;
using QSB.Messaging;
using QSB.Player;
using QSB.Player.TransformSync;
using QSB.WorldSync;
namespace QSB.EchoesOfTheEye.DreamWorld.Messages;
/// <summary>
/// todo SendInitialState
/// </summary>
public class ExitDreamWorldMessage : QSBMessage
{
static ExitDreamWorldMessage()
{
GlobalMessenger.AddListener(OWEvents.ExitDreamWorld, () =>
{
if (!PlayerTransformSync.LocalInstance)
{
return;
}
new ExitDreamWorldMessage().Send();
});
}
public override void OnReceiveLocal()
{
var player = QSBPlayerManager.LocalPlayer;
player.InDreamWorld = false;
player.AssignedSimulationLantern = null;
foreach (var ghost in QSBWorldSync.GetWorldObjects<QSBGhostBrain>())
{
ghost.OnExitDreamWorld(player);
}
}
public override void OnReceiveRemote()
{
var player = QSBPlayerManager.GetPlayer(From);
player.InDreamWorld = false;
player.AssignedSimulationLantern = null;
if (QSBCore.IsHost)
{
foreach (var ghost in QSBWorldSync.GetWorldObjects<QSBGhostBrain>())
{
ghost.OnExitDreamWorld(player);
ghost.GetEffects().OnSectorOccupantsUpdated();
}
}
Locator.GetAlarmSequenceController().OnExitDreamWorld();
DreamWorldFakePlayer.Destroy(player);
}
}