Example #1
0
    public virtual void ModifyStatPermanently(float value, StatModifier.StatModificationType modType)
    {
        switch (modType)
        {
        case StatModifier.StatModificationType.Additive:
            BaseValue += value;
            break;

        case StatModifier.StatModificationType.Multiplicative:
            float adj;

            if (value < 0)
            {
                adj = Mathf.Clamp01(1 + value);
            }
            else
            {
                adj = 1 + value;
            }

            BaseValue *= adj;

            break;
        }

        if (this is CappedStat)
        {
            CappedStat stat = this as CappedStat;

            if (stat.BaseValue > stat.MaxValue)
            {
                stat.Refresh();
            }
        }
    }
Example #2
0
    public void RemoveTrackedMod(StatType type, StatModifier mod, GameObject cause, params StatModifierOption[] statOptions)
    {
        List <StatModifierOption> options = ConvertStatOptionsToList(statOptions);

        BaseStat targetStat = GetStat(type);

        if (targetStat == null)
        {
            Debug.Log("Stat: " + type + " not found");
            return;
        }

        if (options.Contains(StatModifierOption.Cap))
        {
            CappedStat capped = TryConvertToCappedStat(targetStat);

            if (capped != null)
            {
                capped.RemoveCapModifier(mod);
                OnStatChanged(type, cause);
            }
        }

        if ((options.Count < 1 || options.Contains(StatModifierOption.Base)))
        {
            targetStat.RemoveModifier(mod);
            OnStatChanged(type, cause);
        }
    }
Example #3
0
    public void ResetStat(StatType type, params StatModifierOption[] statOptions)
    {
        List <StatModifierOption> options = ConvertStatOptionsToList(statOptions);

        BaseStat targetStat = GetStat(type);

        if (targetStat == null)
        {
            Debug.Log("Stat: " + type + " not found");
            return;
        }

        if (options.Contains(StatModifierOption.Cap))
        {
            CappedStat capped = TryConvertToCappedStat(targetStat);

            if (capped != null)
            {
                capped.ResetCap();
                OnStatChanged(type, null);
            }
        }

        if ((options.Count < 1 || options.Contains(StatModifierOption.Base)))
        {
            targetStat.Reset();
            OnStatChanged(type, null);
        }
    }
Example #4
0
    public void ApplyPermanentMod(StatType type, float value, StatModificationType modType, GameObject cause, params StatModifierOption[] statOptions)
    {
        List <StatModifierOption> options = ConvertStatOptionsToList(statOptions);

        BaseStat targetStat = GetStat(type);

        if (targetStat == null)
        {
            Debug.LogError("Stat: " + type + " not found");
            return;
        }

        if (options.Contains(StatModifierOption.Cap))
        {
            CappedStat capped = TryConvertToCappedStat(targetStat);

            if (capped != null)
            {
                capped.ModifyCapPermanently(value, modType);
                OnStatChanged(type, cause);
            }
        }

        if ((options.Count < 1 || options.Contains(StatModifierOption.Base)))
        {
            targetStat.ModifyStatPermanently(value, modType);
            OnStatChanged(type, cause);
        }
    }
Example #5
0
    public float GetCappedStatRatio(StatType type)
    {
        BaseStat targetStat = GetStat(type);

        //Debug.Log("trying to get the stat ratio for " + type);

        CappedStat cap = TryConvertToCappedStat(targetStat);

        if (cap != null)
        {
            //Debug.Log(type + " has a ratio of " + cap.Ratio);

            return(cap.Ratio);
        }



        //if (targetStat != null && targetStat is CappedStat) {
        //    CappedStat capped = targetStat as CappedStat;

        //    return capped.Ratio;
        //}

        Debug.LogError("The ratio value was reqested for a stat with no max. Returning 0");

        return(0f);
    }
Example #6
0
 public void TakeDamage(float damage, LivingThing attacker)
 {
     Health -= damage;
     if (TakeDamageEvent != null)
     {
         TakeDamageEvent(damage, attacker);
     }
     if (Health.GetVal() <= 0)
     {
         Die();
     }
 }
Example #7
0
    private CappedStat TryConvertToCappedStat(BaseStat targetStat)
    {
        CappedStat capped = null;

        try {
            capped = targetStat as CappedStat;
            if (capped == null)
            {
                throw new System.NullReferenceException();
            }
        }
        catch {
            Debug.LogError(targetStat.Type + " is not a capped stat but told to convert to a capped stat");
            return(null);
        }

        return(capped);
    }
Example #8
0
    private CappedStat TryConvertToCappedStat(BaseStat targetStat)
    {
        CappedStat capped = null;

        //Debug.Log(targetStat.Type + " is being converted");

        try {
            capped = targetStat as CappedStat;
            if (capped == null)
            {
                throw new System.NullReferenceException();
            }
        }
        catch {
            Debug.LogError(" Stat collection tried to convert a stat to a capped stat but failed");
            return(null);
        }

        return(capped);
    }
Example #9
0
    public float GetStatMaxValue(StatType type)
    {
        BaseStat targetStat = GetStat(type);

        CappedStat cap = TryConvertToCappedStat(targetStat);

        if (cap != null)
        {
            return(cap.MaxValue);
        }

        //if(targetStat != null && targetStat is CappedStat) {
        //    CappedStat capped = targetStat as CappedStat;

        //    return capped.MaxValue;
        //}

        Debug.LogError("The maximum value was reqested for a stat with no max. Returning 0");

        return(0f);
    }
Example #10
0
 public static CappedStat operator -(CappedStat argLHS, float argRHS)
 {
     CappedStat myStat = new CappedStat(argLHS);
     myStat.Current -= argRHS;
     return myStat;
 }
Example #11
0
 /// <summary>
 /// Copy Constructor
 /// </summary>
 /// <param name="argStat"></param>
 public CappedStat(CappedStat argStat)
     : base(argStat)
 {
     cap = argStat.Cap;
 }
Example #12
0
    public void AddStat(StatType type, float value, float maxValue)
    {
        CappedStat newCappedStat = new CappedStat(type, value, maxValue);

        AddStat(newCappedStat);
    }