2022-01-26 04:16:53 +00:00
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.ShipSync.Messages.Hull;
|
|
|
|
|
using QSB.Utility;
|
2021-06-20 08:48:37 +00:00
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
|
|
|
|
namespace QSB.ShipSync.WorldObjects
|
|
|
|
|
{
|
2021-07-12 21:02:50 +00:00
|
|
|
|
internal class QSBShipHull : WorldObject<ShipHull>
|
2021-06-20 08:48:37 +00:00
|
|
|
|
{
|
2022-01-26 07:40:38 +00:00
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 08:48:37 +00:00
|
|
|
|
public void SetDamaged()
|
|
|
|
|
{
|
2022-01-26 04:16:53 +00:00
|
|
|
|
if (AttachedObject._damaged)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 08:48:37 +00:00
|
|
|
|
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 08:48:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 08:48:37 +00:00
|
|
|
|
public void ChangeIntegrity(float newIntegrity)
|
|
|
|
|
{
|
2022-01-26 04:16:53 +00:00
|
|
|
|
if (OWMath.ApproxEquals(AttachedObject._integrity, newIntegrity))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 08:48:37 +00:00
|
|
|
|
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;
|
2021-06-20 08:48:37 +00:00
|
|
|
|
damageEffect.SetEffectBlend(1f - newIntegrity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|