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

@@ -18,24 +18,22 @@ using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Server.Atmos.Components namespace Content.Server.Atmos.Components
{ {
[RegisterComponent] [RegisterComponent]
public class FlammableComponent : SharedFlammableComponent, IStartCollide, IFireAct, IInteractUsing public class FlammableComponent : SharedFlammableComponent, IFireAct, IInteractUsing
{ {
private bool _resisting = false; private bool _resisting = false;
private readonly List<EntityUid> _collided = new(); private readonly List<EntityUid> _collided = new();
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public bool OnFire { get; private set; } public bool OnFire { get; set; }
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public float FireStacks { get; private set; } public float FireStacks { get; set; }
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("fireSpread")] [DataField("fireSpread")]
@@ -45,17 +43,6 @@ namespace Content.Server.Atmos.Components
[DataField("canResistFire")] [DataField("canResistFire")]
public bool CanResistFire { get; private set; } = false; public bool CanResistFire { get; private set; } = false;
public void Ignite()
{
if (FireStacks > 0 && !OnFire)
{
OnFire = true;
}
UpdateAppearance();
}
public void Extinguish() public void Extinguish()
{ {
if (!OnFire) return; if (!OnFire) return;
@@ -145,37 +132,7 @@ namespace Content.Server.Atmos.Components
} }
} }
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold) public void UpdateAppearance()
{
if (!otherFixture.Body.Owner.TryGetComponent(out FlammableComponent? otherFlammable))
return;
if (!FireSpread || !otherFlammable.FireSpread)
return;
if (OnFire)
{
if (otherFlammable.OnFire)
{
var fireSplit = (FireStacks + otherFlammable.FireStacks) / 2;
FireStacks = fireSplit;
otherFlammable.FireStacks = fireSplit;
}
else
{
FireStacks /= 2;
otherFlammable.FireStacks += FireStacks;
otherFlammable.Ignite();
}
} else if (otherFlammable.OnFire)
{
otherFlammable.FireStacks /= 2;
FireStacks += otherFlammable.FireStacks;
Ignite();
}
}
private void UpdateAppearance()
{ {
if (Owner.Deleted || !Owner.TryGetComponent(out AppearanceComponent? appearanceComponent)) return; if (Owner.Deleted || !Owner.TryGetComponent(out AppearanceComponent? appearanceComponent)) return;
appearanceComponent.SetData(FireVisuals.OnFire, OnFire); appearanceComponent.SetData(FireVisuals.OnFire, OnFire);
@@ -185,7 +142,7 @@ namespace Content.Server.Atmos.Components
public void FireAct(float temperature, float volume) public void FireAct(float temperature, float volume)
{ {
AdjustFireStacks(3); AdjustFireStacks(3);
Ignite(); EntitySystem.Get<FlammableSystem>().Ignite(this);
} }
// This needs some improvements... // This needs some improvements...
@@ -212,7 +169,7 @@ namespace Content.Server.Atmos.Components
{ {
if (hotItem.IsCurrentlyHot()) if (hotItem.IsCurrentlyHot())
{ {
Ignite(); EntitySystem.Get<FlammableSystem>().Ignite(this);
return true; return true;
} }
} }

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();
}
}
}