Exemple #1
0
    /// <summary>
    /// Add a new status effect to this component.
    /// </summary>
    /// <param name="statusEffects">The status effect to add.</param>
    public void AddStatusEffect(ScriptableStatusEffectData statusEffectData)
    {
        StatusEffectBase statusEffect = statusEffectData.InitializeStatusEffect(this);

        bool hasMerged = false;

        if (mergeEffectsOfSameType)
        {
            // Todo: not efficient if there are many status effects active
            System.Type statusEffectType = statusEffect.GetType();
            foreach (StatusEffectBase activeStatusEffect in activeStatusEffects)
            {
                if (activeStatusEffect.GetType() == statusEffectType)
                {
                    activeStatusEffect.Merge(statusEffect);
                    hasMerged = true;
                    break;
                }
            }
        }

        if (hasMerged == false)
        {
            activeStatusEffects.Add(statusEffect);
            OnstatusEffectAdded?.Invoke(statusEffect);

            statusEffect.Activate();
        }

        UpdateProcessingState();
    }
 public HungerStatusEffect(ScriptableStatusEffectData statusEffect, StatusEffectComponent statusEffectComponent) : base(statusEffect, statusEffectComponent)
 {
     hungerComponent        = statusEffectComponent.GetComponent <HungerComponent>();
     hungerStatusEffectData = (HungerStatusEffectData)statusEffect;
 }
 public HealthStatusEffect(ScriptableStatusEffectData statusEffect, StatusEffectComponent statusEffectComponent) : base(statusEffect, statusEffectComponent)
 {
     healthComponent        = statusEffectComponent.GetComponent <HealthComponent>();
     healthStatusEffectData = (HealthStatusEffectData)statusEffect;
 }
 public StatusEffectBase(ScriptableStatusEffectData statusEffect, StatusEffectComponent statusEffectComponent)
 {
     this.statusEffectComponent = statusEffectComponent;
     this.statusEffectData      = statusEffect;
     this.timeRemaining         = statusEffect.Duration;
 }