Remove IStartCollide from flammable (#4314)

I ported some stuff to be ECS but didn't feel like porting the rest, sue me.
This commit is contained in:
metalgearsloth
2021-07-21 20:32:00 +10:00
committed by GitHub
parent cf1b6246da
commit e93692245e
2 changed files with 62 additions and 49 deletions

View File

@@ -0,0 +1,56 @@
using Content.Server.Atmos.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Dynamics;
namespace Content.Server.Atmos.EntitySystems
{
internal sealed class FlammableSystem : EntitySystem
{
// TODO: Port the rest of Flammable.
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FlammableComponent, StartCollideEvent>(HandleCollide);
}
private void HandleCollide(EntityUid uid, FlammableComponent component, StartCollideEvent args)
{
if (!args.OtherFixture.Body.Owner.TryGetComponent(out FlammableComponent? otherFlammable))
return;
if (!component.FireSpread || !otherFlammable.FireSpread)
return;
if (component.OnFire)
{
if (otherFlammable.OnFire)
{
var fireSplit = (component.FireStacks + otherFlammable.FireStacks) / 2;
component.FireStacks = fireSplit;
otherFlammable.FireStacks = fireSplit;
}
else
{
component.FireStacks /= 2;
otherFlammable.FireStacks += component.FireStacks;
Ignite(otherFlammable);
}
} else if (otherFlammable.OnFire)
{
otherFlammable.FireStacks /= 2;
component.FireStacks += otherFlammable.FireStacks;
Ignite(component);
}
}
internal void Ignite(FlammableComponent component)
{
if (component.FireStacks > 0 && !component.OnFire)
{
component.OnFire = true;
}
component.UpdateAppearance();
}
}
}