From f66e89e8cc5f4bcf776ea8beeab7d37a40b8ffdd Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 7 Jan 2022 15:08:20 -0800 Subject: [PATCH] store player in syncbase --- QSB/Player/PlayerInfo.cs | 3 +++ QSB/Syncs/SyncBase.cs | 55 +++++++--------------------------------- 2 files changed, 12 insertions(+), 46 deletions(-) diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index bfdd7a6d..5f3437f5 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -23,6 +23,9 @@ namespace QSB.Player { public class PlayerInfo { + /// + /// the player transform sync's net id + /// public uint PlayerId { get; } public string Name { get; set; } public PlayerHUDMarker HudMarker { get; set; } diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index 8c74bfd0..315420f7 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -1,6 +1,5 @@ using OWML.Common; using QSB.Player; -using QSB.Player.TransformSync; using QSB.Utility; using QSB.WorldSync; using QuantumUNET.Components; @@ -17,48 +16,14 @@ namespace QSB.Syncs public abstract class SyncBase : QNetworkTransform where T : Component { - public uint AttachedNetId - { - get - { - if (NetIdentity == null) - { - DebugLog.ToConsole($"Error - Trying to get AttachedNetId with null NetIdentity! Type:{GetType().Name} GrandType:{GetType().GetType().Name}", MessageType.Error); - return uint.MaxValue; - } - - return NetIdentity.NetId.Value; - } - } - - public uint PlayerId - { - get - { - if (!IsPlayerObject) - { - return uint.MaxValue; - } - - if (NetIdentity == null) - { - DebugLog.ToConsole($"Error - Trying to get PlayerId with null NetIdentity! Type:{GetType().Name} GrandType:{GetType().GetType().Name}", MessageType.Error); - return uint.MaxValue; - } - - return NetIdentity.RootIdentity != null - ? NetIdentity.RootIdentity.NetId.Value - : AttachedNetId; - } - } - - public PlayerInfo Player => QSBPlayerManager.GetPlayer(PlayerId); + public PlayerInfo Player { get; private set; } + public uint PlayerId => Player.PlayerId; private bool _baseIsReady { get { - if (NetId.Value is uint.MaxValue or 0U) + if (NetId.Value is uint.MaxValue or 0) { return false; } @@ -70,11 +35,6 @@ namespace QSB.Syncs if (IsPlayerObject) { - if (!QSBPlayerManager.PlayerExists(PlayerId)) - { - return false; - } - if (Player == null) { return false; @@ -117,9 +77,12 @@ namespace QSB.Syncs { if (IsPlayerObject) { - var lowestBound = QSBWorldSync.GetUnityObjects() - .Where(x => x.NetId.Value <= NetId.Value).OrderBy(x => x.NetId.Value).Last(); - NetIdentity.SetRootIdentity(lowestBound.NetIdentity); + // get player objects spawned before this object (or is this one) + // and use the closest one + Player = QSBPlayerManager.PlayerList + .Where(x => x.PlayerId <= NetId.Value) + .OrderBy(x => x.PlayerId).Last(); + NetIdentity.SetRootIdentity(Player.TransformSync.NetIdentity); } DontDestroyOnLoad(gameObject);