Refactor Flammable to be ECS. (#4671)
- Refactor IHotItem into IsHotEvent. - Refactor IFireAct into TileFireEvent.
This commit is contained in:
committed by
GitHub
parent
9bde39c533
commit
6cea9cb973
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Atmos.Components;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Atmos.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Shared.Alert;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Alert.Click
|
||||
@@ -16,7 +18,7 @@ namespace Content.Server.Alert.Click
|
||||
{
|
||||
if (args.Player.TryGetComponent(out FlammableComponent? flammable))
|
||||
{
|
||||
flammable.Resist();
|
||||
EntitySystem.Get<FlammableSystem>().Resist(args.Player.Uid, flammable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Atmos.Components
|
||||
{
|
||||
// TODO: Kill this. With fire.
|
||||
/// <summary>
|
||||
/// Represents that entity can be exposed to Atmos
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class AtmosExposedComponent
|
||||
: Component
|
||||
public class AtmosExposedComponent : Component
|
||||
{
|
||||
public override string Name => "AtmosExposed";
|
||||
|
||||
@@ -20,9 +20,6 @@ namespace Content.Server.Atmos.Components
|
||||
[ViewVariables]
|
||||
[ComponentDependency] private readonly BarotraumaComponent? _barotraumaComponent = null;
|
||||
|
||||
[ViewVariables]
|
||||
[ComponentDependency] private readonly FlammableComponent? _flammableComponent = null;
|
||||
|
||||
public void Update(GasMixture air, float frameDelta, AtmosphereSystem atmosphereSystem)
|
||||
{
|
||||
if (_temperatureComponent != null)
|
||||
@@ -35,8 +32,6 @@ namespace Content.Server.Atmos.Components
|
||||
}
|
||||
|
||||
_barotraumaComponent?.Update(air.Pressure);
|
||||
|
||||
_flammableComponent?.Update(air);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Alert;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Atmos.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Temperature;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Atmos.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class FlammableComponent : SharedFlammableComponent, IFireAct, IInteractUsing
|
||||
public class FlammableComponent : Component
|
||||
{
|
||||
private bool _resisting = false;
|
||||
private readonly List<EntityUid> _collided = new();
|
||||
public override string Name => "Flammable";
|
||||
|
||||
[ViewVariables]
|
||||
public bool Resisting = false;
|
||||
|
||||
[ViewVariables]
|
||||
public readonly List<EntityUid> Collided = new();
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool OnFire { get; set; }
|
||||
@@ -45,136 +35,5 @@ namespace Content.Server.Atmos.Components
|
||||
[DataField("damage", required: true)]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public DamageSpecifier Damage = default!;
|
||||
|
||||
public void Extinguish()
|
||||
{
|
||||
if (!OnFire) return;
|
||||
OnFire = false;
|
||||
FireStacks = 0;
|
||||
|
||||
_collided.Clear();
|
||||
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public void AdjustFireStacks(float relativeFireStacks)
|
||||
{
|
||||
FireStacks = MathF.Min(MathF.Max(-10f, FireStacks + relativeFireStacks), 20f);
|
||||
if (OnFire && FireStacks <= 0)
|
||||
Extinguish();
|
||||
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public void Update(GasMixture air)
|
||||
{
|
||||
// Slowly dry ourselves off if wet.
|
||||
if (FireStacks < 0)
|
||||
{
|
||||
FireStacks = MathF.Min(0, FireStacks + 1);
|
||||
}
|
||||
|
||||
Owner.TryGetComponent(out ServerAlertsComponent? status);
|
||||
|
||||
if (!OnFire)
|
||||
{
|
||||
status?.ClearAlert(AlertType.Fire);
|
||||
return;
|
||||
}
|
||||
|
||||
status?.ShowAlert(AlertType.Fire);
|
||||
|
||||
if (FireStacks > 0)
|
||||
{
|
||||
if (Owner.TryGetComponent(out TemperatureComponent? temp))
|
||||
{
|
||||
temp.ReceiveHeat(200 * FireStacks);
|
||||
}
|
||||
|
||||
// TODO ATMOS Fire resistance from armor
|
||||
var damageScale = Math.Min((int) (FireStacks * 2.5f), 10);
|
||||
EntitySystem.Get<DamageableSystem>().TryChangeDamage(Owner.Uid, Damage * damageScale);
|
||||
|
||||
AdjustFireStacks(-0.1f * (_resisting ? 10f : 1f));
|
||||
}
|
||||
else
|
||||
{
|
||||
Extinguish();
|
||||
return;
|
||||
}
|
||||
|
||||
// If we're in an oxygenless environment, put the fire out.
|
||||
if (air.GetMoles(Gas.Oxygen) < 1f)
|
||||
{
|
||||
Extinguish();
|
||||
return;
|
||||
}
|
||||
|
||||
EntitySystem.Get<AtmosphereSystem>().HotspotExpose(Owner.Transform.Coordinates, 700f, 50f, true);
|
||||
|
||||
var physics = Owner.GetComponent<IPhysBody>();
|
||||
|
||||
foreach (var uid in _collided.ToArray())
|
||||
{
|
||||
if (!uid.IsValid() || !Owner.EntityManager.EntityExists(uid))
|
||||
{
|
||||
_collided.Remove(uid);
|
||||
continue;
|
||||
}
|
||||
|
||||
var entity = Owner.EntityManager.GetEntity(uid);
|
||||
var otherPhysics = entity.GetComponent<IPhysBody>();
|
||||
|
||||
if (!physics.GetWorldAABB().Intersects(otherPhysics.GetWorldAABB()))
|
||||
{
|
||||
_collided.Remove(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateAppearance()
|
||||
{
|
||||
if (Owner.Deleted || !Owner.TryGetComponent(out AppearanceComponent? appearanceComponent)) return;
|
||||
appearanceComponent.SetData(FireVisuals.OnFire, OnFire);
|
||||
appearanceComponent.SetData(FireVisuals.FireStacks, FireStacks);
|
||||
}
|
||||
|
||||
public void FireAct(float temperature, float volume)
|
||||
{
|
||||
AdjustFireStacks(3);
|
||||
EntitySystem.Get<FlammableSystem>().Ignite(this);
|
||||
}
|
||||
|
||||
// This needs some improvements...
|
||||
public void Resist()
|
||||
{
|
||||
if (!OnFire || !EntitySystem.Get<ActionBlockerSystem>().CanInteract(Owner) || _resisting || !Owner.TryGetComponent(out StunnableComponent? stunnable)) return;
|
||||
|
||||
_resisting = true;
|
||||
|
||||
Owner.PopupMessage(Loc.GetString("flammable-component-resist-message"));
|
||||
stunnable.Paralyze(2f);
|
||||
|
||||
Owner.SpawnTimer(2000, () =>
|
||||
{
|
||||
_resisting = false;
|
||||
FireStacks -= 3f;
|
||||
UpdateAppearance();
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
foreach (var hotItem in eventArgs.Using.GetAllComponents<IHotItem>())
|
||||
{
|
||||
if (hotItem.IsCurrentlyHot())
|
||||
{
|
||||
EntitySystem.Get<FlammableSystem>().Ignite(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.Reactions;
|
||||
using Content.Server.Coordinates.Helpers;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
public partial class AtmosphereSystem
|
||||
{
|
||||
[Dependency] private readonly GridTileLookupSystem _gridtileLookupSystem = default!;
|
||||
|
||||
private void ProcessHotspot(GridAtmosphereComponent gridAtmosphere, TileAtmosphere tile)
|
||||
{
|
||||
if (!tile.Hotspot.Valid)
|
||||
@@ -137,14 +139,11 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
Merge(tile.Air, affected);
|
||||
}
|
||||
|
||||
var tileRef = tile.GridIndices.GetTileRef(tile.GridIndex, _mapManager);
|
||||
var fireEvent = new TileFireEvent(tile.Hotspot.Temperature, tile.Hotspot.Volume);
|
||||
|
||||
foreach (var entity in tileRef.GetEntitiesInTileFast())
|
||||
foreach (var entity in _gridtileLookupSystem.GetEntitiesIntersecting(tile.GridIndex, tile.GridIndices))
|
||||
{
|
||||
foreach (var fireAct in entity.GetAllComponents<IFireAct>())
|
||||
{
|
||||
fireAct.FireAct(tile.Hotspot.Temperature, tile.Hotspot.Volume);
|
||||
}
|
||||
RaiseLocalEvent(entity.Uid, fireEvent, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,251 @@
|
||||
using System;
|
||||
using Content.Server.Alert;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Temperature;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
internal sealed class FlammableSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
||||
|
||||
private const float MinimumFireStacks = -10f;
|
||||
private const float MaximumFireStacks = 20f;
|
||||
private const float UpdateTime = 1f;
|
||||
|
||||
private float _timer = 0f;
|
||||
|
||||
// TODO: Port the rest of Flammable.
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<FlammableComponent, StartCollideEvent>(HandleCollide);
|
||||
SubscribeLocalEvent<FlammableComponent, InteractUsingEvent>(OnInteractUsingEvent);
|
||||
SubscribeLocalEvent<FlammableComponent, StartCollideEvent>(OnCollideEvent);
|
||||
SubscribeLocalEvent<FlammableComponent, IsHotEvent>(OnIsHotEvent);
|
||||
SubscribeLocalEvent<FlammableComponent, TileFireEvent>(OnTileFireEvent);
|
||||
}
|
||||
|
||||
private void HandleCollide(EntityUid uid, FlammableComponent component, StartCollideEvent args)
|
||||
private void OnInteractUsingEvent(EntityUid uid, FlammableComponent flammable, InteractUsingEvent args)
|
||||
{
|
||||
if (!args.OtherFixture.Body.Owner.TryGetComponent(out FlammableComponent? otherFlammable))
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!component.FireSpread || !otherFlammable.FireSpread)
|
||||
var isHotEvent = new IsHotEvent();
|
||||
RaiseLocalEvent(args.Used.Uid, isHotEvent, false);
|
||||
|
||||
if (!isHotEvent.IsHot)
|
||||
return;
|
||||
|
||||
if (component.OnFire)
|
||||
Ignite(uid, flammable);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnCollideEvent(EntityUid uid, FlammableComponent flammable, StartCollideEvent args)
|
||||
{
|
||||
var otherUid = args.OtherFixture.Body.Owner.Uid;
|
||||
if (!ComponentManager.TryGetComponent(otherUid, out FlammableComponent? otherFlammable))
|
||||
return;
|
||||
|
||||
if (!flammable.FireSpread || !otherFlammable.FireSpread)
|
||||
return;
|
||||
|
||||
if (flammable.OnFire)
|
||||
{
|
||||
if (otherFlammable.OnFire)
|
||||
{
|
||||
var fireSplit = (component.FireStacks + otherFlammable.FireStacks) / 2;
|
||||
component.FireStacks = fireSplit;
|
||||
var fireSplit = (flammable.FireStacks + otherFlammable.FireStacks) / 2;
|
||||
flammable.FireStacks = fireSplit;
|
||||
otherFlammable.FireStacks = fireSplit;
|
||||
}
|
||||
else
|
||||
{
|
||||
component.FireStacks /= 2;
|
||||
otherFlammable.FireStacks += component.FireStacks;
|
||||
Ignite(otherFlammable);
|
||||
flammable.FireStacks /= 2;
|
||||
otherFlammable.FireStacks += flammable.FireStacks;
|
||||
Ignite(otherUid, otherFlammable);
|
||||
}
|
||||
} else if (otherFlammable.OnFire)
|
||||
{
|
||||
otherFlammable.FireStacks /= 2;
|
||||
component.FireStacks += otherFlammable.FireStacks;
|
||||
Ignite(component);
|
||||
flammable.FireStacks += otherFlammable.FireStacks;
|
||||
Ignite(uid, flammable);
|
||||
}
|
||||
}
|
||||
|
||||
internal void Ignite(FlammableComponent component)
|
||||
private void OnIsHotEvent(EntityUid uid, FlammableComponent flammable, IsHotEvent args)
|
||||
{
|
||||
if (component.FireStacks > 0 && !component.OnFire)
|
||||
{
|
||||
component.OnFire = true;
|
||||
args.IsHot = flammable.OnFire;
|
||||
}
|
||||
|
||||
component.UpdateAppearance();
|
||||
private void OnTileFireEvent(EntityUid uid, FlammableComponent flammable, TileFireEvent args)
|
||||
{
|
||||
AdjustFireStacks(uid, 3, flammable);
|
||||
Ignite(uid, flammable);
|
||||
}
|
||||
|
||||
public void UpdateAppearance(EntityUid uid, FlammableComponent? flammable = null, AppearanceComponent? appearance = null)
|
||||
{
|
||||
if (!Resolve(uid, ref flammable, ref appearance))
|
||||
return;
|
||||
|
||||
appearance.SetData(FireVisuals.OnFire, flammable.OnFire);
|
||||
appearance.SetData(FireVisuals.FireStacks, flammable.FireStacks);
|
||||
}
|
||||
|
||||
public void AdjustFireStacks(EntityUid uid, float relativeFireStacks, FlammableComponent? flammable = null)
|
||||
{
|
||||
if (!Resolve(uid, ref flammable))
|
||||
return;
|
||||
|
||||
flammable.FireStacks = MathF.Min(MathF.Max(MinimumFireStacks, flammable.FireStacks + relativeFireStacks), MaximumFireStacks);
|
||||
|
||||
if (flammable.OnFire && flammable.FireStacks <= 0)
|
||||
Extinguish(uid, flammable);
|
||||
|
||||
UpdateAppearance(uid, flammable);
|
||||
}
|
||||
|
||||
public void Extinguish(EntityUid uid, FlammableComponent? flammable = null)
|
||||
{
|
||||
if (!Resolve(uid, ref flammable))
|
||||
return;
|
||||
|
||||
if (!flammable.OnFire)
|
||||
return;
|
||||
|
||||
flammable.OnFire = false;
|
||||
flammable.FireStacks = 0;
|
||||
|
||||
flammable.Collided.Clear();
|
||||
|
||||
UpdateAppearance(uid, flammable);
|
||||
}
|
||||
|
||||
public void Ignite(EntityUid uid, FlammableComponent? flammable = null)
|
||||
{
|
||||
if (!Resolve(uid, ref flammable))
|
||||
return;
|
||||
|
||||
if (flammable.FireStacks > 0 && !flammable.OnFire)
|
||||
{
|
||||
flammable.OnFire = true;
|
||||
}
|
||||
|
||||
UpdateAppearance(uid, flammable);
|
||||
}
|
||||
|
||||
public void Resist(EntityUid uid, FlammableComponent? flammable = null, StunnableComponent? stunnable = null)
|
||||
{
|
||||
if (!Resolve(uid, ref flammable, ref stunnable))
|
||||
return;
|
||||
|
||||
if (!flammable.OnFire || !_actionBlockerSystem.CanInteract(flammable.Owner) || flammable.Resisting)
|
||||
return;
|
||||
|
||||
flammable.Resisting = true;
|
||||
|
||||
flammable.Owner.PopupMessage(Loc.GetString("flammable-component-resist-message"));
|
||||
stunnable.Paralyze(2f);
|
||||
|
||||
flammable.Owner.SpawnTimer(2000, () =>
|
||||
{
|
||||
flammable.Resisting = false;
|
||||
flammable.FireStacks -= 3f;
|
||||
UpdateAppearance(uid, flammable);
|
||||
});
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
_timer += frameTime;
|
||||
|
||||
if (_timer < UpdateTime)
|
||||
return;
|
||||
|
||||
_timer -= UpdateTime;
|
||||
|
||||
// TODO: This needs cleanup to take off the crust from TemperatureComponent and shit.
|
||||
foreach (var (flammable, physics, transform) in ComponentManager.EntityQuery<FlammableComponent, PhysicsComponent, ITransformComponent>())
|
||||
{
|
||||
var uid = flammable.Owner.Uid;
|
||||
|
||||
// Slowly dry ourselves off if wet.
|
||||
if (flammable.FireStacks < 0)
|
||||
{
|
||||
flammable.FireStacks = MathF.Min(0, flammable.FireStacks + 1);
|
||||
}
|
||||
|
||||
flammable.Owner.TryGetComponent(out ServerAlertsComponent? status);
|
||||
|
||||
if (!flammable.OnFire)
|
||||
{
|
||||
status?.ClearAlert(AlertType.Fire);
|
||||
return;
|
||||
}
|
||||
|
||||
status?.ShowAlert(AlertType.Fire);
|
||||
|
||||
if (flammable.FireStacks > 0)
|
||||
{
|
||||
if (flammable.Owner.TryGetComponent(out TemperatureComponent? temp))
|
||||
{
|
||||
temp.ReceiveHeat(200 * flammable.FireStacks);
|
||||
}
|
||||
|
||||
// TODO ATMOS Fire resistance from armor
|
||||
var damageScale = Math.Min((int) (flammable.FireStacks * 2.5f), 10);
|
||||
_damageableSystem.TryChangeDamage(flammable.Owner.Uid, flammable.Damage * damageScale);
|
||||
|
||||
AdjustFireStacks(uid, -0.1f * (flammable.Resisting ? 10f : 1f), flammable);
|
||||
}
|
||||
else
|
||||
{
|
||||
Extinguish(uid, flammable);
|
||||
return;
|
||||
}
|
||||
|
||||
var air = _atmosphereSystem.GetTileMixture(transform.Coordinates);
|
||||
|
||||
// If we're in an oxygenless environment, put the fire out.
|
||||
if (air == null || air.GetMoles(Gas.Oxygen) < 1f)
|
||||
{
|
||||
Extinguish(uid, flammable);
|
||||
return;
|
||||
}
|
||||
|
||||
_atmosphereSystem.HotspotExpose(transform.Coordinates, 700f, 50f, true);
|
||||
|
||||
foreach (var otherUid in flammable.Collided.ToArray())
|
||||
{
|
||||
if (!otherUid.IsValid() || !EntityManager.EntityExists(otherUid))
|
||||
{
|
||||
flammable.Collided.Remove(otherUid);
|
||||
continue;
|
||||
}
|
||||
|
||||
var otherPhysics = ComponentManager.GetComponent<IPhysBody>(uid);
|
||||
|
||||
// TODO: Sloth, please save our souls!
|
||||
if (!physics.GetWorldAABB().Intersects(otherPhysics.GetWorldAABB()))
|
||||
{
|
||||
flammable.Collided.Remove(otherUid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Content.Server.Atmos
|
||||
{
|
||||
public interface IFireAct
|
||||
{
|
||||
void FireAct(float temperature, float volume);
|
||||
}
|
||||
}
|
||||
19
Content.Server/Atmos/TileFireEvent.cs
Normal file
19
Content.Server/Atmos/TileFireEvent.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Atmos
|
||||
{
|
||||
/// <summary>
|
||||
/// Event raised directed to an entity when it is standing on a tile that's on fire.
|
||||
/// </summary>
|
||||
public class TileFireEvent : EntityEventArgs
|
||||
{
|
||||
public float Temperature { get; }
|
||||
public float Volume { get; }
|
||||
|
||||
public TileFireEvent(float temperature, float volume)
|
||||
{
|
||||
Temperature = temperature;
|
||||
Volume = volume;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using JetBrains.Annotations;
|
||||
@@ -20,8 +21,9 @@ namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||
{
|
||||
if (!entity.TryGetComponent(out FlammableComponent? flammable) || !_reagents.Contains(reagent.ID)) return;
|
||||
|
||||
flammable.Extinguish();
|
||||
flammable.AdjustFireStacks(-1.5f);
|
||||
var flammableSystem = EntitySystem.Get<FlammableSystem>();
|
||||
flammableSystem.Extinguish(entity.Uid, flammable);
|
||||
flammableSystem.AdjustFireStacks(entity.Uid, -1.5f, flammable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using JetBrains.Annotations;
|
||||
@@ -20,7 +21,7 @@ namespace Content.Server.Chemistry.ReagentEntityReactions
|
||||
{
|
||||
if (!entity.TryGetComponent(out FlammableComponent? flammable) || !_reagents.Contains(reagent.ID)) return;
|
||||
|
||||
flammable.AdjustFireStacks(volume.Float() / 10f);
|
||||
EntitySystem.Get<FlammableSystem>().AdjustFireStacks(entity.Uid, volume.Float() / 10f, flammable);
|
||||
source?.RemoveReagent(reagent.ID, volume);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Server.Nutrition.EntitySystems;
|
||||
using Content.Server.Stunnable.Components;
|
||||
@@ -81,7 +82,7 @@ namespace Content.Server.Damage
|
||||
|
||||
if (target.TryGetComponent(out FlammableComponent? flammable))
|
||||
{
|
||||
flammable.Extinguish();
|
||||
EntitySystem.Get<FlammableSystem>().Extinguish(target.Uid, flammable);
|
||||
}
|
||||
|
||||
if (target.TryGetComponent(out CreamPiedComponent? creamPied))
|
||||
|
||||
@@ -12,9 +12,8 @@ using Robust.Shared.ViewVariables;
|
||||
namespace Content.Server.Light.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IHotItem))]
|
||||
[Friend(typeof(MatchstickSystem))]
|
||||
public class MatchstickComponent : Component, IHotItem
|
||||
public class MatchstickComponent : Component
|
||||
{
|
||||
public override string Name => "Matchstick";
|
||||
|
||||
@@ -41,10 +40,5 @@ namespace Content.Server.Light.Components
|
||||
/// </summary>
|
||||
[ComponentDependency]
|
||||
public readonly PointLightComponent? PointLightComponent = default!;
|
||||
|
||||
bool IHotItem.IsCurrentlyHot()
|
||||
{
|
||||
return CurrentState == SharedBurningStates.Lit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace Content.Server.Light.EntitySystems
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<MatchstickComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<MatchstickComponent, IsHotEvent>(OnIsHotEvent);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -40,14 +41,22 @@ namespace Content.Server.Light.EntitySystems
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, MatchstickComponent component, InteractUsingEvent args)
|
||||
{
|
||||
if (!args.Handled
|
||||
&& args.Used.TryGetComponent<IHotItem>(out var hotItem)
|
||||
&& hotItem.IsCurrentlyHot()
|
||||
&& component.CurrentState == SharedBurningStates.Unlit)
|
||||
{
|
||||
if (args.Handled || component.CurrentState != SharedBurningStates.Unlit)
|
||||
return;
|
||||
|
||||
var isHotEvent = new IsHotEvent();
|
||||
RaiseLocalEvent(args.Used.Uid, isHotEvent, false);
|
||||
|
||||
if (!isHotEvent.IsHot)
|
||||
return;
|
||||
|
||||
Ignite(component, args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnIsHotEvent(EntityUid uid, MatchstickComponent component, IsHotEvent args)
|
||||
{
|
||||
args.IsHot = component.CurrentState == SharedBurningStates.Lit;
|
||||
}
|
||||
|
||||
public void Ignite(MatchstickComponent component, IEntity user)
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.Nutrition.Components
|
||||
/// TODO: Allow suicide via excessive Smoking
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class SmokingComponent : Component, IInteractUsing, IHotItem
|
||||
public class SmokingComponent : Component, IInteractUsing
|
||||
{
|
||||
public override string Name => "Smoking";
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Content.Server.Nutrition.Components
|
||||
//private float _temperature = 673.15f;
|
||||
|
||||
[ViewVariables]
|
||||
private SharedBurningStates CurrentState
|
||||
public SharedBurningStates CurrentState
|
||||
{
|
||||
get => _currentState;
|
||||
set
|
||||
@@ -76,25 +76,23 @@ namespace Content.Server.Nutrition.Components
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: ECS this method and component.
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.Using.TryGetComponent(out IHotItem? lighter)
|
||||
&& lighter.IsCurrentlyHot()
|
||||
&& CurrentState == SharedBurningStates.Unlit
|
||||
)
|
||||
{
|
||||
if (CurrentState != SharedBurningStates.Unlit)
|
||||
return false;
|
||||
|
||||
var isHotEvent = new IsHotEvent();
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(eventArgs.Using.Uid, isHotEvent, false);
|
||||
|
||||
if (!isHotEvent.IsHot)
|
||||
return false;
|
||||
|
||||
CurrentState = SharedBurningStates.Lit;
|
||||
// TODO More complex handling of cigar consumption
|
||||
Owner.SpawnTimer(_duration * 1000, () => CurrentState = SharedBurningStates.Burnt);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IHotItem.IsCurrentlyHot()
|
||||
{
|
||||
return _currentState == SharedBurningStates.Lit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
Content.Server/Nutrition/EntitySystems/SmokingSystem.cs
Normal file
20
Content.Server/Nutrition/EntitySystems/SmokingSystem.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Shared.Smoking;
|
||||
using Content.Shared.Temperature;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Nutrition.EntitySystems
|
||||
{
|
||||
public class SmokingSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<SmokingComponent, IsHotEvent>(OnIsHotEvent);
|
||||
}
|
||||
|
||||
private void OnIsHotEvent(EntityUid uid, SmokingComponent component, IsHotEvent args)
|
||||
{
|
||||
args.IsHot = component.CurrentState == SharedBurningStates.Lit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,8 @@ namespace Content.Server.Tools.Components
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(ToolComponent))]
|
||||
[ComponentReference(typeof(IToolComponent))]
|
||||
[ComponentReference(typeof(IHotItem))]
|
||||
[NetworkedComponent()]
|
||||
public class WelderComponent : ToolComponent, IUse, ISuicideAct, IHotItem, IAfterInteract
|
||||
public class WelderComponent : ToolComponent, IUse, ISuicideAct, IAfterInteract
|
||||
{
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
|
||||
@@ -98,11 +97,6 @@ namespace Content.Server.Tools.Components
|
||||
}
|
||||
}
|
||||
|
||||
bool IHotItem.IsCurrentlyHot()
|
||||
{
|
||||
return WelderLit;
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using Content.Server.Tools.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Temperature;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
@@ -21,9 +22,15 @@ namespace Content.Server.Tools
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<WelderComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
SubscribeLocalEvent<WelderComponent, IsHotEvent>(OnIsHotEvent);
|
||||
SubscribeLocalEvent<WelderComponent, ExaminedEvent>(OnExamine);
|
||||
}
|
||||
|
||||
private void OnIsHotEvent(EntityUid uid, WelderComponent component, IsHotEvent args)
|
||||
{
|
||||
args.IsHot = component.WelderLit;
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, WelderComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (component.WelderLit)
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Atmos.Components
|
||||
{
|
||||
public class SharedFlammableComponent : Component
|
||||
{
|
||||
public override string Name => "Flammable";
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum FireVisuals
|
||||
{
|
||||
OnFire,
|
||||
FireStacks,
|
||||
}
|
||||
}
|
||||
12
Content.Shared/Atmos/FireVisuals.cs
Normal file
12
Content.Shared/Atmos/FireVisuals.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Atmos
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public enum FireVisuals
|
||||
{
|
||||
OnFire,
|
||||
FireStacks,
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using Robust.Shared.Analyzers;
|
||||
|
||||
namespace Content.Shared.Temperature
|
||||
{
|
||||
/// <summary>
|
||||
/// This interface gives components hot quality when they are used.
|
||||
/// E.g if you hold a lit match or a welder then it will be hot,
|
||||
/// presuming match is lit or the welder is on respectively.
|
||||
/// However say you hold an item that is always hot like lava rock,
|
||||
/// it will be permanently hot.
|
||||
/// </summary>
|
||||
[RequiresExplicitImplementation]
|
||||
public interface IHotItem
|
||||
{
|
||||
bool IsCurrentlyHot();
|
||||
}
|
||||
}
|
||||
14
Content.Shared/Temperature/IsHotEvent.cs
Normal file
14
Content.Shared/Temperature/IsHotEvent.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Temperature
|
||||
{
|
||||
/// <summary>
|
||||
/// Directed event raised on entities to query whether they're "hot" or not.
|
||||
/// For example, a lit welder or matchstick would be hot, etc.
|
||||
/// </summary>
|
||||
public class IsHotEvent : EntityEventArgs
|
||||
{
|
||||
public bool IsHot { get; set; } = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user