/// <summary>
        /// When overridden in the derived class, tries to add an <see cref="IStatusEffect{StatType, StatusEffectType}"/> to
        /// this collection.
        /// </summary>
        /// <param name="statusEffect">The status effect to add.</param>
        /// <param name="power">The power of the status effect.</param>
        /// <returns>True if the <paramref name="statusEffect"/> of the given <paramref name="power"/> was added
        /// to this collection; otherwise false.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="statusEffect" /> is <c>null</c>.</exception>
        public override bool TryAdd(IStatusEffect<StatType, StatusEffectType> statusEffect, ushort power)
        {
            if (statusEffect == null)
                throw new ArgumentNullException("statusEffect");

            ActiveStatusEffect existingStatusEffect;
            var alreadyExists = TryGetStatusEffect(statusEffect.StatusEffectType, out existingStatusEffect);

            var time = GetTime();
            var disableTime = (TickCount)(time + statusEffect.GetEffectTime(power));

            if (alreadyExists)
            {
                var changed = existingStatusEffect.MergeWith(time, power, disableTime);
                if (changed)
                    RecalculateStatBonuses();
                return changed;
            }
            else
            {
                var ase = new ActiveStatusEffect(statusEffect, power, disableTime);
                _statusEffects.Add(ase);
                OnAdded(ase);
                return true;
            }
        }
		bool CheckEnd(IStatusEffect runtime)
		{
			if (runtime.IsEndEffect())
			{
				runtime.OnEndStatusEffect();
				return true;
			}
			return false;
		}
Example #3
0
        /// <summary>
        /// Removes status effect if exist.
        /// </summary>
        /// <param name="e"></param>
        public void RemoveEffect(IStatusEffect e)
        {
            KeyValue <IStatusEffect, float> effect = Effects.Where(p => p.Key == e).SingleOrDefault();

            if (effect != null)
            {
                Effects.Remove(effect);
                e.Revert(this);
            }
        }
Example #4
0
 public void AddStatusEffect(IStatusEffect effect)
 {
     if (HasStatusEffect(effect.Name))
     {
         CurrentStatusEffects.First(x => x.Name == effect.Name).RemainingTime = effect.Duration;
     }
     else
     {
         CurrentStatusEffects.Add(effect.Copy());
     }
 }
Example #5
0
        /// <summary>
        /// Uniquely add a status effects if it's not already added.
        /// </summary>
        /// <param name="e"></param>
        public void AddEffect(IStatusEffect e, float Duration)
        {
            KeyValue <IStatusEffect, float> effect = Effects.Where(p => p.Key == e).SingleOrDefault();

            if (effect == null)
            {
                Effects.Add(new KeyValue <IStatusEffect, float>(e, Duration));
                e.Init(this);
            }
            else
            {
                effect.Value = Duration;
            }
        }
Example #6
0
    //Apply the status effect for the remaining ticks.
    IEnumerator ApplyStatusEffect(IStatusEffect effect)
    {
        effect.OnAdd(this);
        while (effect.GetRemainingTicks() > 0)
        {
            effect.UseTick(this);
            yield return(new WaitForSeconds(1f));
        }

        effect.OnRemove(this);
        effects.Remove(effect);

        yield break;
    }
        private void Update()
        {
            float time = Time.time;

            for (int i = 0; i < _statusEffects.Count; i++)
            {
                IStatusEffect statusEffect = _statusEffects[i];
                statusEffect.Update();

                if (time - _statusEffectStartTimes[i] >= statusEffect.Duration)
                {
                    Remove(i);
                }
            }
        }
Example #8
0
 /// <summary>
 /// Handles the add status.
 /// </summary>
 /// <param name="effect">Effect.</param>
 /// <param name="printLog">If set to <c>true</c> print log.</param>
 public void HandleAddStatus(BattleEntity sourceEntity, IStatusEffect effect)
 {
     StatusEffectNode node = GetNode (effect);
     bool wasEmpty = node.isEmpty;
     node.ApplyEffect(sourceEntity, effect);
     CheckCleanup(node);
     // check to see if we should fire an event
     if(wasEmpty && !node.isEmpty) {
         BattleSystem.Instance.PostBattleEvent(new StatusEffectEvent(
             mBattleEntity,
             effect.property,
             StatusEffectEvent.StatusEventType.NEW,
             effect.type));
     }
       	else if(!wasEmpty && node.isEmpty) {
         BattleSystem.Instance.PostBattleEvent(new StatusEffectEvent(
             mBattleEntity,
             effect.property,
             StatusEffectEvent.StatusEventType.REMOVED,
             effect.type));
     }
 }
        /// <summary>
        /// When overridden in the derived class, tries to add an <see cref="IStatusEffect{StatType, StatusEffectType}"/> to
        /// this collection.
        /// </summary>
        /// <param name="statusEffect">The status effect to add.</param>
        /// <param name="power">The power of the status effect.</param>
        /// <returns>True if the <paramref name="statusEffect"/> of the given <paramref name="power"/> was added
        /// to this collection; otherwise false.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="statusEffect" /> is <c>null</c>.</exception>
        public override bool TryAdd(IStatusEffect <StatType, StatusEffectType> statusEffect, ushort power)
        {
            if (statusEffect == null)
            {
                throw new ArgumentNullException("statusEffect");
            }

            ASEWithID existingStatusEffect;
            var       alreadyExists = TryGetStatusEffect(statusEffect.StatusEffectType, out existingStatusEffect);

            var time        = GetTime();
            var disableTime = (TickCount)(time + statusEffect.GetEffectTime(power));

            if (alreadyExists)
            {
                // Status effect already exists - merge with it
                var changed = existingStatusEffect.Value.MergeWith(time, power, disableTime);
                if (changed)
                {
                    RecalculateStatBonuses();
                    UpdateInDatabase(existingStatusEffect);
                }
                return(changed);
            }
            else
            {
                // Status effect doesn't exist - create new instance
                var ase = new ActiveStatusEffect(statusEffect, power, disableTime);

                var id = InsertInDatabase(ase);

                var aseWithID = new ASEWithID(id, ase);
                _statusEffects.Add(aseWithID);

                OnAdded(aseWithID.Value);

                return(true);
            }
        }
Example #10
0
 public void AddStatusEffect(IStatusEffect effect)
 {
     state.statusHandler.AddStatus(effect);
 }
Example #11
0
 /// <summary>
 /// When overridden in the derived class, tries to add an <see cref="IStatusEffect{StatType, StatusEffectType}"/> to
 /// this collection.
 /// </summary>
 /// <param name="statusEffect">The status effect to add.</param>
 /// <param name="power">The power of the status effect.</param>
 /// <returns>True if the <paramref name="statusEffect"/> of the given <paramref name="power"/> was added
 /// to this collection; otherwise false.</returns>
 public abstract bool TryAdd(IStatusEffect <StatType, StatusEffectType> statusEffect, ushort power);
        /// <summary>
        /// When overridden in the derived class, tries to add an <see cref="IStatusEffect{StatType, StatusEffectType}"/> to
        /// this collection.
        /// </summary>
        /// <param name="statusEffect">The status effect to add.</param>
        /// <param name="power">The power of the status effect.</param>
        /// <returns>True if the <paramref name="statusEffect"/> of the given <paramref name="power"/> was added
        /// to this collection; otherwise false.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="statusEffect" /> is <c>null</c>.</exception>
        public override bool TryAdd(IStatusEffect<StatType, StatusEffectType> statusEffect, ushort power)
        {
            if (statusEffect == null)
                throw new ArgumentNullException("statusEffect");

            ASEWithID existingStatusEffect;
            var alreadyExists = TryGetStatusEffect(statusEffect.StatusEffectType, out existingStatusEffect);

            var time = GetTime();
            var disableTime = (TickCount)(time + statusEffect.GetEffectTime(power));

            if (alreadyExists)
            {
                // Status effect already exists - merge with it
                var changed = existingStatusEffect.Value.MergeWith(time, power, disableTime);
                if (changed)
                {
                    RecalculateStatBonuses();
                    UpdateInDatabase(existingStatusEffect);
                }
                return changed;
            }
            else
            {
                // Status effect doesn't exist - create new instance
                var ase = new ActiveStatusEffect(statusEffect, power, disableTime);

                var id = InsertInDatabase(ase);

                var aseWithID = new ASEWithID(id, ase);
                _statusEffects.Add(aseWithID);

                OnAdded(aseWithID.Value);

                return true;
            }
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActiveStatusEffect"/> class.
 /// </summary>
 /// <param name="statusEffect">The <see cref="IStatusEffect{TStatType, TSkillType}"/> to use.</param>
 /// <param name="power">The power of the StatusEffect.</param>
 /// <param name="disableTime">The game time at which this <see cref="ActiveStatusEffect"/> will be disabled.</param>
 public ActiveStatusEffect(IStatusEffect <StatType, StatusEffectType> statusEffect, ushort power, TickCount disableTime)
 {
     _statusEffect = statusEffect;
     _power        = power;
     _disableTime  = disableTime;
 }
Example #14
0
 public void AddStatusEffect(IStatusEffect effect)
 {
     CurrentStatusEffects.Add(effect);
 }
Example #15
0
 public StatusEffectRunner(BattleEntity sourceEntity, IStatusEffect statusEffect)
 {
     m_SourceEntity = sourceEntity;
     m_StatusEffect = statusEffect;
 }
Example #16
0
 /// <summary>
 /// Lazy create the node.
 /// </summary>
 /// <returns>The node.</returns>
 /// <param name="effect">Effect.</param>
 private StatusEffectNode GetNode(IStatusEffect effect)
 {
     StatusEffectNode node = null;
     mEffectNodeMap.TryGetValue(effect.property, out node);
     if(node == null) {
         node = new StatusEffectNode(this);
         mEffectNodeMap[effect.property] = node;
     }
     return node;
 }
Example #17
0
		/// <summary>
		/// 状態異常の追加
		/// </summary>
		/// <param name="statusEffect"></param>
		public void AddStatusEffect(IStatusEffect statusEffect)
		{
			runtimeStatusEffects.Add(statusEffect);
			statusEffect.OnStartStatusEffect();
		}
Example #18
0
 public void setUp()
 {
     statusEffect = new StaminaRegenEffect();
 }
Example #19
0
            public void AddEffect(BattleEntity sourceEntity, IStatusEffect statusEffect)
            {
                // TODO sorted list from capacity solves max capacity problem
                // TODO sorted list from endDuration solves checking all

                IStatusEffectRunner runner = new StatusEffectRunner(sourceEntity, statusEffect);
                maxCapacity = Math.Max(maxCapacity, runner.capacity);
                effects.Add(runner);
                netValue += runner.strength;
            }
Example #20
0
 /// <summary>
 /// Applies the magical buff effect. If we have a debuff, lets remove it instead.
 /// </summary>
 /// <param name="effect">Effect.</param>
 private void ApplyEffect(BattleEntity sourceEntity, IStatusEffect effect, StatusEffectAggregator aggregator)
 {
     aggregator.AddEffect(sourceEntity, effect);
 }
Example #21
0
 public void ApplyEffect(BattleEntity sourceEntity, IStatusEffect effect)
 {
     switch(effect.type) {
     case StatusEffectType.POSITIVE:
         ApplyEffect(sourceEntity, effect, positiveEffects);
         break;
     case StatusEffectType.NEGATIVE:
         ApplyEffect(sourceEntity, effect, negativeEffects);
         break;
     case StatusEffectType.NULLIFY:
         ClearEffects();
         break;
     }
 }
Example #22
0
 /// <summary>
 /// 状態異常の追加
 /// </summary>
 /// <param name="statusEffect"></param>
 public void AddStatusEffect(IStatusEffect statusEffect)
 {
     runtimeStatusEffects.Add(statusEffect);
     statusEffect.OnStartStatusEffect();
 }
Example #23
0
 public void AddEffect(IStatusEffect effect)
 {
     StatusEffects.Add(new Tuple <IStatusEffect, int>(effect, effect.Duration));
     effect.BeforeFirstTick(this);
 }
Example #24
0
 public void RemoveEffect(IStatusEffect effect)
 {
     StatusEffects.RemoveAll(e => e.Item1 == effect);
 }
Example #25
0
 public virtual void AddStatusEffect(IStatusEffect effect)
 {
     StatusEffects.Add(effect);
     effect.Apply(this);
 }
Example #26
0
 //Get a status effect and start coroutine to apply
 void GetStatusEffect(IStatusEffect effect)
 {
     effects.Add(effect);
     StartCoroutine(ApplyStatusEffect(effect));
 }
Example #27
0
 public virtual void RemoveStatusEffect(IStatusEffect effect)
 {
     effectsToRemove.Add(effect);
     effect.Remove(this);
 }
Example #28
0
 public void AddStatusEffect(IStatusEffect statusEffect)
 {
     statusEffects.Add(statusEffect);
 }
Example #29
0
 public void ApplyStatusEffect(BattleEntity sourceEntity, IStatusEffect statusEffect)
 {
     mStatusEffectManager.HandleAddStatus(sourceEntity, statusEffect);
 }