コード例 #1
0
ファイル: SoundEx.cs プロジェクト: ForeverZer0/fmod-net
        public void AddEffect(DspType effect)
        {
            var dsp = _system.CreateDspByType(effect);

            _effects.Add(dsp);
            EffectAdded?.Invoke(this, EventArgs.Empty);
        }
コード例 #2
0
ファイル: ItemManagerComponent.cs プロジェクト: KHCmaster/PPD
 public void AddEffect(ItemEffect effect)
 {
     effects.Add(effect);
     effect.StartTime = stopwatch.ElapsedMilliseconds;
     if (EffectAdded != null)
     {
         EffectAdded.Invoke(effect);
     }
 }
コード例 #3
0
        /// <summary>
        /// Add a new active effect
        /// </summary>
        /// <param name="effect"></param>
        public void AddEffect(StatEffect effect)
        {
            StatValue stat;
            bool      addToActive = false;

            // Check for stack issues
            if (!effect.canStack)
            {
                foreach (StatEffect fx in Effects)
                {
                    if (fx.name == effect.name)
                    {
                        if (fx.resetLifeOnAdd)
                        {
                            fx.RemainingTime = fx.lifeInSeconds;
                        }
                        return;
                    }
                }
            }

            // Check if effect is prevented
            foreach (StatEffect fx in Effects)
            {
                if (fx.IsEffectPrevented(effect.name))
                {
                    return;
                }
            }

            // Check for resist
            foreach (EffectResistance effectResistance in effectResistances)
            {
                if (effectResistance.effect.name == effect.name)
                {
                    float resistRoll = Random.Range(0f, 1f);

                    if (resistRoll <= effectResistance.resistChance)
                    {
                        onEffectResisted?.Invoke(effect);
                        return;
                    }

                    break;
                }
            }

            // Remove cancelled & prevented effects
            List <StatEffect> removeByNew = new List <StatEffect>();

            foreach (StatEffect fx in Effects)
            {
                if (!removeByNew.Contains(fx) && effect.IsEffectCancelled(fx.name) || effect.IsEffectPrevented(fx.name))
                {
                    removeByNew.Add(fx);
                }
            }

            foreach (StatEffect fx in removeByNew)
            {
                RemoveEffect(fx);
            }

            // Find modifier targets
            foreach (StatModifier mod in effect.modifiers)
            {
                stat = FindStat(mod.affectedStat);
                if (stat == null)
                {
                    // Apply to modifiers
                    List <DamageModifier> modifiers = FindDamageModifiers(mod.affectedStat);
                    foreach (DamageModifier dm in modifiers)
                    {
                        dm.AddModifier(mod);
                        if (mod.effectType != EffectTypes.Instant)
                        {
                            addToActive = true;
                        }
                    }
                }
                else
                {
                    stat.AddModifier(mod);
                    if (mod.effectType != EffectTypes.Instant)
                    {
                        addToActive = true;
                    }
                }
            }

            // Check for duration only items
            if (!addToActive && (effect.hasLifeSpan || effect.preventEffects.Count > 0))
            {
                if (!effect.canStack)
                {
                    bool hasInstance = false;
                    foreach (StatEffect fx in Effects)
                    {
                        if (fx.name == effect.name)
                        {
                            hasInstance = true;
                            break;
                        }
                    }

                    if (!hasInstance)
                    {
                        addToActive = true;
                    }
                }
                else
                {
                    addToActive = true;
                }
            }

            if (addToActive)
            {
                StatEffect instance = InstanceStatEffect(effect);
                instance.Initialize();
                Effects.Add(instance);
                onEffectAdded?.Invoke(instance);
            }
        }