/* * All right reserved to CrystallEdge. * * BUT this file is sublicensed under MIT License * */ using System.Diagnostics.CodeAnalysis; using JetBrains.Annotations; using Robust.Shared.Map; using Robust.Shared.Random; namespace Content.Server._CP14.RoundSeed; /// /// Provides a round seed for another systems /// public sealed class CP14RoundSeedSystem : EntitySystem { [Dependency] private readonly IRobustRandom _random = default!; public override void Initialize() { SubscribeLocalEvent(OnComponentStartup); } private void OnComponentStartup(Entity ent, ref ComponentStartup args) { ent.Comp.Seed = _random.Next(CP14RoundSeedComponent.MaxValue); } private int SetupSeed() { return AddComp(Spawn(null, MapCoordinates.Nullspace)).Seed; } /// /// Returns the round seed if assigned, otherwise assigns the round seed itself. /// /// seed of the round public int GetSeed() { var query = EntityQuery(); foreach (var comp in query) { return comp.Seed; } var seed = SetupSeed(); Log.Warning($"Missing RoundSeed. Seed set to {seed}"); return seed; } }