Пример #1
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, DiceStoppedRollingData dice = null)
        {
            ExpectingArguments(args, 2);

            string variableName = args[0];
            // TODO: incorrectValue:
            //object incorrectValue = evaluator.Evaluate(Expressions.Clean(args[1]));
            object value = Expressions.Get(Expressions.Clean(args[1]), player, target, spell);

            object instance     = player;
            Type   instanceType = typeof(Character);

            if (KnownQualifiers.IsSpellQualifier(variableName))
            {
                if (evaluator.Variables.ContainsKey(Expressions.STR_CastedSpell))
                {
                    instance     = evaluator.Variables[Expressions.STR_CastedSpell];
                    instanceType = typeof(CastedSpell);
                    variableName = variableName.EverythingAfter(KnownQualifiers.Spell);
                }
            }

            FieldInfo field = instanceType.GetField(variableName);

            if (field != null)
            {
                if (instance != null)
                {
                    field.SetValue(instance, value);
                }
                return(null);
            }

            PropertyInfo property = instanceType.GetProperty(variableName);

            if (property != null)
            {
                if (instance != null)
                {
                    property.SetValue(instance, value);
                }
                return(null);
            }

            player.SetState(variableName, value);

            return(null);
        }
        public override bool Handles(string tokenName, Creature player, CastedSpell castedSpell)
        {
            if (player == null)
            {
                return(false);
            }

            GetPropertyNames();
            if (propertyNames.IndexOf(tokenName) >= 0 | fieldNames.IndexOf(tokenName) >= 0)
            {
                return(true);
            }

            if (KnownQualifiers.StartsWithKnownQualifier(tokenName))
            {
                return(false);
            }

            return(player.HoldsState(tokenName) || tokenName.StartsWith("_"));            // ;
        }
Пример #3
0
        public override object Evaluate(List <string> args, ExpressionEvaluator evaluator, Creature player, Target target, CastedSpell spell, RollResults 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);
        }