private void HandleStatsData(StatsData statsData) { statsData.GameFileID = GameFile.GameFileID.Value; if (!m_statistics.Contains(statsData)) { m_statistics.Add(statsData); NewStastics?.Invoke(this, new NewStatisticsEventArgs(statsData)); } }
private static StatsData CreateBinaryStatsDataSource(UInt32 totalkills, UInt32 killcount, UInt32 totalsecrets, UInt32 secretcount, UInt32 leveltime, string name) { float calctime = Convert.ToSingle(leveltime) / 35.0f; StatsData stats = new StatsData(); stats.RecordTime = DateTime.Now; stats.TotalKills = (int)totalkills; stats.KillCount = (int)killcount; stats.TotalSecrets = (int)totalsecrets; stats.SecretCount = (int)secretcount; stats.LevelTime = calctime; stats.MapName = name; return(stats); }
public void SetStatistics(IEnumerable <IStatsData> stats) { StatsData statTotal = new StatsData(); foreach (IStatsData stat in stats) { statTotal.KillCount += stat.KillCount; statTotal.TotalKills += stat.TotalKills; statTotal.SecretCount += stat.SecretCount; statTotal.TotalSecrets += stat.TotalSecrets; statTotal.ItemCount += stat.ItemCount; statTotal.TotalItems += stat.TotalItems; statTotal.LevelTime += stat.LevelTime; } m_stats = statTotal; }
//separate json and binary to avoid stat overflow with how binary (old save format) is read private static StatsData CreateJsonStatsDataSource(UInt32 totalkills, UInt32 killcount, UInt32 totalitems, UInt32 itemcount, UInt32 totalsecrets, UInt32 secretcount, UInt32 leveltime, string name) { float calctime = Convert.ToSingle(leveltime) / 35.0f; StatsData stats = new StatsData { RecordTime = DateTime.Now, TotalKills = (int)totalkills, KillCount = (int)killcount, TotalItems = (int)totalitems, ItemCount = (int)itemcount, TotalSecrets = (int)totalsecrets, SecretCount = (int)secretcount, LevelTime = calctime, MapName = name }; return(stats); }
public void SetStatistics(IEnumerable <IGameFile> gameFiles, IEnumerable <IStatsData> stats) { StatsData statTotal = new StatsData(); int maps = 0, totalMaps = 0; var groupedStats = stats.OrderByDescending(x => x.RecordTime).GroupBy(x => x.GameFileID); foreach (var group in groupedStats) { var gameFile = gameFiles.FirstOrDefault(x => x.GameFileID.Value == group.Key); if (gameFile != null) { var mapStats = group.GroupBy(x => x.MapName).Select(x => x.First()); if (gameFile.MapCount.HasValue) { int mapCount = mapStats.Count(); if (mapCount > gameFile.MapCount.Value) { mapCount = gameFile.MapCount.Value; } maps += mapCount; totalMaps += gameFile.MapCount.Value; } foreach (var stat in mapStats) { statTotal.KillCount += stat.KillCount; statTotal.TotalKills += stat.TotalKills; statTotal.SecretCount += stat.SecretCount; statTotal.TotalSecrets += stat.TotalSecrets; statTotal.ItemCount += stat.ItemCount; statTotal.TotalItems += stat.TotalItems; statTotal.LevelTime += stat.LevelTime; } } } ctrlStatsMaps.SetStats(maps, totalMaps, string.Format("{0} / {1}", maps, totalMaps)); ctrlStatsKills.SetStats(statTotal.KillCount, statTotal.TotalKills, statTotal.FormattedKills); ctrlStatsSecrets.SetStats(statTotal.SecretCount, statTotal.TotalSecrets, statTotal.FormattedSecrets); ctrlStatsItems.SetStats(statTotal.ItemCount, statTotal.TotalItems, statTotal.FormattedItems); }
private IStatsData ParseLine(string line) { line = line.Replace(" ", string.Empty); StatsData ret = new StatsData(); foreach (ParseItem item in s_regexItems) { Match match = Regex.Match(line, item.RegexInput); if (match.Success) { SetStatProperty(ret, item, match.Value); } else { m_errors.Add(string.Format("Failed to parse {0} from levelstat file.", item.DataSourceProperty)); } } return(ret); }
protected void SetStatProperty(StatsData stats, ParseItem item, string value) { foreach (char c in item.Replace) { value = value.Replace(c.ToString(), string.Empty); } PropertyInfo pi = stats.GetType().GetProperty(item.DataSourceProperty); if (item.DataSourceProperty == "LevelTime") //speical case, need to split out ':' and calculate time { string[] time = value.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); pi.SetValue(stats, (Convert.ToSingle(time[0], CultureInfo.InvariantCulture) * 60) + Convert.ToSingle(time[1], CultureInfo.InvariantCulture)); } else { try { if (pi.PropertyType == typeof(string)) { pi.SetValue(stats, value); } else if (pi.PropertyType == typeof(int)) { pi.SetValue(stats, Convert.ToInt32(value)); } else if (pi.PropertyType == typeof(float)) { pi.SetValue(stats, Convert.ToSingle(value)); } } catch { m_errors.Add(string.Format("Failed for parse value[{0}] for [{1}]", value, item.DataSourceProperty)); } } }
private void ReadStatistics(MemoryStream ms) { LevelCount count = ReadStuctureFromFile <LevelCount>(ms); count = CheckLevelCount(count); int stringLength = ReadCount(ms); ms.Position += stringLength - 1; //This part MAY contain the start episode map, just skip it for (int i = 0; i < count.levelcount; i++) { LevelStats stats = ReadStuctureFromFile <LevelStats>(ms); stats = CheckStats(stats); ms.Position += 1; //skip NEW_NAME (27) stringLength = ReadCount(ms) - 1; byte[] levelNameBytes = new byte[stringLength]; ms.Read(levelNameBytes, 0, levelNameBytes.Length); string levelName = Encoding.ASCII.GetString(levelNameBytes).ToLower(); StatsData statsData = CreateBinaryStatsDataSource(stats.totalkills, stats.killcount, stats.totalsecrets, stats.secretcount, stats.leveltime, levelName); HandleStatsData(statsData); } }