This commit is contained in:
Mister_Nebula 2021-02-06 21:31:12 +00:00
parent edf4b22faf
commit 545cf27f8f
4 changed files with 53 additions and 47 deletions

View File

@ -1,5 +1,6 @@
using QSB.Events;
using QSB.Patches;
using QSB.Utility;
using System.Linq;
namespace QSB.DeathSync.Patches
@ -17,14 +18,14 @@ namespace QSB.DeathSync.Patches
if (RespawnOnDeath.Instance.AllowedDeathTypes.Contains(deathType))
{
// Allow real death
DebugLog.DebugWrite($"Allowing death of {deathType}");
return true;
}
DebugLog.DebugWrite($"Not allowing death of {deathType}");
RespawnOnDeath.Instance.ResetShip();
RespawnOnDeath.Instance.ResetPlayer();
// Prevent original death method from running.
return false;
}

View File

@ -17,6 +17,9 @@ namespace QSB.DeathSync
DeathType.TimeLoop
};
private readonly Vector3 ShipContainerOffset = new Vector3(-16.45f, -52.67f, 227.39f);
private readonly Quaternion ShipContainerRotation = Quaternion.Euler(-76.937f, 1.062f, -185.066f);
private SpawnPoint _shipSpawnPoint;
private SpawnPoint _playerSpawnPoint;
private OWRigidbody _shipBody;
@ -34,25 +37,56 @@ namespace QSB.DeathSync
{
var playerTransform = Locator.GetPlayerTransform();
_playerResources = playerTransform.GetComponent<PlayerResources>();
_spaceSuit = playerTransform.GetComponentInChildren<PlayerSpacesuit>(true);
_spaceSuit = Locator.GetPlayerSuit();
_playerSpawner = FindObjectOfType<PlayerSpawner>();
_fluidDetector = Locator.GetPlayerCamera().GetComponentInChildren<FluidDetector>();
_playerSpawnPoint = GetSpawnPoint();
_shipSpawnPoint = GetSpawnPoint(true);
var shipTransform = Locator.GetShipTransform();
if (shipTransform == null)
{
DebugLog.DebugWrite($"Warning - Init() ran when ship was null?", MessageType.Warning);
return;
}
_shipComponents = shipTransform.GetComponentsInChildren<ShipComponent>();
_hatchController = shipTransform.GetComponentInChildren<HatchController>();
_cockpitController = shipTransform.GetComponentInChildren<ShipCockpitController>();
_shipBody = Locator.GetShipBody();
_shipSpawnPoint = GetSpawnPoint(true);
// Move debug spawn point to initial ship position.
_playerSpawnPoint = GetSpawnPoint();
_shipSpawnPoint.transform.position = shipTransform.position;
_shipSpawnPoint.transform.rotation = shipTransform.rotation;
if (_shipSpawnPoint == null)
{
DebugLog.ToConsole("Warning - _shipSpawnPoint is null in Init()!", MessageType.Warning);
return;
}
// Move debug spawn point to initial ship position (so ship doesnt spawn in space!)
var timberHearth = Locator.GetAstroObject(AstroObject.Name.TimberHearth).transform;
_shipSpawnPoint.transform.SetParent(timberHearth);
_shipSpawnPoint.transform.localPosition = ShipContainerOffset;
_shipSpawnPoint.transform.localRotation = ShipContainerRotation;
}
public void ResetPlayer()
{
if (_playerSpawnPoint == null)
{
DebugLog.ToConsole("Warning - _playerSpawnPoint is null!", MessageType.Warning);
Init();
}
// Cant use _playerSpawner.DebugWarp because that will warp the ship if the player is in it
var playerBody = Locator.GetPlayerBody();
playerBody.WarpToPositionRotation(_playerSpawnPoint.transform.position, _playerSpawnPoint.transform.rotation);
playerBody.SetVelocity(_playerSpawnPoint.GetPointVelocity());
_playerSpawnPoint.AddObjectToTriggerVolumes(Locator.GetPlayerDetector().gameObject);
_playerSpawnPoint.AddObjectToTriggerVolumes(_fluidDetector.gameObject);
_playerSpawnPoint.OnSpawnPlayer();
_playerResources.SetValue("_isSuffocating", false);
_playerResources.DebugRefillResources();
_spaceSuit.RemoveSuit(true);
}
public void ResetShip()
@ -65,20 +99,16 @@ namespace QSB.DeathSync
if (_shipBody == null)
{
DebugLog.DebugWrite($"Warning - Tried to reset ship, but the ship is null!", MessageType.Warning);
return;
}
// Reset ship position.
_shipBody.SetVelocity(_shipSpawnPoint.GetPointVelocity());
_shipBody.WarpToPositionRotation(_shipSpawnPoint.transform.position, _shipSpawnPoint.transform.rotation);
// Reset ship damage.
if (Locator.GetShipTransform())
foreach (var shipComponent in _shipComponents)
{
foreach (var shipComponent in _shipComponents)
{
shipComponent.SetDamaged(false);
}
shipComponent.SetDamaged(false);
}
Invoke(nameof(ExitShip), 0.01f);
@ -90,38 +120,13 @@ namespace QSB.DeathSync
_cockpitController.Invoke("CompleteExitFlightConsole");
_hatchController.SetValue("_isPlayerInShip", false);
_hatchController.Invoke("OpenHatch");
GlobalMessenger.FireEvent(EventNames.ExitShip);
}
public void ResetPlayer()
{
if (_shipSpawnPoint == null)
{
DebugLog.ToConsole("Warning - _playerSpawnPoint is null!", MessageType.Warning);
Init();
}
// Reset player position.
var playerBody = Locator.GetPlayerBody();
playerBody.WarpToPositionRotation(_playerSpawnPoint.transform.position, _playerSpawnPoint.transform.rotation);
playerBody.SetVelocity(_playerSpawnPoint.GetPointVelocity());
_playerSpawnPoint.AddObjectToTriggerVolumes(Locator.GetPlayerDetector().gameObject);
_playerSpawnPoint.AddObjectToTriggerVolumes(_fluidDetector.gameObject);
_playerSpawnPoint.OnSpawnPlayer();
// Stop suffocation sound effect.
_playerResources.SetValue("_isSuffocating", false);
// Reset player health and resources.
_playerResources.DebugRefillResources();
// Remove space suit.
_spaceSuit.RemoveSuit(true);
}
private SpawnPoint GetSpawnPoint(bool isShip = false) =>
_playerSpawner
private SpawnPoint GetSpawnPoint(bool isShip = false)
=> _playerSpawner
.GetValue<SpawnPoint[]>("_spawnList")
.FirstOrDefault(spawnPoint => spawnPoint.GetSpawnLocation() == SpawnLocation.TimberHearth && spawnPoint.IsShipSpawn() == isShip);
.FirstOrDefault(spawnPoint =>
spawnPoint.GetSpawnLocation() == SpawnLocation.TimberHearth
&& spawnPoint.IsShipSpawn() == isShip);
}
}

View File

@ -15,7 +15,6 @@
public static string RemoveSuit = "RemoveSuit";
public static string EquipTranslator = "EquipTranslator";
public static string UnequipTranslator = "UnequipTranslator";
public static string ExitShip = "ExitShip";
public static string RestartTimeLoop = "RestartTimeLoop";
public static string WakeUp = "WakeUp";
public static string DialogueCondition = "DialogueConditionChanged";

View File

@ -84,6 +84,7 @@ namespace QSB.TimeSync
if (IsServer)
{
SendServerTime();
RespawnOnDeath.Instance.Init();
}
else
{