Example #1
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Creature target, CastedSpell spell)
        {
            ExpectingArguments(args, 1);

            string propertyName = args[0];

            FieldInfo field = typeof(Character).GetField(propertyName);

            if (field != null)
            {
                return(field.GetValue(player));
            }

            PropertyInfo property = typeof(Character).GetProperty(propertyName);

            if (property != null)
            {
                return(property.GetValue(player));
            }

            if (player != null)
            {
                return(player.GetState(propertyName));
            }

            return(null);
        }
        public override object GetValue(string variableName, ExpressionEvaluator evaluator, Character player)
        {
            if (fieldNames.IndexOf(variableName) >= 0)
            {
                FieldInfo field = typeof(Character).GetField(variableName);
                return(field?.GetValue(player));
            }

            if (propertyNames.IndexOf(variableName) >= 0)
            {
                PropertyInfo property = typeof(Character).GetProperty(variableName);
                return(property?.GetValue(player));
            }

            return(player.GetState(variableName));
        }
Example #3
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 1);

            string propertyName = args[0];

            FieldInfo field = typeof(Character).GetField(propertyName);

            if (field != null)
            {
                return(field.GetValue(player));
            }

            PropertyInfo property = typeof(Character).GetProperty(propertyName);

            if (property != null)
            {
                return(property.GetValue(player));
            }

            if (KnownQualifiers.IsSpellQualifier(propertyName))
            {
                if (evaluator.Variables.ContainsKey(Expressions.STR_CastedSpell))
                {
                    object castedSpell  = evaluator.Variables[Expressions.STR_CastedSpell];
                    Type   instanceType = typeof(CastedSpell);
                    propertyName = propertyName.EverythingAfter(KnownQualifiers.Spell);
                    property     = instanceType.GetProperty(propertyName);
                    return(property.GetValue(castedSpell));
                }
            }

            if (player != null)
            {
                return(player.GetState(propertyName));
            }

            return(null);
        }
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Character player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            if (player == null)
            {
                return(null);
            }

            ExpectingArguments(args, 2);

            string variableName = args[0];
            object rawValue     = Expressions.Get <object>(args[1], player, target, spell);
            double valueDouble;

            if (rawValue == null)
            {
                valueDouble = 0;
            }
            else
            {
                valueDouble = MathUtils.GetDouble(rawValue.ToString());
            }
            int valueInt = (int)Math.Round(valueDouble);

            // TODO: Wil says Convert.ConvertTo() can simplify this.

            FieldInfo field = typeof(Character).GetField(variableName);

            if (field != null)
            {
                if (field.FieldType.FullName == "System.Int32")
                {
                    field.SetValue(player, MathUtils.GetInt(field.GetValue(player).ToString()) + valueInt);
                }
                else
                {
                    field.SetValue(player, MathUtils.GetDouble(field.GetValue(player).ToString()) + valueDouble);
                }
                return(null);
            }

            PropertyInfo property = typeof(Character).GetProperty(variableName);

            if (property != null)
            {
                if (property.PropertyType.FullName == "System.Int32")
                {
                    property.SetValue(player, MathUtils.GetInt(property.GetValue(player).ToString()) + valueInt);
                }
                else
                {
                    property.SetValue(player, MathUtils.GetDouble(property.GetValue(player).ToString()) + valueDouble);
                }
                return(null);
            }

            object existingValueRaw = player.GetState(variableName);

            if (existingValueRaw != null)
            {
                if (existingValueRaw is int)
                {
                    player.SetState(variableName, MathUtils.GetInt(existingValueRaw.ToString()) + valueInt);
                }
                else
                {
                    player.SetState(variableName, MathUtils.GetDouble(existingValueRaw.ToString()) + valueDouble);
                }
                return(null);
            }

            throw new Exception($"Variable \"{variableName}\" not found.");
        }