2022-01-26 04:16:53 +00:00
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.ShipSync.Messages.Component;
|
|
|
|
|
using QSB.Utility;
|
2021-06-20 08:48:37 +00:00
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.ShipSync.WorldObjects;
|
|
|
|
|
|
|
|
|
|
internal class QSBShipComponent : WorldObject<ShipComponent>
|
2021-06-20 08:48:37 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void SendInitialState(uint to)
|
2021-06-20 08:48:37 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
if (AttachedObject._damaged)
|
2021-06-20 08:48:37 +00:00
|
|
|
|
{
|
2022-03-29 20:49:02 +00:00
|
|
|
|
this.SendMessage(new ComponentDamagedMessage { To = to });
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
else
|
2022-02-25 06:04:54 +00:00
|
|
|
|
{
|
2022-03-29 20:49:02 +00:00
|
|
|
|
this.SendMessage(new ComponentRepairedMessage { To = to });
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
2022-03-29 20:49:02 +00:00
|
|
|
|
this.SendMessage(new ComponentRepairTickMessage(AttachedObject._repairFraction) { To = to });
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public void SetDamaged()
|
|
|
|
|
{
|
|
|
|
|
if (AttachedObject._damaged)
|
|
|
|
|
{
|
|
|
|
|
return;
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
2022-01-26 04:16:53 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
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)
|
2022-02-25 06:04:54 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public void RepairTick(float repairFraction)
|
|
|
|
|
{
|
|
|
|
|
if (OWMath.ApproxEquals(AttachedObject._repairFraction, repairFraction))
|
|
|
|
|
{
|
|
|
|
|
return;
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
|
|
|
|
|
AttachedObject._repairFraction = repairFraction;
|
|
|
|
|
var damageEffect = AttachedObject._damageEffect;
|
|
|
|
|
damageEffect.SetEffectBlend(1f - repairFraction);
|
2021-06-20 08:48:37 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|