Files
tbd-station-14/Content.Server/GameObjects/Components/Damage/DestructibleComponent.cs
Pieter-Jan Briers b34591ab59 Data Rework Content Edition (#82)
* WiP Data Rework.

* Convert stationstation to new map format.

* stationstation.yml v2

* Update submodule
2018-07-26 23:38:16 +02:00

75 lines
2.2 KiB
C#

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;
using SS14.Shared.Serialization;
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>
public DamageThreshold Threshold { get; private set; }
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
// TODO: Writing
if (serializer.Reading)
{
DamageType damageType = DamageType.Total;
int damageValue = 0;
serializer.DataReadFunction("thresholdtype", DamageType.Total, type => damageType = type);
serializer.DataReadFunction("thresholdvalue", 0, val => damageValue = val);
Threshold = new DamageThreshold(damageType, damageValue);
}
}
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
if (Owner.TryGetComponent<DamageableComponent>(out DamageableComponent damageable))
{
damageable.DamageThresholdPassed += OnDamageThresholdPassed;
}
}
/// <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);
}
}
}
}