]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Rat King Refactor Part 0: Separate Rummaging from RatKingComponent. (#40530)
authorJessica M <jessica@jessicamaybe.com>
Thu, 25 Sep 2025 01:50:24 +0000 (18:50 -0700)
committerGitHub <noreply@github.com>
Thu, 25 Sep 2025 01:50:24 +0000 (03:50 +0200)
* separate rummager into its own component/system

* thing

* address review and entitytables

* reviews

* review

* warnings

* Update Content.Shared/RatKing/Systems/RummagerSystem.cs

---------

Co-authored-by: Jessica M <jessica@maybe.sh>
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Shared/RatKing/Components/RummageableComponent.cs [moved from Content.Shared/RatKing/RatKingRummageableComponent.cs with 59% similarity]
Content.Shared/RatKing/Components/RummagerComponent.cs [new file with mode: 0644]
Content.Shared/RatKing/SharedRatKingSystem.cs
Content.Shared/RatKing/Systems/RummagerSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Mobs/NPCs/regalrat.yml
Resources/Prototypes/Entities/Structures/Furniture/toilet.yml
Resources/Prototypes/Entities/Structures/Piping/Disposal/units.yml

similarity index 59%
rename from Content.Shared/RatKing/RatKingRummageableComponent.cs
rename to Content.Shared/RatKing/Components/RummageableComponent.cs
index f3a389ef76405aa3fff870d1c50c3d5ac93483f8..ea92b5580547433d5c14899ea88b4bb972bc7329 100644 (file)
@@ -1,17 +1,16 @@
-using Content.Shared.Random;
+using Content.Shared.EntityTable.EntitySelectors;
 using Robust.Shared.Audio;
 using Robust.Shared.GameStates;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
 
-namespace Content.Shared.RatKing;
+namespace Content.Shared.RatKing.Components;
 
 /// <summary>
 /// This is used for entities that can be
 /// rummaged through by the rat king to get loot.
 /// </summary>
-[RegisterComponent, NetworkedComponent, Access(typeof(SharedRatKingSystem))]
+[RegisterComponent, NetworkedComponent]
 [AutoGenerateComponentState]
-public sealed partial class RatKingRummageableComponent : Component
+public sealed partial class RummageableComponent : Component
 {
     /// <summary>
     /// Whether or not this entity has been rummaged through already.
@@ -28,11 +27,10 @@ public sealed partial class RatKingRummageableComponent : Component
     public float RummageDuration = 3f;
 
     /// <summary>
-    /// A weighted random entity prototype containing the different loot that rummaging can provide.
+    /// The entity table to select loot from.
     /// </summary>
-    [DataField("rummageLoot", customTypeSerializer: typeof(PrototypeIdSerializer<WeightedRandomEntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
-    [AutoNetworkedField]
-    public string RummageLoot = "RatKingLoot";
+    [DataField(required: true)]
+    public EntityTableSelector Table = default!;
 
     /// <summary>
     /// Sound played on rummage completion.
diff --git a/Content.Shared/RatKing/Components/RummagerComponent.cs b/Content.Shared/RatKing/Components/RummagerComponent.cs
new file mode 100644 (file)
index 0000000..338e9ee
--- /dev/null
@@ -0,0 +1,11 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.RatKing.Components;
+
+/// <summary>
+/// This is used for entities that can rummage through entities
+/// with the <see cref="RummageableComponent"/>
+/// </summary>
+///
+[RegisterComponent, NetworkedComponent]
+public sealed partial class RummagerComponent : Component;
index edb2ab90db69afba7d8cc38dba29128e91faf890..3f6c9bdc2249d6cf4b5050d239acbe94cc74908f 100644 (file)
@@ -1,26 +1,15 @@
 using Content.Shared.Actions;
-using Content.Shared.Actions.Components;
-using Content.Shared.DoAfter;
-using Content.Shared.Random;
-using Content.Shared.Random.Helpers;
-using Content.Shared.Verbs;
-using Robust.Shared.Audio;
-using Robust.Shared.Audio.Systems;
-using Robust.Shared.Network;
+using Content.Shared.Actions.Components;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
-using Robust.Shared.Serialization;
 
 namespace Content.Shared.RatKing;
 
 public abstract class SharedRatKingSystem : EntitySystem
 {
-    [Dependency] private readonly INetManager _net = default!;
     [Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
     [Dependency] protected readonly IRobustRandom Random = default!;
     [Dependency] private readonly SharedActionsSystem _action = default!;
-    [Dependency] private readonly SharedAudioSystem _audio = default!;
-    [Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
 
     /// <inheritdoc/>
     public override void Initialize()
@@ -28,11 +17,7 @@ public abstract class SharedRatKingSystem : EntitySystem
         SubscribeLocalEvent<RatKingComponent, ComponentStartup>(OnStartup);
         SubscribeLocalEvent<RatKingComponent, ComponentShutdown>(OnShutdown);
         SubscribeLocalEvent<RatKingComponent, RatKingOrderActionEvent>(OnOrderAction);
-
         SubscribeLocalEvent<RatKingServantComponent, ComponentShutdown>(OnServantShutdown);
-
-        SubscribeLocalEvent<RatKingRummageableComponent, GetVerbsEvent<AlternativeVerb>>(OnGetVerb);
-        SubscribeLocalEvent<RatKingRummageableComponent, RatKingRummageDoAfterEvent>(OnDoAfterComplete);
     }
 
     private void OnStartup(EntityUid uid, RatKingComponent component, ComponentStartup args)
@@ -105,43 +90,6 @@ public abstract class SharedRatKingSystem : EntitySystem
         _action.StartUseDelay(component.ActionOrderLooseEntity);
     }
 
-    private void OnGetVerb(EntityUid uid, RatKingRummageableComponent component, GetVerbsEvent<AlternativeVerb> args)
-    {
-        if (!HasComp<RatKingComponent>(args.User) || component.Looted)
-            return;
-
-        args.Verbs.Add(new AlternativeVerb
-        {
-            Text = Loc.GetString("rat-king-rummage-text"),
-            Priority = 0,
-            Act = () =>
-            {
-                _doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, component.RummageDuration,
-                    new RatKingRummageDoAfterEvent(), uid, uid)
-                {
-                    BlockDuplicate = true,
-                    BreakOnDamage = true,
-                    BreakOnMove = true,
-                    DistanceThreshold = 2f
-                });
-            }
-        });
-    }
-
-    private void OnDoAfterComplete(EntityUid uid, RatKingRummageableComponent component, RatKingRummageDoAfterEvent args)
-    {
-        if (args.Cancelled || component.Looted)
-            return;
-
-        component.Looted = true;
-        Dirty(uid, component);
-        _audio.PlayPredicted(component.Sound, uid, args.User);
-
-        var spawn = PrototypeManager.Index<WeightedRandomEntityPrototype>(component.RummageLoot).Pick(Random);
-        if (_net.IsServer)
-            Spawn(spawn, Transform(uid).Coordinates);
-    }
-
     public void UpdateAllServants(EntityUid uid, RatKingComponent component)
     {
         foreach (var servant in component.Servants)
@@ -160,9 +108,3 @@ public abstract class SharedRatKingSystem : EntitySystem
 
     }
 }
-
-[Serializable, NetSerializable]
-public sealed partial class RatKingRummageDoAfterEvent : SimpleDoAfterEvent
-{
-
-}
diff --git a/Content.Shared/RatKing/Systems/RummagerSystem.cs b/Content.Shared/RatKing/Systems/RummagerSystem.cs
new file mode 100644 (file)
index 0000000..d9e9a87
--- /dev/null
@@ -0,0 +1,82 @@
+using Content.Shared.DoAfter;
+using Content.Shared.EntityTable;
+using Content.Shared.RatKing.Components;
+using Content.Shared.Verbs;
+using Robust.Shared.Audio.Systems;
+using Robust.Shared.Network;
+using Robust.Shared.Serialization;
+
+namespace Content.Shared.RatKing.Systems;
+
+public sealed class RummagerSystem : EntitySystem
+{
+    [Dependency] private readonly EntityTableSystem _entityTable =  default!;
+    [Dependency] private readonly SharedAudioSystem _audio = default!;
+    [Dependency] private readonly INetManager _net = default!;
+    [Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
+
+    /// <inheritdoc/>
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<RummageableComponent, GetVerbsEvent<AlternativeVerb>>(OnGetVerb);
+        SubscribeLocalEvent<RummageableComponent, RummageDoAfterEvent>(OnDoAfterComplete);
+    }
+
+    private void OnGetVerb(Entity<RummageableComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
+    {
+        if (!HasComp<RummagerComponent>(args.User) || ent.Comp.Looted)
+            return;
+
+        var user = args.User;
+
+        args.Verbs.Add(new AlternativeVerb
+        {
+            Text = Loc.GetString("rat-king-rummage-text"),
+            Priority = 0,
+            Act = () =>
+            {
+                _doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager,
+                    user,
+                    ent.Comp.RummageDuration,
+                    new RummageDoAfterEvent(),
+                    ent,
+                    ent)
+                {
+                    BlockDuplicate = true,
+                    BreakOnDamage = true,
+                    BreakOnMove = true,
+                    DistanceThreshold = 2f
+                });
+            }
+        });
+    }
+
+    private void OnDoAfterComplete(Entity<RummageableComponent> ent, ref RummageDoAfterEvent args)
+    {
+        if (args.Cancelled || ent.Comp.Looted)
+            return;
+
+        ent.Comp.Looted = true;
+        Dirty(ent, ent.Comp);
+        _audio.PlayPredicted(ent.Comp.Sound, ent, args.User);
+
+        if (_net.IsClient)
+            return;
+
+        var spawns = _entityTable.GetSpawns(ent.Comp.Table);
+        var coordinates = Transform(ent).Coordinates;
+
+        foreach (var spawn in spawns)
+        {
+            Spawn(spawn, coordinates);
+        }
+    }
+}
+
+/// <summary>
+/// DoAfter event for rummaging through a container with RummageableComponent.
+/// </summary>
+[Serializable, NetSerializable]
+public sealed partial class RummageDoAfterEvent : SimpleDoAfterEvent;
index 711a638ec8f0ccc9e11545bf2b6dabbcdba7e5ad..d48ac0dd78ec7e86a919841d80aad26a25261a78 100644 (file)
       - CannotSuicide
       - FootstepSound
   - type: NoSlip
+  - type: Rummager
   - type: RatKing
     hungerPerArmyUse: 25
     hungerPerDomainUse: 50
     sprite: Mobs/Effects/onfire.rsi
     normalState: Mouse_burning
 
-- type: weightedRandomEntity
+- type: entityTable
   id: RatKingLoot
-  weights:
-    RandomSpawner100: 66 #garbage
-    FoodCheese: 28 #food
-    IngotGold1: 5 #loot
+  table: !type:GroupSelector
+    children:
+    - id: RandomSpawner100
+      weight: 66
+    - id: FoodCheese
+      weight: 28
+    - id: IngotGold1
+      weight: 5
 
 - type: entity
   parent: BaseAction
index 3af5a9d2911c6e41f6b68860b1c86ad8e355f1df..90c450e1c7f90ea89e45bf2c9db66347d8243d8a 100644 (file)
@@ -80,7 +80,9 @@
     interfaces:
       enum.DisposalUnitUiKey.Key:
         type: DisposalUnitBoundUserInterface
-  - type: RatKingRummageable
+  - type: Rummageable
+    table: !type:NestedSelector
+      tableId: RatKingLoot
   - type: SolutionContainerManager
     solutions:
       drainBuffer:
index dda7d51b69a6d4fb77618b03e4f2a77e7bf327e3..6a9f0b30bcc3a8ed1d2b462bc2b4768854b6a6a7 100644 (file)
@@ -97,7 +97,9 @@
     interfaces:
       enum.DisposalUnitUiKey.Key:
         type: DisposalUnitBoundUserInterface
-  - type: RatKingRummageable
+  - type: Rummageable
+    table: !type:NestedSelector
+      tableId: RatKingLoot
   - type: RequireProjectileTarget
 
 - type: entity