Esempio n. 1
0
    public Affix(AffixType type, AffixValue value, int tier)
    {
        Type  = type;
        Value = value;
        Tier  = tier;

        info = AffixInfo.GetAffixInfo(type);
    }
Esempio n. 2
0
 /// <summary>
 /// Exponential progression with the parameter as the base
 /// </summary>
 public static AffixValue Exponential(AffixValue value, int tier, float[] parameters)
 {
     if (parameters.Length != ParameterRequirements[nameof(Exponential)])
     {
         throw new ArgumentException("Exponential progression requires exactly 1 parameter!", nameof(parameters));
     }
     return(Mathf.Pow(parameters[0], tier) * value);
 }
Esempio n. 3
0
 /// <summary>
 /// Simple linear progression of the form y = kx + d
 /// </summary>
 public static AffixValue Linear(AffixValue value, int tier, float[] parameters)
 {
     if (parameters.Length != ParameterRequirements[nameof(Linear)])
     {
         throw new ArgumentException("Linear progression requires exactly 2 parameters!", nameof(parameters));
     }
     return((parameters[0] + parameters[1] * tier) * value);
 }
Esempio n. 4
0
    // Valid progression functions should follow the signature
    // public static Affixvalue <name>(AffixValue, int, float[])
    // and throw an exception if parameters are invalid

    /// <summary>
    /// Always returns the single parameter as result
    /// </summary>
    public static AffixValue Constant(AffixValue value, int tier, float[] parameters)
    {
        if (parameters.Length != ParameterRequirements[nameof(Constant)])
        {
            throw new ArgumentException("Constant progression requires exactly 1 parameter!", nameof(parameters));
        }
        return((value * 0) + parameters[0]);
    }
Esempio n. 5
0
 public override AffixValue Add(AffixValue val)
 {
     if (val is AffixValueSingle)
     {
         return(Add(((AffixValueSingle)val).Value));
     }
     ThrowIncompatipleArgumentTypeException(val);
     return(null);
 }
Esempio n. 6
0
    /// <summary>
    /// Applies the progression function to an instance of AffixValue
    /// </summary>
    /// <param name="value">The value to apply the funciton to</param>
    /// <param name="tier">The tier of the affix</param>
    /// <returns>The progressed AffixValue</returns>
    public AffixValue Apply(AffixValue value, int tier)
    {
        if (progressionFunction == null)
        {
            throw new InvalidOperationException("Can't apply progression without a valid progression function set!");
        }

        return((AffixValue)progressionFunction.Invoke(null, new object[] { value, tier, Parameters }));
    }
Esempio n. 7
0
 public AffixValueMultiple(Tuple <string, AffixValue>[] values)
 {
     Values = new AffixValue[values.Length];
     for (int i = 0; i < values.Length; i++)
     {
         var tuple = values[i];
         Values[i] = tuple.Item2;
         valueNames.Add(tuple.Item1, i);
     }
 }
Esempio n. 8
0
    /// <summary>
    /// Generates an affixValue based on min and max values, a tier, and a progression function
    /// </summary>
    protected AffixValue GetValueForTier(AffixValue min, AffixValue max, int tier, AffixProgression prog)
    {
        if (!prog.HasProgressionFunction())
        {
            throw new InvalidOperationException("Trying to generate affix value with no or invalid progression function set!");
        }
        // At this point we are sure that the prog function is set, but not if parameters are valid

        var   rng  = new Random();
        float frac = rng.Next(101) / 100.0f;

        // This will raise an exception if parameters are invalid
        AffixValue progressedMin = prog.Apply(min, tier);
        AffixValue progressedMax = prog.Apply(max, tier);

        return(progressedMin + (progressedMax - progressedMin) * frac);
    }
Esempio n. 9
0
 public override AffixValue Add(AffixValue val)
 {
     if (val is AffixValueMultiple)
     {
         AffixValueMultiple valMultiple = val as AffixValueMultiple;
         AffixValue[]       vals        = new AffixValue[Values.Length];
         Values.CopyTo(vals, 0);
         for (int i = 0; i < Values.Length; i++)
         {
             vals[i] += valMultiple.Values[i];
         }
     }
     else if (val is AffixValueSingle)
     {
         return(Add(((AffixValueSingle)val).Value));
     }
     ThrowIncompatipleArgumentTypeException(val);
     return(null);
 }
Esempio n. 10
0
    public AffixValueInfo(AffixValue baseValueMin, AffixValue baseValueMax, AffixProgression[] progressions)
    {
        if (!baseValueMin.IsSameType(baseValueMax))
        {
            throw new ArgumentException($"Mininum and maximum value have to be of the same type!");
        }

        if (BaseValueMin is AffixValueMultiple)
        {
            if ((BaseValueMin as AffixValueMultiple).Count != progressions.Length)
            {
                throw new ArgumentException($"Info AffixValueMultiple needs the same amount of progressions as affix values!", nameof(progressions));
            }
        }

        BaseValueMin = baseValueMin;
        BaseValueMax = baseValueMax;
        Progressions = new AffixProgression[progressions.Length];
        for (int i = 0; i < progressions.Length; i++)
        {
            Progressions[i] = new AffixProgression(progressions[i]);
        }
    }
Esempio n. 11
0
    public override bool IsSameType(AffixValue affixValue)
    {
        if (!(affixValue is AffixValueMultiple))
        {
            return(false);
        }

        var affixValueMultiple = affixValue as AffixValueMultiple;

        if (affixValueMultiple.Values.Length != Values.Length)
        {
            return(false);
        }

        for (int i = 0; i < Values.Length; i++)
        {
            if (!affixValueMultiple.Values[i].IsSameType(Values[i]))
            {
                return(false);
            }
        }
        return(true);;
    }
Esempio n. 12
0
 public AffixValueMultiple(params AffixValue[] values)
 {
     Values = new AffixValue[values.Length];
     values.CopyTo(Values, 0);
 }
Esempio n. 13
0
 public AffixValueInfo(AffixValue baseValueMin, AffixValue baseValueMax, AffixProgression progression)
     : this(baseValueMin, baseValueMax, new AffixProgression[] { progression })
 {
 }
Esempio n. 14
0
 public AffixValueInfo(AffixValue baseValueMin, AffixValue baseValueMax) : this(baseValueMin, baseValueMax, new AffixProgression("Linear", 0, 1))
 {
 }
Esempio n. 15
0
 protected void ThrowIncompatipleArgumentTypeException(AffixValue val)
 {
     throw new ArgumentException(string.Format("Cannot add object of type {0} to object of type {1}", val.GetType(), this.GetType()), "val");
 }
Esempio n. 16
0
 public abstract bool IsSameType(AffixValue affixValue);
Esempio n. 17
0
 public abstract AffixValue Add(AffixValue val);
Esempio n. 18
0
 public override bool IsSameType(AffixValue affixValue)
 {
     return(affixValue is AffixValueRange);
 }