Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figures can now be activated remotely #32769

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some documentation here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it in the component! That's usually how I see it done (At least for this it would be copy pasted the same from the component). I feel like it should either be in one or the other and I guess I feel like component makes more sense. Let me know what you think!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, it doesn't hurt but won't be a blocker.
Usually the components have the documentation since one system can handle multiple components.

{
[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
Loading