]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix hugging mispredict (#28432)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Fri, 31 May 2024 17:25:03 +0000 (05:25 +1200)
committerGitHub <noreply@github.com>
Fri, 31 May 2024 17:25:03 +0000 (11:25 -0600)
* git mv

* Move namespaces

* Fix hugging mispredict

Content.Server/Nutrition/EntitySystems/AnimalHusbandrySystem.cs
Content.Shared/Interaction/Components/InteractionPopupComponent.cs [moved from Content.Server/Interaction/Components/InteractionPopupComponent.cs with 98% similarity]
Content.Shared/Interaction/InteractionPopupSystem.cs [moved from Content.Server/Interaction/InteractionPopupSystem.cs with 75% similarity]

index d0fcd113595df2a5308b77ad07e95e90073b5ae6..cd0541340564825ec65233a3d84d4f600ef9ab43 100644 (file)
@@ -1,8 +1,8 @@
 using Content.Server.Administration.Logs;
-using Content.Server.Interaction.Components;
 using Content.Server.Popups;
 using Content.Shared.Database;
 using Content.Shared.IdentityManagement;
+using Content.Shared.Interaction.Components;
 using Content.Shared.Mind.Components;
 using Content.Shared.Mobs.Systems;
 using Content.Shared.Nutrition.AnimalHusbandry;
similarity index 98%
rename from Content.Server/Interaction/Components/InteractionPopupComponent.cs
rename to Content.Shared/Interaction/Components/InteractionPopupComponent.cs
index 000344e61c610839fc7619aed478687606af21dd..4ef5a1d18083d73ee0a027196e4f83a984bee70c 100644 (file)
@@ -1,7 +1,7 @@
 using Robust.Shared.Audio;
 using Robust.Shared.Prototypes;
 
-namespace Content.Server.Interaction.Components;
+namespace Content.Shared.Interaction.Components;
 
 [RegisterComponent, Access(typeof(InteractionPopupSystem))]
 public sealed partial class InteractionPopupComponent : Component
similarity index 75%
rename from Content.Server/Interaction/InteractionPopupSystem.cs
rename to Content.Shared/Interaction/InteractionPopupSystem.cs
index 77b76f898a7a05d0f23a6e33049d14b754bb54dd..030bc0ae6b8782400dd03b25df57ea15bbe38467 100644 (file)
@@ -1,26 +1,27 @@
-using Content.Server.Interaction.Components;
-using Content.Server.Popups;
 using Content.Shared.Bed.Sleep;
 using Content.Shared.IdentityManagement;
-using Content.Shared.Interaction;
+using Content.Shared.Interaction.Components;
 using Content.Shared.Mobs.Components;
 using Content.Shared.Mobs.Systems;
+using Content.Shared.Popups;
 using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
+using Robust.Shared.Network;
 using Robust.Shared.Player;
 using Robust.Shared.Random;
 using Robust.Shared.Timing;
 
-namespace Content.Server.Interaction;
+namespace Content.Shared.Interaction;
 
 public sealed class InteractionPopupSystem : EntitySystem
 {
     [Dependency] private readonly IGameTiming _gameTiming = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly MobStateSystem _mobStateSystem = default!;
-    [Dependency] private readonly PopupSystem _popupSystem = default!;
+    [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
     [Dependency] private readonly SharedAudioSystem _audio = default!;
     [Dependency] private readonly SharedTransformSystem _transform = default!;
+    [Dependency] private readonly INetManager _netMan = default!;
 
     public override void Initialize()
     {
@@ -53,9 +54,17 @@ public sealed class InteractionPopupSystem : EntitySystem
             return;
 
         //Handling does nothing and this thing annoyingly plays way too often.
+        // HUH? What does this comment even mean?
+
         if (HasComp<SleepingComponent>(uid))
             return;
 
+        if (TryComp<MobStateComponent>(uid, out var state)
+            && !_mobStateSystem.IsAlive(uid, state))
+        {
+            return;
+        }
+
         args.Handled = true;
 
         var curTime = _gameTiming.CurTime;
@@ -63,18 +72,21 @@ public sealed class InteractionPopupSystem : EntitySystem
         if (curTime < component.LastInteractTime + component.InteractDelay)
             return;
 
-        if (TryComp<MobStateComponent>(uid, out var state)
-            && !_mobStateSystem.IsAlive(uid, state))
-        {
-            return;
-        }
+        component.LastInteractTime = curTime;
 
         // TODO: Should be an attempt event
         // TODO: Need to handle pausing with an accumulator.
 
-        string msg = ""; // Stores the text to be shown in the popup message
+        var msg = ""; // Stores the text to be shown in the popup message
         SoundSpecifier? sfx = null; // Stores the filepath of the sound to be played
 
+        var predict = component.SuccessChance is 0 or 1
+                      && component.InteractSuccessSpawn == null
+                      && component.InteractFailureSpawn == null;
+
+        if (_netMan.IsClient && !predict)
+            return;
+
         if (_random.Prob(component.SuccessChance))
         {
             if (component.InteractSuccessString != null)
@@ -102,20 +114,39 @@ public sealed class InteractionPopupSystem : EntitySystem
         {
             var msgOthers = Loc.GetString(component.MessagePerceivedByOthers,
                 ("user", Identity.Entity(user, EntityManager)), ("target", Identity.Entity(uid, EntityManager)));
-            _popupSystem.PopupEntity(msg, uid, user);
             _popupSystem.PopupEntity(msgOthers, uid, Filter.PvsExcept(user, entityManager: EntityManager), true);
         }
-        else
-            _popupSystem.PopupEntity(msg, uid, user); //play only for the initiating entity.
 
-        if (sfx is not null) //not all cases will have sound.
+        if (!predict)
         {
+            _popupSystem.PopupEntity(msg, uid, user);
+
             if (component.SoundPerceivedByOthers)
-                _audio.PlayPvs(sfx, target); //play for everyone in range
+                _audio.PlayPvs(sfx, target);
             else
-                _audio.PlayEntity(sfx, Filter.Entities(user, target), target, true); //play only for the initiating entity and its target.
+                _audio.PlayEntity(sfx, Filter.Entities(user, target), target, false);
+            return;
         }
 
-        component.LastInteractTime = curTime;
+        _popupSystem.PopupPredicted(msg, uid, user);
+
+        if (sfx == null)
+            return;
+
+        if (component.SoundPerceivedByOthers)
+        {
+            _audio.PlayPredicted(sfx, target, user);
+            return;
+        }
+
+        if (_netMan.IsClient)
+        {
+            if (_gameTiming.IsFirstTimePredicted)
+                _audio.PlayEntity(sfx, Filter.Local(), target, true);
+        }
+        else
+        {
+            _audio.PlayEntity(sfx, Filter.Empty().FromEntities(target), target, false);
+        }
     }
 }