Fire damage (#2024)
* Moved the uplink creation code to the PresetSuspicion.Start method to ensure uplink created when we give the traitor role Moved the starting TC balance to cvars * Added component to handle interaction with Atmospheric system Added damage from high and cold temperature * renamed AtmoExposable to AtmosExposed moved AtmosExposed updates to its own system refactored TemperatureComponent renamed fire to heat added null check for Air added self-heating and self-cooling to body system * small refactoring for checking on airless tile in MetabolismComponent * Added component to handle interaction with Atmospheric system Added damage from high and cold temperature * renamed AtmoExposable to AtmosExposed moved AtmosExposed updates to its own system refactored TemperatureComponent renamed fire to heat added null check for Air added self-heating and self-cooling to body system * small refactoring for checking on airless tile in MetabolismComponent * Removed Pressure property from BarotraumaComponent Changed CanShiver method to match style of other CanX method in ActionBlockerSystem * Merged EntityCoordinates and changed components to reflect the change * Fix typo * Wrapped string to Loc.GetString Added CanSweat Refactored dead state check
This commit is contained in:
@@ -1,61 +1,103 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
using Content.Shared.Maths;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Temperature
|
||||
{
|
||||
public interface ITemperatureComponent : IComponent
|
||||
{
|
||||
float CurrentTemperature { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles changing temperature,
|
||||
/// informing others of the current temperature,
|
||||
/// and taking fire damage from high temperature.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class TemperatureComponent : Component, ITemperatureComponent
|
||||
public class TemperatureComponent : Component
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Temperature";
|
||||
|
||||
//TODO: should be programmatic instead of how it currently is
|
||||
[ViewVariables] public float CurrentTemperature { get; private set; } = PhysicalConstants.ZERO_CELCIUS;
|
||||
[ViewVariables] public float CurrentTemperature { get => _currentTemperature; set => _currentTemperature = value; }
|
||||
|
||||
float _fireDamageThreshold = 0;
|
||||
float _fireDamageCoefficient = 1;
|
||||
[ViewVariables] public float HeatDamageThreshold => _heatDamageThreshold;
|
||||
[ViewVariables] public float ColdDamageThreshold => _coldDamageThreshold;
|
||||
[ViewVariables] public float TempDamageCoefficient => _tempDamageCoefficient;
|
||||
[ViewVariables] public float HeatCapacity {
|
||||
get
|
||||
{
|
||||
if (Owner.TryGetComponent<ICollidableComponent>(out var physics))
|
||||
{
|
||||
return SpecificHeat * physics.Mass;
|
||||
}
|
||||
|
||||
float _secondsSinceLastDamageUpdate = 0;
|
||||
return Atmospherics.MinimumHeatCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables] public float SpecificHeat => _specificHeat;
|
||||
|
||||
private float _heatDamageThreshold;
|
||||
private float _coldDamageThreshold;
|
||||
private float _tempDamageCoefficient;
|
||||
private float _currentTemperature;
|
||||
private float _specificHeat;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _fireDamageThreshold, "firedamagethreshold", 0);
|
||||
serializer.DataField(ref _fireDamageCoefficient, "firedamagecoefficient", 1);
|
||||
serializer.DataField(ref _heatDamageThreshold, "heatDamageThreshold", 0);
|
||||
serializer.DataField(ref _coldDamageThreshold, "coldDamageThreshold", 0);
|
||||
serializer.DataField(ref _tempDamageCoefficient, "tempDamageCoefficient", 1);
|
||||
serializer.DataField(ref _currentTemperature, "currentTemperature", Atmospherics.T20C);
|
||||
serializer.DataField(ref _specificHeat, "specificHeat", Atmospherics.MinimumHeatCapacity);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void OnUpdate(float frameTime)
|
||||
public void Update()
|
||||
{
|
||||
var fireDamage =
|
||||
(int) Math.Floor(Math.Max(0, CurrentTemperature - _fireDamageThreshold) / _fireDamageCoefficient);
|
||||
|
||||
_secondsSinceLastDamageUpdate += frameTime;
|
||||
|
||||
Owner.TryGetComponent(out IDamageableComponent component);
|
||||
|
||||
while (_secondsSinceLastDamageUpdate >= 1)
|
||||
var tempDamage = 0;
|
||||
DamageType? damageType = null;
|
||||
if (CurrentTemperature >= _heatDamageThreshold)
|
||||
{
|
||||
component?.ChangeDamage(DamageType.Heat, fireDamage, false, null);
|
||||
_secondsSinceLastDamageUpdate -= 1;
|
||||
tempDamage = (int) Math.Floor((CurrentTemperature - _heatDamageThreshold) * _tempDamageCoefficient);
|
||||
damageType = DamageType.Heat;
|
||||
}
|
||||
else if (CurrentTemperature <= _coldDamageThreshold)
|
||||
{
|
||||
tempDamage = (int) Math.Floor((_coldDamageThreshold - CurrentTemperature) * _tempDamageCoefficient);
|
||||
damageType = DamageType.Cold;
|
||||
}
|
||||
|
||||
if (!damageType.HasValue) return;
|
||||
|
||||
if (!Owner.TryGetComponent(out IDamageableComponent component)) return;
|
||||
component.ChangeDamage(damageType.Value, tempDamage, false);
|
||||
Debug.Write($"Temp is: {CurrentTemperature}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forcefully give heat to this component
|
||||
/// </summary>
|
||||
/// <param name="heatAmount"></param>
|
||||
public void ReceiveHeat(float heatAmount)
|
||||
{
|
||||
CurrentTemperature += heatAmount / HeatCapacity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forcefully remove heat from this component
|
||||
/// </summary>
|
||||
/// <param name="heatAmount"></param>
|
||||
public void RemoveHeat(float heatAmount)
|
||||
{
|
||||
CurrentTemperature -= heatAmount / HeatCapacity;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user