Example #1
0
 public StatMod(Stat stat, float value, StatModSource source, long ident)
 {
     this.Stat   = stat;
     this.Value  = value;
     this.Source = source;
     this.Ident  = ident;
 }
Example #2
0
 public StatModifier(float value, StatModType type, int duration, StatModSource source)
 {
     Value       = value;
     Type        = type;
     CurrentLife = 0;
     Duration    = duration;
     Source      = source;
 }
Example #3
0
 /// <summary>
 /// Removes all stat mods for source and ident.
 /// </summary>
 /// <param name="stat"></param>
 /// <param name="source"></param>
 /// <param name="ident"></param>
 public void Remove(StatModSource source, long ident)
 {
     lock (_mods)
     {
         foreach (var mod in _mods)
         {
             mod.Value.RemoveAll(a => a.Source == source && a.Ident == ident);
             this.UpdateCache(mod.Key);
         }
     }
 }
Example #4
0
        public StatMod(Stat stat, float value, StatModSource source, long ident, int timeout)
        {
            this.Stat   = stat;
            this.Value  = value;
            this.Source = source;
            this.Ident  = ident;

            this.Timeout = timeout;
            this.Start   = DateTime.Now;
            this.End     = (this.Timeout > 0 ? this.Start.AddSeconds(this.Timeout) : DateTime.MaxValue);
        }
Example #5
0
		/// <summary>
		/// Removes stat mod.
		/// </summary>
		/// <param name="stat"></param>
		/// <param name="source"></param>
		/// <param name="ident"></param>
		public void Remove(Stat stat, StatModSource source, long ident)
		{
			lock (_mods)
			{
				if (!_mods.ContainsKey(stat))
					return;

				_mods[stat].RemoveAll(a => a.Source == source && a.Ident == ident);
			}

			this.UpdateCache(stat);
		}
Example #6
0
        /// <summary>
        /// Removes stat mod.
        /// </summary>
        /// <param name="stat"></param>
        /// <param name="source"></param>
        /// <param name="ident"></param>
        public void Remove(Stat stat, StatModSource source, long ident)
        {
            lock (_mods)
            {
                if (!_mods.ContainsKey(stat))
                {
                    return;
                }

                _mods[stat].RemoveAll(a => a.Source == source && a.Ident == ident);
            }

            this.UpdateCache(stat);
        }
Example #7
0
        /// <summary>
        /// Adds stat mod.
        /// </summary>
        /// <param name="stat">Stat to change</param>
        /// <param name="value">Amount</param>
        /// <param name="source">What is changing the stat?</param>
        /// <param name="ident">Identificator for the source, eg skill or title id.</param>
        /// <param name="timeout">Time in seconds after which the mod is removed.</param>
        public void Add(Stat stat, float value, StatModSource source, long ident, int timeout = 0)
        {
            lock (_mods)
            {
                if (!_mods.ContainsKey(stat))
                    _mods.Add(stat, new List<StatMod>(1));

                if (_mods[stat].Any(a => a.Source == source && a.Ident == ident))
                    Log.Warning("StatMods.Add: Double stat mod for '{0}:{1}'.", source, ident);

                _mods[stat].Add(new StatMod(stat, value, source, ident, timeout));
            }

            this.UpdateCache(stat);
        }
Example #8
0
        /// <summary>
        /// Returns true if any mod for the given source and ident exists.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="ident"></param>
        /// <returns></returns>
        public bool Has(StatModSource source, long ident)
        {
            lock (_mods)
            {
                foreach (var mods in _mods)
                {
                    if (mods.Value.Any(a => a.Source == source && a.Ident == ident))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #9
0
        public virtual bool RemoveAllModifiersFromSource(StatModSource source)
        {
            bool didRemove = false;

            for (int i = statModifiers.Count - 1; i >= 0; i--)
            {
                if (statModifiers[i].Source == source)
                {
                    isDirty   = true;
                    didRemove = true;
                    statModifiers.RemoveAt(i);
                }
            }
            return(didRemove);
        }
Example #10
0
        /// <summary>
        /// Adds stat mod.
        /// </summary>
        /// <param name="stat">Stat to change</param>
        /// <param name="value">Amount</param>
        /// <param name="source">What is changing the stat?</param>
        /// <param name="ident">Identificator for the source, eg skill or title id.</param>
        public void Add(Stat stat, float value, StatModSource source, long ident)
        {
            lock (_mods)
            {
                if (!_mods.ContainsKey(stat))
                    _mods.Add(stat, new List<StatMod>(1));

                var mod = _mods[stat].FirstOrDefault(a => a.Source == source && a.Ident == ident);
                if (mod != null)
                    Log.Warning("StatMods.Add: Double stat mod for '{0}:{1}'.", source, ident);

                _mods[stat].Add(new StatMod(stat, value, source, ident));
            }

            this.UpdateCache(stat);
        }
Example #11
0
        /// <summary>
        /// Adds stat mod.
        /// </summary>
        /// <param name="stat">Stat to change</param>
        /// <param name="value">Amount</param>
        /// <param name="source">What is changing the stat?</param>
        /// <param name="ident">Identificator for the source, eg skill or title id.</param>
        /// <param name="timeout">Time in seconds after which the mod is removed.</param>
        public void Add(Stat stat, float value, StatModSource source, long ident, int timeout = 0)
        {
            lock (_mods)
            {
                if (!_mods.ContainsKey(stat))
                {
                    _mods.Add(stat, new List <StatMod>(1));
                }

                if (_mods[stat].Any(a => a.Source == source && a.Ident == ident))
                {
                    Log.Warning("StatMods.Add: Double stat mod for '{0}:{1}'.", source, ident);
                }

                _mods[stat].Add(new StatMod(stat, value, source, ident, timeout));
            }

            this.UpdateCache(stat);
        }
Example #12
0
        /// <summary>
        /// Adds stat mod.
        /// </summary>
        /// <param name="stat">Stat to change</param>
        /// <param name="value">Amount</param>
        /// <param name="source">What is changing the stat?</param>
        /// <param name="ident">Identificator for the source, eg skill or title id.</param>
        public void Add(Stat stat, float value, StatModSource source, long ident)
        {
            lock (_mods)
            {
                if (!_mods.ContainsKey(stat))
                {
                    _mods.Add(stat, new List <StatMod>(1));
                }

                var mod = _mods[stat].FirstOrDefault(a => a.Source == source && a.Ident == ident);
                if (mod != null)
                {
                    Log.Warning("StatMods.Add: Double stat mod for '{0}:{1}'.", source, ident);
                }

                _mods[stat].Add(new StatMod(stat, value, source, ident));
            }

            this.UpdateCache(stat);
        }
Example #13
0
        public void Add(Stat stat, float amount, StatModSource source, ulong id, DateTime expires)
        {
            if (expires < DateTime.Now)
                throw new ArgumentException("Expires has already passed...");

            lock (this.Mods)
            {
                if (!this.Mods.ContainsKey(stat))
                    this.Mods.Add(stat, new List<StatMod>());

                this.Mods[stat].Add(new StatMod(stat, amount, source, id, expires));

                UpdateCache(stat);
            }

            if (expires != DateTime.MaxValue)
            {
                InitExpiryTimer();
            }
        }
Example #14
0
        public void Remove(Stat stat, StatModSource source, ulong id)
        {
            lock (this.Mods)
            {
                if (!this.Mods.ContainsKey(stat))
                    this.Mods.Add(stat, new List<StatMod>());

                var mod = this.Mods[stat].FirstOrDefault(a => a.Source == source && a.Id == id);

                if (mod == null)
                    return;

                this.Mods[stat].Remove(mod);

                UpdateCache(stat);

                if (mod.Expires != DateTime.MaxValue)
                    InitExpiryTimer();
            }
        }
Example #15
0
        private Timer _expiryTimer = null; // TODO: Busy wait (?) Events may be better

        #endregion Fields

        #region Methods

        public void Add(Stat stat, float amount, StatModSource source, ulong id)
        {
            this.Add(stat, amount, source, id, DateTime.MaxValue);
        }
Example #16
0
 /// <summary>
 /// Removes stat mod.
 /// </summary>
 /// <param name="stat"></param>
 /// <param name="source"></param>
 /// <param name="ident"></param>
 public void Remove(Stat stat, StatModSource source, SkillId ident)
 {
     this.Remove(stat, source, (long)ident);
 }
Example #17
0
 public StatMod(Stat stat, float amount, StatModSource source, ulong id, DateTime expires)
 {
     this.StatEffect = stat;
     this.Amount = amount;
     this.Source = source;
     this.Id = id;
     this.Expires = expires;
 }
Example #18
0
 /// <summary>
 /// Adds stat mod.
 /// </summary>
 /// <param name="stat">Stat to change</param>
 /// <param name="value">Amount</param>
 /// <param name="source">What is changing the stat?</param>
 /// <param name="ident">Identificator for the source, eg skill or title id.</param>
 public void Add(Stat stat, float value, StatModSource source, SkillId ident)
 {
     this.Add(stat, value, source, (long)ident);
 }
Example #19
0
        public StatMod(Stat stat, float value, StatModSource source, long ident, int timeout)
        {
            this.Stat = stat;
            this.Value = value;
            this.Source = source;
            this.Ident = ident;

            this.Timeout = timeout;
            this.Start = DateTime.Now;
            this.End = (this.Timeout > 0 ? this.Start.AddSeconds(this.Timeout) : DateTime.MaxValue);
        }
Example #20
0
 /// <summary>
 /// Adds stat mod.
 /// </summary>
 /// <param name="stat">Stat to change</param>
 /// <param name="value">Amount</param>
 /// <param name="source">What is changing the stat?</param>
 /// <param name="ident">Identificator for the source, eg skill or title id.</param>
 public void Add(Stat stat, float value, StatModSource source, SkillId ident)
 {
     this.Add(stat, value, source, (long)ident);
 }
Example #21
0
 public StatMod(Stat stat, float value, StatModSource source, long ident)
 {
     this.Stat = stat;
     this.Value = value;
     this.Source = source;
     this.Ident = ident;
 }
Example #22
0
 public StatModifier(float value, StatModType type, StatModSource source) : this(value, type, INDEFINITE_BUFF, source)
 {
 }
Example #23
0
 /// <summary>
 /// Removes stat mod.
 /// </summary>
 /// <param name="stat"></param>
 /// <param name="source"></param>
 /// <param name="ident"></param>
 public void Remove(Stat stat, StatModSource source, SkillId ident)
 {
     this.Remove(stat, source, (long)ident);
 }
Example #24
0
        /// <summary>
        /// Returns true if any mod for the given source and ident exists.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="ident"></param>
        /// <returns></returns>
        public bool Has(StatModSource source, long ident)
        {
            lock (_mods)
            {
                foreach (var mods in _mods)
                {
                    if (mods.Value.Any(a => a.Source == source && a.Ident == ident))
                        return true;
                }
            }

            return false;
        }
Example #25
0
 /// <summary>
 /// Removes all stat mods for source and ident.
 /// </summary>
 /// <param name="stat"></param>
 /// <param name="source"></param>
 /// <param name="ident"></param>
 public void Remove(StatModSource source, long ident)
 {
     lock (_mods)
     {
         foreach (var mod in _mods)
         {
             mod.Value.RemoveAll(a => a.Source == source && a.Ident == ident);
             this.UpdateCache(mod.Key);
         }
     }
 }