using Content.Shared.Examine; using Content.Shared.Interaction; using Content.Shared.Lathe; using Content.Shared.NameModifier.EntitySystems; using Content.Shared.Popups; using Content.Shared.Random.Helpers; using Content.Shared.Research.Components; using Content.Shared.Research.Prototypes; using Content.Shared.Research.Systems; using Content.Shared.Research.TechnologyDisk.Components; using Robust.Shared.Network; using Robust.Shared.Prototypes; using Robust.Shared.Random; namespace Content.Shared.Research.TechnologyDisk.Systems; public sealed class TechnologyDiskSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _protoMan = default!; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly SharedResearchSystem _research = default!; [Dependency] private readonly SharedLatheSystem _lathe = default!; [Dependency] private readonly NameModifierSystem _nameModifier = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnAfterInteract); SubscribeLocalEvent(OnExamine); SubscribeLocalEvent(OnRefreshNameModifiers); } private void OnMapInit(Entity ent, ref MapInitEvent args) { if (ent.Comp.Recipes != null) return; var weightedRandom = _protoMan.Index(ent.Comp.TierWeightPrototype); var tier = int.Parse(weightedRandom.Pick(_random)); //get a list of every distinct recipe in all the technologies. var techs = new HashSet>(); foreach (var tech in _protoMan.EnumeratePrototypes()) { if (tech.Tier != tier) continue; techs.UnionWith(tech.RecipeUnlocks); } if (techs.Count == 0) return; //pick one ent.Comp.Recipes = []; ent.Comp.Recipes.Add(_random.Pick(techs)); Dirty(ent); _nameModifier.RefreshNameModifiers(ent.Owner); } private void OnAfterInteract(Entity ent, ref AfterInteractEvent args) { if (args.Handled || !args.CanReach || args.Target is not { } target) return; if (!HasComp(target) || !TryComp(target, out var database)) return; if (ent.Comp.Recipes != null) { foreach (var recipe in ent.Comp.Recipes) { _research.AddLatheRecipe(target, recipe, database); } } _popup.PopupClient(Loc.GetString("tech-disk-inserted"), target, args.User); PredictedQueueDel(ent.Owner); args.Handled = true; } private void OnExamine(Entity ent, ref ExaminedEvent args) { var message = Loc.GetString("tech-disk-examine-none"); if (ent.Comp.Recipes != null && ent.Comp.Recipes.Count > 0) { var prototype = _protoMan.Index(ent.Comp.Recipes[0]); message = Loc.GetString("tech-disk-examine", ("result", _lathe.GetRecipeName(prototype))); if (ent.Comp.Recipes.Count > 1) //idk how to do this well. sue me. message += " " + Loc.GetString("tech-disk-examine-more"); } args.PushMarkup(message); } private void OnRefreshNameModifiers(Entity entity, ref RefreshNameModifiersEvent args) { if (entity.Comp.Recipes != null) { foreach (var recipe in entity.Comp.Recipes) { var proto = _protoMan.Index(recipe); args.AddModifier("tech-disk-name-format", extraArgs: ("technology", _lathe.GetRecipeName(proto))); } } } }