Beispiel #1
0
 private void HandleStatsData(StatsDataSource statsData)
 {
     statsData.GameFileID = this.m_gameFile.GameFileID.Value;
     (from x in this.m_statistics
      where x is StatsDataSource
      select x).Cast <StatsDataSource>();
     if (!this.m_statistics.Contains(statsData))
     {
         this.m_statistics.Add(statsData);
         if (this.NewStastics != null)
         {
             this.NewStastics(this, new NewStatisticsEventArgs(statsData));
         }
     }
 }
Beispiel #2
0
        public void SetStatistics(IEnumerable <IStatsDataSource> stats)
        {
            StatsDataSource source = new StatsDataSource();

            foreach (IStatsDataSource source2 in stats)
            {
                source.KillCount    += source2.KillCount;
                source.TotalKills   += source2.TotalKills;
                source.SecretCount  += source2.SecretCount;
                source.TotalSecrets += source2.TotalSecrets;
                source.ItemCount    += source2.ItemCount;
                source.TotalItems   += source2.TotalItems;
                source.LevelTime    += source2.LevelTime;
            }
            this.m_stats = source;
        }
Beispiel #3
0
        private IStatsDataSource ParseLine(string line)
        {
            StatsDataSource stats = new StatsDataSource();

            foreach (StatFileScanner.ParseItem item in s_regexItems)
            {
                Match match = Regex.Match(line, item.RegexInput);
                if (match.Success)
                {
                    line = ReplaceFirst(line, match.Value, string.Empty);
                    base.SetStatProperty(stats, item, match.Value);
                }
                else
                {
                    base.m_errors.Add($"Failed to parse {item.DataSourceProperty} from levelstat file.");
                }
            }
            return(stats);
        }
Beispiel #4
0
        private void ReadStatistics(MemoryStream ms)
        {
            LevelCount count = ReadStuctureFromFile <LevelCount>(ms);

            count = this.CheckLevelCount(count);
            int num = ReadCount(ms);

            ms.Position += num - 1;
            for (int i = 0; i < count.levelcount; i++)
            {
                LevelStats stats = ReadStuctureFromFile <LevelStats>(ms);
                stats        = this.CheckStats(stats);
                ms.Position += 1L;
                num          = ReadCount(ms) - 1;
                byte[] buffer = new byte[num];
                ms.Read(buffer, 0, buffer.Length);
                string          name      = Encoding.ASCII.GetString(buffer).ToLower();
                StatsDataSource statsData = CreateStatsDataSource(stats.totalkills, stats.killcount, stats.totalsecrets, stats.secretcount, stats.leveltime, name);
                this.HandleStatsData(statsData);
            }
        }
Beispiel #5
0
        protected void SetStatProperty(StatsDataSource stats, ParseItem item, string value)
        {
            foreach (char ch in item.Replace)
            {
                value = value.Replace(ch.ToString(), string.Empty);
            }
            PropertyInfo property = stats.GetType().GetProperty(item.DataSourceProperty);

            if (item.DataSourceProperty == "LevelTime")
            {
                char[]   separator = new char[] { ':' };
                string[] strArray  = value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                property.SetValue(stats, (Convert.ToSingle(strArray[0]) * 60f) + Convert.ToSingle(strArray[1]));
            }
            else
            {
                try
                {
                    if (property.PropertyType == typeof(string))
                    {
                        property.SetValue(stats, value);
                    }
                    else if (property.PropertyType == typeof(int))
                    {
                        property.SetValue(stats, Convert.ToInt32(value));
                    }
                    else if (property.PropertyType == typeof(float))
                    {
                        property.SetValue(stats, Convert.ToSingle(value));
                    }
                }
                catch
                {
                    this.m_errors.Add($"Failed for parse value[{value}] for [{item.DataSourceProperty}]");
                }
            }
        }