Added the ability to refuel torches (and other expendable lights) (#36209)

* Added expendable light source refueling. Also fixed it to use the name modifier system so attributes like glue show up.

* Removed a duplicate line of code.

* Replaced TryGetComponent with TryComp, changed a variable name to be a little more clear.

* Removed the removed field "spentDesc" in flares and glowsticks

* Fixed to comply with slarticodefast's review. Name modifiers don't work yet (fixing that tmr)

* Fixed the localization!!!! :DDDD
This commit is contained in:
mjarduk
2025-04-18 04:59:41 +03:00
committed by GitHub
parent 2c60d6b27f
commit fb912b3d5c
6 changed files with 73 additions and 46 deletions

View File

@@ -1,10 +1,14 @@
using Content.Server.Light.Components; using Content.Server.Light.Components;
using Content.Server.Stack;
using Content.Shared.Clothing.Components; using Content.Shared.Clothing.Components;
using Content.Shared.Clothing.EntitySystems; using Content.Shared.Clothing.EntitySystems;
using Content.Shared.IgnitionSource; using Content.Shared.IgnitionSource;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
using Content.Shared.Item; using Content.Shared.Item;
using Content.Shared.Light.Components; using Content.Shared.Light.Components;
using Content.Shared.NameModifier.EntitySystems;
using Content.Shared.Stacks;
using Content.Shared.Tag; using Content.Shared.Tag;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using JetBrains.Annotations; using JetBrains.Annotations;
@@ -23,7 +27,8 @@ namespace Content.Server.Light.EntitySystems
[Dependency] private readonly TagSystem _tagSystem = default!; [Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!; [Dependency] private readonly StackSystem _stackSystem = default!;
[Dependency] private readonly NameModifierSystem _nameModifier = default!;
private static readonly ProtoId<TagPrototype> TrashTag = "Trash"; private static readonly ProtoId<TagPrototype> TrashTag = "Trash";
@@ -34,6 +39,8 @@ namespace Content.Server.Light.EntitySystems
SubscribeLocalEvent<ExpendableLightComponent, ComponentInit>(OnExpLightInit); SubscribeLocalEvent<ExpendableLightComponent, ComponentInit>(OnExpLightInit);
SubscribeLocalEvent<ExpendableLightComponent, UseInHandEvent>(OnExpLightUse); SubscribeLocalEvent<ExpendableLightComponent, UseInHandEvent>(OnExpLightUse);
SubscribeLocalEvent<ExpendableLightComponent, GetVerbsEvent<ActivationVerb>>(AddIgniteVerb); SubscribeLocalEvent<ExpendableLightComponent, GetVerbsEvent<ActivationVerb>>(AddIgniteVerb);
SubscribeLocalEvent<ExpendableLightComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<ExpendableLightComponent, RefreshNameModifiersEvent>(OnRefreshNameModifiers);
} }
public override void Update(float frameTime) public override void Update(float frameTime)
@@ -59,7 +66,7 @@ namespace Content.Server.Light.EntitySystems
{ {
case ExpendableLightState.Lit: case ExpendableLightState.Lit:
component.CurrentState = ExpendableLightState.Fading; component.CurrentState = ExpendableLightState.Fading;
component.StateExpiryTime = component.FadeOutDuration; component.StateExpiryTime = (float)component.FadeOutDuration.TotalSeconds;
UpdateVisualizer(ent); UpdateVisualizer(ent);
@@ -68,9 +75,7 @@ namespace Content.Server.Light.EntitySystems
default: default:
case ExpendableLightState.Fading: case ExpendableLightState.Fading:
component.CurrentState = ExpendableLightState.Dead; component.CurrentState = ExpendableLightState.Dead;
var meta = MetaData(ent); _nameModifier.RefreshNameModifiers(ent.Owner);
_metaData.SetEntityName(ent, Loc.GetString(component.SpentName), meta);
_metaData.SetEntityDescription(ent, Loc.GetString(component.SpentDesc), meta);
_tagSystem.AddTag(ent, TrashTag); _tagSystem.AddTag(ent, TrashTag);
@@ -104,15 +109,47 @@ namespace Content.Server.Light.EntitySystems
RaiseLocalEvent(ent, ref ignite); RaiseLocalEvent(ent, ref ignite);
component.CurrentState = ExpendableLightState.Lit; component.CurrentState = ExpendableLightState.Lit;
component.StateExpiryTime = component.GlowDuration;
UpdateSounds(ent); UpdateSounds(ent);
UpdateVisualizer(ent); UpdateVisualizer(ent);
}
return true; return true;
} }
return false; private void OnInteractUsing(EntityUid uid, ExpendableLightComponent component, ref InteractUsingEvent args)
{
if (args.Handled)
return;
if (!TryComp(args.Used, out StackComponent? stack))
return;
if (stack.StackTypeId != component.RefuelMaterialID)
return;
if (component.StateExpiryTime + component.RefuelMaterialTime.TotalSeconds >= component.RefuelMaximumDuration.TotalSeconds)
return;
if (component.CurrentState is ExpendableLightState.Dead)
{
component.CurrentState = ExpendableLightState.BrandNew;
component.StateExpiryTime = (float)component.RefuelMaterialTime.TotalSeconds;
_nameModifier.RefreshNameModifiers(uid);
_stackSystem.SetCount(args.Used, stack.Count - 1, stack);
UpdateVisualizer((uid, component));
return;
}
component.StateExpiryTime += (float)component.RefuelMaterialTime.TotalSeconds;
_stackSystem.SetCount(args.Used, stack.Count - 1, stack);
args.Handled = true;
}
private void OnRefreshNameModifiers(Entity<ExpendableLightComponent> entity, ref RefreshNameModifiersEvent args)
{
if (entity.Comp.CurrentState is ExpendableLightState.Dead)
args.AddModifier("expendable-light-spent-prefix");
} }
private void UpdateVisualizer(Entity<ExpendableLightComponent> ent, AppearanceComponent? appearance = null) private void UpdateVisualizer(Entity<ExpendableLightComponent> ent, AppearanceComponent? appearance = null)
@@ -171,6 +208,7 @@ namespace Content.Server.Light.EntitySystems
} }
component.CurrentState = ExpendableLightState.BrandNew; component.CurrentState = ExpendableLightState.BrandNew;
component.StateExpiryTime = (float)component.GlowDuration.TotalSeconds;
EntityManager.EnsureComponent<PointLightComponent>(uid); EntityManager.EnsureComponent<PointLightComponent>(uid);
} }

View File

@@ -1,5 +1,7 @@
using Content.Shared.Stacks;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
namespace Content.Shared.Light.Components; namespace Content.Shared.Light.Components;
@@ -9,34 +11,37 @@ public abstract partial class SharedExpendableLightComponent : Component
{ {
[ViewVariables(VVAccess.ReadOnly)] [ViewVariables(VVAccess.ReadOnly)]
public ExpendableLightState CurrentState { get; set; } public ExpendableLightState CurrentState;
[DataField("turnOnBehaviourID")] [DataField]
public string TurnOnBehaviourID { get; set; } = string.Empty; public string TurnOnBehaviourID = string.Empty;
[DataField("fadeOutBehaviourID")] [DataField]
public string FadeOutBehaviourID { get; set; } = string.Empty; public string FadeOutBehaviourID = string.Empty;
[DataField("glowDuration")] [DataField]
public float GlowDuration { get; set; } = 60 * 15f; public TimeSpan GlowDuration = TimeSpan.FromSeconds(60 * 15f);
[DataField("fadeOutDuration")] [DataField]
public float FadeOutDuration { get; set; } = 60 * 5f; public TimeSpan FadeOutDuration = TimeSpan.FromSeconds(60 * 5f);
[DataField("spentDesc")] [DataField]
public string SpentDesc { get; set; } = string.Empty; public ProtoId<StackPrototype>? RefuelMaterialID;
[DataField("spentName")] [DataField]
public string SpentName { get; set; } = string.Empty; public TimeSpan RefuelMaterialTime = TimeSpan.FromSeconds(15f);
[DataField("litSound")] [DataField]
public SoundSpecifier? LitSound { get; set; } public TimeSpan RefuelMaximumDuration = TimeSpan.FromSeconds(60 * 15f * 2);
[DataField("loopedSound")] [DataField]
public SoundSpecifier? LoopedSound { get; set; } public SoundSpecifier? LitSound;
[DataField("dieSound")] [DataField]
public SoundSpecifier? DieSound { get; set; } = null; public SoundSpecifier? LoopedSound;
[DataField]
public SoundSpecifier? DieSound;
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -1,14 +1,2 @@
expendable-light-start-verb = Start Light expendable-light-start-verb = Start Light
expendable-light-spent-prefix = spent {$baseName}
expendable-light-spent-flare-name = spent flare
expendable-light-spent-flare-desc = It looks like this flare has burnt out. What a bummer.
expendable-light-burnt-torch-name = burnt torch
expendable-light-burnt-torch-desc = It looks like this torch has burnt out. What a bummer.
expendable-light-spent-green-glowstick-name = spent green glowstick
expendable-light-spent-red-glowstick-name = spent red glowstick
expendable-light-spent-purple-glowstick-name = spent purple glowstick
expendable-light-spent-yellow-glowstick-name = spent purple glowstick
expendable-light-spent-blue-glowstick-name = spent blue glowstick
expendable-light-spent-glowstick-desc = It looks like this glowstick has stopped glowing. How tragic.

View File

@@ -5,9 +5,9 @@
description: A torch fashioned from some wood. description: A torch fashioned from some wood.
components: components:
- type: ExpendableLight - type: ExpendableLight
spentName: expendable-light-burnt-torch-name refuelMaterialID: WoodPlank
spentDesc: expendable-light-burnt-torch-desc
glowDuration: 100 glowDuration: 100
refuelMaximumDuration: 205
fadeOutDuration: 4 fadeOutDuration: 4
iconStateSpent: torch_spent iconStateSpent: torch_spent
turnOnBehaviourID: turn_on turnOnBehaviourID: turn_on

View File

@@ -10,8 +10,6 @@
- Trash - Trash
- type: SpaceGarbage - type: SpaceGarbage
- type: ExpendableLight - type: ExpendableLight
spentName: expendable-light-spent-flare-name
spentDesc: expendable-light-spent-flare-desc
glowDuration: 225 glowDuration: 225
fadeOutDuration: 15 fadeOutDuration: 15
iconStateOn: flare_unlit iconStateOn: flare_unlit

View File

@@ -6,8 +6,6 @@
components: components:
- type: SpaceGarbage - type: SpaceGarbage
- type: ExpendableLight - type: ExpendableLight
spentName: expendable-light-spent-green-glowstick-name
spentDesc: expendable-light-spent-glowstick-desc
glowDuration: 900 # time in seconds glowDuration: 900 # time in seconds
glowColorLit: "#00FF00" glowColorLit: "#00FF00"
fadeOutDuration: 300 fadeOutDuration: 300