72 lines
2.0 KiB
C#
Raw Normal View History

2022-01-25 20:31:00 -08:00
using QSB.Messaging;
using QSB.Utility;
2021-11-29 22:57:13 +00:00
using QSB.WorldSync;
2022-01-25 20:31:00 -08:00
using QSB.ZeroGCaveSync.Messages;
2021-11-29 22:57:13 +00:00
namespace QSB.ZeroGCaveSync.WorldObjects
{
internal class QSBSatelliteNode : WorldObject<SatelliteNode>
{
public override void SendInitialState(uint to)
2022-01-25 20:31:00 -08:00
{
if (QSBCore.IsHost)
{
if (!AttachedObject._damaged)
{
this.SendMessage(new SatelliteNodeRepairedMessage());
}
this.SendMessage(new SatelliteNodeRepairTickMessage(AttachedObject._repairFraction));
}
}
2021-11-29 22:57:13 +00:00
public void SetRepaired()
{
2022-01-25 20:31:00 -08:00
if (!AttachedObject._damaged)
{
return;
}
2021-11-29 22:57:13 +00:00
DebugLog.DebugWrite($"[SATELLITE NODE] {AttachedObject} Set repaired.");
AttachedObject._damaged = false;
var component = Locator.GetPlayerTransform().GetComponent<ReferenceFrameTracker>();
2021-12-26 21:08:36 -08:00
if (component.GetReferenceFrame() == AttachedObject._rfVolume.GetReferenceFrame())
2021-11-29 22:57:13 +00:00
{
component.UntargetReferenceFrame();
}
if (AttachedObject._rfVolume != null)
{
AttachedObject._rfVolume.gameObject.SetActive(false);
}
if (AttachedObject._lanternLight != null)
{
AttachedObject._lanternLight.color = AttachedObject._lightRepairedColor;
}
if (AttachedObject._lanternEmissiveRenderer != null)
{
AttachedObject._lanternEmissiveRenderer.sharedMaterials.CopyTo(AttachedObject._lanternMaterials, 0);
AttachedObject._lanternMaterials[AttachedObject._lanternMaterialIndex] = AttachedObject._lanternRepairedMaterial;
AttachedObject._lanternEmissiveRenderer.sharedMaterials = AttachedObject._lanternMaterials;
}
2021-12-26 21:01:24 -08:00
AttachedObject.RaiseEvent(nameof(AttachedObject.OnRepaired), AttachedObject);
2021-11-29 22:57:13 +00:00
}
public void RepairTick(float repairFraction)
{
2022-01-25 20:31:00 -08:00
if (OWMath.ApproxEquals(AttachedObject._repairFraction, repairFraction))
{
return;
}
2021-11-29 22:57:13 +00:00
DebugLog.DebugWrite($"[SATELLITE NODE] {AttachedObject} repair tick {repairFraction}");
AttachedObject._repairFraction = repairFraction;
var damageEffect = AttachedObject._damageEffect;
damageEffect.SetEffectBlend(1f - repairFraction);
}
}
}