61 lines
1.3 KiB
C#
Raw Normal View History

2022-01-25 20:16:53 -08:00
using QSB.Messaging;
using QSB.ShipSync.Messages.Hull;
using QSB.Utility;
using QSB.WorldSync;
2022-03-02 19:46:33 -08:00
namespace QSB.ShipSync.WorldObjects;
internal class QSBShipHull : WorldObject<ShipHull>
{
2022-03-02 19:46:33 -08:00
public override void SendInitialState(uint to)
{
2022-03-02 19:46:33 -08:00
if (AttachedObject._damaged)
{
this.SendMessage(new HullDamagedMessage());
}
else
2022-01-25 20:16:53 -08:00
{
2022-03-02 19:46:33 -08:00
this.SendMessage(new HullRepairedMessage());
2022-01-25 20:16:53 -08:00
}
2022-03-02 19:46:33 -08:00
this.SendMessage(new HullChangeIntegrityMessage(AttachedObject._integrity));
}
public void SetDamaged()
{
if (AttachedObject._damaged)
{
2022-03-02 19:46:33 -08:00
return;
}
2022-03-02 19:46:33 -08:00
DebugLog.DebugWrite($"[HULL] {AttachedObject} Set damaged.");
AttachedObject._damaged = true;
AttachedObject.RaiseEvent(nameof(AttachedObject.OnDamaged), AttachedObject);
}
public void SetRepaired()
{
if (!AttachedObject._damaged)
2021-06-20 10:06:29 +01:00
{
2022-03-02 19:46:33 -08:00
return;
2021-06-20 10:06:29 +01:00
}
2022-03-02 19:46:33 -08:00
DebugLog.DebugWrite($"[HULL] {AttachedObject} Set repaired.");
AttachedObject._damaged = false;
AttachedObject.RaiseEvent(nameof(AttachedObject.OnRepaired), AttachedObject);
var damageEffect = AttachedObject._damageEffect;
damageEffect.SetEffectBlend(0f);
}
public void ChangeIntegrity(float newIntegrity)
{
if (OWMath.ApproxEquals(AttachedObject._integrity, newIntegrity))
{
2022-03-02 19:46:33 -08:00
return;
}
2022-03-02 19:46:33 -08:00
AttachedObject._integrity = newIntegrity;
var damageEffect = AttachedObject._damageEffect;
damageEffect.SetEffectBlend(1f - newIntegrity);
}
}