using System.Linq; using Robust.Shared.Prototypes; using Robust.Shared.Random; namespace Content.Shared.BarSign; public sealed class BarSignSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly MetaDataSystem _metaData = default!; public override void Initialize() { SubscribeLocalEvent(OnMapInit); Subs.BuiEvents(BarSignUiKey.Key, subs => { subs.Event(OnSetBarSignMessage); }); } private void OnMapInit(Entity ent, ref MapInitEvent args) { if (ent.Comp.Current != null) return; var newPrototype = _random.Pick(GetAllBarSigns(_prototypeManager)); SetBarSign(ent, newPrototype); } private void OnSetBarSignMessage(Entity ent, ref SetBarSignMessage args) { if (!_prototypeManager.TryIndex(args.Sign, out var signPrototype)) return; SetBarSign(ent, signPrototype); } public void SetBarSign(Entity ent, BarSignPrototype newPrototype) { var meta = MetaData(ent); var name = Loc.GetString(newPrototype.Name); _metaData.SetEntityName(ent, name, meta); _metaData.SetEntityDescription(ent, Loc.GetString(newPrototype.Description), meta); ent.Comp.Current = newPrototype.ID; Dirty(ent); } public static List GetAllBarSigns(IPrototypeManager prototypeManager) { return prototypeManager .EnumeratePrototypes() .Where(p => !p.Hidden) .ToList(); } }