Merge pull request #438 from misternebula/probe-destruction

fix probe destruction
This commit is contained in:
_nebula 2021-12-27 21:36:41 +00:00 committed by GitHub
commit 47385623fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 104 additions and 7 deletions

View File

@ -6,7 +6,7 @@ namespace QSB.MeteorSync.WorldObjects
public class QSBMeteor : WorldObject<MeteorController>
{
public static bool IsSpecialImpact(GameObject go) =>
go == Locator.GetPlayerCollider().gameObject || go == Locator.GetProbe()._anchor._collider.gameObject;
go == Locator.GetPlayerCollider().gameObject || (Locator.GetProbe() != null && go == Locator.GetProbe()._anchor._collider.gameObject);
public void SpecialImpact()
{

View File

@ -284,7 +284,8 @@ namespace QSB.Player.TransformSync
}
public override bool IsReady
=> Locator.GetPlayerTransform() != null;
=> AttachedObject != null
|| Locator.GetPlayerTransform() != null;
public static PlayerTransformSync LocalInstance { get; private set; }

View File

@ -104,6 +104,7 @@ namespace QSB.Syncs
protected virtual float DistanceLeeway { get; } = 5f;
private float _previousDistance;
protected const float SmoothTime = 0.1f;
protected const int MaxLabelSize = 15;
private Vector3 _positionSmoothVelocity;
private Quaternion _rotationSmoothVelocity;
protected bool _isInitialized;
@ -294,5 +295,40 @@ namespace QSB.Syncs
Popcron.Gizmos.Cube(ReferenceTransform.position, ReferenceTransform.rotation, Vector3.one / 8, Color.magenta);
Popcron.Gizmos.Line(AttachedObject.transform.position, ReferenceTransform.position, Color.cyan);
}
void OnGUI()
{
GUIStyle guiStyle = new();
guiStyle.normal.textColor = Color.white;
GUI.contentColor = Color.white;
if (Locator.GetPlayerCamera() == null)
{
return;
}
if (AttachedObject == null)
{
return;
}
var screenPosition = Locator.GetPlayerCamera().WorldToScreenPoint(AttachedObject.transform.position);
var distance = screenPosition.z;
var mappedFontSize = distance.Map(0, 250, MaxLabelSize, 0, true);
guiStyle.fontSize = (int)mappedFontSize;
if ((int)mappedFontSize <= 0)
{
return;
}
if ((int)mappedFontSize >= MaxLabelSize)
{
return;
}
// WorldToScreenPoint's (0,0) is at screen bottom left, GUI's (0,0) is at screen top left. grrrr
GUI.Label(new Rect(screenPosition.x, Screen.height - screenPosition.y, 100f, 20f), LogName, guiStyle);
}
}
}

View File

@ -412,7 +412,7 @@ namespace QSB.TimeSync
return;
}
var mappedTimescale = diff.Map(-PauseOrFastForwardThreshold, PauseOrFastForwardThreshold, 1 + TimescaleBounds, 1 - TimescaleBounds);
var mappedTimescale = diff.Map(-PauseOrFastForwardThreshold, PauseOrFastForwardThreshold, 1 + TimescaleBounds, 1 - TimescaleBounds, true);
if (mappedTimescale > 100f)
{
DebugLog.ToConsole($"Warning - CheckTimeDifference() returned over 100 - should have switched into fast-forward!", MessageType.Warning);

View File

@ -0,0 +1,41 @@
using HarmonyLib;
using QSB.Patches;
namespace QSB.Tools.ProbeTool.Patches
{
internal class ProbeToolPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
/*
* This patch is just to avoid error spam when testing probe destruction in SolarSystem
*/
[HarmonyPrefix]
[HarmonyPatch(typeof(NomaiWarpStreaming), nameof(NomaiWarpStreaming.FixedUpdate))]
public static bool FixedUpdateOverride(NomaiWarpStreaming __instance)
{
if (__instance._warpTransmitter != null)
{
var ableToBeWarped = __instance._warpTransmitter.GetViewAngleToTarget() < __instance._streamingAngle;
var probeAbove = __instance._probe != null && __instance._probe.IsLaunched() && (!__instance._probe.IsAnchored() || __instance._warpTransmitter.IsProbeOnPlatform());
var shouldBeLoadingRequiredAssets = ableToBeWarped && (__instance._playerInVolume || (__instance._probeInVolume && probeAbove));
var shouldBeLoadingGeneralAssets = ableToBeWarped && __instance._warpTransmitter.IsPlayerOnPlatform();
__instance.UpdatePreloadingState(shouldBeLoadingRequiredAssets, shouldBeLoadingGeneralAssets);
}
if (__instance._warpReceiver != null)
{
var ableToBeWarped = __instance._warpReceiver.IsReturnWarpEnabled() || __instance._warpReceiver.IsBlackHoleOpen();
var probeAbove = __instance._probe != null && __instance._probe.IsLaunched() && (!__instance._probe.IsAnchored() || __instance._warpReceiver.IsProbeOnPlatform());
var shouldBeLoadingRequiredAssets = ableToBeWarped && (__instance._playerInVolume || (__instance._probeInVolume && probeAbove));
var shouldBeLoadingGeneralAssets = ableToBeWarped && __instance._playerInVolume;
__instance.UpdatePreloadingState(shouldBeLoadingRequiredAssets, shouldBeLoadingGeneralAssets);
}
return false;
}
}
}

View File

@ -27,9 +27,15 @@ namespace QSB.Tools.ProbeTool
// ProbeDetector
//Object.Destroy(newProbe.Find("ProbeDetector").gameObject);
var probeDetector = newProbe.Find("ProbeDetector").gameObject;
probeDetector.tag = "Untagged";
Object.Destroy(probeDetector.GetComponent<ForceApplier>());
Object.Destroy(probeDetector.GetComponent<ProbeFluidDetector>());
Object.Destroy(probeDetector.GetComponent<SectorDetector>());
Object.Destroy(probeDetector.GetComponent<AlignmentForceDetector>());
Object.Destroy(probeDetector.GetComponent<OxygenDetector>());
Object.Destroy(probeDetector.GetComponent<RulesetDetector>());
Object.Destroy(probeDetector.GetComponent<ProbeDestructionDetector>());
Object.Destroy(probeDetector.GetComponent<VisionDetector>());
// CameraPivot
var cameraPivot = newProbe.Find("CameraPivot");

View File

@ -101,6 +101,8 @@ namespace QSB.Tools.ProbeTool
OnRetrieveProbe();
break;
case ProbeEvent.Destroy:
Destroy(gameObject);
if (OnProbeDestroyed == null)
{
DebugLog.ToConsole($"Warning - OnProbeDestroyed is null!", OWML.Common.MessageType.Warning);

View File

@ -113,6 +113,6 @@ namespace QSB.Tools.ProbeTool.TransformSync
return true;
}
public override bool IsReady => Locator.GetProbe() != null;
public override bool IsReady => AttachedObject != null || Locator.GetProbe() != null;
}
}

View File

@ -73,11 +73,16 @@ namespace QSB.Utility
}
}
if (Keyboard.current[Key.Numpad1].wasPressedThisFrame)
if (Keyboard.current[Key.Numpad2].wasPressedThisFrame)
{
TimeLoop._isTimeFlowing = true;
}
if (Keyboard.current[Key.Numpad3].wasPressedThisFrame)
{
Destroy(Locator.GetProbe().gameObject);
}
if (Keyboard.current[Key.Numpad4].wasPressedThisFrame)
{
DamageShipElectricalSystem();

View File

@ -100,8 +100,14 @@ namespace QSB.Utility
}
}
public static float Map(this float value, float inputFrom, float inputTo, float outputFrom, float outputTo)
=> ((value - inputFrom) / (inputTo - inputFrom) * (outputTo - outputFrom)) + outputFrom;
public static float Map(this float value, float inputFrom, float inputTo, float outputFrom, float outputTo, bool clamp)
{
var mappedValue = ((value - inputFrom) / (inputTo - inputFrom) * (outputTo - outputFrom)) + outputFrom;
return clamp
? Mathf.Clamp(mappedValue, outputTo, outputFrom)
: mappedValue;
}
public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
{