predict IgnitionSourceComponent (#36310)
* PREDICTION * comment * don't overwrite event args * totally not a web edit * intn't
This commit is contained in:
47
Content.Shared/IgnitionSource/SharedIgnitionSourceSystem.cs
Normal file
47
Content.Shared/IgnitionSource/SharedIgnitionSourceSystem.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Content.Shared.Item.ItemToggle.Components;
|
||||
using Content.Shared.Temperature;
|
||||
|
||||
namespace Content.Shared.IgnitionSource;
|
||||
|
||||
/// <summary>
|
||||
/// Ignites flammable gases when the ignition source is toggled on.
|
||||
/// Also makes the entity hot so that it can be used to ignite matchsticks, cigarettes ect.
|
||||
/// </summary>
|
||||
public abstract partial class SharedIgnitionSourceSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<IgnitionSourceComponent, IsHotEvent>(OnIsHot);
|
||||
SubscribeLocalEvent<ItemToggleHotComponent, ItemToggledEvent>(OnItemToggle);
|
||||
SubscribeLocalEvent<IgnitionSourceComponent, IgnitionEvent>(OnIgnitionEvent);
|
||||
}
|
||||
|
||||
private void OnIsHot(Entity<IgnitionSourceComponent> ent, ref IsHotEvent args)
|
||||
{
|
||||
args.IsHot |= ent.Comp.Ignited;
|
||||
}
|
||||
|
||||
private void OnItemToggle(Entity<ItemToggleHotComponent> ent, ref ItemToggledEvent args)
|
||||
{
|
||||
SetIgnited(ent.Owner, args.Activated);
|
||||
}
|
||||
|
||||
private void OnIgnitionEvent(Entity<IgnitionSourceComponent> ent, ref IgnitionEvent args)
|
||||
{
|
||||
SetIgnited((ent.Owner, ent.Comp), args.Ignite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simply sets the ignited field to the ignited param.
|
||||
/// </summary>
|
||||
public void SetIgnited(Entity<IgnitionSourceComponent?> ent, bool ignited = true)
|
||||
{
|
||||
if (!Resolve(ent, ref ent.Comp, false))
|
||||
return;
|
||||
|
||||
ent.Comp.Ignited = ignited;
|
||||
Dirty(ent, ent.Comp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user