mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
74 lines
1.8 KiB
C#
74 lines
1.8 KiB
C#
using QSB.Messaging;
|
|
using QSB.ShipSync.Messages.Component;
|
|
using QSB.Utility;
|
|
using QSB.WorldSync;
|
|
|
|
namespace QSB.ShipSync.WorldObjects
|
|
{
|
|
internal class QSBShipComponent : WorldObject<ShipComponent>
|
|
{
|
|
public override void SendInitialState(uint to)
|
|
{
|
|
if (QSBCore.IsHost)
|
|
{
|
|
if (AttachedObject._damaged)
|
|
{
|
|
this.SendMessage(new ComponentDamagedMessage());
|
|
}
|
|
else
|
|
{
|
|
this.SendMessage(new ComponentRepairedMessage());
|
|
}
|
|
|
|
this.SendMessage(new ComponentRepairTickMessage(AttachedObject._repairFraction));
|
|
}
|
|
}
|
|
|
|
public void SetDamaged()
|
|
{
|
|
if (AttachedObject._damaged)
|
|
{
|
|
return;
|
|
}
|
|
|
|
DebugLog.DebugWrite($"[S COMPONENT] {AttachedObject} Set damaged.");
|
|
AttachedObject._damaged = true;
|
|
AttachedObject._repairFraction = 0f;
|
|
AttachedObject.OnComponentDamaged();
|
|
AttachedObject.RaiseEvent(nameof(AttachedObject.OnDamaged), AttachedObject);
|
|
AttachedObject.UpdateColliderState();
|
|
var damageEffect = AttachedObject._damageEffect;
|
|
damageEffect.SetEffectBlend(1f);
|
|
}
|
|
|
|
public void SetRepaired()
|
|
{
|
|
if (!AttachedObject._damaged)
|
|
{
|
|
return;
|
|
}
|
|
|
|
DebugLog.DebugWrite($"[S COMPONENT] {AttachedObject} Set repaired.");
|
|
AttachedObject._damaged = false;
|
|
AttachedObject._repairFraction = 1f;
|
|
AttachedObject.OnComponentRepaired();
|
|
AttachedObject.RaiseEvent(nameof(AttachedObject.OnRepaired), AttachedObject);
|
|
AttachedObject.UpdateColliderState();
|
|
var damageEffect = AttachedObject._damageEffect;
|
|
damageEffect.SetEffectBlend(0f);
|
|
}
|
|
|
|
public void RepairTick(float repairFraction)
|
|
{
|
|
if (OWMath.ApproxEquals(AttachedObject._repairFraction, repairFraction))
|
|
{
|
|
return;
|
|
}
|
|
|
|
AttachedObject._repairFraction = repairFraction;
|
|
var damageEffect = AttachedObject._damageEffect;
|
|
damageEffect.SetEffectBlend(1f - repairFraction);
|
|
}
|
|
}
|
|
}
|