Makes Match[sticks/box] ECS, Makes Matchsticks ignite plasma
This commit is contained in:
@@ -8,22 +8,8 @@ namespace Content.Server.Light.Components
|
|||||||
// TODO make changes in icons when different threshold reached
|
// TODO make changes in icons when different threshold reached
|
||||||
// e.g. different icons for 10% 50% 100%
|
// e.g. different icons for 10% 50% 100%
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public class MatchboxComponent : Component, IInteractUsing
|
public class MatchboxComponent : Component
|
||||||
{
|
{
|
||||||
public override string Name => "Matchbox";
|
public override string Name => "Matchbox";
|
||||||
|
|
||||||
int IInteractUsing.Priority => 1;
|
|
||||||
|
|
||||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
|
||||||
{
|
|
||||||
if (eventArgs.Using.TryGetComponent<MatchstickComponent>(out var matchstick)
|
|
||||||
&& matchstick.CurrentState == SharedBurningStates.Unlit)
|
|
||||||
{
|
|
||||||
matchstick.Ignite(eventArgs.User);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
using System.Threading.Tasks;
|
|
||||||
using Content.Shared.Audio;
|
|
||||||
using Content.Shared.Interaction;
|
|
||||||
using Content.Shared.Smoking;
|
using Content.Shared.Smoking;
|
||||||
using Content.Shared.Sound;
|
using Content.Shared.Sound;
|
||||||
using Content.Shared.Temperature;
|
using Content.Shared.Temperature;
|
||||||
using Content.Server.Items;
|
using Content.Server.Items;
|
||||||
|
using Content.Server.Light.EntitySystems;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Analyzers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Player;
|
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
@@ -16,94 +13,38 @@ namespace Content.Server.Light.Components
|
|||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[ComponentReference(typeof(IHotItem))]
|
[ComponentReference(typeof(IHotItem))]
|
||||||
public class MatchstickComponent : Component, IHotItem, IInteractUsing
|
[Friend(typeof(MatchstickSystem))]
|
||||||
|
public class MatchstickComponent : Component, IHotItem
|
||||||
{
|
{
|
||||||
public override string Name => "Matchstick";
|
public override string Name => "Matchstick";
|
||||||
|
|
||||||
private SharedBurningStates _currentState = SharedBurningStates.Unlit;
|
/// <summary>
|
||||||
|
/// Current state to matchstick. Can be <code>Unlit</code>, <code>Lit</code> or <code>Burnt</code>.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables]
|
||||||
|
public SharedBurningStates CurrentState = SharedBurningStates.Unlit;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How long will matchstick last in seconds.
|
/// How long will matchstick last in seconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
[DataField("duration")]
|
[DataField("duration")]
|
||||||
private int _duration = 10;
|
public int Duration = 10;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sound played when you ignite the matchstick.
|
/// Sound played when you ignite the matchstick.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("igniteSound", required: true)] private SoundSpecifier _igniteSound = default!;
|
[DataField("igniteSound", required: true)] public SoundSpecifier IgniteSound = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Point light component. Gives matches a glow in dark effect.
|
/// Point light component. Gives matches a glow in dark effect.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ComponentDependency]
|
[ComponentDependency]
|
||||||
private readonly PointLightComponent? _pointLightComponent = default!;
|
public readonly PointLightComponent? PointLightComponent = default!;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Current state to matchstick. Can be <code>Unlit</code>, <code>Lit</code> or <code>Burnt</code>.
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables]
|
|
||||||
public SharedBurningStates CurrentState
|
|
||||||
{
|
|
||||||
get => _currentState;
|
|
||||||
private set
|
|
||||||
{
|
|
||||||
_currentState = value;
|
|
||||||
|
|
||||||
if (_pointLightComponent != null)
|
|
||||||
{
|
|
||||||
_pointLightComponent.Enabled = _currentState == SharedBurningStates.Lit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Owner.TryGetComponent(out ItemComponent? item))
|
|
||||||
{
|
|
||||||
switch (_currentState)
|
|
||||||
{
|
|
||||||
case SharedBurningStates.Lit:
|
|
||||||
item.EquippedPrefix = "lit";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
item.EquippedPrefix = "unlit";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
|
||||||
{
|
|
||||||
appearance.SetData(SmokingVisuals.Smoking, _currentState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IHotItem.IsCurrentlyHot()
|
bool IHotItem.IsCurrentlyHot()
|
||||||
{
|
{
|
||||||
return CurrentState == SharedBurningStates.Lit;
|
return CurrentState == SharedBurningStates.Lit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Ignite(IEntity user)
|
|
||||||
{
|
|
||||||
// Play Sound
|
|
||||||
SoundSystem.Play(
|
|
||||||
Filter.Pvs(Owner), _igniteSound.GetSound(), Owner,
|
|
||||||
AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
|
|
||||||
|
|
||||||
// Change state
|
|
||||||
CurrentState = SharedBurningStates.Lit;
|
|
||||||
Owner.SpawnTimer(_duration * 1000, () => CurrentState = SharedBurningStates.Burnt);
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
|
||||||
{
|
|
||||||
if (eventArgs.Target.TryGetComponent<IHotItem>(out var hotItem)
|
|
||||||
&& hotItem.IsCurrentlyHot()
|
|
||||||
&& CurrentState == SharedBurningStates.Unlit)
|
|
||||||
{
|
|
||||||
Ignite(eventArgs.User);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
Content.Server/Light/EntitySystems/MatchboxSystem.cs
Normal file
27
Content.Server/Light/EntitySystems/MatchboxSystem.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using Content.Server.Light.Components;
|
||||||
|
using Content.Shared.Interaction;
|
||||||
|
using Content.Shared.Smoking;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Server.Light.EntitySystems
|
||||||
|
{
|
||||||
|
public class MatchboxSystem : EntitySystem
|
||||||
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<MatchboxComponent, InteractUsingEvent>(OnInteractUsing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnInteractUsing(EntityUid uid, MatchboxComponent component, InteractUsingEvent args)
|
||||||
|
{
|
||||||
|
if (!args.Handled
|
||||||
|
&& args.Used.TryGetComponent<MatchstickComponent>(out var matchstick)
|
||||||
|
&& matchstick.CurrentState == SharedBurningStates.Unlit)
|
||||||
|
{
|
||||||
|
Get<MatchstickSystem>().Ignite(matchstick, args.User);
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
97
Content.Server/Light/EntitySystems/MatchstickSystem.cs
Normal file
97
Content.Server/Light/EntitySystems/MatchstickSystem.cs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Content.Server.Atmos.EntitySystems;
|
||||||
|
using Content.Server.Items;
|
||||||
|
using Content.Server.Light.Components;
|
||||||
|
using Content.Shared.Audio;
|
||||||
|
using Content.Shared.Interaction;
|
||||||
|
using Content.Shared.Smoking;
|
||||||
|
using Content.Shared.Temperature;
|
||||||
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Player;
|
||||||
|
|
||||||
|
namespace Content.Server.Light.EntitySystems
|
||||||
|
{
|
||||||
|
public class MatchstickSystem : EntitySystem
|
||||||
|
{
|
||||||
|
private HashSet<MatchstickComponent> _litMatches = new();
|
||||||
|
private AtmosphereSystem _atmosphereSystem = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
_atmosphereSystem = Get<AtmosphereSystem>();
|
||||||
|
SubscribeLocalEvent<MatchstickComponent, InteractUsingEvent>(OnInteractUsing);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(float frameTime)
|
||||||
|
{
|
||||||
|
base.Update(frameTime);
|
||||||
|
foreach (var match in _litMatches)
|
||||||
|
{
|
||||||
|
if (match.CurrentState != SharedBurningStates.Lit)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
_atmosphereSystem.HotspotExpose(match.Owner.Transform.Coordinates, 400, 50, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnInteractUsing(EntityUid uid, MatchstickComponent component, InteractUsingEvent args)
|
||||||
|
{
|
||||||
|
if (!args.Handled
|
||||||
|
&& args.Used.TryGetComponent<IHotItem>(out var hotItem)
|
||||||
|
&& hotItem.IsCurrentlyHot()
|
||||||
|
&& component.CurrentState == SharedBurningStates.Unlit)
|
||||||
|
{
|
||||||
|
Ignite(component, args.User);
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Ignite(MatchstickComponent component, IEntity user)
|
||||||
|
{
|
||||||
|
// Play Sound
|
||||||
|
SoundSystem.Play(
|
||||||
|
Filter.Pvs(component.Owner), component.IgniteSound.GetSound(), component.Owner,
|
||||||
|
AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
|
||||||
|
|
||||||
|
// Change state
|
||||||
|
SetState(component, SharedBurningStates.Lit);
|
||||||
|
_litMatches.Add(component);
|
||||||
|
component.Owner.SpawnTimer(component.Duration * 1000, delegate
|
||||||
|
{
|
||||||
|
SetState(component, SharedBurningStates.Burnt);
|
||||||
|
_litMatches.Remove(component);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetState(MatchstickComponent component, SharedBurningStates value)
|
||||||
|
{
|
||||||
|
component.CurrentState = value;
|
||||||
|
|
||||||
|
if (component.PointLightComponent != null)
|
||||||
|
{
|
||||||
|
component.PointLightComponent.Enabled = component.CurrentState == SharedBurningStates.Lit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component.Owner.TryGetComponent(out ItemComponent? item))
|
||||||
|
{
|
||||||
|
switch (component.CurrentState)
|
||||||
|
{
|
||||||
|
case SharedBurningStates.Lit:
|
||||||
|
item.EquippedPrefix = "lit";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
item.EquippedPrefix = "unlit";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component.Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||||
|
{
|
||||||
|
appearance.SetData(SmokingVisuals.Smoking, component.CurrentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user