add hull repaired event

This commit is contained in:
Mister_Nebula 2021-06-20 10:06:29 +01:00
parent d044bcef4d
commit beae3f9f7a
6 changed files with 56 additions and 0 deletions

View File

@ -72,6 +72,7 @@
public static string QSBHullImpact = "QSBHullImpact";
public static string QSBHullDamaged = "QSBHullDamaged";
public static string QSBHullChangeIntegrity = "QSBHullChangeIntegrity";
public static string QSBHullRepaired = "QSBHullRepaired";
public static string QSBComponentDamaged = "QSBComponentDamaged";
public static string QSBComponentRepaired = "QSBComponentRepaired";
}

View File

@ -49,6 +49,7 @@
HullImpact,
HullDamaged,
HullChangeIntegrity,
HullRepaired,
ComponentDamaged,
ComponentRepaired
}

View File

@ -87,6 +87,7 @@ namespace QSB.Events
new HullImpactEvent(),
new HullDamagedEvent(),
new HullChangeIntegrityEvent(),
new HullRepairedEvent(),
new ComponentDamagedEvent(),
new ComponentRepairedEvent()
};

View File

@ -249,6 +249,7 @@
<Compile Include="ShipSync\Events\Hull\HullDamagedEvent.cs" />
<Compile Include="ShipSync\Events\Hull\HullImpactEvent.cs" />
<Compile Include="ShipSync\Events\Hull\HullImpactMessage.cs" />
<Compile Include="ShipSync\Events\Hull\HullRepairedEvent.cs" />
<Compile Include="ShipSync\Events\ImpactDataMessage.cs" />
<Compile Include="ShipSync\WorldObjects\QSBShipComponent.cs" />
<Compile Include="ShipSync\WorldObjects\QSBShipHull.cs" />

View File

@ -0,0 +1,43 @@
using QSB.Events;
using QSB.ShipSync.WorldObjects;
using QSB.Utility;
using QSB.WorldSync.Events;
using QSB.WorldSync;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QSB.ShipSync.Events.Hull
{
class HullRepairedEvent : QSBEvent<WorldObjectMessage>
{
public override EventType Type => EventType.HullRepaired;
public override void SetupListener() => GlobalMessenger<ShipHull>.AddListener(EventNames.QSBHullRepaired, Handler);
public override void CloseListener() => GlobalMessenger<ShipHull>.RemoveListener(EventNames.QSBHullRepaired, Handler);
private void Handler(ShipHull hull) => SendEvent(CreateMessage(hull));
private WorldObjectMessage CreateMessage(ShipHull hull)
{
var worldObject = QSBWorldSync.GetWorldFromUnity<QSBShipHull, ShipHull>(hull);
return new WorldObjectMessage
{
AboutId = LocalPlayerId,
ObjectId = worldObject.ObjectId
};
}
public override void OnReceiveLocal(bool server, WorldObjectMessage message)
{
DebugLog.DebugWrite($"[HULL] {message.ObjectId} OnRepaired.", OWML.Common.MessageType.Warning);
}
public override void OnReceiveRemote(bool server, WorldObjectMessage message)
{
var worldObject = QSBWorldSync.GetWorldFromId<QSBShipHull>(message.ObjectId);
worldObject.SetRepaired();
}
}
}

View File

@ -19,6 +19,15 @@ namespace QSB.ShipSync.WorldObjects
QSBWorldSync.RaiseEvent(AttachedObject, "OnDamaged", AttachedObject);
}
public void SetRepaired()
{
DebugLog.DebugWrite($"[HULL] {AttachedObject} Set repaired.");
AttachedObject.SetValue("_damaged", false);
QSBWorldSync.RaiseEvent(AttachedObject, "OnRepaired", AttachedObject);
var damageEffect = AttachedObject.GetValue<DamageEffect>("_damageEffect");
damageEffect.SetEffectBlend(0f);
}
public void ChangeIntegrity(float newIntegrity)
{
DebugLog.DebugWrite($"[HULL] {AttachedObject} Change integrity to {newIntegrity}.");