Convert spam letters to a LocalizedDataset (#36393)
* Convert spam letters to a LocalizedDataset * Error -> warning * Comments * Add migrations for old spam mail entities
This commit is contained in:
@@ -4,18 +4,22 @@ using Content.Shared.UserInterface;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Random.Helpers;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using static Content.Shared.Paper.PaperComponent;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared.Paper;
|
||||
|
||||
public sealed class PaperSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
@@ -27,6 +31,8 @@ public sealed class PaperSystem : EntitySystem
|
||||
private static readonly ProtoId<TagPrototype> WriteIgnoreStampsTag = "WriteIgnoreStamps";
|
||||
private static readonly ProtoId<TagPrototype> WriteTag = "Write";
|
||||
|
||||
private EntityQuery<PaperComponent> _paperQuery;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -38,7 +44,11 @@ public sealed class PaperSystem : EntitySystem
|
||||
SubscribeLocalEvent<PaperComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<PaperComponent, PaperInputTextMessage>(OnInputTextMessage);
|
||||
|
||||
SubscribeLocalEvent<RandomPaperContentComponent, MapInitEvent>(OnRandomPaperContentMapInit);
|
||||
|
||||
SubscribeLocalEvent<ActivateOnPaperOpenedComponent, PaperWriteEvent>(OnPaperWrite);
|
||||
|
||||
_paperQuery = GetEntityQuery<PaperComponent>();
|
||||
}
|
||||
|
||||
private void OnMapInit(Entity<PaperComponent> entity, ref MapInitEvent args)
|
||||
@@ -203,6 +213,30 @@ public sealed class PaperSystem : EntitySystem
|
||||
UpdateUserInterface(entity);
|
||||
}
|
||||
|
||||
private void OnRandomPaperContentMapInit(Entity<RandomPaperContentComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
if (!_paperQuery.TryComp(ent, out var paperComp))
|
||||
{
|
||||
Log.Warning($"{EntityManager.ToPrettyString(ent)} has a {nameof(RandomPaperContentComponent)} but no {nameof(PaperComponent)}!");
|
||||
RemCompDeferred(ent, ent.Comp);
|
||||
return;
|
||||
}
|
||||
var dataset = _protoMan.Index(ent.Comp.Dataset);
|
||||
// Intentionally not using the Pick overload that directly takes a LocalizedDataset,
|
||||
// because we want to get multiple attributes from the same pick.
|
||||
var pick = _random.Pick(dataset.Values);
|
||||
|
||||
// Name
|
||||
_metaSystem.SetEntityName(ent, Loc.GetString(pick));
|
||||
// Description
|
||||
_metaSystem.SetEntityDescription(ent, Loc.GetString($"{pick}.desc"));
|
||||
// Content
|
||||
SetContent((ent, paperComp), Loc.GetString($"{pick}.content"));
|
||||
|
||||
// Our work here is done
|
||||
RemCompDeferred(ent, ent.Comp);
|
||||
}
|
||||
|
||||
private void OnPaperWrite(Entity<ActivateOnPaperOpenedComponent> entity, ref PaperWriteEvent args)
|
||||
{
|
||||
_interaction.UseInHandInteraction(args.User, entity);
|
||||
|
||||
Reference in New Issue
Block a user