ignition source refactor (#21044)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -35,21 +35,21 @@ public sealed class IgniteOnTriggerSystem : EntitySystem
|
|||||||
if (_timing.CurTime < comp.IgnitedUntil)
|
if (_timing.CurTime < comp.IgnitedUntil)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_source.SetIgnited(uid, false, source);
|
_source.SetIgnited((uid, source), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTrigger(EntityUid uid, IgniteOnTriggerComponent comp, TriggerEvent args)
|
private void OnTrigger(Entity<IgniteOnTriggerComponent> ent, ref TriggerEvent args)
|
||||||
{
|
{
|
||||||
// prevent spamming sound and ignition
|
// prevent spamming sound and ignition
|
||||||
TryComp<UseDelayComponent>(uid, out var delay);
|
TryComp<UseDelayComponent>(ent, out var delay);
|
||||||
if (_useDelay.ActiveDelay(uid, delay))
|
if (_useDelay.ActiveDelay(ent, delay))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_source.SetIgnited(uid);
|
_source.SetIgnited(ent.Owner);
|
||||||
_audio.PlayPvs(comp.IgniteSound, uid);
|
_audio.PlayPvs(ent.Comp.IgniteSound, ent);
|
||||||
|
|
||||||
_useDelay.BeginDelay(uid, delay);
|
_useDelay.BeginDelay(ent, delay);
|
||||||
comp.IgnitedUntil = _timing.CurTime + comp.IgnitedTime;
|
ent.Comp.IgnitedUntil = _timing.CurTime + ent.Comp.IgnitedTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
namespace Content.Server.IgnitionSource;
|
namespace Content.Server.IgnitionSource;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is used for...
|
/// This is used for creating atmosphere hotspots while ignited to start reactions such as fire.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent, Access(typeof(IgnitionSourceSystem))]
|
||||||
[Access(typeof(IgnitionSourceSystem))]
|
|
||||||
public sealed partial class IgnitionSourceComponent : Component
|
public sealed partial class IgnitionSourceComponent : Component
|
||||||
{
|
{
|
||||||
[DataField("ignited")]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public bool Ignited = false;
|
public bool Ignited;
|
||||||
|
|
||||||
[DataField("temperature", required: true)]
|
[DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||||
public int Temperature;
|
public int Temperature;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,34 +7,32 @@ namespace Content.Server.IgnitionSource;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// This handles ignition, Jez basically coded this.
|
/// This handles ignition, Jez basically coded this.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
|
||||||
public sealed class IgnitionSourceSystem : EntitySystem
|
public sealed class IgnitionSourceSystem : EntitySystem
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
|
||||||
///
|
[Dependency] private readonly TransformSystem _transform = default!;
|
||||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
|
||||||
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<IgnitionSourceComponent,IsHotEvent>(OnIsHot);
|
|
||||||
|
SubscribeLocalEvent<IgnitionSourceComponent, IsHotEvent>(OnIsHot);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnIsHot(EntityUid uid, IgnitionSourceComponent component, IsHotEvent args)
|
private void OnIsHot(Entity<IgnitionSourceComponent> ent, ref IsHotEvent args)
|
||||||
{
|
{
|
||||||
SetIgnited(uid, args.IsHot, component);
|
SetIgnited((ent.Owner, ent.Comp), args.IsHot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Simply sets the ignited field to the ignited param.
|
/// Simply sets the ignited field to the ignited param.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetIgnited(EntityUid uid, bool ignited = true, IgnitionSourceComponent? comp = null)
|
public void SetIgnited(Entity<IgnitionSourceComponent?> ent, bool ignited = true)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref comp))
|
if (!Resolve(ent, ref ent.Comp))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
comp.Ignited = ignited;
|
ent.Comp.Ignited = ignited;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
@@ -42,17 +40,16 @@ public sealed class IgnitionSourceSystem : EntitySystem
|
|||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
|
|
||||||
var query = EntityQueryEnumerator<IgnitionSourceComponent, TransformComponent>();
|
var query = EntityQueryEnumerator<IgnitionSourceComponent, TransformComponent>();
|
||||||
while (query.MoveNext(out var source, out var component, out var transform))
|
while (query.MoveNext(out var uid, out var comp, out var xform))
|
||||||
{
|
{
|
||||||
if (!component.Ignited)
|
if (!comp.Ignited)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (transform.GridUid is { } gridUid)
|
if (xform.GridUid is { } gridUid)
|
||||||
{
|
{
|
||||||
var position = _transformSystem.GetGridOrMapTilePosition(source, transform);
|
var position = _transform.GetGridOrMapTilePosition(uid, xform);
|
||||||
_atmosphereSystem.HotspotExpose(gridUid, position, component.Temperature, 50, source, true);
|
_atmosphere.HotspotExpose(gridUid, position, comp.Temperature, 50, uid, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user