Skip to content

Commit

Permalink
Figures can now be activated remotely (space-wizards#32769)
Browse files Browse the repository at this point in the history
* First commit

* I'm silly

* weh

* will this work?

* Better design

* Fixes!

* rider :(

* L rider
  • Loading branch information
beck-thompson authored Dec 16, 2024
1 parent 001b0ed commit 74e9576
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 105 deletions.
17 changes: 17 additions & 0 deletions Content.Server/Chat/SpeakOnTriggerComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Shared.Dataset;
using Robust.Shared.Prototypes;

namespace Content.Server.Chat;

/// <summary>
/// Makes the entity speak when triggered. If the item has UseDelay component, the system will respect that cooldown.
/// </summary>
[RegisterComponent]
public sealed partial class SpeakOnTriggerComponent : Component
{
/// <summary>
/// The identifier for the dataset prototype containing messages to be spoken by this entity.
/// </summary>
[DataField(required: true)]
public ProtoId<LocalizedDatasetPrototype> Pack = string.Empty;
}
18 changes: 0 additions & 18 deletions Content.Server/Chat/SpeakOnUseComponent.cs

This file was deleted.

42 changes: 42 additions & 0 deletions Content.Server/Chat/Systems/SpeakOnTriggerSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Content.Server.Explosion.EntitySystems;
using Content.Shared.Timing;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Server.Chat.Systems;

public sealed class SpeakOnTriggerSystem : EntitySystem
{
[Dependency] private readonly UseDelaySystem _useDelay = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly ChatSystem _chat = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SpeakOnTriggerComponent, TriggerEvent>(OnTrigger);
}

private void OnTrigger(Entity<SpeakOnTriggerComponent> ent, ref TriggerEvent args)
{
TrySpeak(ent);
args.Handled = true;
}

private void TrySpeak(Entity<SpeakOnTriggerComponent> ent)
{
// If it doesn't have the use delay component, still send the message.
if (TryComp<UseDelayComponent>(ent.Owner, out var useDelay) && _useDelay.IsDelayed((ent.Owner, useDelay)))
return;

if (!_prototypeManager.TryIndex(ent.Comp.Pack, out var messagePack))
return;

var message = Loc.GetString(_random.Pick(messagePack.Values));
_chat.TrySendInGameICMessage(ent.Owner, message, InGameICChatType.Speak, true);

if (useDelay != null)
_useDelay.TryResetDelay((ent.Owner, useDelay));
}
}
42 changes: 0 additions & 42 deletions Content.Server/Chat/Systems/SpeakOnUseSystem.cs

This file was deleted.

Loading

0 comments on commit 74e9576

Please sign in to comment.