2020-11-04 09:34:01 +00:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.EventsCore;
|
|
|
|
|
using QSB.Utility;
|
2020-11-04 09:09:50 +00:00
|
|
|
|
|
|
|
|
|
namespace QSB.Player.Events
|
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class ServerSendPlayerStatesEvent : QSBEvent<PlayerStateMessage>
|
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.PlayerState;
|
2020-11-04 09:09:50 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBServerSendPlayerStates, Handler);
|
|
|
|
|
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBServerSendPlayerStates, Handler);
|
2020-11-04 09:09:50 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private void Handler()
|
|
|
|
|
{
|
|
|
|
|
foreach (var player in QSBPlayerManager.PlayerList)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($" - Sending playerstate of player ID {player.PlayerId}", MessageType.Info);
|
|
|
|
|
SendEvent(CreateMessage(player));
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-04 09:09:50 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private PlayerStateMessage CreateMessage(PlayerInfo player) => new PlayerStateMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = player.PlayerId,
|
|
|
|
|
PlayerName = player.Name,
|
|
|
|
|
PlayerReady = player.IsReady,
|
|
|
|
|
PlayerState = player.State
|
|
|
|
|
};
|
2020-11-04 09:09:50 +00:00
|
|
|
|
|
2020-12-11 22:42:21 +00:00
|
|
|
|
public override void OnReceiveRemote(bool server, PlayerStateMessage message)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"Received playerstate of player ID {message.AboutId}", MessageType.Info);
|
|
|
|
|
QSB.Helper.Events.Unity.RunWhen(
|
|
|
|
|
() => QSBPlayerManager.GetSyncObject<TransformSync.TransformSync>(message.AboutId) != null,
|
|
|
|
|
() => QSBPlayerManager.HandleFullStateMessage(message));
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|