mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-12 22:14:37 +00:00
cleanup + fixes
This commit is contained in:
parent
81f4b13739
commit
0cfa74ef70
@ -33,8 +33,6 @@ namespace QSB
|
||||
DebugLog.DebugWrite($"Creating player id {id}", MessageType.Info);
|
||||
player = new PlayerInfo(id);
|
||||
PlayerList.Add(player);
|
||||
DebugLog.DebugWrite("PlayerList now contains :");
|
||||
PlayerList.ForEach(x => DebugLog.DebugWrite($"* {x.PlayerId}, {x.Name}"));
|
||||
return player;
|
||||
}
|
||||
|
||||
@ -83,8 +81,9 @@ namespace QSB
|
||||
return behaviours.Where(x => x.netId == id).First().isLocalPlayer;
|
||||
}
|
||||
|
||||
public static NetworkInstanceId GetPlayerOfObject(this NetworkBehaviour behaviour)
|
||||
public static NetworkInstanceId GetPlayerOfObject(this PlayerSyncObject syncObject)
|
||||
{
|
||||
var behaviour = (NetworkBehaviour)syncObject;
|
||||
// Function to get a player id from any netid, for example input of 7 and players 1 and 5
|
||||
|
||||
// Get all players (eg 1, 5)
|
||||
@ -97,13 +96,18 @@ namespace QSB
|
||||
// don't want to send the wrong player. The problem with this is that the objects for the previous player will also stop working (as it will see a mismatch)
|
||||
if (PlayerList.Count != PlayerSyncObjects.Count(x => x.GetType() == behaviour.GetType()) && lowerBound.Value == playerIds.Select(n => n.Value).ToList().Max())
|
||||
{
|
||||
DebugLog.ToConsole($"Warning - Player ({PlayerList.Count}) and syncobject ({PlayerSyncObjects.Count(x => x.GetType() == behaviour.GetType())}) count differ.", MessageType.Warning);
|
||||
if (behaviour.GetType() == typeof(PlayerTransformSync))
|
||||
if (syncObject.PreviousPlayerId != NetworkInstanceId.Invalid)
|
||||
{
|
||||
return syncObject.PreviousPlayerId;
|
||||
}
|
||||
if (behaviour.GetType() == typeof(PlayerTransformSync) && behaviour.netId.Value != 0U)
|
||||
{
|
||||
return GetPlayer(behaviour.netId).PlayerId;
|
||||
}
|
||||
syncObject.PreviousPlayerId = NetworkInstanceId.Invalid;
|
||||
return NetworkInstanceId.Invalid;
|
||||
}
|
||||
syncObject.PreviousPlayerId = lowerBound;
|
||||
return lowerBound;
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,8 @@ namespace QSB
|
||||
public abstract class PlayerSyncObject : NetworkBehaviour
|
||||
{
|
||||
public NetworkInstanceId NetId => GetComponent<NetworkIdentity>()?.netId ?? NetworkInstanceId.Invalid;
|
||||
public bool IsLocal => hasAuthority;
|
||||
[Obsolete("Use Player.PlayerId instead")]
|
||||
public NetworkInstanceId PlayerId => this.GetPlayerOfObject();
|
||||
public NetworkInstanceId PreviousPlayerId { get; set; }
|
||||
public PlayerInfo Player => PlayerRegistry.GetPlayer(PlayerId);
|
||||
}
|
||||
}
|
||||
|
@ -160,8 +160,8 @@ namespace QSB
|
||||
foreach (var player in PlayerRegistry.PlayerList)
|
||||
{
|
||||
PlayerRegistry.GetPlayerNetIds(player).ForEach(CleanupNetworkBehaviour);
|
||||
PlayerRegistry.RemovePlayer(player.PlayerId);
|
||||
}
|
||||
PlayerRegistry.PlayerList.ForEach(x => PlayerRegistry.PlayerList.Remove(x));
|
||||
|
||||
_lobby.CanEditName = true;
|
||||
}
|
||||
@ -216,7 +216,7 @@ namespace QSB
|
||||
|
||||
public void CleanupNetworkBehaviour(NetworkInstanceId netId)
|
||||
{
|
||||
DebugLog.DebugWrite($"Cleaning up object {netId.Value}");
|
||||
DebugLog.DebugWrite($"Cleaning up netId {netId}");
|
||||
// Multiple networkbehaviours can use the same networkidentity (same netId), so get all of them
|
||||
var networkBehaviours = FindObjectsOfType<NetworkBehaviour>()
|
||||
.Where(x => x != null && x.netId == netId);
|
||||
@ -227,12 +227,16 @@ namespace QSB
|
||||
if (transformSync != null)
|
||||
{
|
||||
PlayerRegistry.PlayerSyncObjects.Remove(transformSync);
|
||||
if (transformSync.SyncedTransform != null && netId != PlayerRegistry.LocalPlayerId)
|
||||
if (transformSync.SyncedTransform != null && netId != PlayerRegistry.LocalPlayerId && !networkBehaviour.hasAuthority)
|
||||
{
|
||||
Destroy(transformSync.SyncedTransform.gameObject);
|
||||
}
|
||||
}
|
||||
Destroy(networkBehaviour.gameObject);
|
||||
|
||||
if (!networkBehaviour.hasAuthority)
|
||||
{
|
||||
Destroy(networkBehaviour.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ namespace QSB.TransformSync
|
||||
{
|
||||
return;
|
||||
}
|
||||
PlayerRegistry.GetSyncObjects<TransformSync>().Where(x => x.IsLocal).ToList().ForEach(CheckTransformSyncSector);
|
||||
PlayerRegistry.GetSyncObjects<TransformSync>().Where(x => x.hasAuthority).ToList().ForEach(CheckTransformSyncSector);
|
||||
_checkTimer = 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user