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
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.ZeroGCaveSync.WorldObjects;
|
|
|
|
|
|
|
|
|
|
internal class QSBSatelliteNode : WorldObject<SatelliteNode>
|
2021-11-29 22:57:13 +00:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override void SendInitialState(uint to)
|
2021-11-29 22:57:13 +00:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (!AttachedObject._damaged)
|
2022-01-25 20:31:00 -08:00
|
|
|
|
{
|
2022-03-29 13:49:02 -07:00
|
|
|
|
this.SendMessage(new SatelliteNodeRepairedMessage { To = to });
|
2022-02-24 22:04:54 -08:00
|
|
|
|
}
|
2021-11-29 22:57:13 +00:00
|
|
|
|
|
2022-03-29 13:49:02 -07:00
|
|
|
|
this.SendMessage(new SatelliteNodeRepairTickMessage(AttachedObject._repairFraction) { To = to });
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
2021-11-29 22:57:13 +00:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public void SetRepaired()
|
|
|
|
|
{
|
|
|
|
|
if (!AttachedObject._damaged)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-29 22:57:13 +00:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
DebugLog.DebugWrite($"[SATELLITE NODE] {AttachedObject} Set repaired.");
|
|
|
|
|
AttachedObject._damaged = false;
|
|
|
|
|
var component = Locator.GetPlayerTransform().GetComponent<ReferenceFrameTracker>();
|
|
|
|
|
if (component.GetReferenceFrame() == AttachedObject._rfVolume.GetReferenceFrame())
|
|
|
|
|
{
|
|
|
|
|
component.UntargetReferenceFrame();
|
|
|
|
|
}
|
2022-01-25 20:31:00 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (AttachedObject._rfVolume != null)
|
|
|
|
|
{
|
|
|
|
|
AttachedObject._rfVolume.gameObject.SetActive(false);
|
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (AttachedObject._lanternLight != null)
|
|
|
|
|
{
|
|
|
|
|
AttachedObject._lanternLight.color = AttachedObject._lightRepairedColor;
|
2021-11-29 22:57:13 +00:00
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
if (AttachedObject._lanternEmissiveRenderer != null)
|
2022-02-27 04:40:44 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
AttachedObject._lanternEmissiveRenderer.sharedMaterials.CopyTo(AttachedObject._lanternMaterials, 0);
|
|
|
|
|
AttachedObject._lanternMaterials[AttachedObject._lanternMaterialIndex] = AttachedObject._lanternRepairedMaterial;
|
|
|
|
|
AttachedObject._lanternEmissiveRenderer.sharedMaterials = AttachedObject._lanternMaterials;
|
|
|
|
|
}
|
2022-02-27 04:40:44 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
AttachedObject.RaiseEvent(nameof(AttachedObject.OnRepaired), AttachedObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RepairTick(float repairFraction)
|
|
|
|
|
{
|
|
|
|
|
if (OWMath.ApproxEquals(AttachedObject._repairFraction, repairFraction))
|
|
|
|
|
{
|
|
|
|
|
return;
|
2022-02-27 04:40:44 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
|
|
|
|
|
DebugLog.DebugWrite($"[SATELLITE NODE] {AttachedObject} repair tick {repairFraction}");
|
|
|
|
|
AttachedObject._repairFraction = repairFraction;
|
|
|
|
|
var damageEffect = AttachedObject._damageEffect;
|
|
|
|
|
damageEffect.SetEffectBlend(1f - repairFraction);
|
2021-11-29 22:57:13 +00:00
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
}
|