]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Nerf ninja research stealing (#26421)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Tue, 26 Mar 2024 00:52:27 +0000 (20:52 -0400)
committerGitHub <noreply@github.com>
Tue, 26 Mar 2024 00:52:27 +0000 (11:52 +1100)
* nerf ninja steal objective

* fubar

Content.Server/Research/Systems/ResearchStealerSystem.cs
Content.Shared/Research/Components/ResearchStealerComponent.cs
Content.Shared/Research/Systems/SharedResearchSystem.cs
Resources/Prototypes/Objectives/ninja.yml

index 5bab6048de5700a09a809913b296615e62d96c61..d40134f1e9ffc44fa6f1db3fe1cea8fe9764475e 100644 (file)
@@ -1,11 +1,13 @@
 using Content.Shared.Research.Components;
 using Content.Shared.Research.Systems;
+using Robust.Shared.Random;
 
 namespace Content.Server.Research.Systems;
 
 public sealed class ResearchStealerSystem : SharedResearchStealerSystem
 {
     [Dependency] private readonly SharedResearchSystem _research = default!;
+    [Dependency] private readonly IRobustRandom _random = default!;
 
     public override void Initialize()
     {
@@ -24,16 +26,26 @@ public sealed class ResearchStealerSystem : SharedResearchStealerSystem
         if (!TryComp<TechnologyDatabaseComponent>(target, out var database))
             return;
 
-        var ev = new ResearchStolenEvent(uid, target, database.UnlockedTechnologies);
+        var ev = new ResearchStolenEvent(uid, target, new());
+        var count = _random.Next(comp.MinToSteal, comp.MaxToSteal + 1);
+        for (var i = 0; i < count; i++)
+        {
+            if (database.UnlockedTechnologies.Count == 0)
+                break;
+
+            var toRemove = _random.Pick(database.UnlockedTechnologies);
+            if (_research.TryRemoveTechnology((target, database), toRemove))
+                ev.Techs.Add(toRemove);
+        }
         RaiseLocalEvent(uid, ref ev);
-        // oops, no more advanced lasers!
-        _research.ClearTechs(target, database);
+
+        args.Handled = true;
     }
 }
 
 /// <summary>
-/// Event raised on the user when research is stolen from a R&D server.
+/// Event raised on the user when research is stolen from a RND server.
 /// Techs contains every technology id researched.
 /// </summary>
 [ByRefEvent]
-public record struct ResearchStolenEvent(EntityUid Used, EntityUid Target, List<String> Techs);
+public record struct ResearchStolenEvent(EntityUid Used, EntityUid Target, List<string> Techs);
index e0331fad1bb942f7f65f7597358a811c495af619..df8878e6516e02e610357f466e23a83f9be8b02b 100644 (file)
@@ -14,4 +14,16 @@ public sealed partial class ResearchStealerComponent : Component
     /// </summary>
     [DataField("delay"), ViewVariables(VVAccess.ReadWrite)]
     public TimeSpan Delay = TimeSpan.FromSeconds(20);
+
+    /// <summary>
+    /// The minimum number of technologies that will be stolen
+    /// </summary>
+    [DataField]
+    public int MinToSteal = 4;
+
+    /// <summary>
+    /// The maximum number of technologies that will be stolen
+    /// </summary>
+    [DataField]
+    public int MaxToSteal = 8;
 }
index 12f27d0b9c920fdfcf4d333cb46b20b3e3a8310a..9819e949b8b68ae9225a2e5f863632d1f60c2b15 100644 (file)
@@ -1,6 +1,7 @@
 using System.Linq;
 using Content.Shared.Research.Components;
 using Content.Shared.Research.Prototypes;
+using JetBrains.Annotations;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
 using Robust.Shared.Utility;
@@ -219,16 +220,58 @@ public abstract class SharedResearchSystem : EntitySystem
         if (!Resolve(uid, ref component))
             return;
 
-        var discipline = PrototypeManager.Index<TechDisciplinePrototype>(prototype.Discipline);
+        var discipline = PrototypeManager.Index(prototype.Discipline);
         if (prototype.Tier < discipline.LockoutTier)
             return;
         component.MainDiscipline = prototype.Discipline;
         Dirty(uid, component);
     }
 
+    /// <summary>
+    /// Removes a technology and its recipes from a technology database.
+    /// </summary>
+    public bool TryRemoveTechnology(Entity<TechnologyDatabaseComponent> entity, ProtoId<TechnologyPrototype> tech)
+    {
+        return TryRemoveTechnology(entity, PrototypeManager.Index(tech));
+    }
+
+    /// <summary>
+    /// Removes a technology and its recipes from a technology database.
+    /// </summary>
+    [PublicAPI]
+    public bool TryRemoveTechnology(Entity<TechnologyDatabaseComponent> entity, TechnologyPrototype tech)
+    {
+        if (!entity.Comp.UnlockedTechnologies.Remove(tech.ID))
+            return false;
+
+        // check to make sure we didn't somehow get the recipe from another tech.
+        // unlikely, but whatever
+        var recipes = tech.RecipeUnlocks;
+        foreach (var recipe in recipes)
+        {
+            var hasTechElsewhere = false;
+            foreach (var unlockedTech in entity.Comp.UnlockedTechnologies)
+            {
+                var unlockedTechProto = PrototypeManager.Index<TechnologyPrototype>(unlockedTech);
+
+                if (!unlockedTechProto.RecipeUnlocks.Contains(recipe))
+                    continue;
+                hasTechElsewhere = true;
+                break;
+            }
+
+            if (!hasTechElsewhere)
+                entity.Comp.UnlockedRecipes.Remove(recipe);
+        }
+        Dirty(entity, entity.Comp);
+        UpdateTechnologyCards(entity, entity);
+        return true;
+    }
+
     /// <summary>
     /// Clear all unlocked technologies from the database.
     /// </summary>
+    [PublicAPI]
     public void ClearTechs(EntityUid uid, TechnologyDatabaseComponent? comp = null)
     {
         if (!Resolve(uid, ref comp) || comp.UnlockedTechnologies.Count == 0)
index 43def65d7a0cec53e9313cd9b7aa40d5c5a39986..f2ac97be58bb3674e762e6ddfcdff7b61ee54824 100644 (file)
@@ -39,8 +39,8 @@
       sprite: Structures/Machines/server.rsi
       state: server
   - type: NumberObjective
-    min: 5
-    max: 10
+    min: 9
+    max: 13
     title: objective-condition-steal-research-title
   - type: StealResearchCondition