]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
SlowContactsSystem to SpeedModifierContactsSystem mini rework (#26110)
authorEd <96445749+TheShuEd@users.noreply.github.com>
Sun, 17 Mar 2024 02:27:22 +0000 (05:27 +0300)
committerGitHub <noreply@github.com>
Sun, 17 Mar 2024 02:27:22 +0000 (13:27 +1100)
* rework

* update logic

Content.Server/Chemistry/TileReactions/SpillTileReaction.cs
Content.Server/Fluids/EntitySystems/PuddleSystem.cs
Content.Shared/Movement/Components/SpeedModifiedByContactComponent.cs [moved from Content.Shared/Movement/Components/SlowedByContactComponent.cs with 80% similarity]
Content.Shared/Movement/Components/SpeedModifierContactsComponent.cs [moved from Content.Shared/Movement/Components/SlowContactsComponent.cs with 83% similarity]
Content.Shared/Movement/Systems/FrictionContactsSystem.cs
Content.Shared/Movement/Systems/SpeedModifierContactsSystem.cs [moved from Content.Shared/Movement/Systems/SlowContactsSystem.cs with 59% similarity]
Resources/Prototypes/Entities/Objects/Misc/kudzu.yml
Resources/Prototypes/Entities/Objects/Misc/spider_web.yml
Resources/Prototypes/Entities/Tiles/water.yml

index 49fdaa5c7ee7381f9640cd84acfff6c9abbb5488..8f8b0626a28a22afab69274e75281a227b3979bc 100644 (file)
@@ -45,9 +45,9 @@ namespace Content.Server.Chemistry.TileReactions
                 var step = entityManager.EnsureComponent<StepTriggerComponent>(puddleUid);
                 entityManager.EntitySysManager.GetEntitySystem<StepTriggerSystem>().SetRequiredTriggerSpeed(puddleUid, _requiredSlipSpeed, step);
 
-                var slow = entityManager.EnsureComponent<SlowContactsComponent>(puddleUid);
+                var slow = entityManager.EnsureComponent<SpeedModifierContactsComponent>(puddleUid);
                 var speedModifier = 1 - reagent.Viscosity;
-                entityManager.EntitySysManager.GetEntitySystem<SlowContactsSystem>().ChangeModifiers(puddleUid, speedModifier, slow);
+                entityManager.EntitySysManager.GetEntitySystem<SpeedModifierContactsSystem>().ChangeModifiers(puddleUid, speedModifier, slow);
 
                 return reactVolume;
             }
index c03e6f593c6d54114460183c8690c3b2549e2acb..e3481f98da3b7fabacb9e278e98139c9f40381b3 100644 (file)
@@ -54,7 +54,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
     [Dependency] private readonly SharedPopupSystem _popups = default!;
     [Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
     [Dependency] private readonly StepTriggerSystem _stepTrigger = default!;
-    [Dependency] private readonly SlowContactsSystem _slowContacts = default!;
+    [Dependency] private readonly SpeedModifierContactsSystem _speedModContacts = default!;
     [Dependency] private readonly TileFrictionController _tile = default!;
 
     [ValidatePrototypeId<ReagentPrototype>]
@@ -435,13 +435,13 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
 
         if (maxViscosity > 0)
         {
-            var comp = EnsureComp<SlowContactsComponent>(uid);
+            var comp = EnsureComp<SpeedModifierContactsComponent>(uid);
             var speed = 1 - maxViscosity;
-            _slowContacts.ChangeModifiers(uid, speed, comp);
+            _speedModContacts.ChangeModifiers(uid, speed, comp);
         }
         else
         {
-            RemComp<SlowContactsComponent>(uid);
+            RemComp<SpeedModifierContactsComponent>(uid);
         }
     }
 
similarity index 80%
rename from Content.Shared/Movement/Components/SlowedByContactComponent.cs
rename to Content.Shared/Movement/Components/SpeedModifiedByContactComponent.cs
index eafefefee180b3ef4daa1065a8e55828cd51269e..4f791e13cab0fda5fc9521a5dc28c9410568b930 100644 (file)
@@ -7,6 +7,6 @@ namespace Content.Shared.Movement.Components;
 /// Exists just to listen to a single event. What a life.
 /// </summary>
 [NetworkedComponent, RegisterComponent] // must be networked to properly predict adding & removal
-public sealed partial class SlowedByContactComponent : Component
+public sealed partial class SpeedModifiedByContactComponent : Component
 {
 }
similarity index 83%
rename from Content.Shared/Movement/Components/SlowContactsComponent.cs
rename to Content.Shared/Movement/Components/SpeedModifierContactsComponent.cs
index 00cbc55d1980491c341a694dd942f3920ecd35ce..73bb0690fdc1a201d2b1103af163b875c4a57b22 100644 (file)
@@ -6,8 +6,8 @@ namespace Content.Shared.Movement.Components;
 
 [NetworkedComponent, RegisterComponent]
 [AutoGenerateComponentState]
-[Access(typeof(SlowContactsSystem))]
-public sealed partial class SlowContactsComponent : Component
+[Access(typeof(SpeedModifierContactsSystem))]
+public sealed partial class SpeedModifierContactsComponent : Component
 {
     [DataField("walkSpeedModifier"), ViewVariables(VVAccess.ReadWrite)]
     [AutoNetworkedField]
index b104c549e69c04794b7047e8af8cc53fa1e9ee8d..b086bc0e05f5753a7386d9fbbec4a7456d5d3a65 100644 (file)
@@ -10,7 +10,7 @@ public sealed class FrictionContactsSystem : EntitySystem
     [Dependency] private readonly SharedPhysicsSystem _physics = default!;
     [Dependency] private readonly MovementSpeedModifierSystem _speedModifierSystem = default!;
 
-    // Comment copied from "original" SlowContactsSystem.cs
+    // Comment copied from "original" SlowContactsSystem.cs (now SpeedModifierContactsSystem.cs)
     // TODO full-game-save 
     // Either these need to be processed before a map is saved, or slowed/slowing entities need to update on init.
     private HashSet<EntityUid> _toUpdate = new();
similarity index 59%
rename from Content.Shared/Movement/Systems/SlowContactsSystem.cs
rename to Content.Shared/Movement/Systems/SpeedModifierContactsSystem.cs
index 1ee145075f6b8410157b9201a4da6a2604b13a2b..f9f6b82bb182b948f4398ba9f741b0caad2c3e96 100644 (file)
@@ -5,7 +5,7 @@ using Robust.Shared.Physics.Systems;
 
 namespace Content.Shared.Movement.Systems;
 
-public sealed class SlowContactsSystem : EntitySystem
+public sealed class SpeedModifierContactsSystem : EntitySystem
 {
     [Dependency] private readonly SharedPhysicsSystem _physics = default!;
     [Dependency] private readonly MovementSpeedModifierSystem _speedModifierSystem = default!;
@@ -18,10 +18,10 @@ public sealed class SlowContactsSystem : EntitySystem
     public override void Initialize()
     {
         base.Initialize();
-        SubscribeLocalEvent<SlowContactsComponent, StartCollideEvent>(OnEntityEnter);
-        SubscribeLocalEvent<SlowContactsComponent, EndCollideEvent>(OnEntityExit);
-        SubscribeLocalEvent<SlowedByContactComponent, RefreshMovementSpeedModifiersEvent>(MovementSpeedCheck);
-        SubscribeLocalEvent<SlowContactsComponent, ComponentShutdown>(OnShutdown);
+        SubscribeLocalEvent<SpeedModifierContactsComponent, StartCollideEvent>(OnEntityEnter);
+        SubscribeLocalEvent<SpeedModifierContactsComponent, EndCollideEvent>(OnEntityExit);
+        SubscribeLocalEvent<SpeedModifiedByContactComponent, RefreshMovementSpeedModifiersEvent>(MovementSpeedCheck);
+        SubscribeLocalEvent<SpeedModifierContactsComponent, ComponentShutdown>(OnShutdown);
 
         UpdatesAfter.Add(typeof(SharedPhysicsSystem));
     }
@@ -39,18 +39,18 @@ public sealed class SlowContactsSystem : EntitySystem
 
         foreach (var ent in _toRemove)
         {
-            RemComp<SlowedByContactComponent>(ent);
+            RemComp<SpeedModifiedByContactComponent>(ent);
         }
 
         _toUpdate.Clear();
     }
 
-    public void ChangeModifiers(EntityUid uid, float speed, SlowContactsComponent? component = null)
+    public void ChangeModifiers(EntityUid uid, float speed, SpeedModifierContactsComponent? component = null)
     {
         ChangeModifiers(uid, speed, speed, component);
     }
 
-    public void ChangeModifiers(EntityUid uid, float walkSpeed, float sprintSpeed, SlowContactsComponent? component = null)
+    public void ChangeModifiers(EntityUid uid, float walkSpeed, float sprintSpeed, SpeedModifierContactsComponent? component = null)
     {
         if (!Resolve(uid, ref component))
         {
@@ -62,7 +62,7 @@ public sealed class SlowContactsSystem : EntitySystem
         _toUpdate.UnionWith(_physics.GetContactingEntities(uid));
     }
 
-    private void OnShutdown(EntityUid uid, SlowContactsComponent component, ComponentShutdown args)
+    private void OnShutdown(EntityUid uid, SpeedModifierContactsComponent component, ComponentShutdown args)
     {
         if (!TryComp(uid, out PhysicsComponent? phys))
             return;
@@ -71,48 +71,56 @@ public sealed class SlowContactsSystem : EntitySystem
         _toUpdate.UnionWith(_physics.GetContactingEntities(uid, phys));
     }
 
-    private void MovementSpeedCheck(EntityUid uid, SlowedByContactComponent component, RefreshMovementSpeedModifiersEvent args)
+    private void MovementSpeedCheck(EntityUid uid, SpeedModifiedByContactComponent component, RefreshMovementSpeedModifiersEvent args)
     {
         if (!EntityManager.TryGetComponent<PhysicsComponent>(uid, out var physicsComponent))
             return;
 
-        var walkSpeed = 1.0f;
-        var sprintSpeed = 1.0f;
+        var walkSpeed = 0.0f;
+        var sprintSpeed = 0.0f;
 
         bool remove = true;
+        var entries = 0;
         foreach (var ent in _physics.GetContactingEntities(uid, physicsComponent))
         {
-            if (!TryComp<SlowContactsComponent>(ent, out var slowContactsComponent))
+            if (!TryComp<SpeedModifierContactsComponent>(ent, out var slowContactsComponent))
                 continue;
 
             if (slowContactsComponent.IgnoreWhitelist != null && slowContactsComponent.IgnoreWhitelist.IsValid(uid))
                 continue;
 
-            walkSpeed = Math.Min(walkSpeed, slowContactsComponent.WalkSpeedModifier);
-            sprintSpeed = Math.Min(sprintSpeed, slowContactsComponent.SprintSpeedModifier);
+            walkSpeed += slowContactsComponent.WalkSpeedModifier;
+            sprintSpeed += slowContactsComponent.SprintSpeedModifier;
             remove = false;
+            entries++;
         }
 
-        args.ModifySpeed(walkSpeed, sprintSpeed);
+        if (entries > 0)
+        {
+            walkSpeed /= entries;
+            sprintSpeed /= entries;
+
+            args.ModifySpeed(walkSpeed, sprintSpeed);
+        }
 
         // no longer colliding with anything
         if (remove)
             _toRemove.Add(uid);
     }
 
-    private void OnEntityExit(EntityUid uid, SlowContactsComponent component, ref EndCollideEvent args)
+    private void OnEntityExit(EntityUid uid, SpeedModifierContactsComponent component, ref EndCollideEvent args)
     {
         var otherUid = args.OtherEntity;
         _toUpdate.Add(otherUid);
     }
 
-    private void OnEntityEnter(EntityUid uid, SlowContactsComponent component, ref StartCollideEvent args)
+    private void OnEntityEnter(EntityUid uid, SpeedModifierContactsComponent component, ref StartCollideEvent args)
     {
         var otherUid = args.OtherEntity;
         if (!HasComp<MovementSpeedModifierComponent>(otherUid))
             return;
 
-        EnsureComp<SlowedByContactComponent>(otherUid);
+        EnsureComp<SpeedModifiedByContactComponent>(otherUid);
         _toUpdate.Add(otherUid);
     }
 }
index 5de1f0b7f935d01d5e1a4a60bb7d9f07a0f6dafe..657201912e86527c3708e0b9b76868ed922e22bd 100644 (file)
@@ -82,7 +82,7 @@
     - type: AtmosExposed
       growthTickChance: 0.3
       spreadChance: 0.4
-    - type: SlowContacts
+    - type: SpeedModifierContacts
       walkSpeedModifier: 0.2
       sprintSpeedModifier: 0.2
       ignoreWhitelist:
     - type: Kudzu
       spriteVariants: 5
       spreadChance: 0.01
-    - type: SlowContacts
+    - type: SpeedModifierContacts
       walkSpeedModifier: 0.8
       sprintSpeedModifier: 0.8
       ignoreWhitelist:
          Heat: 3
       growthTickChance: 0.3
     - type: AtmosExposed
-    - type: SlowContacts
+    - type: SpeedModifierContacts
       walkSpeedModifier: 0.3
       sprintSpeedModifier: 0.3
       ignoreWhitelist:
index af65ac95a8a7c8338ab53592f6bb5e71c3c8ea33..e1f4d086d4594aaf8f93d3fd771c1d4d2f30012c 100644 (file)
@@ -72,7 +72,7 @@
         Flammable: [Touch]
         Extinguish: [Touch]
     - type: SpiderWebObject
-    - type: SlowContacts
+    - type: SpeedModifierContacts
       walkSpeedModifier: 0.5
       sprintSpeedModifier: 0.5
       ignoreWhitelist:
index e2c0421aef3b669728b5f23f4df77394d4f95d52..2fd1c8547deb678fd1cfc4563a6476da32b3f1cf 100644 (file)
@@ -32,7 +32,7 @@
         Quantity: 100
   - type: DrainableSolution
     solution: pool
-  - type: SlowContacts
+  - type: SpeedModifierContacts
     walkSpeedModifier: 0.5
     sprintSpeedModifier: 0.5
   - type: Physics