Skip to content

Commit

Permalink
Fix collisions passing firestacks between mobs (#9324)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirrorcult authored Jul 5, 2022
1 parent 407514f commit 33e1c77
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Content.Server/Atmos/Components/FlammableComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Damage;
using Robust.Shared.Physics.Collision.Shapes;

namespace Content.Server.Atmos.Components
{
Expand Down Expand Up @@ -28,5 +29,11 @@ public sealed class FlammableComponent : Component
[DataField("damage", required: true)]
[ViewVariables(VVAccess.ReadWrite)]
public DamageSpecifier Damage = new(); // Empty by default, we don't want any funny NREs.

/// <summary>
/// Used for the fixture created to handle passing firestacks when two flammable objects collide.
/// </summary>
[DataField("flammableCollisionShape")]
public IPhysShape FlammableCollisionShape = new PhysShapeCircle() { Radius = 0.35f };
}
}
35 changes: 31 additions & 4 deletions Content.Server/Atmos/EntitySystems/FlammableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Interaction;
using Content.Shared.Physics;
using Content.Shared.Popups;
using Content.Shared.Temperature;
using Robust.Server.GameObjects;
Expand All @@ -32,23 +33,25 @@ internal sealed class FlammableSystem : EntitySystem
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly FixtureSystem _fixture = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;

private const float MinimumFireStacks = -10f;
private const float MaximumFireStacks = 20f;
private const float UpdateTime = 1f;

private const float MinIgnitionTemperature = 373.15f;
public const string FlammableFixtureID = "flammable";

private float _timer = 0f;

private Dictionary<FlammableComponent, float> _fireEvents = new();

// TODO: Port the rest of Flammable.
public override void Initialize()
{
UpdatesAfter.Add(typeof(AtmosphereSystem));

SubscribeLocalEvent<FlammableComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<FlammableComponent, InteractUsingEvent>(OnInteractUsingEvent);
SubscribeLocalEvent<FlammableComponent, StartCollideEvent>(OnCollideEvent);
SubscribeLocalEvent<FlammableComponent, IsHotEvent>(OnIsHotEvent);
Expand All @@ -67,7 +70,7 @@ private void OnMeleeHit(EntityUid uid, IgniteOnMeleeHitComponent component, Mele
flammable.FireStacks += component.FireStacks;
Ignite(entity, flammable);
}

}

private void IgniteOnCollide(EntityUid uid, IgniteOnCollideComponent component, StartCollideEvent args)
Expand All @@ -81,13 +84,30 @@ private void IgniteOnCollide(EntityUid uid, IgniteOnCollideComponent component,
Ignite(otherFixture, flammable);
}

private void OnMapInit(EntityUid uid, FlammableComponent component, MapInitEvent args)
{
// Sets up a fixture for flammable collisions.
// TODO: Should this be generalized into a general non-hard 'effects' fixture or something? I can't think of other use cases for it.
// This doesn't seem great either (lots more collisions generated) but there isn't a better way to solve it either that I can think of.

if (!TryComp<PhysicsComponent>(uid, out var body))
return;

_fixture.TryCreateFixture(body, new Fixture(body, component.FlammableCollisionShape)
{
Hard = false,
ID = FlammableFixtureID,
CollisionMask = (int) CollisionGroup.FullTileLayer
});
}

private void OnInteractUsingEvent(EntityUid uid, FlammableComponent flammable, InteractUsingEvent args)
{
if (args.Handled)
return;

var isHotEvent = new IsHotEvent();
RaiseLocalEvent(args.Used, isHotEvent, false);
RaiseLocalEvent(args.Used, isHotEvent);

if (!isHotEvent.IsHot)
return;
Expand All @@ -99,6 +119,12 @@ private void OnInteractUsingEvent(EntityUid uid, FlammableComponent flammable, I
private void OnCollideEvent(EntityUid uid, FlammableComponent flammable, StartCollideEvent args)
{
var otherUid = args.OtherFixture.Body.Owner;

// Normal hard collisions, though this isn't generally possible since most flammable things are mobs
// which don't collide with one another, shouldn't work here.
if (args.OtherFixture.ID != FlammableFixtureID && args.OurFixture.ID != FlammableFixtureID)
return;

if (!EntityManager.TryGetComponent(otherUid, out FlammableComponent? otherFlammable))
return;

Expand All @@ -119,7 +145,8 @@ private void OnCollideEvent(EntityUid uid, FlammableComponent flammable, StartCo
otherFlammable.FireStacks += flammable.FireStacks;
Ignite(otherUid, otherFlammable);
}
} else if (otherFlammable.OnFire)
}
else if (otherFlammable.OnFire)
{
otherFlammable.FireStacks /= 2;
flammable.FireStacks += otherFlammable.FireStacks;
Expand Down

0 comments on commit 33e1c77

Please sign in to comment.