Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collisions passing firestacks between mobs #9324

Merged
merged 2 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Comment on lines +89 to +91
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

area of note

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could add groups specifically for this so that they only collide with the other flammable fixtures and don't generate other collisions but like. that seems a lot ickier


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