From a63183e20fc5ffa1c10e25854cbc8ecb5dbc9551 Mon Sep 17 00:00:00 2001 From: MSWS Date: Mon, 12 Aug 2024 19:14:58 -0700 Subject: [PATCH] Detect when speedrunner is afk --- .../SpecialDay/SoloDayLocale.cs | 6 +++++- .../SpecialDays/SpeedrunDay.cs | 19 +++++++++++++------ mod/Jailbreak.Trail/ActivePlayerTrail.cs | 2 +- .../Mod/SpecialDay/AbstractSpecialDay.cs | 3 ++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lang/Jailbreak.English/SpecialDay/SoloDayLocale.cs b/lang/Jailbreak.English/SpecialDay/SoloDayLocale.cs index 8d5ef5d9..d42c769f 100644 --- a/lang/Jailbreak.English/SpecialDay/SoloDayLocale.cs +++ b/lang/Jailbreak.English/SpecialDay/SoloDayLocale.cs @@ -1,5 +1,6 @@ using Jailbreak.Formatting.Base; using Jailbreak.Formatting.Views.SpecialDay; +using Jailbreak.Public.Extensions; using Jailbreak.Public.Utils; namespace Jailbreak.English.SpecialDay; @@ -27,7 +28,10 @@ public virtual IView BeginsIn(int seconds) { } public IView GenerateStartMessage() { - var result = new SimpleView { PREFIX, { "Today is a", Name, "day!" } }; + var result = new SimpleView { + PREFIX, + { "Today is a" + (Name.ToLower()[0].IsVowel() ? "n" : ""), Name, "day!" } + }; if (description.Length == 0) return result; diff --git a/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs b/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs index ff185eed..8afa173c 100644 --- a/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs +++ b/mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs @@ -254,10 +254,15 @@ private ActivePlayerTrail createFirstTrail( var tps = 1 / trail.UpdateRate; var didntMoveSeconds = (int)Math.Ceiling(trail.DidntMoveTicks / tps); var thresholdTicks = (int)Math.Ceiling(tps * 3); - if (trail.GetTrailLengthSquared() < 500) { + if (start == null) { + panic("start is null"); + return; + } + + if (start.DistanceSquared(speedrunner?.Pawn.Value?.AbsOrigin!) < 100) { if (trail.DidntMoveTicks <= tps * 10) return; - // If the player left mid-run, we need to pick the nearest player - // to continue the run + // If the player is afk, we need to pick the closet player + // that has moved to continue the run var end = trail.GetEndSegment()?.GetEnd() ?? start; if (end == null) { panic("Speedrunner is invalid, and we cannot find the start"); @@ -267,6 +272,9 @@ private ActivePlayerTrail createFirstTrail( var furthest = PlayerUtil.GetAlive() .Where(p => p.Pawn.IsValid && p.Pawn.Value != null) .Where(p => p.Pawn.Value!.IsValid && p.Pawn.Value.AbsOrigin != null) + .Where(p + => p.Pawn.Value!.AbsOrigin!.DistanceSquared(speedrunner?.Pawn.Value! + .AbsOrigin!) > 100) // Ensure they have moved .MinBy(p => p.Pawn.Value!.AbsOrigin!.DistanceSquared(end)); if (furthest == null) { @@ -277,16 +285,15 @@ private ActivePlayerTrail createFirstTrail( speedrunner = furthest; foreach (var p in PlayerUtil.GetAlive()) { if (p.Slot == speedrunner.Slot) continue; - p.Teleport(furthest); + p.Teleport(speedrunner); } - start = furthest.Pawn.Value?.AbsOrigin!.Clone(); furthest.Pawn.Value?.Teleport(end); furthest.SetColor(Color.DodgerBlue); msg.RunnerAFKAndReassigned(furthest).ToAllChat(); msg.YouAreRunner(RoundUtil.GetTimeRemaining()).ToChat(furthest); trail.StartTracking(furthest); - + trail.DidntMoveTicks = 0; return; } diff --git a/mod/Jailbreak.Trail/ActivePlayerTrail.cs b/mod/Jailbreak.Trail/ActivePlayerTrail.cs index ee6445c7..f247db57 100644 --- a/mod/Jailbreak.Trail/ActivePlayerTrail.cs +++ b/mod/Jailbreak.Trail/ActivePlayerTrail.cs @@ -23,7 +23,7 @@ public ActivePlayerTrail(BasePlugin plugin, CCSPlayerController player, } public float UpdateRate { get; protected set; } - public int DidntMoveTicks { get; protected set; } + public int DidntMoveTicks { get; set; } public CCSPlayerController? Player { get; protected set; } public event Action OnPlayerInvalid = () => { }; diff --git a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs index 2dd5db54..671587dc 100644 --- a/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs +++ b/public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs @@ -284,7 +284,8 @@ protected void SetConvarValue(ConVar? cvar, object value) { break; } - if (cvar.Name is "mp_teammates_are_enemies" or "sv_autobunnyhopping") { + if (cvar.Name is "mp_teammates_are_enemies" or "sv_autobunnyhopping" + or "mp_death_drop_gun") { // These convars require a frame to take effect, otherwise client-side // stuff is not properly updated var opposite = !(bool)value;