add debug damage electricals, turn of electricals when no players left in ship

This commit is contained in:
Mister_Nebula 2021-06-19 15:35:40 +01:00
parent ed187e13bd
commit 9fe915962d
4 changed files with 42 additions and 11 deletions

View File

@ -49,7 +49,7 @@ namespace QSB.Player.Events
public override void OnReceiveRemote(bool server, EnumWorldObjectMessage<EnterLeaveType> message)
{
var player = QSBPlayerManager.GetPlayer(message.FromId);
DebugLog.DebugWrite($"{message.FromId} {message.EnumValue}", OWML.Common.MessageType.Debug);
DebugLog.DebugWrite($"{message.FromId} {message.EnumValue}", OWML.Common.MessageType.Info);
switch (message.EnumValue)
{
case EnterLeaveType.EnterMoon:

View File

@ -89,11 +89,6 @@ namespace QSB.ShipSync.Patches
public static bool ShipElectricalComponent_OnEnterShip(ShipElectricalComponent __instance, bool ____damaged, ElectricalSystem ____electricalSystem)
{
__instance.CallBase<ShipElectricalComponent, ShipComponent>("OnEnterShip");
//if (!____damaged)
//{
// DebugLog.DebugWrite($"ShipElectricalComponent - OnEnterShip");
// ____electricalSystem.SetPowered(true);
//}
return false;
}
@ -101,11 +96,6 @@ namespace QSB.ShipSync.Patches
public static bool ShipElectricalComponent_OnExitShip(ShipElectricalComponent __instance, bool ____damaged, ElectricalSystem ____electricalSystem)
{
__instance.CallBase<ShipElectricalComponent, ShipComponent>("OnExitShip");
//if (!____damaged)
//{
// DebugLog.DebugWrite($"ShipElectricalComponent - OnExitShip");
// ____electricalSystem.SetPowered(false);
//}
return false;
}

View File

@ -1,4 +1,5 @@
using OWML.Common;
using OWML.Utils;
using QSB.Player;
using QSB.ShipSync.TransformSync;
using QSB.Utility;
@ -19,6 +20,7 @@ namespace QSB.ShipSync
public HatchController HatchController;
public ShipTractorBeamSwitch ShipTractorBeam;
public ShipCockpitController CockpitController;
public ShipElectricalComponent ShipElectricalComponent;
public bool HasAuthority
=> ShipTransformSync.LocalInstance.HasAuthority;
public uint CurrentFlyer
@ -49,6 +51,7 @@ namespace QSB.ShipSync
HatchInteractZone = HatchController.GetComponent<InteractZone>();
ShipTractorBeam = Resources.FindObjectsOfTypeAll<ShipTractorBeamSwitch>().First();
CockpitController = Resources.FindObjectsOfTypeAll<ShipCockpitController>().First();
ShipElectricalComponent = Resources.FindObjectsOfTypeAll<ShipElectricalComponent>().First();
var sphereShape = HatchController.GetComponent<SphereShape>();
sphereShape.radius = 2.5f;
@ -88,12 +91,39 @@ namespace QSB.ShipSync
public void AddPlayerToShip(PlayerInfo player)
{
DebugLog.DebugWrite($"{player.PlayerId} enter ship.");
_playersInShip.Add(player);
UpdateElectricalComponent();
}
public void RemovePlayerFromShip(PlayerInfo player)
{
DebugLog.DebugWrite($"{player.PlayerId} leave ship.");
_playersInShip.Remove(player);
UpdateElectricalComponent();
}
private void UpdateElectricalComponent()
{
var electricalSystem = ShipElectricalComponent.GetValue<ElectricalSystem>("_electricalSystem");
var damaged = ShipElectricalComponent.GetValue<bool>("_damaged");
if (_playersInShip.Count == 0)
{
if (!damaged)
{
DebugLog.DebugWrite($"No players left in ship - turning off electricals.");
electricalSystem.SetPowered(false);
}
}
else
{
if (!damaged)
{
DebugLog.DebugWrite($"Player in ship - turning on electricals.");
electricalSystem.SetPowered(true);
}
}
}
private void PrintAll(Array array)

View File

@ -1,4 +1,5 @@
using OWML.Utils;
using QSB.ShipSync;
using UnityEngine;
namespace QSB.Utility
@ -24,6 +25,11 @@ namespace QSB.Utility
bridgeVolume.AddObjectToVolume(Locator.GetPlayerCameraDetector());
}
private void DamageShipElectricalSystem()
{
ShipManager.Instance.ShipElectricalComponent.SetDamaged(true);
}
public void Update()
{
if (!QSBCore.DebugMode)
@ -31,6 +37,11 @@ namespace QSB.Utility
return;
}
if (Input.GetKeyDown(KeyCode.Keypad4))
{
DamageShipElectricalSystem();
}
if (Input.GetKeyDown(KeyCode.Keypad7))
{
GoToVessel();