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

33 lines
1008 B
C#
Raw Normal View History

2020-08-09 09:17:00 +02:00
using QSB.Messaging;
using QSB.TransformSync;
2020-08-08 12:23:23 +01:00
using QSB.Utility;
namespace QSB.Events
{
class PlayerJoinEvent : QSBEvent
{
2020-08-09 09:17:00 +02:00
public override MessageType Type => MessageType.PlayerJoin;
2020-08-08 12:23:23 +01:00
public override void SetupListener()
{
2020-08-09 09:17:00 +02:00
GlobalMessenger<string>.AddListener("QSBPlayerJoin", var => SendEvent(PlayerTransformSync.LocalInstance.netId.Value, var));
2020-08-08 12:23:23 +01:00
}
public override void OnReceive(uint sender, object[] data)
{
var player = PlayerRegistry.CreatePlayer(sender);
player.Name = (string)data[0];
player.IsReady = true;
DebugLog.ToAll($"{player.Name} joined!");
}
public override void OnReceiveLocal(object[] data)
{
2020-08-08 13:27:49 +01:00
var player = PlayerRegistry.CreatePlayer(PlayerTransformSync.LocalInstance.netId.Value);
player.Name = (string)data[0];
player.IsReady = true;
DebugLog.ToAll($"{player.Name} joined!");
2020-08-08 12:23:23 +01:00
}
}
}