Replace BreakableConstructionComponent with a destructible threshold behavior (#3111)

* Replace BreakableConstructionComponent with ChangeConstructionNodeBehavior

* Fix ordering of behaviors in MachineFrame
This commit is contained in:
Vera Aguilera Puerto
2021-02-09 20:08:06 +01:00
committed by GitHub
8 changed files with 90 additions and 51 deletions

View File

@@ -1,36 +0,0 @@
#nullable enable
using Content.Server.GameObjects.Components.Construction;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Damage
{
[RegisterComponent]
public class BreakableConstructionComponent : Component, IDestroyAct
{
public override string Name => "BreakableConstruction";
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(this, x => x.Node, "node", string.Empty);
}
public string Node { get; private set; } = string.Empty;
async void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
{
if (Owner.Deleted ||
!Owner.TryGetComponent(out ConstructionComponent? construction) ||
string.IsNullOrEmpty(Node))
{
return;
}
await construction.ChangeNode(Node);
}
}
}

View File

@@ -0,0 +1,32 @@
#nullable enable
using System;
using Content.Server.GameObjects.Components.Construction;
using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behaviors
{
[Serializable]
public class ChangeConstructionNodeBehavior : IThresholdBehavior
{
public string Node { get; private set; } = string.Empty;
void IExposeData.ExposeData(ObjectSerializer serializer)
{
serializer.DataField(this, x => x.Node, "node", string.Empty);
}
public async void Execute(IEntity owner, DestructibleSystem system)
{
if (string.IsNullOrEmpty(Node) ||
!owner.TryGetComponent(out ConstructionComponent? construction))
{
return;
}
await construction.ChangeNode(Node);
}
}
}