2017-10-07 15:15:29 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using SS14.Shared.GameObjects;
|
|
|
|
|
|
using SS14.Shared.Log;
|
|
|
|
|
|
using SS14.Shared.Utility;
|
|
|
|
|
|
using YamlDotNet.RepresentationModel;
|
|
|
|
|
|
using Content.Server.Interfaces;
|
|
|
|
|
|
using Content.Shared.GameObjects;
|
2018-07-26 23:38:16 +02:00
|
|
|
|
using SS14.Shared.Serialization;
|
2018-09-09 15:34:43 +02:00
|
|
|
|
using SS14.Shared.ViewVariables;
|
2017-10-07 15:15:29 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Deletes the entity once a certain damage threshold has been reached.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class DestructibleComponent : Component, IOnDamageBehavior
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public override string Name => "Destructible";
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public override uint? NetID => ContentNetIDs.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; }
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-07-26 23:38:16 +02:00
|
|
|
|
// TODO: Writing
|
|
|
|
|
|
if (serializer.Reading)
|
|
|
|
|
|
{
|
|
|
|
|
|
DamageType damageType = DamageType.Total;
|
|
|
|
|
|
int damageValue = 0;
|
2017-10-07 15:15:29 +02:00
|
|
|
|
|
2018-07-26 23:38:16 +02:00
|
|
|
|
serializer.DataReadFunction("thresholdtype", DamageType.Total, type => damageType = type);
|
|
|
|
|
|
serializer.DataReadFunction("thresholdvalue", 0, val => damageValue = val);
|
2017-10-07 15:15:29 +02:00
|
|
|
|
|
2018-12-13 07:47:19 -06:00
|
|
|
|
Threshold = new DamageThreshold(damageType, damageValue, ThresholdType.Destruction);
|
2017-10-07 15:15:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public List<DamageThreshold> GetAllDamageThresholds()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new List<DamageThreshold>() { Threshold };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public void OnDamageThresholdPassed(object obj, DamageThresholdPassedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.Passed && e.DamageThreshold == Threshold)
|
|
|
|
|
|
{
|
|
|
|
|
|
Owner.EntityManager.DeleteEntity(Owner);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|