示例#1
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);
        }
示例#2
0
        public SlotSelectorDialog(Object item, Game game)
        {
            InitializeComponent();

            ComboBoxItem bagItem = new ComboBoxItem();

            bagItem.Content = "Bag";
            bagItem.Tag     = SpecialSlots.Bag;
            cb.Items.Add(bagItem);

            foreach (var slot in game.Config.CharacterConfig.InventorySlots)
            {
                if (SchemeExecutor.CheckTypeCompatibility(slot.Type, item.Scheme?.Name, game.Config))
                {
                    ComboBoxItem cbItem = new ComboBoxItem();
                    cbItem.Content = slot.Name;
                    cbItem.Tag     = slot.Name;
                    cb.Items.Add(cbItem);

                    if (game.CurrentPlayer.Character.GetItemBySlot(slot.Name, game.Config) == item)
                    {
                        cbItem.IsSelected = true;
                    }
                }
            }

            if (cb.SelectedItem == null)
            {
                bagItem.IsSelected = true;
            }
        }
示例#3
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);
        }
示例#4
0
        public bool MoveItemToSlot(Item item, string slotName, Config config)
        {
            var variable = GetVariableByName(slotName, config);

            if (item.Scheme == null || !SchemeExecutor.CheckTypeCompatibility(variable.Type, item.Scheme.Name, config))
            {
                return(false);
            }

            variable.Value = item;
            return(true);
        }
示例#5
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);
        }
示例#6
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));
        }