mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-25 06:35:45 +00:00
store local visibility in world object, patch to redirect to global visibility
This commit is contained in:
parent
d3b08df89c
commit
856d980301
@ -56,44 +56,37 @@ public class AlarmTotemPatches : QSBPatch
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// do local fixed update to check for local visibility
|
||||
/// </summary>
|
||||
/// <param name="__instance"></param>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(AlarmTotem), nameof(AlarmTotem.FixedUpdate))]
|
||||
private static bool FixedUpdate(AlarmTotem __instance)
|
||||
private static void FixedUpdate(AlarmTotem __instance)
|
||||
{
|
||||
var isPlayerVisible = __instance._isPlayerVisible;
|
||||
__instance._isPlayerVisible = __instance.CheckPlayerVisible();
|
||||
if (__instance._isPlayerVisible && !isPlayerVisible)
|
||||
if (!QSBWorldSync.AllObjectsReady)
|
||||
{
|
||||
Locator.GetAlarmSequenceController().IncreaseAlarmCounter();
|
||||
__instance._simTotemMaterials[0] = __instance._simAlarmMaterial;
|
||||
__instance._simTotemRenderer.sharedMaterials = __instance._simTotemMaterials;
|
||||
__instance._simVisionConeRenderer.SetColor(__instance._simAlarmColor);
|
||||
if (__instance._isTutorialTotem)
|
||||
{
|
||||
GlobalMessenger.FireEvent("TutorialAlarmTotemTriggered");
|
||||
}
|
||||
|
||||
if (QSBWorldSync.AllObjectsReady)
|
||||
{
|
||||
__instance.GetWorldObject<QSBAlarmTotem>()
|
||||
.SendMessage(new SetVisibleMessage(true));
|
||||
}
|
||||
}
|
||||
else if (isPlayerVisible && !__instance._isPlayerVisible)
|
||||
{
|
||||
Locator.GetAlarmSequenceController().DecreaseAlarmCounter();
|
||||
__instance._simTotemMaterials[0] = __instance._origSimEyeMaterial;
|
||||
__instance._simTotemRenderer.sharedMaterials = __instance._simTotemMaterials;
|
||||
__instance._simVisionConeRenderer.SetColor(__instance._simVisionConeRenderer.GetOriginalColor());
|
||||
__instance._pulseLightController.FadeTo(0f, 0.5f);
|
||||
|
||||
if (QSBWorldSync.AllObjectsReady)
|
||||
{
|
||||
__instance.GetWorldObject<QSBAlarmTotem>()
|
||||
.SendMessage(new SetVisibleMessage(false));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var qsbAlarmTotem = __instance.GetWorldObject<QSBAlarmTotem>();
|
||||
qsbAlarmTotem.FixedUpdate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// check for global visibility
|
||||
/// </summary>
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(AlarmTotem), nameof(AlarmTotem.CheckPlayerVisible))]
|
||||
private static bool CheckPlayerVisible(AlarmTotem __instance, ref bool __result)
|
||||
{
|
||||
if (!QSBWorldSync.AllObjectsReady)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var qsbAlarmTotem = __instance.GetWorldObject<QSBAlarmTotem>();
|
||||
__result = qsbAlarmTotem.IsVisible();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ public class QSBAlarmTotem : WorldObject<AlarmTotem>
|
||||
private void OnPlayerLeave(PlayerInfo player) =>
|
||||
_visibleFor.QuickRemove(player.PlayerId);
|
||||
|
||||
public bool IsVisible() => _visibleFor.Count > 0;
|
||||
|
||||
public void SetVisible(uint playerId, bool visible)
|
||||
{
|
||||
if (visible)
|
||||
@ -84,4 +86,56 @@ public class QSBAlarmTotem : WorldObject<AlarmTotem>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region local visibility
|
||||
|
||||
private bool _isLocallyVisible;
|
||||
|
||||
public void FixedUpdate()
|
||||
{
|
||||
var isLocallyVisible = _isLocallyVisible;
|
||||
_isLocallyVisible = CheckPlayerVisible();
|
||||
if (_isLocallyVisible && !isLocallyVisible)
|
||||
{
|
||||
Locator.GetAlarmSequenceController().IncreaseAlarmCounter();
|
||||
AttachedObject._simTotemMaterials[0] = AttachedObject._simAlarmMaterial;
|
||||
AttachedObject._simTotemRenderer.sharedMaterials = AttachedObject._simTotemMaterials;
|
||||
AttachedObject._simVisionConeRenderer.SetColor(AttachedObject._simAlarmColor);
|
||||
if (AttachedObject._isTutorialTotem)
|
||||
{
|
||||
GlobalMessenger.FireEvent("TutorialAlarmTotemTriggered");
|
||||
}
|
||||
}
|
||||
else if (isLocallyVisible && !_isLocallyVisible)
|
||||
{
|
||||
Locator.GetAlarmSequenceController().DecreaseAlarmCounter();
|
||||
AttachedObject._simTotemMaterials[0] = AttachedObject._origSimEyeMaterial;
|
||||
AttachedObject._simTotemRenderer.sharedMaterials = AttachedObject._simTotemMaterials;
|
||||
AttachedObject._simVisionConeRenderer.SetColor(AttachedObject._simVisionConeRenderer.GetOriginalColor());
|
||||
AttachedObject._pulseLightController.FadeTo(0f, 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckPlayerVisible()
|
||||
{
|
||||
if (!AttachedObject._isFaceOpen)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var lanternController = Locator.GetDreamWorldController().GetPlayerLantern().GetLanternController();
|
||||
var playerLightSensor = Locator.GetPlayerLightSensor();
|
||||
if (lanternController.IsHeldByPlayer() && !lanternController.IsConcealed() || playerLightSensor.IsIlluminated())
|
||||
{
|
||||
var position = Locator.GetPlayerCamera().transform.position;
|
||||
if (AttachedObject.CheckPointInVisionCone(position) && !AttachedObject.CheckLineOccluded(AttachedObject._sightOrigin.position, position))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user