2017-10-07 15:15:29 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Log;
|
|
|
|
|
|
using Robust.Shared.Utility;
|
2017-10-07 15:15:29 +02:00
|
|
|
|
using YamlDotNet.RepresentationModel;
|
|
|
|
|
|
using Content.Server.Interfaces;
|
|
|
|
|
|
using Content.Shared.GameObjects;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
2017-10-07 15:15:29 +02:00
|
|
|
|
|
2019-03-26 02:27:03 +05:00
|
|
|
|
namespace Content.Server.GameObjects.Components.Destructible
|
2017-10-07 15:15:29 +02:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Deletes the entity once a certain damage threshold has been reached.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class DestructibleComponent : Component, IOnDamageBehavior
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public override string Name => "Destructible";
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Damage threshold calculated from the values
|
|
|
|
|
|
/// given in the prototype declaration.
|
|
|
|
|
|
/// </summary>
|
2018-09-09 15:34:43 +02:00
|
|
|
|
[ViewVariables]
|
2017-10-07 15:15:29 +02:00
|
|
|
|
public DamageThreshold Threshold { get; private set; }
|
|
|
|
|
|
|
2019-03-26 02:27:03 +05:00
|
|
|
|
public DamageType damageType = DamageType.Total;
|
|
|
|
|
|
public int damageValue = 0;
|
|
|
|
|
|
public string spawnOnDestroy = "SteelSheet";
|
|
|
|
|
|
public bool destroyed = false;
|
2018-07-26 23:38:16 +02:00
|
|
|
|
|
|
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
2017-10-07 15:15:29 +02:00
|
|
|
|
{
|
2018-07-26 23:38:16 +02:00
|
|
|
|
base.ExposeData(serializer);
|
2017-10-07 15:15:29 +02:00
|
|
|
|
|
2019-03-26 02:27:03 +05:00
|
|
|
|
serializer.DataField(ref damageValue, "thresholdvalue", 100);
|
|
|
|
|
|
serializer.DataField(ref damageType, "thresholdtype", DamageType.Total);
|
|
|
|
|
|
serializer.DataField(ref spawnOnDestroy, "spawnondestroy", "SteelSheet");
|
2017-10-07 15:15:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2019-03-26 02:27:03 +05:00
|
|
|
|
List<DamageThreshold> IOnDamageBehavior.GetAllDamageThresholds()
|
2017-10-07 15:15:29 +02:00
|
|
|
|
{
|
2019-03-26 02:27:03 +05:00
|
|
|
|
Threshold = new DamageThreshold(damageType, damageValue, ThresholdType.Destruction);
|
2017-10-07 15:15:29 +02:00
|
|
|
|
return new List<DamageThreshold>() { Threshold };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2019-03-26 02:27:03 +05:00
|
|
|
|
void IOnDamageBehavior.OnDamageThresholdPassed(object obj, DamageThresholdPassedEventArgs e)
|
2017-10-07 15:15:29 +02:00
|
|
|
|
{
|
2019-03-26 02:27:03 +05:00
|
|
|
|
if (e.Passed && e.DamageThreshold == Threshold && destroyed == false)
|
2017-10-07 15:15:29 +02:00
|
|
|
|
{
|
2019-03-26 02:27:03 +05:00
|
|
|
|
destroyed = true;
|
|
|
|
|
|
var wreck = Owner.EntityManager.SpawnEntity(spawnOnDestroy);
|
|
|
|
|
|
wreck.Transform.GridPosition = Owner.Transform.GridPosition;
|
2017-10-07 15:15:29 +02:00
|
|
|
|
Owner.EntityManager.DeleteEntity(Owner);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|