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-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-10 18:17:54 +02:00
|
|
|
|
public class PlayerSectorEvent : QSBEvent<SectorMessage>
|
2020-08-09 12:38:35 +01:00
|
|
|
|
{
|
|
|
|
|
public override MessageType Type => MessageType.PlayerSectorChange;
|
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-10 19:44:04 +02:00
|
|
|
|
GlobalMessenger<uint, Sector.Name, string>.AddListener(EventNames.QSBSectorChange, (netId, sectorId, sectorName) => SendEvent(CreateMessage(netId, sectorId, sectorName)));
|
2020-08-09 12:38:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 19:44:04 +02:00
|
|
|
|
private SectorMessage CreateMessage(uint netId, Sector.Name sectorId, string sectorName) => new SectorMessage
|
2020-08-10 18:17:54 +02:00
|
|
|
|
{
|
|
|
|
|
SenderId = netId,
|
2020-08-10 19:44:04 +02:00
|
|
|
|
SectorId = sectorId,
|
|
|
|
|
SectorName = sectorName
|
2020-08-10 18:17:54 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-08-10 14:40:06 +01:00
|
|
|
|
public override void OnReceiveRemote(SectorMessage message)
|
2020-08-09 12:38:35 +01:00
|
|
|
|
{
|
2020-08-10 20:14:19 +02:00
|
|
|
|
if (!IsInUniverse)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var sector = SectorSync.LocalInstance.FindSectorByName(message.SectorId, message.SectorName);
|
2020-08-09 13:54:05 +01:00
|
|
|
|
|
|
|
|
|
if (sector == null)
|
|
|
|
|
{
|
2020-08-10 20:14:19 +02:00
|
|
|
|
DebugLog.ToScreen($"Sector {message.SectorName}, {message.SectorId} not found!");
|
2020-08-09 13:54:05 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var transformSync = PlayerRegistry.GetTransformSync(message.SenderId);
|
|
|
|
|
DebugLog.ToScreen($"{transformSync.GetType().Name} of ID {message.SenderId} set to {message.SectorName}");
|
2020-08-14 21:04:29 +02:00
|
|
|
|
transformSync.SetReference(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
|
|
|
|
}
|
|
|
|
|
}
|