From e62c11dd85d4a35276206916e26d9cb8866f9599 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Thu, 25 May 2023 18:07:39 -0400 Subject: [PATCH] Tech disk 4891 (#16752) * Tech disk gacha * customtypeserializer --- .../Components/TechnologyDiskComponent.cs | 11 +++++- .../Systems/DiskConsoleSystem.cs | 4 +- .../Systems/TechnologyDiskSystem.cs | 39 +++++-------------- .../Devices/Circuitboards/computer.yml | 2 +- .../Objects/Specific/Research/disk.yml | 2 + .../Machines/Computers/techdiskterminal.yml | 9 ++++- 6 files changed, 34 insertions(+), 33 deletions(-) diff --git a/Content.Server/Research/TechnologyDisk/Components/TechnologyDiskComponent.cs b/Content.Server/Research/TechnologyDisk/Components/TechnologyDiskComponent.cs index 36af9dc326..a3aee909f7 100644 --- a/Content.Server/Research/TechnologyDisk/Components/TechnologyDiskComponent.cs +++ b/Content.Server/Research/TechnologyDisk/Components/TechnologyDiskComponent.cs @@ -1,4 +1,7 @@ -namespace Content.Server.Research.TechnologyDisk.Components; +using Content.Shared.Random; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; + +namespace Content.Server.Research.TechnologyDisk.Components; [RegisterComponent] public sealed class TechnologyDiskComponent : Component @@ -8,4 +11,10 @@ public sealed class TechnologyDiskComponent : Component /// [DataField("recipes")] public List? Recipes; + + /// + /// A weighted random prototype for how rare each tier should be. + /// + [DataField("tierWeightPrototype", customTypeSerializer: typeof(PrototypeIdSerializer))] + public string TierWeightPrototype = "TechDiskTierWeights"; } diff --git a/Content.Server/Research/TechnologyDisk/Systems/DiskConsoleSystem.cs b/Content.Server/Research/TechnologyDisk/Systems/DiskConsoleSystem.cs index 492d1d2471..0d60f0af4f 100644 --- a/Content.Server/Research/TechnologyDisk/Systems/DiskConsoleSystem.cs +++ b/Content.Server/Research/TechnologyDisk/Systems/DiskConsoleSystem.cs @@ -85,7 +85,9 @@ public sealed class DiskConsoleSystem : EntitySystem { totalPoints = server.Points; } - var canPrint = !HasComp(uid) && totalPoints >= component.PricePerDisk; + + var canPrint = !(TryComp(uid, out var printing) && printing.FinishTime >= _timing.CurTime) && + totalPoints >= component.PricePerDisk; var state = new DiskConsoleBoundUserInterfaceState(totalPoints, component.PricePerDisk, canPrint); _ui.TrySetUiState(uid, DiskConsoleUiKey.Key, state); diff --git a/Content.Server/Research/TechnologyDisk/Systems/TechnologyDiskSystem.cs b/Content.Server/Research/TechnologyDisk/Systems/TechnologyDiskSystem.cs index 9db6c837bf..d886493e3f 100644 --- a/Content.Server/Research/TechnologyDisk/Systems/TechnologyDiskSystem.cs +++ b/Content.Server/Research/TechnologyDisk/Systems/TechnologyDiskSystem.cs @@ -4,6 +4,8 @@ using Content.Server.Research.Systems; using Content.Server.Research.TechnologyDisk.Components; using Content.Shared.Examine; using Content.Shared.Interaction; +using Content.Shared.Random; +using Content.Shared.Random.Helpers; using Content.Shared.Research.Components; using Content.Shared.Research.Prototypes; using Robust.Shared.Prototypes; @@ -66,46 +68,25 @@ public sealed class TechnologyDiskSystem : EntitySystem if (component.Recipes != null) return; - var lockoutTiers = new Dictionary(); - foreach (var discipline in _prototype.EnumeratePrototypes()) - { - lockoutTiers.Add(discipline.ID, discipline.LockoutTier); - } + var weightedRandom = _prototype.Index(component.TierWeightPrototype); + var tier = int.Parse(weightedRandom.Pick(_random)); //get a list of every distinct recipe in all the technologies. - var allTechs = new List(); + var techs = new List(); foreach (var tech in _prototype.EnumeratePrototypes()) { - if (tech.Tier >= lockoutTiers[tech.Discipline]) + if (tech.Tier != tier) continue; - allTechs.AddRange(tech.RecipeUnlocks); + techs.AddRange(tech.RecipeUnlocks); } - allTechs = allTechs.Distinct().ToList(); + techs = techs.Distinct().ToList(); - //get a list of every distinct unlocked tech across all databases - var allUnlocked = new List(); - foreach (var database in EntityQuery()) - { - allUnlocked.AddRange(database.UnlockedRecipes); - } - allUnlocked = allUnlocked.Distinct().ToList(); - - //make a list of every single non-unlocked tech - var validTechs = new List(); - foreach (var tech in allTechs) - { - if (allUnlocked.Contains(tech)) - continue; - - validTechs.Add(tech); - } - - if (!validTechs.Any()) + if (!techs.Any()) return; //pick one component.Recipes = new(); - component.Recipes.Add(_random.Pick(validTechs)); + component.Recipes.Add(_random.Pick(techs)); } } diff --git a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/computer.yml b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/computer.yml index fde5e6d4fe..7acf33c448 100644 --- a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/computer.yml +++ b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/computer.yml @@ -169,7 +169,7 @@ - type: entity parent: BaseComputerCircuitboard id: TechDiskComputerCircuitboard - name: technology disk terminal board + name: tech disk terminal board description: A computer printed circuit board for a technology disk terminal. components: - type: Sprite diff --git a/Resources/Prototypes/Entities/Objects/Specific/Research/disk.yml b/Resources/Prototypes/Entities/Objects/Specific/Research/disk.yml index 2c5bdd4250..3f053df6c8 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Research/disk.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Research/disk.yml @@ -54,3 +54,5 @@ - enum.DamageStateVisualLayers.Base: datadisk_base: Sixteen - type: TechnologyDisk + - type: StaticPrice + price: 50 diff --git a/Resources/Prototypes/Entities/Structures/Machines/Computers/techdiskterminal.yml b/Resources/Prototypes/Entities/Structures/Machines/Computers/techdiskterminal.yml index 2e97630ed4..2c512eb743 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/Computers/techdiskterminal.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/Computers/techdiskterminal.yml @@ -1,7 +1,7 @@ - type: entity parent: BaseComputer id: ComputerTechnologyDiskTerminal - name: technology disk terminal + name: tech disk terminal description: A terminal used to print out technology disks. components: - type: Sprite @@ -31,3 +31,10 @@ radius: 0.8 energy: 0.5 color: "#b53ca1" + +- type: weightedRandom + id: TechDiskTierWeights + weights: + 1: 25 + 2: 10 + 3: 1