Fix tippy speech time (#36616)

This commit is contained in:
metalgearsloth
2025-04-16 22:23:40 +10:00
committed by GitHub
parent de33ed7f02
commit a436032963
2 changed files with 21 additions and 1 deletions

View 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
{