using Content.Shared.StationRecords;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
+using Robust.Shared.Random;
namespace Content.Server.StationRecords.Systems;
[Dependency] private readonly StationRecordKeyStorageSystem _keyStorage = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IdCardSystem _idCard = default!;
+ [Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
return records.Records.TryGetRecordEntry(key.Id, out entry);
}
+ /// <summary>
+ /// Gets a random record from the station's record entries.
+ /// </summary>
+ /// <param name="ent">The EntityId of the station from which you want to get the record.</param>
+ /// <param name="entry">The resulting entry.</param>
+ /// <typeparam name="T">Type to get from the record set.</typeparam>
+ /// <returns>True if a record was obtained. False otherwise.</returns>
+ public bool TryGetRandomRecord<T>(Entity<StationRecordsComponent?> ent, [NotNullWhen(true)] out T? entry)
+ {
+ entry = default;
+
+ if (!Resolve(ent.Owner, ref ent.Comp))
+ return false;
+
+ if (ent.Comp.Records.Keys.Count == 0)
+ return false;
+
+ var key = _random.Pick(ent.Comp.Records.Keys);
+
+ return ent.Comp.Records.TryGetRecordEntry(key, out entry);
+ }
+
/// <summary>
/// Returns an id if a record with the same name exists.
/// </summary>