public StatMod(Stat stat, float value, StatModSource source, long ident) { this.Stat = stat; this.Value = value; this.Source = source; this.Ident = ident; }
public StatModifier(float value, StatModType type, int duration, StatModSource source) { Value = value; Type = type; CurrentLife = 0; Duration = duration; Source = source; }
/// <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); } } }
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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
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); }
/// <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); }
/// <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); }
/// <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); }
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(); } }
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(); } }
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); }
/// <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); }
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; }
/// <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); }
public StatModifier(float value, StatModType type, StatModSource source) : this(value, type, INDEFINITE_BUFF, source) { }
/// <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; }