コード例 #1
0
 public object ProcessStat(Stat stat, object value, float strength, StatMachine statMachine)
 {
     foreach (Skill skill in Data.Values)
     {
         value = skill.ProcessStat(stat, value, strength, statMachine);
     }
     return(value);
 }
コード例 #2
0
 /// <summary>
 /// Creates a new StatMachine and registers it in the system. It can be found again using its Owner or by using the reference returned by this method.
 /// </summary>
 /// <param name="Owner">The Owner of the created StatMachine.</param>
 public StatMachine CreateStatMachine(StatEntity Owner, Statset Statset)
 {
     if (!StatMachines.ContainsKey(Owner))
     {
         StatMachine newMachine = new StatMachine(Owner, Statset);
         StatMachines.Add(Owner, newMachine);
         return(newMachine);
     }
     Debug.LogError("Only one stat machine per owner allowed: <b>" + Owner.ToString() + "</b> already controls a stat machine.");
     return(null);
 }
コード例 #3
0
 /// <summary>
 /// <para>Creates a FactInt, which is linked to a Stat.</para>
 /// <para>Be carefull when creating Facts that get their values from stats, as an evaluation is called everytime the value gets asked and you can possibly create infinite loops with this.</para>
 /// </summary>
 /// <param name="Identifier">Identifier of this Fact.</param>
 /// <param name="StatToLink">The Stat that will output the value of this fact.</param>
 /// <param name="StatMachineLink">The Stat machine that should hold this Stat.</param>
 public FactIntFromStat(string Identifier, string StatToLink, StatMachine StatMachineLink) : base(Identifier, 0)
 {
     if (FactFromStatSyntaxChecker.Check(StatMachineLink, StatToLink, typeof(StatInt)))
     {
         StatName             = StatToLink;
         this.StatMachineLink = StatMachineLink;
     }
     else
     {
         throw new System.Exception("Could not create FactIntFromStat as the linked stat is not derived from StatInt or does not exist in this statMachine.");
     }
 }
コード例 #4
0
 public override object ProcessStat(Stat stat, object value, float strength, StatMachine statMachine)
 {
     if (stat is StatFloat)
     {
         return(AddToInitialValue ? (float)stat.GetValueAsObject() * (MultiplyWith - 1f) * strength + (float)value : (float)value * (MultiplyWith * strength));
     }
     if (stat is StatInt)
     {
         return((int)(AddToInitialValue ? (float)stat.GetValueAsObject() * (MultiplyWith - 1f) * strength + (float)value : (float)value * (MultiplyWith * strength)));
     }
     return(base.ProcessStat(stat, value, strength, statMachine));
 }
コード例 #5
0
 public override object ProcessStat(Stat stat, object value, float strength, StatMachine statMachine)
 {
     if (stat is StatFloat)
     {
         return((float)value + (amountToAdd * strength));
     }
     if (stat is StatInt)
     {
         return((int)((int)value + (amountToAdd * strength)));
     }
     return(base.ProcessStat(stat, value, strength, statMachine));
 }
コード例 #6
0
 public override object ProcessStat(Stat stat, object value, float strength, StatMachine statMachine)
 {
     if (HasMaximum)
     {
         value = Mathf.Min((float)value, Maximum);
     }
     if (HasMinimum)
     {
         value = Mathf.Max((float)value, Minimum);
     }
     return(base.ProcessStat(stat, value, strength, statMachine));
 }
コード例 #7
0
 public override object ProcessStat(Stat stat, object value, float strength, StatMachine statMachine)
 {
     if (stat is StatFloat)
     {
         return((float)newValue);
     }
     if (stat is StatInt)
     {
         return((int)newValue);
     }
     if (stat is StatBool)
     {
         return((bool)newValue);
     }
     return(base.ProcessStat(stat, value, strength, statMachine));
 }
コード例 #8
0
        /// <summary>
        /// Processing a stat and wiring it through all the skill effects to return the correct result. Note that if a condition returns false, the SkillEffects will not be applied.
        /// </summary>
        /// <param name="stat">The stat to evaluate.</param>
        /// <param name="value">The initial stat value</param>
        /// <param name="strength">The strength modifier that will be passed to the effects.</param>
        /// <param name="statMachine">A link to the statMachine that ordered the processing.</param>
        /// <returns>The value of the stat after all skill effects have been applied.</returns>
        public object ProcessStat(Stat stat, object value, float strength, StatMachine statMachine)
        {
            if (!AffectedStats.Contains(stat.Identifier))
            {
                return(value);
            }

            //evaluate the conditions in this skill
            foreach (Condition condition in Conditions)
            {
                if (condition.SelfEvaluate(statMachine) == false)
                {
                    return(value);
                }
            }

            foreach (SkillEffect effect in Effects)
            {
                if (effect.Identifier.Equals(stat.Identifier))
                {
                    bool AllConditionsTrue = true;

                    //evaluate the conditions in the SkillEffect. If one condition is false, continue with next SkillEffect
                    foreach (Condition condition in effect.Conditions)
                    {
                        if (condition.SelfEvaluate(statMachine) == false)
                        {
                            AllConditionsTrue = false;
                            break;
                        }
                    }

                    if (AllConditionsTrue)
                    {
                        value = effect.ProcessStat(stat, value, effect.ignoreSkillStrength ? 1f : strength, statMachine);
                    }
                }
            }
            return(value);
        }
コード例 #9
0
        public override object ProcessStat(Stat stat, object value, float strength, StatMachine statMachine)
        {
            Fact searchResultFact = default;

            if (statMachine.FactStorage.HasKey(MultiplyWith, out searchResultFact))
            {
                if (searchResultFact is FactFloat || searchResultFact is FactInt)
                {
                    float factor    = Convert.ToSingle(searchResultFact.getValueAsObject());
                    float tempValue = Convert.ToSingle(value);
                    if (stat is StatFloat)
                    {
                        return(AddToInitialValue ? (float)stat.GetValueAsObject() * (factor - 1f) * strength + tempValue : tempValue *(factor * strength));
                    }
                    if (stat is StatInt)
                    {
                        return((int)(AddToInitialValue ? (int)stat.GetValueAsObject() * (factor - 1f) * strength + tempValue : tempValue *(factor * strength)));
                    }
                }
            }
            return(base.ProcessStat(stat, value, strength, statMachine));
        }
コード例 #10
0
 public virtual object ProcessStat(Stat stat, object value, float strength, StatMachine statMachine)
 {
     return(value);
 }