Exemple #1
0
    protected SpawnedPuzzleItem spawnItem(PuzzleItem item)
    {
        _itemNames.Add(item.Name);
        GameObject        puzzleItemObj = GameObject.Instantiate(PlayState.instance.puzzleItemPrefab) as GameObject;
        SpawnedPuzzleItem spawnedItem   = puzzleItemObj.GetComponent <SpawnedPuzzleItem>();

        // Give the spawned item all the appropriate properties.
        foreach (string propertyName in item.getPropertyNames())
        {
            spawnedItem.setProperty(propertyName, item.getProperty(propertyName));
        }
        if (getRequest(spawnedItem.itemName) != null)
        {
            spawnedItem.initRequest(getRequest(spawnedItem.itemName));
        }

        // Figure out where to spawn the item
        if (item.propertyExists("spawnArea"))
        {
            string spawnAreaName = item.getProperty("spawnArea") as string;
            addArea(spawnAreaName);
            _areaRooms[spawnAreaName].addPiece(spawnedItem);
        }
        return(spawnedItem);
    }
Exemple #2
0
        // 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);
        }