quantum-space-buddies/QSB/Events/PlayerSectorEvent.cs
AmazingAlek 22b028ce26
Alek/overhaul thing (#153)
* probe.SetState
* sectormessage enum
2020-08-10 19:44:04 +02:00

39 lines
1.4 KiB
C#

using QSB.Messaging;
using QSB.TransformSync;
using QSB.Utility;
namespace QSB.Events
{
public class PlayerSectorEvent : QSBEvent<SectorMessage>
{
public override MessageType Type => MessageType.PlayerSectorChange;
public override void SetupListener()
{
GlobalMessenger<uint, Sector.Name, string>.AddListener(EventNames.QSBSectorChange, (netId, sectorId, sectorName) => SendEvent(CreateMessage(netId, sectorId, sectorName)));
}
private SectorMessage CreateMessage(uint netId, Sector.Name sectorId, string sectorName) => new SectorMessage
{
SenderId = netId,
SectorId = sectorId,
SectorName = sectorName
};
public override void OnReceiveRemote(SectorMessage message)
{
var sector = SectorSync.LocalInstance.FindSectorByName((Sector.Name)message.SectorId, message.SectorName);
if (sector == null)
{
DebugLog.ToScreen($"Sector {message.SectorName},{(Sector.Name)message.SectorId} not found!");
return;
}
var transformSync = PlayerRegistry.GetTransformSync(message.SenderId);
DebugLog.ToScreen($"{transformSync.GetType().Name} of ID {message.SenderId} set to {message.SectorName}");
transformSync.ReferenceTransform = sector.transform;
}
}
}