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

39 lines
1.3 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
{
2020-08-10 16:17:54 +00:00
public class PlayerSectorEvent : QSBEvent<SectorMessage>
2020-08-09 11:38:35 +00:00
{
public override MessageType Type => MessageType.PlayerSectorChange;
public override void SetupListener()
{
2020-08-10 16:17:54 +00:00
GlobalMessenger<uint, int, string>.AddListener("QSBSectorChange", (netId, id, name) => SendEvent(CreateMessage(netId, id, name)));
2020-08-09 11:38:35 +00:00
}
2020-08-10 16:17:54 +00:00
private SectorMessage CreateMessage(uint netId, int id, string name) => new SectorMessage
{
SenderId = netId,
SectorId = id,
SectorName = name
};
2020-08-10 13:40:06 +00:00
public override void OnReceiveRemote(SectorMessage message)
2020-08-09 11:38:35 +00:00
{
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
}
}
}