Skip to content
Open
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
9 changes: 7 additions & 2 deletions CounterStrikeProgression.Site/Views/CompareViewBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace ktsu.CounterStrikeProgression.Site.Views;
using ktsu.CounterStrikeProgression.Core.Challenges;
using ktsu.CounterStrikeProgression.Core.Progression;
using ktsu.CounterStrikeProgression.Core.SkillShots;
using ktsu.CounterStrikeProgression.Core.Weapons;

/// <summary>One player's totals on the compare page.</summary>
/// <param name="SteamId">The 64-bit Steam ID as a decimal string.</param>
Expand Down Expand Up @@ -126,8 +127,12 @@ private static CompareSide Side(PlayerProgress progress, PlayerView view, Player
{
long kills = progress.Weapons.Values.Sum(w => w.Kills);
long headshots = progress.Weapons.Values.Sum(w => w.Headshots);
long hits = progress.Weapons.Values.Sum(w => w.Hits);
long shots = progress.Weapons.Values.Sum(w => w.Shots);

// Only guns record shots, so knife and Zeus hits would raise accuracy with nothing to divide
// them by. Count hits and shots over guns alone, as LifeTracker does for a life's accuracy.
List<WeaponProgress> guns = [.. progress.Weapons.Where(w => WeaponCatalog.Find(w.Key)?.IsGun == true).Select(w => w.Value)];
long hits = guns.Sum(w => w.Hits);
long shots = guns.Sum(w => w.Shots);
return new(
view.SteamId,
view.Name,
Expand Down
17 changes: 17 additions & 0 deletions CounterStrikeProgression.Test/CompareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ public void Build_TotalsEachPlayerAcrossWeapons()
Assert.AreEqual(75, view.B.Accuracy);
}

[TestMethod]
public void Build_AccuracyCountsOnlyGunsBecauseKnifeAndZeusRecordNoShots()
{
PlayerProgress player = Shooter();
WeaponProgress knife = player.Weapon(TestHelpers.Weapon("knife").Key);
knife.Kills = 4;
knife.Hits = 30;
WeaponProgress taser = player.Weapon(TestHelpers.Weapon("taser").Key);
taser.Kills = 1;
taser.Hits = 1;

CompareView view = CompareViewBuilder.Build(player, true, NoSeason, Sniper(), false, NoSeason, new ProgressionSettings());

Assert.AreEqual(50, view.A.Accuracy, "Knife and Zeus hits, which never record a shot, raised the gun accuracy.");
Assert.AreEqual(15, view.A.Kills, "Knife and Zeus kills still count toward the kill total.");
}

[TestMethod]
public void Build_ListsEveryWeaponEitherPlayerUsed()
{
Expand Down
Loading