diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index 571cd1c4..bfdd7a6d 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -4,6 +4,7 @@ using QSB.Animation.Player.Thrusters; using QSB.Audio; using QSB.CampfireSync.WorldObjects; using QSB.ClientServerStateSync; +using QSB.Instruments; using QSB.ItemSync.WorldObjects.Items; using QSB.Messaging; using QSB.Player.Messages; @@ -25,7 +26,9 @@ namespace QSB.Player public uint PlayerId { get; } public string Name { get; set; } public PlayerHUDMarker HudMarker { get; set; } - public PlayerTransformSync TransformSync { get; set; } + public PlayerTransformSync TransformSync { get; } + public AnimationSync AnimationSync { get; } + public InstrumentsManager InstrumentsManager { get; } public ClientState State { get; set; } public EyeState EyeState { get; set; } public bool IsDead { get; set; } @@ -114,11 +117,10 @@ namespace QSB.Player public bool ProbeActive { get; set; } // Conversation - public int CurrentCharacterDialogueTreeId { get; set; } + public int CurrentCharacterDialogueTreeId { get; set; } = -1; public GameObject CurrentDialogueBox { get; set; } // Animation - public AnimationSync AnimationSync => QSBPlayerManager.GetSyncObject(PlayerId); public bool PlayingInstrument => AnimationSync.CurrentType is not AnimationType.PlayerSuited and not AnimationType.PlayerUnsuited; @@ -181,10 +183,12 @@ namespace QSB.Player } } - public PlayerInfo(uint id) + public PlayerInfo(PlayerTransformSync transformSync) { - PlayerId = id; - CurrentCharacterDialogueTreeId = -1; + PlayerId = transformSync.NetId.Value; + TransformSync = transformSync; + AnimationSync = transformSync.GetComponent(); + InstrumentsManager = transformSync.GetComponent(); } public void UpdateObjectsFromStates() diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index d27ccbdb..6a991ec4 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -53,20 +53,6 @@ namespace QSB.Player return player; } - public static void AddPlayer(uint id) - { - DebugLog.DebugWrite($"Create Player : id<{id}>", MessageType.Info); - var player = new PlayerInfo(id); - PlayerList.Add(player); - OnAddPlayer?.Invoke(id); - } - - public static void RemovePlayer(uint id) - { - DebugLog.DebugWrite($"Remove Player : id<{id}>", MessageType.Info); - PlayerList.RemoveAll(x => x.PlayerId == id); - } - public static bool PlayerExists(uint id) => id is not (uint.MaxValue or 0) && PlayerList.Any(x => x.PlayerId == id); diff --git a/QSB/Player/TransformSync/PlayerTransformSync.cs b/QSB/Player/TransformSync/PlayerTransformSync.cs index ce7b0389..2893e4f5 100644 --- a/QSB/Player/TransformSync/PlayerTransformSync.cs +++ b/QSB/Player/TransformSync/PlayerTransformSync.cs @@ -1,4 +1,5 @@ -using QSB.Animation.Player; +using OWML.Common; +using QSB.Animation.Player; using QSB.Audio; using QSB.Instruments; using QSB.Messaging; @@ -48,9 +49,11 @@ namespace QSB.Player.TransformSync public override void Start() { + var player = new PlayerInfo(this); + QSBPlayerManager.PlayerList.Add(player); base.Start(); - QSBPlayerManager.AddPlayer(PlayerId); - Player.TransformSync = this; + QSBPlayerManager.OnAddPlayer?.Invoke(PlayerId); + DebugLog.DebugWrite($"Create Player : id<{PlayerId}>", MessageType.Info); } protected override void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isInUniverse) @@ -88,11 +91,9 @@ namespace QSB.Player.TransformSync // TODO : Maybe move this to a leave event...? Would ensure everything could finish up before removing the player QSBPlayerManager.OnRemovePlayer?.Invoke(PlayerId); base.OnDestroy(); - if (QSBPlayerManager.PlayerExists(PlayerId)) - { - Player.HudMarker?.Remove(); - QSBPlayerManager.RemovePlayer(PlayerId); - } + Player.HudMarker?.Remove(); + QSBPlayerManager.PlayerList.RemoveAll(x => x.PlayerId == PlayerId); + DebugLog.DebugWrite($"Remove Player : id<{PlayerId}>", MessageType.Info); } protected override Transform InitLocalTransform()