コード例 #1
0
ファイル: BuildingBlock.cs プロジェクト: nixlim/Puzzledice
        // General outline of puzzle generation
        protected virtual bool spawnFilteredOutput(string outputName)
        {
            if (!Database.Instance.itemExists(outputName))
            {
                if (_verbose)
                {
                    Debug.Log("Failed to generate puzzle, output does not exist in database " + outputName);
                }
                return(false);
            }

            DBItem dbitem = Database.Instance.getItem(outputName);

            if (dbitem.Spawned)
            {
                if (_verbose)
                {
                    Debug.Log("Failed to generate puzzle: " + outputName + " already spawned");
                }
                return(false);
            }

            PuzzleItem output = dbitem.spawnItem();

            _spawnedItems.Add(outputName);
            output = applyPropertiesToSpawnedItem(_desiredOutputProperties, output);
            // Give the output a unique id if it doesn't already have one
            if (!output.propertyExists("spawnIndex"))
            {
                output.setProperty("spawnIndex", dbitem.NextSpawnIndex);
            }
            _spawnedOutput = output;
            return(true);
        }
コード例 #2
0
        public PuzzleItem spawnItem()
        {
            _numSpawned++;

            PuzzleItem    itemToReturn = new PuzzleItem(_className);
            List <string> mutables;

            if (_properties.ContainsKey("mutables"))
            {
                mutables = _properties["mutables"] as List <string>;
            }
            else
            {
                mutables = new List <string>();
            }


            // Copy properties from the dbitem to the output item
            foreach (string propertyName in _properties.Keys)
            {
                if (!mutables.Contains(propertyName))
                {
                    itemToReturn.setProperty(propertyName, _properties[propertyName]);
                }
            }

            return(itemToReturn);
        }
コード例 #3
0
ファイル: BuildingBlock.cs プロジェクト: nixlim/Puzzledice
        // A useful function for applying our desired properties to a spawned item
        // useful primarily because it allows leeway for doing things like inserting items into containers
        // via the contains property
        protected virtual PuzzleItem applyPropertiesToSpawnedItem(Dictionary <string, object> desiredProperties, PuzzleItem item)
        {
            foreach (string propertyName in desiredProperties.Keys)
            {
                if (propertyName == "contains")
                {
                    List <PuzzleItem> itemsInside   = new List <PuzzleItem>();
                    List <string>     itemsToInsert = desiredProperties["contains"] as List <string>;
                    foreach (string itemToInsertName in itemsToInsert)
                    {
                        if (!Database.Instance.itemExists(itemToInsertName))
                        {
                            if (_verbose)
                            {
                                Debug.Log("Puzzle failed to generate output, internal item " + itemToInsertName + " does not exist");
                            }
                            return(null);
                        }
                        if (Database.Instance.getItem(itemToInsertName).Spawned)
                        {
                            if (_verbose)
                            {
                                Debug.Log("Puzzle failed to generate output. Internal item " + itemToInsertName + " already spawned");
                            }
                            return(null);
                        }
                        PuzzleItem itemToInsert = Database.Instance.getItem(itemToInsertName).spawnItem();
                        applyPropertiesToSpawnedItem(desiredProperties["innerItemProps"] as Dictionary <string, object>, itemToInsert);
                        itemsInside.Add(itemToInsert);
                        _spawnedItems.Add(itemToInsertName);
                    }
                    item.setProperty("contains", itemsInside);
                }
                else
                {
                    item.setProperty(propertyName, desiredProperties[propertyName]);
                }
            }

            return(item);
        }
コード例 #4
0
ファイル: DBItem.cs プロジェクト: alect/Puzzledice
        public PuzzleItem spawnItem()
        {
            _numSpawned++;

            PuzzleItem itemToReturn = new PuzzleItem(_className);
            List<string> mutables;
            if (_properties.ContainsKey("mutables"))
                mutables = _properties["mutables"] as List<string>;
            else
                mutables = new List<string>();

            // Copy properties from the dbitem to the output item
            foreach (string propertyName in _properties.Keys) {
                if (!mutables.Contains(propertyName))
                    itemToReturn.setProperty(propertyName, _properties[propertyName]);
            }

            return itemToReturn;
        }