Files
tbd-station-14/Content.Server/RandomMetadata/RandomMetadataSystem.cs
Ed 7464d8284c Infinity books (#25840)
* setup text data

* roundstart reshuffling keywords with gibberish words

* saved data categorized

* add book with hints

* start redrawing books

* +4 book design

* +books +random visual upgrade

* finish first file

* finish lore file

* finish with books.rsi now authorbooks.rsi...

* aurora! and some fix

* nuke author books

* speelbuke update

* finish respriting work

* fix scientist guide visual

* setup datasets

* setup stupid funny random story

* restore author books, upgrade hint generation

* add variety to story generator

* add learning system

* minor textgen edit

* file restruct, hint count variation

* more restruct

* more renaming
add basis learning system logic. Spears locked for special book for test.

* nuke all systems, for splitting PR gods

* typo fix

* update migration with deleted books

* add random story books to maint

* Update construction-system.ftl

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: Hrosts <35345601+Hrosts@users.noreply.github.com>

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>

* typo fix

* interchangeably

* final

* Update Resources/Prototypes/Datasets/Names/books.yml

Co-authored-by: Hrosts <35345601+Hrosts@users.noreply.github.com>

* "."

* Update Content.Server/Paper/PaperRandomStorySystem.cs

Co-authored-by: Hrosts <35345601+Hrosts@users.noreply.github.com>

* Ubazer fix

* inadequate

* localized

* Update meta.json

* fuck merge conflicts

* fix jani book

---------

Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>
Co-authored-by: Hrosts <35345601+Hrosts@users.noreply.github.com>
2024-04-01 14:00:10 -07:00

57 lines
2.0 KiB
C#

using Content.Shared.Dataset;
using JetBrains.Annotations;
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!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RandomMetadataComponent, MapInitEvent>(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.NameSegments != null)
{
_metaData.SetEntityName(uid, GetRandomFromSegments(component.NameSegments, component.NameSeparator), meta);
}
if (component.DescriptionSegments != null)
{
_metaData.SetEntityDescription(uid,
GetRandomFromSegments(component.DescriptionSegments, component.DescriptionSeparator), meta);
}
}
/// <summary>
/// Generates a random string from segments and a separator.
/// </summary>
/// <param name="segments">The segments that it will be generated from</param>
/// <param name="separator">The separator that will be inbetween each segment</param>
/// <returns>The newly generated string</returns>
[PublicAPI]
public string GetRandomFromSegments(List<string> segments, string? separator)
{
var outputSegments = new List<string>();
foreach (var segment in segments)
{
outputSegments.Add(_prototype.TryIndex<DatasetPrototype>(segment, out var proto)
? Loc.GetString(_random.Pick(proto.Values))
: Loc.GetString(segment));
}
return string.Join(separator, outputSegments);
}
}