Skip to content

Commit 948187c

Browse files
v1.1.14 - Fixed logic for Wingman Hostage matches + added tests + minor formatting changes
1 parent 43a9916 commit 948187c

File tree

2 files changed

+117
-18
lines changed

2 files changed

+117
-18
lines changed

TopStatsWaffle.Tests/TopStatsWaffleTests.cs

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void Should_return_kills_stats_correctly()
154154
}
155155

156156
[Fact]
157-
public void Should_return_map_info_correctly()
157+
public void Should_return_map_info_correctly_for_defuse_maps()
158158
{
159159
// Arrange
160160

@@ -168,6 +168,99 @@ public void Should_return_map_info_correctly()
168168
allStats.mapInfo.TestType.ShouldBe("Defuse");
169169
}
170170

171+
[Fact]
172+
public void Should_return_map_info_correctly_for_hostage_maps()
173+
{
174+
// Arrange
175+
var ProcessedData2 = ProcessedData;
176+
ProcessedData2.DemoInformation = new DemoInformation()
177+
{
178+
DemoName = "demo2",
179+
MapName = "de_testmap2",
180+
TestDate = new DateTime(2020, 1, 1, 0, 0, 0).ToString(),
181+
TestType = "Hostage",
182+
};
183+
ProcessedData2.MatchStartValues = new List<MatchStartedEventArgs>()
184+
{
185+
new MatchStartedEventArgs
186+
{
187+
Mapname = "de_testmap2",
188+
HasBombsites = false,
189+
}
190+
};
191+
192+
// Act
193+
AllStats allStats = MatchData.CreateFiles(ProcessedData, false);
194+
195+
// Assess
196+
allStats.mapInfo.DemoName.ShouldBe("demo2");
197+
allStats.mapInfo.MapName.ShouldBe("de_testmap2");
198+
allStats.mapInfo.TestDate.ShouldBe(new DateTime(2020, 1, 1, 0, 0, 0).ToString());
199+
allStats.mapInfo.TestType.ShouldBe("Hostage");
200+
}
201+
202+
[Fact]
203+
public void Should_return_map_info_correctly_for_wingman_defuse_maps()
204+
{
205+
// Arrange
206+
var ProcessedData3 = ProcessedData;
207+
ProcessedData3.DemoInformation = new DemoInformation()
208+
{
209+
DemoName = "demo3",
210+
MapName = "de_testmap3",
211+
TestDate = new DateTime(2020, 1, 1, 0, 0, 0).ToString(),
212+
TestType = "Wingman",
213+
};
214+
ProcessedData3.MatchStartValues = new List<MatchStartedEventArgs>()
215+
{
216+
new MatchStartedEventArgs
217+
{
218+
Mapname = "de_testmap3",
219+
HasBombsites = true,
220+
}
221+
};
222+
223+
// Act
224+
AllStats allStats = MatchData.CreateFiles(ProcessedData, false);
225+
226+
// Assess
227+
allStats.mapInfo.DemoName.ShouldBe("demo3");
228+
allStats.mapInfo.MapName.ShouldBe("de_testmap3");
229+
allStats.mapInfo.TestDate.ShouldBe(new DateTime(2020, 1, 1, 0, 0, 0).ToString());
230+
allStats.mapInfo.TestType.ShouldBe("Wingman");
231+
}
232+
233+
[Fact]
234+
public void Should_return_map_info_correctly_for_wingman_hostage_maps()
235+
{
236+
// Arrange
237+
var ProcessedData3 = ProcessedData;
238+
ProcessedData3.DemoInformation = new DemoInformation()
239+
{
240+
DemoName = "demo4",
241+
MapName = "de_testmap4",
242+
TestDate = new DateTime(2020, 1, 1, 0, 0, 0).ToString(),
243+
TestType = "Wingman",
244+
};
245+
ProcessedData3.MatchStartValues = new List<MatchStartedEventArgs>()
246+
{
247+
new MatchStartedEventArgs
248+
{
249+
Mapname = "de_testmap4",
250+
HasBombsites = false,
251+
}
252+
};
253+
254+
// Act
255+
AllStats allStats = MatchData.CreateFiles(ProcessedData, false);
256+
257+
// Assess
258+
allStats.mapInfo.DemoName.ShouldBe("demo4");
259+
allStats.mapInfo.MapName.ShouldBe("de_testmap4");
260+
allStats.mapInfo.TestDate.ShouldBe(new DateTime(2020, 1, 1, 0, 0, 0).ToString());
261+
allStats.mapInfo.TestType.ShouldBe("Wingman");
262+
}
263+
171264
[Fact]
172265
public void Should_return_player_stats_correctly()
173266
{
@@ -344,7 +437,7 @@ public void Should_return_version_number_correctly()
344437
AllStats allStats = MatchData.CreateFiles(ProcessedData, false);
345438

346439
// Assess
347-
allStats.versionNumber.Version.ShouldBe("1.1.13");
440+
allStats.versionNumber.Version.ShouldBe("1.1.14");
348441
}
349442

350443
[Fact]

TopStatsWaffle/DemoProcessor.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class PlayerWeapon
3232

3333
public class MatchData
3434
{
35+
private static DemoParser dp;
36+
3537
public Dictionary<Type, List<object>> events = new Dictionary<Type, List<object>>();
3638

3739
Dictionary<int, TickCounter> playerTicks = new Dictionary<int, TickCounter>();
@@ -183,7 +185,7 @@ public static MatchData FromDemoFile(string file, bool parseChickens, bool lowOu
183185
MatchData md = new MatchData();
184186

185187
//Create demo parser instance
186-
DemoParser dp = new DemoParser(File.OpenRead(file), parseChickens);
188+
dp = new DemoParser(File.OpenRead(file), parseChickens);
187189

188190
dp.ParseHeader();
189191

@@ -578,13 +580,14 @@ public AllStats CreateFiles(ProcessedData processedData, bool createJsonFile = t
578580

579581
var dataAndPlayerNames = GetDataAndPlayerNames(processedData);
580582

581-
AllStats allStats = new AllStats();
582-
583-
allStats.versionNumber = GetVersionNumber();
584-
allStats.supportedGamemodes = GetSupportedGamemodes();
585-
allStats.mapInfo = GetMapInfo(processedData, mapNameSplit);
586-
allStats.tanookiStats = processedData.tanookiStats;
587-
allStats.playerStats = GetPlayerStats(processedData, dataAndPlayerNames.Data, dataAndPlayerNames.PlayerNames);
583+
AllStats allStats = new AllStats
584+
{
585+
versionNumber = GetVersionNumber(),
586+
supportedGamemodes = GetSupportedGamemodes(),
587+
mapInfo = GetMapInfo(processedData, mapNameSplit),
588+
tanookiStats = processedData.tanookiStats,
589+
playerStats = GetPlayerStats(processedData, dataAndPlayerNames.Data, dataAndPlayerNames.PlayerNames)
590+
};
588591

589592
var generalroundsStats = GetGeneralRoundsStats(processedData, dataAndPlayerNames.PlayerNames);
590593
allStats.winnersStats = generalroundsStats.winnersStats;
@@ -664,7 +667,7 @@ public DataAndPlayerNames GetDataAndPlayerNames(ProcessedData processedData)
664667

665668
public versionNumber GetVersionNumber()
666669
{
667-
return new versionNumber() { Version = "1.1.13" };
670+
return new versionNumber() { Version = "1.1.14" };
668671
}
669672

670673
public List<string> GetSupportedGamemodes()
@@ -683,21 +686,24 @@ public mapInfo GetMapInfo(ProcessedData processedData, string[] mapNameSplit)
683686
// attempts to get the gamemode
684687
var roundsWonReasons = GetRoundsWonReasons(processedData.RoundEndReasonValues);
685688

686-
if (processedData.MatchStartValues.Any(m => m.HasBombsites) || processedData.BombsitePlantValues.Count() > 0 || roundsWonReasons.Any(w => w.ToString() == winReasonBombed) || roundsWonReasons.Any(w => w.ToString() == winReasonDefused) || roundsWonReasons.Any(w => w.ToString() == winReasonTSaved))
689+
if (processedData.TeamPlayersValues.Any(t => t.Terrorists.Count() > 2 && processedData.TeamPlayersValues.Any(ct => ct.CounterTerrorists.Count() > 2)))
687690
{
688-
if (processedData.TeamPlayersValues.Any(t => t.Terrorists.Count() > 2 && processedData.TeamPlayersValues.Any(ct => ct.CounterTerrorists.Count() > 2)))
691+
if (dp.bombsiteAIndex > -1 || dp.bombsiteBIndex > -1 || processedData.MatchStartValues.Any(m => m.HasBombsites))
689692
{
690693
mapInfo.GameMode = "Defuse";
691694
}
692-
else
695+
else if ((dp.hostageAIndex > -1 || dp.hostageBIndex > -1) && !processedData.MatchStartValues.Any(m => m.HasBombsites))
693696
{
694-
mapInfo.GameMode = "Wingman";
697+
mapInfo.GameMode = "Hostage";
698+
}
699+
else // what the hell is this gamemode ??
700+
{
701+
mapInfo.GameMode = "Unknown";
695702
}
696703
}
697-
else // assumes it's hostage if no bomb events are triggered --- is there a better way to decide this since matches with no plants will fall into this category ???
698-
// maybe instead check the entity list for entities that are bombs or hostages?
704+
else
699705
{
700-
mapInfo.GameMode = "Hostage";
706+
mapInfo.GameMode = "Wingman";
701707
}
702708

703709
return mapInfo;

0 commit comments

Comments
 (0)