random fixes (#200)

* usings
* fixed wakeup teleport
* marker bug
* reset ship thing
* cache
* config order
* playerid
* nre sector

Co-authored-by: Mister_Nebula <41904486+misternebula@users.noreply.github.com>
This commit is contained in:
AmazingAlek 2020-08-23 21:01:09 +02:00 committed by GitHub
parent 8c3f0d3b1f
commit 321c7db7f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 34 additions and 58 deletions

View File

@ -1,6 +1,8 @@
using OWML.ModHelper.Events;
using QSB.Events;
using System.Linq;
using OWML.Common;
using QSB.Utility;
using UnityEngine;
namespace QSB.DeathSync
@ -28,7 +30,6 @@ namespace QSB.DeathSync
private HatchController _hatchController;
private ShipCockpitController _cockpitController;
private PlayerSpacesuit _spaceSuit;
private bool _isSetUp;
private void Awake()
{
@ -48,11 +49,6 @@ namespace QSB.DeathSync
public void Init()
{
if (_isSetUp)
{
return;
}
_isSetUp = true;
var playerTransform = Locator.GetPlayerTransform();
_playerResources = playerTransform.GetComponent<PlayerResources>();
_spaceSuit = playerTransform.GetComponentInChildren<PlayerSpacesuit>(true);
@ -84,6 +80,11 @@ namespace QSB.DeathSync
}
// Reset ship position.
if (_shipSpawnPoint == null)
{
DebugLog.ToConsole("_shipSpawnPoint is null!", MessageType.Warning);
return;
}
_shipBody.SetVelocity(_shipSpawnPoint.GetPointVelocity());
_shipBody.WarpToPositionRotation(_shipSpawnPoint.transform.position, _shipSpawnPoint.transform.rotation);
@ -132,9 +133,7 @@ namespace QSB.DeathSync
{
return _playerSpawner
.GetValue<SpawnPoint[]>("_spawnList")
.FirstOrDefault(spawnPoint =>
spawnPoint.GetSpawnLocation() == SpawnLocation.TimberHearth && spawnPoint.IsShipSpawn() == isShip
);
.FirstOrDefault(spawnPoint => spawnPoint.GetSpawnLocation() == SpawnLocation.TimberHearth && spawnPoint.IsShipSpawn() == isShip);
}
}
}

View File

@ -1,6 +1,5 @@
using QSB.Messaging;
using QSB.TransformSync;
using QSB.Utility;
using UnityEngine.Networking;
namespace QSB.Events

View File

@ -1,6 +1,5 @@
using QSB.Events;
using QSB.Messaging;
using QSB.Utility;
using QSB.WorldSync;
namespace QSB.GeyserSync

View File

@ -29,11 +29,11 @@ namespace QSB.GeyserSync
{
if (state)
{
_geyserController.ActivateGeyser();
_geyserController?.ActivateGeyser();
}
else
{
_geyserController.DeactivateGeyser();
_geyserController?.DeactivateGeyser();
}
}
}

View File

@ -2,7 +2,6 @@
using QSB.Tools;
using QSB.TransformSync;
using QSB.Utility;
using System;
using System.Linq;
using UnityEngine;

View File

@ -2,10 +2,9 @@
using QSB.Messaging;
using QSB.TransformSync;
using QSB.Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using UnityEngine.Networking;
namespace QSB
{
@ -13,7 +12,7 @@ namespace QSB
{
public const int NetworkObjectCount = 4;
public static uint LocalPlayerId => PlayerTransformSync.LocalInstance.netId.Value;
public static uint LocalPlayerId => PlayerTransformSync.LocalInstance.GetComponent<NetworkIdentity>()?.netId.Value ?? 0;
public static PlayerInfo LocalPlayer => GetPlayer(LocalPlayerId);
public static List<PlayerInfo> PlayerList { get; } = new List<PlayerInfo>();

View File

@ -1,34 +1,13 @@
using OWML.Common;
using QSB.Utility;
using System;
using UnityEngine.Networking;
using UnityEngine.Networking;
namespace QSB
{
public abstract class PlayerSyncObject : NetworkBehaviour
{
protected abstract uint PlayerIdOffset { get; }
public uint NetId => netId.Value;
public uint NetId => GetComponent<NetworkIdentity>()?.netId.Value ?? 0;
public bool IsLocal => hasAuthority;
public uint PlayerId => GetPlayerId();
public uint PlayerId => NetId - PlayerIdOffset;
public PlayerInfo Player => PlayerRegistry.GetPlayer(PlayerId);
private uint GetPlayerId()
{
try
{
return NetId - PlayerIdOffset;
}
catch
{
DebugLog.ToConsole($"Error while getting netId of {GetType().Name}! " +
$"{Environment.NewLine} - Did you destroy the TransformSync without destroying the {GetType().Name}?" +
$"{Environment.NewLine} - Did a destroyed TransformSync/{GetType().Name} still have an active action/event listener?" +
$"{Environment.NewLine} If you are a user seeing this, please report this error.", MessageType.Error);
return uint.MaxValue;
}
}
}
}

View File

@ -150,7 +150,16 @@ namespace QSB
private void CleanupConnection(NetworkConnection connection)
{
var playerId = connection.playerControllers[0].gameObject.GetComponent<PlayerTransformSync>().netId.Value;
uint playerId;
try
{
playerId = connection.playerControllers[0].gameObject.GetComponent<PlayerTransformSync>().netId.Value;
}
catch (Exception ex)
{
DebugLog.ToConsole("Error when getting playerId in CleanupConnection: " + ex.Message, MessageType.Error);
return;
}
if (!PlayerRegistry.PlayerExists(playerId))
{
return;
@ -161,7 +170,7 @@ namespace QSB
if (playerId != PlayerRegistry.LocalPlayerId) // We don't want to delete the local player!
{
var netIds = connection.clientOwnedObjects.Select(x => x.Value).ToList();
var netIds = connection.clientOwnedObjects?.Select(x => x.Value).ToList();
netIds.ForEach(CleanupNetworkBehaviour);
}
}

View File

@ -1,7 +1,4 @@
using OWML.Common;
using QSB.Utility;
using System;
using UnityEngine;
using UnityEngine;
namespace QSB.TransformSync
{
@ -50,17 +47,13 @@ namespace QSB.TransformSync
public void Remove()
{
// do N O T destroy the parent - it completely breaks the ENTIRE GAME
try
if (_canvasMarker?.gameObject != null)
{
_canvasMarker.DestroyMarker();
Destroy(_markerTarget.gameObject);
Destroy(this);
}
catch (Exception ex)
{
DebugLog.ToConsole($"Warning - Failed to remove PlayerHUDMarker for {_player.Name} ({_player.NetId}) : {ex}", MessageType.Warning);
}
Destroy(_markerTarget.gameObject);
Destroy(this);
}
}
}

View File

@ -51,7 +51,7 @@ namespace QSB.TransformSync
protected override void UpdateTransform()
{
base.UpdateTransform();
if (Player.GetState(State.ProbeActive))
if (Player.GetState(State.ProbeActive) || ReferenceSector.Sector == null)
{
return;
}

View File

@ -2,7 +2,7 @@
"enabled": true,
"settings": {
"defaultServerIP": "localhost",
"debugMode": true,
"port": 7777
"port": 7777,
"debugMode": false
}
}