From c862ac79df5eff39181528ab895a3a88e3e89c26 Mon Sep 17 00:00:00 2001 From: AmazingAlek Date: Sat, 29 Feb 2020 14:02:09 +0100 Subject: [PATCH] allowing nova to kill players (#39) --- QSB.sln.DotSettings | 2 + QSB/QSB.cs | 1 + QSB/QSB.csproj | 2 +- QSB/{ => TimeSync}/RespawnOnDeath.cs | 67 ++++++++++++++++------------ 4 files changed, 42 insertions(+), 30 deletions(-) rename QSB/{ => TimeSync}/RespawnOnDeath.cs (67%) diff --git a/QSB.sln.DotSettings b/QSB.sln.DotSettings index f6f68c56..0022b6c2 100644 --- a/QSB.sln.DotSettings +++ b/QSB.sln.DotSettings @@ -1,4 +1,6 @@  HUD QSB + True + True True \ No newline at end of file diff --git a/QSB/QSB.cs b/QSB/QSB.cs index 81a0e58c..55c26ff7 100644 --- a/QSB/QSB.cs +++ b/QSB/QSB.cs @@ -1,5 +1,6 @@ using OWML.Common; using OWML.ModHelper; +using QSB.TimeSync; using UnityEngine; using UnityEngine.Networking; diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index d18317b4..2d258ec0 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -104,7 +104,7 @@ - + diff --git a/QSB/RespawnOnDeath.cs b/QSB/TimeSync/RespawnOnDeath.cs similarity index 67% rename from QSB/RespawnOnDeath.cs rename to QSB/TimeSync/RespawnOnDeath.cs index 5e452057..40f81317 100644 --- a/QSB/RespawnOnDeath.cs +++ b/QSB/TimeSync/RespawnOnDeath.cs @@ -1,42 +1,42 @@ -using OWML.ModHelper.Events; -using System.Linq; +using System.Linq; +using OWML.ModHelper.Events; using UnityEngine; -namespace QSB +namespace QSB.TimeSync { - class RespawnOnDeath : MonoBehaviour + public class RespawnOnDeath : MonoBehaviour { - static RespawnOnDeath Instance; + private static RespawnOnDeath _instance; - SpawnPoint _shipSpawnPoint; - SpawnPoint _playerSpawnPoint; - OWRigidbody _shipBody; - PlayerSpawner _playerSpawner; - FluidDetector _fluidDetector; - PlayerResources _playerResources; - ShipComponent[] _shipComponents; - HatchController _hatchController; - ShipCockpitController _cockpitController; - PlayerSpacesuit _spaceSuit; + private SpawnPoint _shipSpawnPoint; + private SpawnPoint _playerSpawnPoint; + private OWRigidbody _shipBody; + private PlayerSpawner _playerSpawner; + private FluidDetector _fluidDetector; + private PlayerResources _playerResources; + private ShipComponent[] _shipComponents; + private HatchController _hatchController; + private ShipCockpitController _cockpitController; + private PlayerSpacesuit _spaceSuit; - void Awake() + private void Awake() { GlobalMessenger.AddListener("WakeUp", PlayerWokeUp); - Instance = this; + _instance = this; QSB.Helper.HarmonyHelper.AddPrefix("KillPlayer", typeof(Patches), nameof(Patches.PreFinishDeathSequence)); } - void PlayerWokeUp() + private void PlayerWokeUp() { var playerTransform = Locator.GetPlayerTransform(); - _playerResources = Locator.GetPlayerTransform().GetComponent(); - _spaceSuit = Locator.GetPlayerTransform().GetComponentInChildren(true); + _playerResources = playerTransform.GetComponent(); + _spaceSuit = playerTransform.GetComponentInChildren(true); _playerSpawner = FindObjectOfType(); _fluidDetector = Locator.GetPlayerCamera().GetComponentInChildren(); var shipTransform = Locator.GetShipTransform(); - if (shipTransform) + if (shipTransform != null) { _shipComponents = shipTransform.GetComponentsInChildren(); _hatchController = shipTransform.GetComponentInChildren(); @@ -54,7 +54,7 @@ namespace QSB public void ResetShip() { - if (!_shipBody) + if (_shipBody == null) { return; } @@ -66,16 +66,16 @@ namespace QSB // Reset ship damage. if (Locator.GetShipTransform()) { - for (int i = 0; i < _shipComponents.Length; i++) + foreach (var shipComponent in _shipComponents) { - _shipComponents[i].SetDamaged(false); + shipComponent.SetDamaged(false); } } Invoke(nameof(ExitShip), 0.01f); } - void ExitShip() + private void ExitShip() { _cockpitController.Invoke("ExitFlightConsole"); _cockpitController.Invoke("CompleteExitFlightConsole"); @@ -104,7 +104,7 @@ namespace QSB _spaceSuit.RemoveSuit(true); } - SpawnPoint GetSpawnPoint(bool isShip = false) + private SpawnPoint GetSpawnPoint(bool isShip = false) { return _playerSpawner .GetValue("_spawnList") @@ -115,10 +115,19 @@ namespace QSB internal static class Patches { - public static bool PreFinishDeathSequence() + public static bool PreFinishDeathSequence(DeathType deathType) { - Instance.ResetShip(); - Instance.ResetPlayer(); + DebugLog.Screen("Death by " + deathType); + QSB.Helper.Console.WriteLine("Death by " + deathType); + + if (deathType == DeathType.Supernova) + { + // Allow real death + return true; + } + + _instance.ResetShip(); + _instance.ResetPlayer(); // Prevent original death method from running. return false;