/// <summary> /// Adds an affect. /// </summary> /// <param name="effect">The effect to add.</param> public virtual void AddEffect(IEffect <T> effect) { if (EffectTimes.Any(x => x.Effect == effect)) { return; } if (!effect.CanBeAppliedTo(EffectTarget)) { throw new WrapperException($"Failed to add effect.\r\nThe effect of type '{effect.GetType()}' can't be applied to the target of type '{EffectTarget.GetType()}'."); } effect.OnAttach(EffectTarget); EffectTimes.Add(new EffectTimeContainer(effect, -1)); }
/// <summary> /// Attaches the given effect. /// </summary> /// <param name="effect">The effect to attach.</param> /// <returns><c>true</c> if the effect could be attached; otherwise, <c>false</c>.</returns> public bool AttachEffect(IEffect effect) { bool retVal = false; lock (Effects) { if (effect != null && Effects.All(x => x.Effect != effect)) { effect.OnAttach(); Effects.AddLast(new EffectTimeContainer(effect, -1)); retVal = true; } } CheckUpdateLoop(); return retVal; }