quantum-space-buddies/QSB/ShipSync/WorldObjects/QSBShipHull.cs

67 lines
1.5 KiB
C#
Raw Normal View History

2022-01-26 04:16:53 +00:00
using QSB.Messaging;
using QSB.ShipSync.Messages.Hull;
using QSB.Utility;
using QSB.WorldSync;
namespace QSB.ShipSync.WorldObjects
{
2021-07-12 21:02:50 +00:00
internal class QSBShipHull : WorldObject<ShipHull>
{
public override void SendInitialState(uint to)
2022-01-26 04:16:53 +00:00
{
if (QSBCore.IsHost)
{
if (AttachedObject._damaged)
{
this.SendMessage(new HullDamagedMessage());
}
else
{
this.SendMessage(new HullRepairedMessage());
}
this.SendMessage(new HullChangeIntegrityMessage(AttachedObject._integrity));
}
}
public void SetDamaged()
{
2022-01-26 04:16:53 +00:00
if (AttachedObject._damaged)
{
return;
}
DebugLog.DebugWrite($"[HULL] {AttachedObject} Set damaged.");
2021-12-27 04:57:34 +00:00
AttachedObject._damaged = true;
AttachedObject.RaiseEvent(nameof(AttachedObject.OnDamaged), AttachedObject);
}
2021-06-20 09:06:29 +00:00
public void SetRepaired()
{
2022-01-26 04:16:53 +00:00
if (!AttachedObject._damaged)
{
return;
}
2021-06-20 09:06:29 +00:00
DebugLog.DebugWrite($"[HULL] {AttachedObject} Set repaired.");
2021-12-27 04:57:34 +00:00
AttachedObject._damaged = false;
AttachedObject.RaiseEvent(nameof(AttachedObject.OnRepaired), AttachedObject);
2021-12-27 04:35:40 +00:00
var damageEffect = AttachedObject._damageEffect;
2021-06-20 09:06:29 +00:00
damageEffect.SetEffectBlend(0f);
}
public void ChangeIntegrity(float newIntegrity)
{
2022-01-26 04:16:53 +00:00
if (OWMath.ApproxEquals(AttachedObject._integrity, newIntegrity))
{
return;
}
DebugLog.DebugWrite($"[HULL] {AttachedObject} Change integrity to {newIntegrity}.");
2021-12-27 04:57:34 +00:00
AttachedObject._integrity = newIntegrity;
2021-12-27 04:35:40 +00:00
var damageEffect = AttachedObject._damageEffect;
damageEffect.SetEffectBlend(1f - newIntegrity);
}
}
}