2022-01-14 22:14:40 +00:00
|
|
|
using Mirror;
|
2022-01-14 07:38:45 +00:00
|
|
|
using OWML.Common;
|
2021-12-23 21:49:04 +00:00
|
|
|
using QSB.Messaging;
|
|
|
|
using QSB.Player.TransformSync;
|
|
|
|
using QSB.PoolSync;
|
|
|
|
using QSB.ShipSync;
|
|
|
|
using QSB.Utility;
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
2021-12-23 21:49:47 +00:00
|
|
|
namespace QSB.Player.Messages
|
2021-12-23 21:49:04 +00:00
|
|
|
{
|
2022-01-27 04:35:43 +00:00
|
|
|
internal class EnterLeaveMessage : QSBMessage<EnterLeaveType>
|
2021-12-23 21:49:04 +00:00
|
|
|
{
|
|
|
|
static EnterLeaveMessage()
|
|
|
|
{
|
2021-12-26 08:53:43 +00:00
|
|
|
GlobalMessenger.AddListener(OWEvents.PlayerEnterQuantumMoon, () => Handler(EnterLeaveType.EnterMoon));
|
|
|
|
GlobalMessenger.AddListener(OWEvents.PlayerExitQuantumMoon, () => Handler(EnterLeaveType.ExitMoon));
|
|
|
|
GlobalMessenger.AddListener(OWEvents.EnterShip, () => Handler(EnterLeaveType.EnterShip));
|
|
|
|
GlobalMessenger.AddListener(OWEvents.ExitShip, () => Handler(EnterLeaveType.ExitShip));
|
2021-12-23 21:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void Handler(EnterLeaveType type, int objectId = -1)
|
|
|
|
{
|
2021-12-24 06:40:37 +00:00
|
|
|
if (PlayerTransformSync.LocalInstance)
|
2021-12-23 21:49:04 +00:00
|
|
|
{
|
|
|
|
new EnterLeaveMessage(type, objectId).Send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int ObjectId;
|
|
|
|
|
|
|
|
public EnterLeaveMessage(EnterLeaveType type, int objectId = -1)
|
|
|
|
{
|
|
|
|
Value = type;
|
|
|
|
ObjectId = objectId;
|
|
|
|
}
|
|
|
|
|
2022-01-14 07:38:45 +00:00
|
|
|
public override void Serialize(NetworkWriter writer)
|
2021-12-23 21:49:04 +00:00
|
|
|
{
|
|
|
|
base.Serialize(writer);
|
|
|
|
writer.Write(ObjectId);
|
|
|
|
}
|
|
|
|
|
2022-01-14 07:38:45 +00:00
|
|
|
public override void Deserialize(NetworkReader reader)
|
2021-12-23 21:49:04 +00:00
|
|
|
{
|
|
|
|
base.Deserialize(reader);
|
2022-01-14 07:38:45 +00:00
|
|
|
ObjectId = reader.Read<int>();
|
2021-12-23 21:49:04 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 08:27:32 +00:00
|
|
|
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
|
2021-12-23 21:49:04 +00:00
|
|
|
|
|
|
|
public override void OnReceiveLocal() => OnReceiveRemote();
|
|
|
|
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
{
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
|
|
switch (Value)
|
|
|
|
{
|
|
|
|
case EnterLeaveType.EnterMoon:
|
|
|
|
player.IsInMoon = true;
|
|
|
|
break;
|
|
|
|
case EnterLeaveType.ExitMoon:
|
|
|
|
player.IsInMoon = false;
|
|
|
|
break;
|
|
|
|
case EnterLeaveType.EnterPlatform:
|
|
|
|
CustomNomaiRemoteCameraPlatform.CustomPlatformList[ObjectId]
|
|
|
|
.OnRemotePlayerEnter(From);
|
|
|
|
break;
|
|
|
|
case EnterLeaveType.ExitPlatform:
|
|
|
|
CustomNomaiRemoteCameraPlatform.CustomPlatformList[ObjectId]
|
|
|
|
.OnRemotePlayerExit(From);
|
|
|
|
break;
|
|
|
|
case EnterLeaveType.EnterShip:
|
|
|
|
ShipManager.Instance.AddPlayerToShip(player);
|
|
|
|
break;
|
|
|
|
case EnterLeaveType.ExitShip:
|
|
|
|
ShipManager.Instance.RemovePlayerFromShip(player);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DebugLog.ToConsole($"Warning - Unknown EnterLeaveType : {Value}", MessageType.Warning);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|