]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix tippy speech time (#36616)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Wed, 16 Apr 2025 12:23:40 +0000 (22:23 +1000)
committerGitHub <noreply@github.com>
Wed, 16 Apr 2025 12:23:40 +0000 (08:23 -0400)
Content.Server/Tips/TipsSystem.cs
Content.Shared/Tips/TippyEvent.cs

index 2f7edd45d672529b36cdd292c16dc510394d277e..effbb7ba87e9290663da6bc9c6115d0d7b7996f7 100644 (file)
@@ -35,6 +35,16 @@ public sealed class TipsSystem : EntitySystem
     private string _tipsDataset = "";
     private float _tipTippyChance;
 
+    /// <summary>
+    /// Always adds this time to a speech message. This is so really short message stay around for a bit.
+    /// </summary>
+    private const float SpeechBuffer = 3f;
+
+    /// <summary>
+    /// Expected reading speed.
+    /// </summary>
+    private const float Wpm = 180f;
+
     [ViewVariables(VVAccess.ReadWrite)]
     private TimeSpan _nextTipTime = TimeSpan.Zero;
 
@@ -127,6 +137,8 @@ public sealed class TipsSystem : EntitySystem
 
         if (args.Length > 3)
             ev.SpeakTime = float.Parse(args[3]);
+        else
+            ev.SpeakTime = GetSpeechTime(ev.Msg);
 
         if (args.Length > 4)
             ev.SlideTime = float.Parse(args[4]);
@@ -183,6 +195,12 @@ public sealed class TipsSystem : EntitySystem
         _tipTippyChance = value;
     }
 
+    public static float GetSpeechTime(string text)
+    {
+        var wordCount = (float)text.Split().Length;
+        return SpeechBuffer + wordCount * (60f / Wpm);
+    }
+
     private void AnnounceRandomTip()
     {
         if (!_prototype.TryIndex<LocalizedDatasetPrototype>(_tipsDataset, out var tips))
@@ -194,7 +212,7 @@ public sealed class TipsSystem : EntitySystem
         if (_random.Prob(_tipTippyChance))
         {
             var ev = new TippyEvent(msg);
-            ev.SpeakTime = 1 + tip.Length * 0.05f;
+            ev.SpeakTime = GetSpeechTime(msg);
             RaiseNetworkEvent(ev);
         } else
         {
index 4370e9c8227dc85a780ea703c2e01f7dfa71e2bc..e5dc0b7f35b22e8485a097b02ed1884d9fdbb928 100644 (file)
@@ -13,6 +13,8 @@ public sealed class TippyEvent : EntityEventArgs
 
     public string Msg;
     public string? Proto;
+
+    // TODO: Why are these defaults even here, have the caller specify. This get overriden only most of the time.
     public float SpeakTime = 5;
     public float SlideTime = 3;
     public float WaddleInterval = 0.5f;