Skip to content

Commit 27bb99c

Browse files
author
Jimmy T-W
committed
v1.1.13 - Added TimeInRound to FeedbackMessages
1 parent ad28d10 commit 27bb99c

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

TopStatsWaffle.Tests/TopStatsWaffleTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public void Should_return_version_number_correctly()
344344
AllStats allStats = MatchData.CreateFiles(ProcessedData, false);
345345

346346
// Assess
347-
allStats.versionNumber.Version.ShouldBe("1.1.11");
347+
allStats.versionNumber.Version.ShouldBe("1.1.13");
348348
}
349349

350350
[Fact]
@@ -412,6 +412,7 @@ public void MockData()
412412
YLastAlivePosition = 130,
413413
ZLastAlivePosition = 140,
414414
Message = "bad map",
415+
TimeInRound = 31.7568,
415416
}
416417
};
417418

TopStatsWaffle/DemoProcessor.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,19 @@ public static MatchData FromDemoFile(string file, bool parseChickens, bool lowOu
266266
string[] currentPositions = SplitPositionString(player?.Position.ToString());
267267
string[] lastAlivePositions = playerAlive ? null : SplitPositionString(player?.LastAlivePosition.ToString());
268268

269+
var roundsEndedEvents = md.events.Where(k => k.Key.Name.ToString() == "RoundEndedEventArgs").Select(v => v.Value);
270+
var freezetimesEndedEvents = md.events.Where(k => k.Key.Name.ToString() == "FreezetimeEndedEventArgs").Select(v => v.Value).ElementAt(0);
271+
272+
int numOfRoundsEnded = roundsEndedEvents.Count() > 0 ? roundsEndedEvents.ElementAt(0).Count() : 0;
273+
int numOfFreezetimesEnded = freezetimesEndedEvents.Count();
274+
275+
float timeInRound = 0; // Stays as '0' if sent during freezetime
276+
if (numOfFreezetimesEnded > numOfRoundsEnded)
277+
{
278+
var freezetimeEnded = (FreezetimeEndedEventArgs)freezetimesEndedEvents.LastOrDefault(); // would it be better to use '.OrderByDescending(f => f.TimeEnd).FirstOrDefault()' ?
279+
timeInRound = dp.CurrentTime - freezetimeEnded.TimeEnd;
280+
}
281+
269282
FeedbackMessage feedbackMessage = new FeedbackMessage()
270283
{
271284
Round = round,
@@ -277,7 +290,8 @@ public static MatchData FromDemoFile(string file, bool parseChickens, bool lowOu
277290
XLastAlivePosition = (lastAlivePositions != null) ? (double?)double.Parse(lastAlivePositions[1]) : null,
278291
YLastAlivePosition = (lastAlivePositions != null) ? (double?)double.Parse(lastAlivePositions[2]) : null,
279292
ZLastAlivePosition = (lastAlivePositions != null) ? (double?)double.Parse(lastAlivePositions[3]) : null,
280-
Message = text
293+
Message = text,
294+
TimeInRound = timeInRound, // counts messages sent after the round_end event fires as the next round, set to '0' as if it was the next round's warmup (done this way instead of using round starts to avoid potential issues when restarting rounds)
281295
};
282296

283297
md.addEvent(typeof(FeedbackMessage), feedbackMessage);
@@ -294,9 +308,24 @@ public static MatchData FromDemoFile(string file, bool parseChickens, bool lowOu
294308
// if round_freeze_end event did not get fired in this round due to error
295309
while (numOfFreezetimesEnded <= numOfRoundsEnded)
296310
{
297-
dp.RaiseFreezetimeEnded();
311+
dp.RaiseFreezetimeEnded(new FreezetimeEndedEventArgs()
312+
{
313+
TimeEnd = -1, // no idea when this actually ended without guessing
314+
});
298315
numOfFreezetimesEnded = freezetimesEndedEvents.ElementAt(0).Count();
299-
}
316+
317+
// set the TimeInRound value to '-1' for any feedback messages sent this round, as it will be wrong
318+
if (md.events.Any(k => k.Key.Name.ToString() == "FeedbackMessage"))
319+
{
320+
foreach (FeedbackMessage message in md.events.Where(k => k.Key.Name.ToString() == "FeedbackMessage").Select(v => v.Value)?.ElementAt(0))
321+
{
322+
if (message.Round == numOfFreezetimesEnded)
323+
{
324+
message.TimeInRound = -1;
325+
}
326+
}
327+
}
328+
}
300329

301330
md.addEvent(typeof(RoundEndedEventArgs), e);
302331

@@ -635,7 +664,7 @@ public DataAndPlayerNames GetDataAndPlayerNames(ProcessedData processedData)
635664

636665
public versionNumber GetVersionNumber()
637666
{
638-
return new versionNumber() { Version = "1.1.12" };
667+
return new versionNumber() { Version = "1.1.13" };
639668
}
640669

641670
public List<string> GetSupportedGamemodes()

TopStatsWaffle/Models/FeedbackMessage.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public class FeedbackMessage
1212
public double? YLastAlivePosition { get; set; }
1313
public double? ZLastAlivePosition { get; set; }
1414
public string Message { get; set; }
15+
public double TimeInRound { get; set; }
1516

16-
public FeedbackMessage() { }
17+
public FeedbackMessage() { }
1718
}
1819
}

0 commit comments

Comments
 (0)