示例#1
0
        /// <summary>
        /// gets the damage occuring in the last maxage seconds.  removes damage
        /// entries from queue older than maxage
        /// </summary>
        /// <param name="maxage">seconds to calculate damage received</param>
        /// <returns>damage received</returns>
        public static long GetRecentDamage(float maxage)
        {
            DateTime since = DateTime.UtcNow - TimeSpan.FromSeconds(maxage);

            while (DamageHistory.Any())
            {
                Damage next = DamageHistory.Peek();
                if (next.Time >= since)
                {
                    break;
                }

                DamageHistory.Dequeue();
            }

            long sum = 0;

            foreach (var q in DamageHistory)
            {
                if (SingularSettings.Debug)
                {
                    if (q.Time < since)
                    {
                        Logger.WriteDebug("GetRecentDamage: Program Error: entry {0} {1:HH:mm:ss.FFFF} older than {2:HH:mm:ss.FFFF}", q.Amount, q.Time, since);
                    }
                }
                sum += q.Amount;
            }
            return(DamageHistory.Sum(v => v.Amount));
        }
示例#2
0
        /// <summary>
        /// gets the damage occuring in the last maxage seconds.  removes damage
        /// entries from queue older than maxage.  additionally calculates damage
        /// at another time boundary less than maxage (referred to as recent)
        /// </summary>
        /// <param name="maxage">seconds to calculate damage received</param>
        /// <param name="alldmg">damage received since maxage</param>
        /// <param name="recentage">more recent timeframe</param>
        /// <param name="recentdmg">damage since more recent timeframe</param>
        public static void GetRecentDamage(float maxage, out long alldmg, float recentage, out long recentdmg)
        {
            DateTime now         = DateTime.UtcNow;
            DateTime sinceoldest = now - TimeSpan.FromSeconds(maxage);
            DateTime sincerecent = now - TimeSpan.FromSeconds(recentage);

            recentdmg = 0;
            alldmg    = 0;

            if (DamageHistory == null)
            {
                return;
            }

            while (DamageHistory.Any())
            {
                Damage next = DamageHistory.Peek();
                if (next.Time >= sinceoldest)
                {
                    break;
                }

                DamageHistory.Dequeue();
            }

            foreach (var q in DamageHistory)
            {
                alldmg += q.Amount;
                if (q.Time < sincerecent)
                {
                    recentage += q.Amount;
                }

                if (SingularSettings.Debug)
                {
                    if (q.Time < sinceoldest)
                    {
                        Logger.WriteDebug("GetRecentDamage: Program Error: entry {0} {1:HH:mm:ss.FFFF} older than {2:HH:mm:ss.FFFF}", q.Amount, q.Time, sinceoldest);
                    }
                }
            }

            return;
        }