2020-08-13 21:46:16 +02:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
2020-08-09 13:54:05 +01:00
|
|
|
|
using QSB.Utility;
|
2020-08-16 17:15:36 +02:00
|
|
|
|
using QSB.WorldSync;
|
2020-08-09 12:38:35 +01:00
|
|
|
|
|
2020-08-13 21:46:16 +02:00
|
|
|
|
namespace QSB.TransformSync
|
2020-08-09 12:38:35 +01:00
|
|
|
|
{
|
2020-08-16 17:15:36 +02:00
|
|
|
|
public class PlayerSectorEvent : QSBEvent<WorldObjectMessage>
|
2020-08-09 12:38:35 +01:00
|
|
|
|
{
|
|
|
|
|
public override MessageType Type => MessageType.PlayerSectorChange;
|
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-16 17:15:36 +02:00
|
|
|
|
GlobalMessenger<uint, QSBSector>.AddListener(EventNames.QSBSectorChange, (netId, sector) => SendEvent(CreateMessage(netId, sector)));
|
2020-08-09 12:38:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-16 17:15:36 +02:00
|
|
|
|
private WorldObjectMessage CreateMessage(uint netId, QSBSector sector) => new WorldObjectMessage
|
2020-08-10 18:17:54 +02:00
|
|
|
|
{
|
|
|
|
|
SenderId = netId,
|
2020-08-16 17:15:36 +02:00
|
|
|
|
ObjectId = sector.ObjectId
|
2020-08-10 18:17:54 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-08-16 17:15:36 +02:00
|
|
|
|
public override void OnReceiveRemote(WorldObjectMessage message)
|
2020-08-09 12:38:35 +01:00
|
|
|
|
{
|
2020-08-10 20:14:19 +02:00
|
|
|
|
if (!IsInUniverse)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-16 17:15:36 +02:00
|
|
|
|
var sector = WorldRegistry.GetObject<QSBSector>(message.ObjectId);
|
2020-08-09 13:54:05 +01:00
|
|
|
|
|
|
|
|
|
if (sector == null)
|
|
|
|
|
{
|
2020-08-16 17:15:36 +02:00
|
|
|
|
DebugLog.ToScreen($"Sector with order id {message.ObjectId} not found!");
|
2020-08-09 13:54:05 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var transformSync = PlayerRegistry.GetTransformSync(message.SenderId);
|
2020-08-16 17:15:36 +02:00
|
|
|
|
DebugLog.ToScreen($"{transformSync.GetType().Name} of ID {message.SenderId} set to {sector.Name}");
|
2020-08-14 22:59:18 +02:00
|
|
|
|
UnityHelper.Instance.RunWhen(() => transformSync.SyncedTransform != null,
|
2020-08-14 23:00:56 +02:00
|
|
|
|
() => transformSync.SetReferenceSector(sector));
|
2020-08-09 12:38:35 +01:00
|
|
|
|
}
|
2020-08-13 17:44:27 +01:00
|
|
|
|
|
2020-08-09 12:38:35 +01:00
|
|
|
|
}
|
|
|
|
|
}
|