Skip to content

Commit 5bdc75b

Browse files
Fixed bugs from new rescueZoneStats implementation
1 parent be101d5 commit 5bdc75b

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/SourceEngine.Demo.Stats/DemoProcessor.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ public AllStats CreateFiles(ProcessedData processedData, bool createJsonFile = t
829829

830830
allStats.bombsiteStats = GetBombsiteStats(processedData);
831831
allStats.hostageStats = GetHostageStats(processedData);
832-
allStats.rescueZoneStats = GetRescueZoneStats();
832+
allStats.rescueZoneStats = GetRescueZoneStats(processedData);
833833

834834
string[] nadeTypes = { "Flash", "Smoke", "HE", "Incendiary", "Decoy" };
835835
var nadeGroups = GetNadeGroups(processedData, nadeTypes);
@@ -1341,8 +1341,8 @@ public List<bombsiteStats> GetBombsiteStats(ProcessedData processedData)
13411341
{
13421342
List<bombsiteStats> bombsiteStats = new List<bombsiteStats>();
13431343

1344-
var bombsiteATrigger = dp.triggers.Where(x => x.Index == dp.bombsiteAIndex).FirstOrDefault();
1345-
var bombsiteBTrigger = dp.triggers.Where(x => x.Index == dp.bombsiteBIndex).FirstOrDefault();
1344+
var bombsiteATrigger = dp?.triggers.Count() > 0 ? dp.triggers.Where(x => x.Index == dp.bombsiteAIndex).FirstOrDefault() : null;
1345+
var bombsiteBTrigger = dp?.triggers.Count() > 0 ? dp.triggers.Where(x => x.Index == dp.bombsiteBIndex).FirstOrDefault() : null;
13461346

13471347
List<char> bombsitePlants = new List<char>(processedData.BombsitePlantValues.Select(x => x.Bombsite));
13481348
List<char> bombsiteExplosions = new List<char>(processedData.BombsiteExplodeValues.Select(x => x.Bombsite));
@@ -1390,6 +1390,9 @@ public List<hostageStats> GetHostageStats(ProcessedData processedData)
13901390
{
13911391
List<hostageStats> hostageStats = new List<hostageStats>();
13921392

1393+
var hostageIndexA = processedData.HostageRescueValues.Where(r => r.Hostage == 'A').FirstOrDefault()?.HostageIndex;
1394+
var hostageIndexB = processedData.HostageRescueValues.Where(r => r.Hostage == 'B').FirstOrDefault()?.HostageIndex;
1395+
13931396
List<char> hostagePickedUps = new List<char>(processedData.HostagePickedUpValues.Select(x => x.Hostage));
13941397
List<char> hostageRescues = new List<char>(processedData.HostageRescueValues.Select(x => x.Hostage));
13951398

@@ -1402,30 +1405,30 @@ public List<hostageStats> GetHostageStats(ProcessedData processedData)
14021405
hostageStats.Add(new hostageStats()
14031406
{
14041407
Hostage = 'A',
1405-
HostageIndex = dp.hostageAIndex,
1408+
HostageIndex = hostageIndexA,
14061409
PickedUps = pickedUpsA,
14071410
Rescues = rescuesA,
14081411
});
14091412
hostageStats.Add(new hostageStats()
14101413
{
14111414
Hostage = 'B',
1412-
HostageIndex = dp.hostageBIndex,
1415+
HostageIndex = hostageIndexB,
14131416
PickedUps = pickedUpsB,
14141417
Rescues = rescuesB,
14151418
});
14161419

14171420
return hostageStats;
14181421
}
14191422

1420-
public List<rescueZoneStats> GetRescueZoneStats()
1423+
public List<rescueZoneStats> GetRescueZoneStats(ProcessedData processedData)
14211424
{
14221425
List<rescueZoneStats> rescueZoneStats = new List<rescueZoneStats>();
14231426

1424-
var rescueZoneTrigger = dp.triggers.FirstOrDefault(); // assume only one rescue zone, (int)data["site"] in GameEventHandler.cs does not line up with newResource.Entity.ID at SendTableParser.FindByName("CBaseTrigger").OnNewEntity
1427+
// assume only one rescue zone, (int)data["site"] in GameEventHandler.cs does not line up with newResource.Entity.ID at SendTableParser.FindByName("CBaseTrigger").OnNewEntity
1428+
var rescueZoneTrigger = dp?.triggers.Count() > 0 ? dp.triggers.Where(x => x.Index != dp.bombsiteAIndex && x.Index != dp.bombsiteBIndex).FirstOrDefault() : null;
14251429

14261430
rescueZoneStats.Add(new rescueZoneStats()
14271431
{
1428-
rescueZoneIndex = dp.rescueZoneIndex, // doesn't line up with the trigger Entity ID
14291432
XPositionMin = rescueZoneTrigger?.Min.X,
14301433
YPositionMin = rescueZoneTrigger?.Min.Y,
14311434
ZPositionMin = rescueZoneTrigger?.Min.Z,

src/SourceEngine.Demo.Stats/Models/rescueZoneStats.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
public class rescueZoneStats
44
{
5-
public int? rescueZoneIndex { get; set; } // doesn't line up with the trigger Entity ID
65
public double? XPositionMin { get; set; }
76
public double? YPositionMin { get; set; }
87
public double? ZPositionMin { get; set; }

tests/SourceEngine.Demo.Stats.Tests/Tests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace SourceEngine.Demo.Stats.Tests
1313
public class TopStatsWaffleTests
1414
{
1515
protected MatchData MatchData;
16+
protected DemoParser DemoParser;
1617
protected ProcessedData ProcessedData;
1718

1819
public TopStatsWaffleTests()
@@ -166,6 +167,18 @@ public void Should_return_hostage_stats_correctly()
166167
allStats.hostageStats[1].Rescues.ShouldBe(1);
167168
}
168169

170+
[Fact]
171+
public void Should_return_rescue_zone_stats_correctly()
172+
{
173+
// Arrange
174+
175+
// Act
176+
AllStats allStats = MatchData.CreateFiles(ProcessedData, false);
177+
178+
// Assess
179+
allStats.rescueZoneStats.Count.ShouldBe(1); // cannot test positions as is currently, as DemoParser is not implemented
180+
}
181+
169182
[Fact]
170183
public void Should_return_kills_stats_correctly()
171184
{

0 commit comments

Comments
 (0)