2020-07-30 22:27:14 +02:00
|
|
|
|
using System.Collections.Generic;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
using System.Linq;
|
2020-07-30 21:57:39 +02:00
|
|
|
|
using QSB.TransformSync;
|
2020-08-07 21:57:29 +02:00
|
|
|
|
using QSB.Animation;
|
2020-08-09 12:40:35 +01:00
|
|
|
|
using QSB.Messaging;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
|
|
|
|
namespace QSB
|
|
|
|
|
{
|
|
|
|
|
public static class PlayerRegistry
|
|
|
|
|
{
|
2020-08-14 20:54:15 +02:00
|
|
|
|
public static uint LocalPlayerId => PlayerTransformSync.LocalInstance.netId.Value;
|
|
|
|
|
public static PlayerInfo LocalPlayer => GetPlayer(LocalPlayerId);
|
2020-07-30 21:57:39 +02:00
|
|
|
|
public static List<PlayerInfo> PlayerList { get; } = new List<PlayerInfo>();
|
2020-08-05 21:59:50 +02:00
|
|
|
|
|
2020-08-07 21:57:29 +02:00
|
|
|
|
public static List<TransformSync.TransformSync> TransformSyncs { get; } = new List<TransformSync.TransformSync>();
|
2020-08-08 18:03:59 +02:00
|
|
|
|
public static List<TransformSync.TransformSync> LocalTransformSyncs => TransformSyncs.Where(t => t != null && t.hasAuthority).ToList();
|
2020-08-07 21:57:29 +02:00
|
|
|
|
public static List<AnimationSync> AnimationSyncs { get; } = new List<AnimationSync>();
|
|
|
|
|
|
2020-08-17 18:58:45 +02:00
|
|
|
|
public static PlayerInfo GetPlayer(uint id)
|
2020-07-28 00:13:43 +01:00
|
|
|
|
{
|
2020-08-17 18:58:45 +02:00
|
|
|
|
var player = PlayerList.FirstOrDefault(x => x.NetId == id);
|
|
|
|
|
if (player != null)
|
2020-07-28 00:13:43 +01:00
|
|
|
|
{
|
2020-08-17 18:58:45 +02:00
|
|
|
|
return player;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
}
|
2020-08-17 18:58:45 +02:00
|
|
|
|
player = new PlayerInfo(id);
|
2020-07-28 15:59:24 +02:00
|
|
|
|
PlayerList.Add(player);
|
2020-07-30 21:57:39 +02:00
|
|
|
|
return player;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RemovePlayer(uint id)
|
|
|
|
|
{
|
2020-07-30 21:57:39 +02:00
|
|
|
|
PlayerList.Remove(GetPlayer(id));
|
2020-07-29 22:04:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 21:46:51 +01:00
|
|
|
|
public static void HandleFullStateMessage(PlayerStateMessage message)
|
2020-07-28 00:13:43 +01:00
|
|
|
|
{
|
2020-08-17 18:58:45 +02:00
|
|
|
|
var player = GetPlayer(message.SenderId);
|
2020-07-30 21:57:39 +02:00
|
|
|
|
player.Name = message.PlayerName;
|
2020-08-10 11:45:24 +01:00
|
|
|
|
player.IsReady = message.PlayerReady;
|
|
|
|
|
player.State = message.PlayerState;
|
2020-08-10 12:12:51 +01:00
|
|
|
|
|
2020-08-13 19:25:12 +02:00
|
|
|
|
if (LocalPlayer.IsReady)
|
2020-08-09 21:46:51 +01:00
|
|
|
|
{
|
2020-08-10 11:45:24 +01:00
|
|
|
|
player.UpdateStateObjects();
|
|
|
|
|
}
|
2020-07-28 00:13:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 21:45:48 +02:00
|
|
|
|
public static TransformSync.TransformSync GetTransformSync(uint id)
|
|
|
|
|
{
|
2020-08-14 19:30:23 +02:00
|
|
|
|
return TransformSyncs.FirstOrDefault(x => x != null && x.netId.Value == id);
|
2020-08-05 21:45:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-14 20:54:15 +02:00
|
|
|
|
public static bool IsBelongingToLocalPlayer(uint id)
|
|
|
|
|
{
|
|
|
|
|
return id == LocalPlayerId || GetTransformSync(id).PlayerId == LocalPlayerId;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-07 21:57:29 +02:00
|
|
|
|
public static AnimationSync GetAnimationSync(uint id)
|
|
|
|
|
{
|
2020-08-08 18:03:59 +02:00
|
|
|
|
return AnimationSyncs.FirstOrDefault(x => x != null && x.netId.Value == id);
|
2020-08-07 21:57:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 00:13:43 +01:00
|
|
|
|
}
|
|
|
|
|
}
|