2019-07-31 15:02:36 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using Content.Server.Interfaces.GameObjects;
|
|
|
|
|
|
using Content.Shared.GameObjects;
|
2017-10-07 15:15:29 +02:00
|
|
|
|
using Content.Shared.Maths;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
2017-10-07 15:15:29 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Handles changing temperature,
|
|
|
|
|
|
/// informing others of the current temperature,
|
|
|
|
|
|
/// and taking fire damage from high temperature.
|
|
|
|
|
|
/// </summary>
|
2019-07-31 15:02:36 +02:00
|
|
|
|
[RegisterComponent]
|
2017-10-07 15:15:29 +02:00
|
|
|
|
public class TemperatureComponent : Component, ITemperatureComponent
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public override string Name => "Temperature";
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: should be programmatic instead of how it currently is
|
2018-09-09 15:34:43 +02:00
|
|
|
|
[ViewVariables]
|
2017-10-07 15:15:29 +02:00
|
|
|
|
public float CurrentTemperature { get; private set; } = PhysicalConstants.ZERO_CELCIUS;
|
|
|
|
|
|
|
|
|
|
|
|
float _fireDamageThreshold = 0;
|
|
|
|
|
|
float _fireDamageCoefficient = 1;
|
|
|
|
|
|
|
|
|
|
|
|
float _secondsSinceLastDamageUpdate = 0;
|
|
|
|
|
|
|
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
|
|
|
|
serializer.DataField(ref _fireDamageThreshold, "firedamagethreshold", 0);
|
|
|
|
|
|
serializer.DataField(ref _fireDamageCoefficient, "firedamagecoefficient", 1);
|
2017-10-07 15:15:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2018-07-26 14:26:19 -07:00
|
|
|
|
public void OnUpdate(float frameTime)
|
2017-10-07 15:15:29 +02:00
|
|
|
|
{
|
|
|
|
|
|
int fireDamage = (int)Math.Floor(Math.Max(0, CurrentTemperature - _fireDamageThreshold) / _fireDamageCoefficient);
|
|
|
|
|
|
|
|
|
|
|
|
_secondsSinceLastDamageUpdate += frameTime;
|
|
|
|
|
|
|
2020-02-13 15:57:40 +01:00
|
|
|
|
Owner.TryGetComponent(out DamageableComponent component);
|
2017-10-07 15:15:29 +02:00
|
|
|
|
|
|
|
|
|
|
while (_secondsSinceLastDamageUpdate >= 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
component?.TakeDamage(DamageType.Heat, fireDamage);
|
|
|
|
|
|
_secondsSinceLastDamageUpdate -= 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|