Skip to content

Commit

Permalink
Detect when speedrunner is afk
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Aug 13, 2024
1 parent 842ff41 commit a63183e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
6 changes: 5 additions & 1 deletion lang/Jailbreak.English/SpecialDay/SoloDayLocale.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand Down
19 changes: 13 additions & 6 deletions mod/Jailbreak.SpecialDay/SpecialDays/SpeedrunDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,15 @@ private ActivePlayerTrail<BeamTrailSegment> 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");
Expand All @@ -267,6 +272,9 @@ private ActivePlayerTrail<BeamTrailSegment> 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) {
Expand All @@ -277,16 +285,15 @@ private ActivePlayerTrail<BeamTrailSegment> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion mod/Jailbreak.Trail/ActivePlayerTrail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => { };
Expand Down
3 changes: 2 additions & 1 deletion public/Jailbreak.Public/Mod/SpecialDay/AbstractSpecialDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a63183e

Please sign in to comment.