Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions apps/utility-sw/src/Hud/PracticeFlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace UtilityPractice;

// What a flash did: everybody it caught, for how long, and how much of that
// was seeing nothing at all. One number in chat said a flash had landed; it
// did not say on whom, or whether "2.1 seconds" meant blind or merely dazzled.
// did not say on whom.
public partial class UtilityPracticePlugin
{
private class FlashHit
Expand Down Expand Up @@ -123,18 +123,17 @@ private void RecordFlash(IPlayer thrower, IPlayer blinded, CCSPlayerPawn? pawn,

int steps = HudSlots.FlashBarSteps - 1;
var rows = new List<NadeBarTemplate.FlashRow>();
List<PracticeCardGroups.FlashHit> hits = report
.Hits.Select(hit => new PracticeCardGroups.FlashHit(
hit.Seconds,
MathF.Max(0f, hit.Seconds - FlashFadeSeconds),
hit.Target,
hit.Bad
))
.ToList();

if (report.Hits.Count > HudSlots.FlashRows)
{
List<PracticeCardGroups.FlashHit> hits = report
.Hits.Select(hit => new PracticeCardGroups.FlashHit(
hit.Seconds,
MathF.Max(0f, hit.Seconds - FlashFadeSeconds),
hit.Target,
hit.Bad
))
.ToList();

foreach (PracticeCardGroups.Group group in PracticeCardGroups.Flash(hits))
{
rows.Add(
Expand Down Expand Up @@ -174,10 +173,8 @@ FlashHit hit in rows.Count > 0
}

int targets = report.Hits.Count(hit => hit.Target);
int worked = report.Hits.Count(hit =>
hit.Target && hit.Seconds - FlashFadeSeconds >= PracticeCardGroups.WorkedWhiteSeconds
);
string foot = targets == 0 ? "No targets caught" : $"{worked} of {targets} fully blind 1s+";
int worked = PracticeCardGroups.Worked(hits);
string foot = targets == 0 ? "No targets caught" : $"{worked} of {targets} blind 1s+";

if (report.Hits.Any(hit => hit.Bad))
{
Expand Down
51 changes: 48 additions & 3 deletions apps/utility-sw/test/PracticeCardGroupsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,55 @@ public void AFlashOnABoxOfBotsIsCountedByWhatItDid()

IReadOnlyList<PracticeCardGroups.Group> groups = PracticeCardGroups.Flash(hits);

Assert.Equal(new[] { "fully blind", "dazzled", "your side" }, groups.Select(group => group.Label));
Assert.Equal(new[] { 2, 3, 1 }, groups.Select(group => group.Count));
Assert.Equal(new[] { "blinded", "your side" }, groups.Select(group => group.Label));
Assert.Equal(new[] { 5, 1 }, groups.Select(group => group.Count));
Assert.Equal(4.8f, groups[0].Seconds);
Assert.True(groups[2].Bad);
Assert.True(groups[1].Bad);
}

[Fact]
public void ThreeSecondsOfBlindIsOverASecondBlind()
{
var hits = new List<PracticeCardGroups.FlashHit>
{
new(3.0f, 0f, Target: true, Bad: false),
};

Assert.Equal(1, PracticeCardGroups.Worked(hits));
Assert.Equal(new[] { ("blinded", 1) }, PracticeCardGroups.Flash(hits).Select(group => (group.Label, group.Count)));
}

[Fact]
public void UnderASecondOrOnYourOwnSideIsNotAWorkedFlash()
{
var hits = new List<PracticeCardGroups.FlashHit>
{
new(0.9f, 0f, Target: true, Bad: false),
new(4.0f, 1f, Target: false, Bad: true),
};

Assert.Equal(0, PracticeCardGroups.Worked(hits));
}

[Fact]
public void ARowThatReadsASecondCountsAsASecond()
{
Assert.Equal(1, PracticeCardGroups.Worked(new List<PracticeCardGroups.FlashHit> { new(0.96f, 0f, Target: true, Bad: false) }));
Assert.Equal(1, PracticeCardGroups.Worked(new List<PracticeCardGroups.FlashHit> { new(1f, 0f, Target: true, Bad: false) }));
Assert.Equal(0, PracticeCardGroups.Worked(new List<PracticeCardGroups.FlashHit> { new(0.94f, 0f, Target: true, Bad: false) }));
}

[Fact]
public void UnderASecondIsDazzledAndStillOnTheCard()
{
var hits = new List<PracticeCardGroups.FlashHit>
{
new(3.0f, 0f, Target: true, Bad: false),
new(0.8f, 0f, Target: true, Bad: false),
new(0.6f, 0f, Target: true, Bad: false),
};

Assert.Equal(new[] { ("blinded", 1), ("dazzled", 2) }, PracticeCardGroups.Flash(hits).Select(group => (group.Label, group.Count)));
}

[Fact]
Expand Down
19 changes: 15 additions & 4 deletions shared/dotnet/FiveStack.Utilities/PracticeCardGroups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ namespace FiveStack.Utilities;
// them rather than listed by name.
public static class PracticeCardGroups
{
// Blind for at least this long with nothing to see is a flash that worked.
public const float WorkedWhiteSeconds = 1f;
// Judged on the same seconds the card shows, or a row reading 3.0s sits
// above a foot saying nobody was blind for one.
public const float WorkedSeconds = 1f;

public record FlashHit(float Seconds, float White, bool Target, bool Bad);

public record Group(string Label, int Count, float Seconds, float White, bool Bad);

public static int Worked(IReadOnlyList<FlashHit> hits)
{
return hits.Count(hit => hit.Target && Blinded(hit));
}

private static bool Blinded(FlashHit hit)
{
return MathF.Round(hit.Seconds, 1, MidpointRounding.AwayFromZero) >= WorkedSeconds;
}

public static IReadOnlyList<Group> Flash(IReadOnlyList<FlashHit> hits)
{
var groups = new List<Group>();
Expand All @@ -28,8 +39,8 @@ void Add(string label, IEnumerable<FlashHit> members, bool bad)
}
}

Add("fully blind", hits.Where(hit => hit.Target && hit.White >= WorkedWhiteSeconds), false);
Add("dazzled", hits.Where(hit => hit.Target && hit.White < WorkedWhiteSeconds), false);
Add("blinded", hits.Where(hit => hit.Target && Blinded(hit)), false);
Add("dazzled", hits.Where(hit => hit.Target && !Blinded(hit)), false);
Add("your side", hits.Where(hit => hit.Bad), true);

return groups;
Expand Down
Loading