Ejemplo n.º 1
0
        public void Execute(SchemeExecutor executor)
        {
            ObjectVariable objectVariable = executor.GetVariableByName(characterName);
            ObjectVariable numberVariable = executor.FindValueByString(numberName);

            if (objectVariable == null)
            {
                throw SchemeExecutor.CreateException($"Character '{characterName}' not found");
            }
            if (numberVariable.Type != VariableTypes.Number)
            {
                throw SchemeExecutor.CreateException($"Number is expected to be of type number");
            }

            int requiredNumber = (int)numberVariable.Value;

            if (!(objectVariable.Value is Character))
            {
                throw SchemeExecutor.CreateException("Items can only be added to characters");
            }

            Character character = (Character)(objectVariable.Value);

            ObjectVariable itemVariable = executor.GetVariableByName(itemName);

            if (!executor.CheckTypeCompatibility(VariableTypes.Object, itemVariable.Type))
            {
                throw SchemeExecutor.CreateException($"Type '{itemVariable.Type}' is not an object type");
            }

            character.AddItem(executor.Game, (Object)itemVariable.Value, requiredNumber);
        }
Ejemplo n.º 2
0
            public override object VisitParameter_definition([NotNull] scheme_langParser.Parameter_definitionContext context)
            {
                //Add parameter to scheme
                string type = context.variable_type()?.GetText();
                string name = context.variable_name()?.GetText();

                if (type == null || name == null)
                {
                    return(base.VisitParameter_definition(context));
                }

                if (CompiledScheme.GetVariableByName(name) != null || CompiledScheme.GetParameterByName(name) != null)
                {
                    Errors.Add(new ErrorDescriptor($"Variable or parameter '{name}' already exists.", context.variable_name()));
                }
                else if (!VariableManager.IsTypeValid(type, Config))
                {
                    Errors.Add(new ErrorDescriptor($"Type '{type}' is not recognized.", context.variable_type()));
                }
                else
                {
                    ObjectVariable param = new ObjectVariable(type, name, null);
                    CompiledScheme.AddParameter(param);
                }

                return(base.VisitParameter_definition(context));
            }
Ejemplo n.º 3
0
        public ObjectVariable AddAbility(string abilityName)
        {
            var ability = new ObjectVariable(VariableTypes.Ability, abilityName, 0);

            Variables.Add(ability);
            return(ability);
        }
Ejemplo n.º 4
0
        public void Execute(SchemeExecutor executor)
        {
            ObjectVariable @object        = executor.GetVariableByName(objectName);
            ObjectVariable numberVariable = executor.FindValueByString(numberName);

            if (@object == null)
            {
                throw SchemeExecutor.CreateException($"Object '{objectName}' not found");
            }
            if (numberVariable.Type != VariableTypes.Number)
            {
                throw SchemeExecutor.CreateException($"Number is expected to be of type number");
            }

            int requiredNumber = (int)numberVariable.Value;

            if (!(@object.Value is Character))
            {
                throw new SchemeExecutionException($"Object '{objectName}' is not a character");
            }

            Character character = (Character)(@object.Value);

            int ownedNumber = character.CountItem(itemName);

            bool owns = ownedNumber >= requiredNumber;

            executor.SetVariable(targetName, new ObjectVariable(VariableTypes.Logical, "", owns));
        }
Ejemplo n.º 5
0
        public void Execute(SchemeExecutor executor)
        {
            ObjectVariable property = executor.GetPropertyOf(propertyName, objectName);
            ObjectVariable value    = executor.FindValueByString(valueName);

            property.Value = value.Value;
        }
Ejemplo n.º 6
0
        public void Execute(SchemeExecutor executor)
        {
            ObjectVariable objectVariable = executor.GetVariableByName(characterName);

            if (objectVariable == null)
            {
                throw SchemeExecutor.CreateException($"Character '{characterName}' not found");
            }

            if (!(objectVariable.Value is Character))
            {
                throw SchemeExecutor.CreateException("Spells can only be added to characters");
            }

            Character character = (Character)(objectVariable.Value);

            ObjectVariable spellVariable = executor.GetVariableByName(spellName);

            if (!executor.CheckTypeCompatibility(VariableTypes.Object, spellVariable.Type))
            {
                throw SchemeExecutor.CreateException($"Type '{spellVariable.Type}' is not an object type");
            }

            character.AddSpell((Object)spellVariable.Value);
        }
Ejemplo n.º 7
0
        public void SetVariable(string variableName, ObjectVariable value)
        {
            //Check if variable is a register
            if (IsRegister(variableName))
            {
                //First we get value, and create register with same type and value
                Registers[variableName] = new ObjectVariable(value.Type, variableName, value.Value);
            }
            else
            {
                ObjectVariable variable = GetVariableByName(variableName);

                if (variable != null)
                {
                    if (!CheckTypeCompatibility(variable.Type, value.Type, Game.Config))
                    {
                        throw CreateException("Incompatible types");
                    }

                    variable.Value = value.Value;
                }
                else
                {
                    throw CreateException($"Unidentifyable variable '{variableName}'");
                }
            }
        }
Ejemplo n.º 8
0
        private void AddParams(Scheme scheme)
        {
            if (scheme?.CompiledScheme == null)
            {
                return;
            }

            foreach (var param in scheme.CompiledScheme.Parameters)
            {
                var value = Object.GetParameterByName(param.Name);

                if (value == null || value.Type != param.Type)
                {
                    // if parameter's type changed, we delete the old and create a new
                    if (value != null && value.Type != param.Type)
                    {
                        Object.Parameters.RemoveAll(p => p.Name == param.Name);
                    }

                    value = new ObjectVariable(param.Type, param.Name, null);
                    Object.Parameters.Add(value);
                }

                var paramRow = ParameterRowFactory.Create(param, value, Project.Current.Config);
                paramRow.Margin = new Thickness(5, 5, 5, 5);
                spParams.Children.Add(paramRow);
            }
        }
Ejemplo n.º 9
0
        protected override bool GetResult(ObjectVariable variable1, ObjectVariable variable2)
        {
            //In case of numbers and logicals we compare values
            if (variable1.Type == VariableTypes.Number)
            {
                if (variable2.Type != VariableTypes.Number)
                {
                    throw SchemeExecutor.CreateException("Cannot compare number and non-number");
                }
                int value1_int = (int)variable1.Value;
                int value2_int = (int)variable2.Value;
                return(value1_int == value2_int);
            }
            if (variable1.Type == VariableTypes.Logical)
            {
                if (variable2.Type != VariableTypes.Logical)
                {
                    throw SchemeExecutor.CreateException("Cannot compare logical and non-logical");
                }
                bool value1_bool = (bool)variable1.Value;
                bool value2_bool = (bool)variable2.Value;
                return(value1_bool == value2_bool);
            }

            //In case of other types, we compare if they are the same object
            return(variable1.Value == variable2.Value);
        }
Ejemplo n.º 10
0
        public UCEParameterRow_StringConst(string paramName, ObjectVariable value) : base(paramName, value)
        {
            InitializeComponent();

            tbParamName.Text = paramName;

            textSelector.SelectByTag((Text)value.Value);
        }
Ejemplo n.º 11
0
        public void Execute(SchemeExecutor executor)
        {
            ObjectVariable variable1 = executor.FindValueByString(value1);
            ObjectVariable variable2 = executor.FindValueByString(value2);

            bool result = GetResult(variable1, variable2);

            executor.SetVariable(target, new ObjectVariable(VariableTypes.Logical, "", result));
        }
Ejemplo n.º 12
0
        private UCETextListElem CreateSlotElem(ObjectVariable slot)
        {
            UCETextListElem elem = new UCETextListElem();

            elem.Content        = $"{slot.Name} [{slot.Type}]";
            elem.Tag            = slot;
            elem.DeleteClicked += SlotElem_DeleteClicked;
            return(elem);
        }
Ejemplo n.º 13
0
        public void CreateLocalVariable(string type, string name, object value)
        {
            if (GetVariableByName(name) != null)
            {
                throw CreateException($"Variable '{name}' already exists");
            }

            ObjectVariable variable = new ObjectVariable(type, name, value);

            LocalVariables.Add(variable);
        }
Ejemplo n.º 14
0
        public UCEParameterRow_Logical(string paramName, ObjectVariable value) : base(paramName, value)
        {
            InitializeComponent();

            tbParamName.Text = paramName;

            if (value.Value == null)
            {
                value.Value = false;
            }
            cb.IsChecked = (bool)value.Value;
        }
Ejemplo n.º 15
0
        public UCEAbilityRow(ObjectVariable ability, AbilityMaxValue abilityMaxValue)
        {
            InitializeComponent();

            Ability         = ability;
            AbilityMaxValue = abilityMaxValue;

            tbAbilityName.Text   = ability.Name;
            nbAbilityValue.Value = (int)ability.Value;

            AbilityMaxValue.RemainingValue -= (int)ability.Value;
        }
Ejemplo n.º 16
0
        protected override bool GetResult(ObjectVariable variable1, ObjectVariable variable2)
        {
            if (variable1.Type != VariableTypes.Number || variable2.Type != VariableTypes.Number)
            {
                throw SchemeExecutor.CreateException("Cannot compare non-numbers");
            }

            int value1_int = (int)variable1.Value;
            int value2_int = (int)variable2.Value;

            return(value1_int < value2_int);
        }
Ejemplo n.º 17
0
        public UCEParameterRow_Number(string paramName, ObjectVariable value) : base(paramName, value)
        {
            InitializeComponent();

            tbParamName.Text = paramName;

            if (value.Value == null)
            {
                value.Value = 0;
            }
            iValue.NumValue = Convert.ToInt32(value.Value);
        }
Ejemplo n.º 18
0
        public void Execute(SchemeExecutor executor)
        {
            ObjectVariable objectVariable = executor.GetVariableByName(objectName);

            if (!executor.CheckTypeCompatibility(VariableTypes.Object, objectVariable.Type))
            {
                throw SchemeExecutor.CreateException($"Object has to be compatible with 'object' (actual type: '{objectVariable.Type}')");
            }

            Object @object = (Object)objectVariable.Value;

            @object.ForbidAttribute(attributeName);
        }
Ejemplo n.º 19
0
        protected override bool Evaluate(SchemeExecutor executor)
        {
            ObjectVariable variable = executor.FindValueByString(value);

            if (variable.Type != VariableTypes.Logical)
            {
                throw SchemeExecutor.CreateException("Cannot use non-logical value in JF");
            }

            bool value_bool = (bool)variable.Value;

            return(!value_bool);
        }
Ejemplo n.º 20
0
        public void Execute(SchemeExecutor executor)
        {
            ObjectVariable variable = executor.FindValueByString(value);

            if (variable.Type != VariableTypes.Logical)
            {
                throw SchemeExecutor.CreateException("Cannot invert non-logical");
            }

            bool value_bool = (bool)variable.Value;

            executor.SetVariable(target, new ObjectVariable(VariableTypes.Logical, "", (!value_bool)));
        }
Ejemplo n.º 21
0
        public UCEParameterRow_Object(string paramName, ObjectVariable value, Config config) : base(paramName, value)
        {
            InitializeComponent();

            tbParamName.Text = paramName;

            if (value.Type != VariableTypes.Object)
            {
                Scheme scheme = config.GetSchemeByName(value.Type);
                objectSelector.SchemeFilter = scheme;
            }

            objectSelector.SelectByTag((Object)value.Value);
        }
Ejemplo n.º 22
0
        //Returns the given property (as reference) of the object identified by objectName
        public ObjectVariable GetPropertyOf(string propertyName, string objectName)
        {
            //First we identify the object
            Object @object = null;

            ObjectVariable objectVariable = GetVariableByName(objectName);

            if (objectVariable == null)
            {
                throw CreateException("Object not found");
            }

            @object = (Object)objectVariable.Value;

            return(@object.GetVariableByName(propertyName, Game.Config));
        }
Ejemplo n.º 23
0
        public UCEClassSelector(ClassList classList, ObjectVariable classVariable)
        {
            InitializeComponent();
            ClassVariable = classVariable;

            if (classList.ShownName != null)
            {
                tbClasslistName.Text = $"{classList.ShownName.Content} ({classList.Name})";
            }
            else
            {
                tbClasslistName.Text = classList.Name;
            }

            BuildClassSelector(classList);
        }
Ejemplo n.º 24
0
        public void Execute(SchemeExecutor executor)
        {
            ObjectVariable objectVariable = executor.GetVariableByName(objectName);

            // ObjectVariable property = executor

            //Uses of 'is':
            //  object has attribute                actor is forest_wanderer
            //  class var                           race of actor is dwarf          // -> OF(race, actor, _0) EQUALS(_0, dwarf, _0)
            //  item/spell is the same as...        some_item is sword_1            //some_item.Name == "sword_1"

            /*
             * 1. Check if object's name equals to propertyName
             * 2. Check if object has attribute named propertyName
             */

            bool value = false;

            //If we check class variable
            if (executor.Game.Config.IsClassType(objectVariable.Type))
            {
                //we search for the required class
                var c = executor.FindValueByString(propertyName);
                //then we compare it to the classvar
                value = objectVariable.Value == c.Value;
            }
            else
            {
                if (!executor.CheckTypeCompatibility(VariableTypes.Object, objectVariable.Type))
                {
                    throw SchemeExecutor.CreateException("Object has to be compatible with 'object'");
                }

                Object @object = (Object)objectVariable.Value;

                if (@object.Name == propertyName)
                {
                    value = true;
                }
                else if (@object.HasAttribute(propertyName))
                {
                    value = true;
                }
            }

            executor.SetVariable(target, new ObjectVariable(VariableTypes.Logical, "", value));
        }
Ejemplo n.º 25
0
        private void BuildClassList(Character character)
        {
            spClasses.Children.Clear();

            foreach (ClassList classList in Config.ClassLists)
            {
                ObjectVariable classVariable = character.GetVariableByName(classList.Name, Config);
                if (classVariable == null)
                {
                    classVariable = new ObjectVariable(classList.Name, classList.Name, null);
                    character.Variables.Add(classVariable);
                }

                UCEClassSelector classSelector = new UCEClassSelector(classList, classVariable);
                spClasses.Children.Add(classSelector);
            }
        }
Ejemplo n.º 26
0
        public void Execute(SchemeExecutor executor)
        {
            ObjectVariable variable1 = executor.FindValueByString(value1);
            ObjectVariable variable2 = executor.FindValueByString(value2);

            if (variable1.Type != VariableTypes.Logical)
            {
                throw new Exception("Cannot do logical operation with non-logical variables");
            }

            bool value1_bool = (bool)variable1.Value;
            bool value2_bool = (bool)variable2.Value;

            bool result = GetResult(value1_bool, value2_bool);

            executor.SetVariable(target, new ObjectVariable(VariableTypes.Logical, "", result));
        }
Ejemplo n.º 27
0
        public static ParameterRow Create(ObjectVariable param, ObjectVariable value, Config config)
        {
            if (param.Type == VariableTypes.Number || param.Type == VariableTypes.Ability)
            {
                return(new UCEParameterRow_Number(param.Name, value));
            }
            if (param.Type == VariableTypes.Logical)
            {
                return(new UCEParameterRow_Logical(param.Name, value));
            }
            if (param.Type == VariableTypes.Text)
            {
                return(new UCEParameterRow_StringConst(param.Name, value));
            }

            return(new UCEParameterRow_Object(param.Name, value, config));
        }
Ejemplo n.º 28
0
        public void Execute(SchemeExecutor executor)
        {
            ObjectVariable variable1 = executor.FindValueByString(value1);
            ObjectVariable variable2 = executor.FindValueByString(value2);

            if (variable1.Type != VariableTypes.Number)
            {
                throw new Exception("Cannot do operation with non-number variables");
            }

            int value1_int = (int)variable1.Value;
            int value2_int = (int)variable2.Value;

            int result = GetResult(value1_int, value2_int);

            executor.SetVariable(target, new ObjectVariable(VariableTypes.Number, "", result));
        }
Ejemplo n.º 29
0
        // Finds the type and value represented by the given string (including variables; and constants like 11, 5, true, $STRING etc.)
        // This method calculates the current value of abilities and return that value (thus cannot be used to change ability values)
        public ObjectVariable FindValueByString(string s)
        {
            //If there is a variable with the name s, we return its value
            ObjectVariable variable = GetVariableByName(s);

            if (variable != null)
            {
                return(variable);
            }

            //If s is a number const we return it as a new number variable
            int  number;
            bool canConvert = int.TryParse(s, out number);

            if (canConvert)
            {
                return(new ObjectVariable("number", "", number));
            }

            //If s is a logical const, we return it as a new logical variable
            if (s.ToLower() == "true")
            {
                return(new ObjectVariable("logical", "", true));
            }
            if (s.ToLower() == "false")
            {
                return(new ObjectVariable("logical", "", false));
            }

            //If s is a string const we return its content as a text variable
            if (s.Length >= 1 && s[0] == '$')
            {
                return(new ObjectVariable("text", "", Game.Config.GetStringConstByName(s)));
            }

            //If s is a class variable we return it as class
            var c = Game.Config.GetClassByName(s);

            if (c != null)
            {
                return(new ObjectVariable(c.Item1.Name, "", c.Item2));
            }

            throw CreateException($"Unidentifyable value '{s}'");
        }
Ejemplo n.º 30
0
        private void bAddItem_Click(object sender, RoutedEventArgs e)
        {
            if (tbSlotName.Text == null || tbSlotName.Text.Length == 0 || slotSchemeSelector.SelectedTag == null)
            {
                return;
            }

            string slotType = slotSchemeSelector.SelectedTag.Name;
            string slotName = tbSlotName.Text;

            ObjectVariable slot = new ObjectVariable(slotType, slotName, null);

            Project.Current.Config.CharacterConfig.InventorySlots.Add(slot);

            var elem = CreateSlotElem(slot);

            spSlots.Children.Add(elem);
        }