Files
tbd-station-14/Content.Server/NPC/HTN/PrimitiveTasks/Operators/SpeakOperator.cs
Centronias d3f85701f7 Adds HugBot (#37557)
* - hugbot
  - bdy with two arms because it needs two arms to hug
  - is constructable from:
    - box of hugs
    - proximity sensor
    - two borg arms
  - lots of voice lines
  - kinda like a medibot, it chases you down and then hugs you
    - except if it's emagged, then it punches you :)
    - it has a 2m cooldown per person by default

- MeleeAttackOperator
  - Read the doc, but it's an operator which makes the NPC hit a target exactly once assuming it's in range.
  - Used to make the hugbot attack
- RaiseEventForOwnerOperator
  - Read the doc, but it's an operator which raises an event on the owning NPC.
  - Used to make the hugbot hug extra code, specifically for the cooldown

- Changes to existing code:
  - `ComponentFilter : UtilityQueryFilter` gets `RetainWithComp` added which, as the name implies, retains entities with the specified comps rather than removing them. Basically, it lets you negate the filter.
  - `SpeakOperator : HTNOperator`'s `speech` field can use a `LocalizedDataSet` instead of just a locstring now
    - (I updated all of the existing usages for this)
  -

* two arms

* wait what if we just used mimebot arms so it doesn't look awful

* smort
2025-10-11 00:51:12 +00:00

77 lines
2.4 KiB
C#

using Content.Server.Chat.Systems;
using Content.Shared.Dataset;
using Content.Shared.Random.Helpers;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using static Content.Server.NPC.HTN.PrimitiveTasks.Operators.SpeakOperator.SpeakOperatorSpeech;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators;
public sealed partial class SpeakOperator : HTNOperator
{
private ChatSystem _chat = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[DataField(required: true)]
public SpeakOperatorSpeech Speech;
/// <summary>
/// Whether to hide message from chat window and logs.
/// </summary>
[DataField]
public bool Hidden;
public override void Initialize(IEntitySystemManager sysManager)
{
base.Initialize(sysManager);
_chat = sysManager.GetEntitySystem<ChatSystem>();
}
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
{
LocId speechLocId;
switch (Speech)
{
case LocalizedSetSpeakOperatorSpeech localizedDataSet:
if (!_proto.TryIndex(localizedDataSet.LineSet, out var speechSet))
return HTNOperatorStatus.Failed;
speechLocId = _random.Pick(speechSet);
break;
case SingleSpeakOperatorSpeech single:
speechLocId = single.Line;
break;
default:
throw new ArgumentOutOfRangeException(nameof(Speech));
}
var speaker = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
_chat.TrySendInGameICMessage(
speaker,
Loc.GetString(speechLocId),
InGameICChatType.Speak,
hideChat: Hidden,
hideLog: Hidden
);
return base.Update(blackboard, frameTime);
}
[ImplicitDataDefinitionForInheritors, MeansImplicitUse]
public abstract partial class SpeakOperatorSpeech
{
public sealed partial class SingleSpeakOperatorSpeech : SpeakOperatorSpeech
{
[DataField(required: true)]
public string Line;
}
public sealed partial class LocalizedSetSpeakOperatorSpeech : SpeakOperatorSpeech
{
[DataField(required: true)]
public ProtoId<LocalizedDatasetPrototype> LineSet;
}
}
}