test QM stuff

This commit is contained in:
_nebula 2023-01-22 00:58:43 +00:00
parent 7b69b649cb
commit 3aa1a2cdc3

View File

@ -1,6 +1,10 @@
using HarmonyLib;
using QSB.Messaging;
using QSB.Patches;
using QSB.Player;
using QSB.ShipSync;
using QSB.Utility;
using System.Linq;
using UnityEngine;
namespace QSB.QuantumSync.Patches.Common;
@ -15,16 +19,30 @@ internal class QuantumMoonPatches : QSBPatch
public static bool CheckPlayerFogProximity(QuantumMoon __instance)
{
var playerDistance = Vector3.Distance(__instance.transform.position, Locator.GetPlayerCamera().transform.position);
var fogOffset = (__instance._stateIndex != 5) ? 0f : __instance._eyeStateFogOffset;
var fogOffset = (__instance._stateIndex == 5) ? __instance._eyeStateFogOffset : 0f;
var distanceFromFog = playerDistance - (__instance._fogRadius + fogOffset);
var fogAlpha = 0f;
if (!__instance._isPlayerInside)
{
fogAlpha = Mathf.InverseLerp(__instance._fogThickness + __instance._fogRolloffDistance, __instance._fogThickness, distanceFromFog);
if (distanceFromFog < 0f)
if (distanceFromFog < 0f) // inside fog
{
if (__instance.IsLockedByProbeSnapshot() || QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)__instance._visibilityTracker, true).FoundPlayers)
var playersWhoCanSeeMoon = QuantumManager.IsVisibleUsingCameraFrustum((ShapeVisibilityTracker)__instance._visibilityTracker, true).PlayersWhoCanSee;
var shipInFog = GetShipInFog(__instance);
DebugLog.DebugWrite($"Inside Fog - shipInFog:{shipInFog} playersWhoCanSeeMoon.Count:{playersWhoCanSeeMoon.Count}, lockedByProbeSnapshot:{__instance.IsLockedByProbeSnapshot()}");
if (playersWhoCanSeeMoon.Any(x => !(shipInFog && x.IsInShip) && !GetTransformInFog(__instance, x.CameraBody.transform)) || __instance.IsLockedByProbeSnapshot())
{
/* Either :
* - The moon is locked with a snapshot
* OR
* - If the ship is in the fog :
* - there are people outside the ship who can see the moon, and who are not in the fog
* - If the ship is not in the fog
* - There are people who can see the moon, who are not in the fog
*/
__instance._isPlayerInside = true;
__instance.SetSurfaceState(__instance._stateIndex);
Locator.GetShipLogManager().RevealFact(__instance._revealFactID);
@ -76,4 +94,22 @@ internal class QuantumMoonPatches : QSBPatch
__instance._shipLandingCamFogBubble.SetFogAlpha(fogAlpha);
return false;
}
private static bool GetShipInFog(QuantumMoon moon)
{
if (ShipManager.Instance.IsShipWrecked)
{
return false;
}
return GetTransformInFog(moon, Locator.GetShipTransform());
}
private static bool GetTransformInFog(QuantumMoon moon, Transform transform)
{
var distance = Vector3.Distance(moon.transform.position, transform.position);
var fogOffset = (moon._stateIndex == 5) ? moon._eyeStateFogOffset : 0f;
var distanceFromFog = distance - (moon._fogRadius + fogOffset);
return distanceFromFog < 0f;
}
}