using Content.Shared.Dataset;
+using Content.Shared.Random.Helpers;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
var outputSegments = new List<string>();
foreach (var segment in segments)
{
- if (_prototype.TryIndex<DatasetPrototype>(segment, out var proto)) {
+ if (_prototype.TryIndex<LocalizedDatasetPrototype>(segment, out var localizedProto))
+ {
+ outputSegments.Add(_random.Pick(localizedProto));
+ }
+ else if (_prototype.TryIndex<DatasetPrototype>(segment, out var proto))
+ {
var random = _random.Pick(proto.Values);
if (Loc.TryGetString(random, out var localizedSegment))
outputSegments.Add(localizedSegment);
else
outputSegments.Add(random);
- } else if (Loc.TryGetString(segment, out var localizedSegment))
+ }
+ else if (Loc.TryGetString(segment, out var localizedSegment))
outputSegments.Add(localizedSegment);
else
outputSegments.Add(segment);
return random.Pick(prototype.Values);
}
+ /// <summary>
+ /// Randomly selects an entry from <paramref name="prototype"/>, attempts to localize it, and returns the result.
+ /// </summary>
public static string Pick(this IRobustRandom random, LocalizedDatasetPrototype prototype)
{
- return random.Pick(prototype.Values);
+ var index = random.Next(prototype.Values.Count);
+ return Loc.GetString(prototype.Values[index]);
}
public static string Pick(this IWeightedRandomPrototype prototype, System.Random random)