diff --git a/CounterStrikeProgression.Site/Views/CompareViewBuilder.cs b/CounterStrikeProgression.Site/Views/CompareViewBuilder.cs
index b816944..b107ea8 100644
--- a/CounterStrikeProgression.Site/Views/CompareViewBuilder.cs
+++ b/CounterStrikeProgression.Site/Views/CompareViewBuilder.cs
@@ -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;
/// One player's totals on the compare page.
/// The 64-bit Steam ID as a decimal string.
@@ -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 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,
diff --git a/CounterStrikeProgression.Test/CompareTests.cs b/CounterStrikeProgression.Test/CompareTests.cs
index ac8ffae..c74970a 100644
--- a/CounterStrikeProgression.Test/CompareTests.cs
+++ b/CounterStrikeProgression.Test/CompareTests.cs
@@ -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()
{