quantum-space-buddies/QSB/EchoesOfTheEye/DreamWorld/Messages/ExitDreamWorldMessage.cs

60 lines
1.2 KiB
C#
Raw Normal View History

2022-05-16 20:38:02 +00:00
using QSB.EchoesOfTheEye.Ghosts.WorldObjects;
using QSB.Messaging;
using QSB.Player;
using QSB.Player.TransformSync;
2022-05-16 20:38:02 +00:00
using QSB.WorldSync;
2022-05-27 04:56:17 +00:00
using System.Linq;
namespace QSB.EchoesOfTheEye.DreamWorld.Messages;
2022-03-26 01:57:26 +00:00
/// <summary>
2022-03-26 02:34:21 +00:00
/// todo SendInitialState
2022-03-26 01:57:26 +00:00
/// </summary>
internal class ExitDreamWorldMessage : QSBMessage
{
static ExitDreamWorldMessage()
{
GlobalMessenger.AddListener(OWEvents.ExitDreamWorld, () =>
{
if (!PlayerTransformSync.LocalInstance)
{
return;
}
new ExitDreamWorldMessage().Send();
});
}
2022-03-28 22:57:31 +00:00
public override void OnReceiveLocal()
{
var player = QSBPlayerManager.LocalPlayer;
player.InDreamWorld = false;
player.AssignedSimulationLantern = null;
2022-05-27 04:39:12 +00:00
foreach (var ghost in QSBWorldSync.GetWorldObjects<QSBGhostBrain>())
{
2022-05-27 04:39:12 +00:00
ghost.OnExitDreamWorld(player);
}
2022-03-28 22:57:31 +00:00
}
public override void OnReceiveRemote()
{
var player = QSBPlayerManager.GetPlayer(From);
player.InDreamWorld = false;
player.AssignedSimulationLantern = null;
2022-05-16 20:38:02 +00:00
if (QSBCore.IsHost)
{
foreach (var ghost in QSBWorldSync.GetWorldObjects<QSBGhostBrain>())
{
ghost.OnExitDreamWorld(player);
2022-05-27 04:56:17 +00:00
if (QSBPlayerManager.PlayerList.Count(x => x.InDreamWorld) == 0)
{
ghost.GetEffects().OnSectorOccupantsUpdated();
}
2022-05-16 20:38:02 +00:00
}
}
}
}