From f361618a0b1ba1193002612901ddccefb3852393 Mon Sep 17 00:00:00 2001 From: Kara Date: Mon, 2 May 2022 13:51:03 -0700 Subject: [PATCH] Random metadata component (#7894) Co-authored-by: Moony --- Content.Client/Entry/IgnoredComponents.cs | 1 + .../RandomMetadata/RandomMetadataComponent.cs | 17 +++++++++ .../RandomMetadata/RandomMetadataSystem.cs | 36 +++++++++++++++++++ Resources/Prototypes/Datasets/Names/atv.yml | 19 ++++++++++ .../Entities/Objects/Vehicles/buckleable.yml | 2 ++ 5 files changed, 75 insertions(+) create mode 100644 Content.Server/RandomMetadata/RandomMetadataComponent.cs create mode 100644 Content.Server/RandomMetadata/RandomMetadataSystem.cs create mode 100644 Resources/Prototypes/Datasets/Names/atv.yml diff --git a/Content.Client/Entry/IgnoredComponents.cs b/Content.Client/Entry/IgnoredComponents.cs index 9f0ac3d086..61c31b7a6e 100644 --- a/Content.Client/Entry/IgnoredComponents.cs +++ b/Content.Client/Entry/IgnoredComponents.cs @@ -50,6 +50,7 @@ namespace Content.Client.Entry "ZombieTransfer", "Mineable", "RangedMagazine", + "RandomMetadata", "Ammo", "AiController", "Computer", diff --git a/Content.Server/RandomMetadata/RandomMetadataComponent.cs b/Content.Server/RandomMetadata/RandomMetadataComponent.cs new file mode 100644 index 0000000000..dbd1e5469f --- /dev/null +++ b/Content.Server/RandomMetadata/RandomMetadataComponent.cs @@ -0,0 +1,17 @@ +using Content.Shared.Dataset; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; + +namespace Content.Server.RandomMetadata; + +/// +/// Randomizes the description and/or the name for an entity by pulling from a dataset prototype. +/// +[RegisterComponent] +public sealed class RandomMetadataComponent : Component +{ + [DataField("descriptionSet", customTypeSerializer:typeof(PrototypeIdSerializer))] + public string? DescriptionSet; + + [DataField("nameSet", customTypeSerializer:typeof(PrototypeIdSerializer))] + public string? NameSet; +} diff --git a/Content.Server/RandomMetadata/RandomMetadataSystem.cs b/Content.Server/RandomMetadata/RandomMetadataSystem.cs new file mode 100644 index 0000000000..5b3dfa23bc --- /dev/null +++ b/Content.Server/RandomMetadata/RandomMetadataSystem.cs @@ -0,0 +1,36 @@ +using Content.Shared.Dataset; +using Robust.Shared.Prototypes; +using Robust.Shared.Random; + +namespace Content.Server.RandomMetadata; + +public sealed class RandomMetadataSystem : EntitySystem +{ + [Dependency] private readonly IPrototypeManager _prototype = default!; + [Dependency] private readonly IRobustRandom _random = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnMapInit); + } + + // This is done on map init so that map-placed entities have it randomized each time the map loads, for fun. + private void OnMapInit(EntityUid uid, RandomMetadataComponent component, MapInitEvent args) + { + var meta = MetaData(uid); + + if (component.NameSet != null) + { + var nameProto = _prototype.Index(component.NameSet); + meta.EntityName = _random.Pick(nameProto.Values); + } + + if (component.DescriptionSet != null) + { + var descProto = _prototype.Index(component.DescriptionSet); + meta.EntityDescription = _random.Pick(descProto.Values); + } + } +} diff --git a/Resources/Prototypes/Datasets/Names/atv.yml b/Resources/Prototypes/Datasets/Names/atv.yml new file mode 100644 index 0000000000..583d6118c0 --- /dev/null +++ b/Resources/Prototypes/Datasets/Names/atv.yml @@ -0,0 +1,19 @@ +- type: dataset + id: ATVDescriptions + values: + - All-Tile Vehicle. + - Ant-Thwarting Vehicle. + - Any-Time Vegetable. + - Actually-Two Vehicles. + - Any-Typed Variable. + - Assisted-Trauma Vehicle. + - Algorithm-Transmitted Virus. + - Alcoholic-Toddler Vacancy. + - Asshole-Tearing Volcano. + - A-Tele Vision. + - Awkward-Tweaking Vagabond. + - Art-Tragedy Volunteer. + - Automatic-Taco Vacancy. + - Another-Terrific View. + - All-The Virgins. + - A-Terrible Vehicle. diff --git a/Resources/Prototypes/Entities/Objects/Vehicles/buckleable.yml b/Resources/Prototypes/Entities/Objects/Vehicles/buckleable.yml index 7e6512a0f8..0da2ce6ab0 100644 --- a/Resources/Prototypes/Entities/Objects/Vehicles/buckleable.yml +++ b/Resources/Prototypes/Entities/Objects/Vehicles/buckleable.yml @@ -226,6 +226,8 @@ tags: - Cargo - Maintenance + - type: RandomMetadata + descriptionSet: ATVDescriptions - type: MovementSpeedModifier baseWalkSpeed : 8 baseSprintSpeed : 8