mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-04 02:47:22 +00:00
add hull repaired event
This commit is contained in:
parent
d044bcef4d
commit
beae3f9f7a
@ -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";
|
||||
}
|
||||
|
@ -49,6 +49,7 @@
|
||||
HullImpact,
|
||||
HullDamaged,
|
||||
HullChangeIntegrity,
|
||||
HullRepaired,
|
||||
ComponentDamaged,
|
||||
ComponentRepaired
|
||||
}
|
||||
|
@ -87,6 +87,7 @@ namespace QSB.Events
|
||||
new HullImpactEvent(),
|
||||
new HullDamagedEvent(),
|
||||
new HullChangeIntegrityEvent(),
|
||||
new HullRepairedEvent(),
|
||||
new ComponentDamagedEvent(),
|
||||
new ComponentRepairedEvent()
|
||||
};
|
||||
|
@ -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" />
|
||||
|
43
QSB/ShipSync/Events/Hull/HullRepairedEvent.cs
Normal file
43
QSB/ShipSync/Events/Hull/HullRepairedEvent.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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}.");
|
||||
|
Loading…
Reference in New Issue
Block a user