quantum-space-buddies/QSB/Events/PlayerSectorEvent.cs

37 lines
1.2 KiB
C#
Raw Normal View History

2020-08-09 11:38:35 +00:00
using QSB.Messaging;
2020-08-09 12:54:05 +00:00
using QSB.TransformSync;
using QSB.Utility;
2020-08-09 11:38:35 +00:00
namespace QSB.Events
{
class PlayerSectorEvent : QSBEvent<SectorMessage>
{
public override MessageType Type => MessageType.PlayerSectorChange;
public override void SetupListener()
{
2020-08-09 12:54:05 +00:00
GlobalMessenger<uint, int, string>.AddListener("QSBSectorChange", (netId, id, name) => SendEvent(
2020-08-09 12:48:55 +00:00
new SectorMessage {
SenderId = netId,
SectorId = id,
SectorName = name
}));
2020-08-09 11:38:35 +00:00
}
public override void OnReceive(SectorMessage message)
{
2020-08-09 12:54:05 +00:00
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;
2020-08-09 11:38:35 +00:00
}
}
}