2020-07-30 20:27:14 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
using System.Linq;
|
2020-07-30 20:27:14 +00:00
|
|
|
|
using QSB.Events;
|
2020-07-30 19:57:39 +00:00
|
|
|
|
using QSB.TransformSync;
|
2020-08-07 19:57:29 +00:00
|
|
|
|
using QSB.Animation;
|
2020-08-07 23:08:44 +00:00
|
|
|
|
using QSB.Utility;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
|
|
|
|
|
namespace QSB
|
|
|
|
|
{
|
|
|
|
|
public static class PlayerRegistry
|
|
|
|
|
{
|
2020-07-30 19:57:39 +00:00
|
|
|
|
public static PlayerInfo LocalPlayer => GetPlayer(PlayerTransformSync.LocalInstance.netId.Value);
|
|
|
|
|
public static List<PlayerInfo> PlayerList { get; } = new List<PlayerInfo>();
|
2020-08-05 19:59:50 +00:00
|
|
|
|
|
2020-08-07 19:57:29 +00:00
|
|
|
|
public static List<TransformSync.TransformSync> TransformSyncs { get; } = new List<TransformSync.TransformSync>();
|
2020-08-05 19:59:50 +00:00
|
|
|
|
public static List<TransformSync.TransformSync> LocalTransformSyncs => TransformSyncs.Where(t => t.hasAuthority).ToList();
|
2020-08-07 19:57:29 +00:00
|
|
|
|
|
|
|
|
|
public static List<AnimationSync> AnimationSyncs { get; } = new List<AnimationSync>();
|
|
|
|
|
|
2020-07-30 19:57:39 +00:00
|
|
|
|
public static PlayerInfo CreatePlayer(uint id)
|
2020-07-27 23:13:43 +00:00
|
|
|
|
{
|
2020-08-07 23:08:44 +00:00
|
|
|
|
DebugLog.ToConsole($"Creating player {id}");
|
2020-07-28 13:59:24 +00:00
|
|
|
|
if (PlayerExists(id))
|
2020-07-27 23:13:43 +00:00
|
|
|
|
{
|
2020-07-30 19:57:39 +00:00
|
|
|
|
return null;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
}
|
2020-07-30 19:57:39 +00:00
|
|
|
|
var player = new PlayerInfo(id);
|
2020-07-28 13:59:24 +00:00
|
|
|
|
PlayerList.Add(player);
|
2020-07-30 19:57:39 +00:00
|
|
|
|
return player;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 19:57:39 +00:00
|
|
|
|
public static PlayerInfo GetPlayer(uint id)
|
2020-07-27 23:13:43 +00:00
|
|
|
|
{
|
2020-07-30 19:57:39 +00:00
|
|
|
|
return PlayerList.FirstOrDefault(x => x.NetId == id);
|
2020-07-29 21:04:50 +00:00
|
|
|
|
}
|
2020-08-05 19:45:48 +00:00
|
|
|
|
|
2020-07-29 21:04:50 +00:00
|
|
|
|
public static bool PlayerExists(uint id)
|
|
|
|
|
{
|
2020-07-30 19:57:39 +00:00
|
|
|
|
return GetPlayer(id) != null;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RemovePlayer(uint id)
|
|
|
|
|
{
|
2020-07-30 19:57:39 +00:00
|
|
|
|
PlayerList.Remove(GetPlayer(id));
|
2020-07-29 21:04:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 23:13:43 +00:00
|
|
|
|
public static void HandleFullStateMessage(FullStateMessage message)
|
|
|
|
|
{
|
2020-07-30 19:57:39 +00:00
|
|
|
|
var player = GetPlayer(message.SenderId) ?? CreatePlayer(message.SenderId);
|
2020-08-07 23:08:44 +00:00
|
|
|
|
DebugLog.ToConsole($"Player Id {message.SenderId} ----------------", OWML.Common.MessageType.Info);
|
2020-07-30 19:57:39 +00:00
|
|
|
|
player.Name = message.PlayerName;
|
2020-08-07 23:08:44 +00:00
|
|
|
|
DebugLog.ToConsole($"Name : {player.Name}", OWML.Common.MessageType.Info);
|
|
|
|
|
player.IsReady = message.IsReady;
|
|
|
|
|
DebugLog.ToConsole($"IsReady : {player.IsReady}", OWML.Common.MessageType.Info);
|
2020-07-27 23:13:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 19:45:48 +00:00
|
|
|
|
public static TransformSync.TransformSync GetTransformSync(uint id)
|
|
|
|
|
{
|
|
|
|
|
return TransformSyncs.Single(x => x.netId.Value == id);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-07 19:57:29 +00:00
|
|
|
|
public static AnimationSync GetAnimationSync(uint id)
|
|
|
|
|
{
|
|
|
|
|
return AnimationSyncs.SingleOrDefault(x => x.netId.Value == id);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 23:13:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|