68 lines
2.0 KiB
C#
Raw Normal View History

2021-11-29 22:57:13 +00:00
using HarmonyLib;
2021-12-24 20:07:50 -08:00
using QSB.Messaging;
2021-11-29 22:57:13 +00:00
using QSB.Patches;
using QSB.Utility;
2021-12-24 20:07:50 -08:00
using QSB.WorldSync;
using QSB.ZeroGCaveSync.Messages;
using QSB.ZeroGCaveSync.WorldObjects;
2021-11-29 22:57:13 +00:00
using UnityEngine;
2022-03-02 19:46:33 -08:00
namespace QSB.ZeroGCaveSync.Patches;
[HarmonyPatch]
internal class ZeroGCavePatches : QSBPatch
2021-11-29 22:57:13 +00:00
{
2022-03-02 19:46:33 -08:00
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPrefix]
[HarmonyPatch(typeof(SatelliteNode), nameof(SatelliteNode.RepairTick))]
public static bool SatelliteNode_RepairTick(SatelliteNode __instance)
2021-11-29 22:57:13 +00:00
{
2022-03-02 19:46:33 -08:00
if (!__instance._damaged)
{
return false;
}
2021-11-29 22:57:13 +00:00
2022-03-02 19:46:33 -08:00
__instance._repairFraction = Mathf.Clamp01(__instance._repairFraction + (Time.deltaTime / __instance._repairTime));
var qsbSatelliteNode = __instance.GetWorldObject<QSBSatelliteNode>();
if (__instance._repairFraction >= 1f)
2021-11-29 22:57:13 +00:00
{
2022-03-02 19:46:33 -08:00
qsbSatelliteNode
.SendMessage(new SatelliteNodeRepairedMessage());
__instance._damaged = false;
var component = Locator.GetPlayerTransform().GetComponent<ReferenceFrameTracker>();
if (component.GetReferenceFrame() == __instance._rfVolume.GetReferenceFrame())
2021-11-29 22:57:13 +00:00
{
2022-03-02 19:46:33 -08:00
component.UntargetReferenceFrame();
2021-11-29 22:57:13 +00:00
}
2022-03-02 19:46:33 -08:00
if (__instance._rfVolume != null)
2021-11-29 22:57:13 +00:00
{
2022-03-02 19:46:33 -08:00
__instance._rfVolume.gameObject.SetActive(false);
}
2022-03-02 19:46:33 -08:00
if (__instance._lanternLight != null)
{
__instance._lanternLight.color = __instance._lightRepairedColor;
2021-11-29 22:57:13 +00:00
}
2022-03-02 19:46:33 -08:00
if (__instance._lanternEmissiveRenderer != null)
2021-11-29 22:57:13 +00:00
{
2022-03-02 19:46:33 -08:00
__instance._lanternEmissiveRenderer.sharedMaterials.CopyTo(__instance._lanternMaterials, 0);
__instance._lanternMaterials[__instance._lanternMaterialIndex] = __instance._lanternRepairedMaterial;
__instance._lanternEmissiveRenderer.sharedMaterials = __instance._lanternMaterials;
2021-11-29 22:57:13 +00:00
}
2022-03-02 19:46:33 -08:00
__instance.RaiseEvent(nameof(__instance.OnRepaired), __instance);
}
2022-03-02 19:46:33 -08:00
if (__instance._damageEffect != null)
{
__instance._damageEffect.SetEffectBlend(1f - __instance._repairFraction);
}
qsbSatelliteNode
.SendMessage(new SatelliteNodeRepairTickMessage(__instance._repairFraction));
return false;
2021-11-29 22:57:13 +00:00
}
}