예제 #1
0
        protected override bool spawnFilteredInputs(string outputName)
        {
            DBItem dbOutput = Database.Instance.getItem(outputName);

            // Get the possible boxes to contain our item
            List<string> possibleContainers = new List<string>();
            if (_desiredOutputProperties.ContainsKey("fills"))
                possibleContainers = new List<string>(_desiredOutputProperties["fills"] as List<string>);
            else if (dbOutput.propertyExists("fills"))
                possibleContainers = new List<string>(dbOutput.getProperty("fills") as List<string>);

            BuildingBlock.shuffle(possibleContainers);
            foreach (string boxName in possibleContainers) {
                Dictionary<string, object> boxProperties = new Dictionary<string, object>();
                boxProperties["open"] = false;
                boxProperties["contains"] = new List<string>() { outputName };
                boxProperties["innerItemProps"] = new Dictionary<string, object>(_desiredOutputProperties);
                // Include the spawn index
                (boxProperties["innerItemProps"] as Dictionary<string, object>)["spawnIndex"] = _outputSpawnIndex;
                PuzzleOutput possibleInput = _containerInput.generatePuzzle(boxName, boxProperties);
                if (possibleInput == null) {
                    if (_verbose) Debug.Log(string.Format("Failed to generate unboxing puzzle with {0} as the box and {1} as the item to remove.", boxName, outputName));
                    continue;
                }

                // If we officially succeed
                if (_verbose) Debug.Log(string.Format("Successfully generated unboxing puzzle with {0} as the box and {1} as the item to remove.", boxName, outputName));
                _itemsToSpawn.AddRange(possibleInput.Items);
                _relationshipsToSpawn.AddRange(possibleInput.Relationships);
                // Add the insertion relationship
                InsertionRelationship insertionRelationship = new InsertionRelationship(outputName, _outputSpawnIndex, boxName, _containerInput.outputSpawnIndex());
                _relationshipsToSpawn.Add(insertionRelationship);

                return true;
            }
            if (_verbose) Debug.Log("Failed to generate unboxing puzzle. No possible boxes worked.");
            return false;
        }
예제 #2
0
        protected override bool spawnFilteredInputs(string outputName)
        {
            // First determine if our desiredProperties specifically has any items it wants to contain
            DBItem dbOutput = Database.Instance.getItem(outputName);
            List<string> possibleFillers;
            if (_desiredOutputProperties["contains"] != null)
                possibleFillers = new List<string>(_desiredOutputProperties["contains"] as List<string>);
            else if (dbOutput.propertyExists("filledby"))
                possibleFillers = new List<string>(dbOutput.getProperty("filledby") as List<string>);
            else {
                if (_verbose) Debug.Log("Failed to generate insertion puzzle. No possible fillers worked.");
                return false;
            }

            BuildingBlock.shuffle(possibleFillers);
            foreach (string fillerName in possibleFillers) {
                if (!areCarryable(new List<string>() { outputName, fillerName }, new List<BuildingBlock>() { _containerInput, _itemToInsertInput }))
                    continue;

                // Update the properties we're passing to our inputs
                Dictionary<string, object> newDesiredOutputProperties = new Dictionary<string, object>();
                foreach (string key in _desiredOutputProperties.Keys) {
                    newDesiredOutputProperties[key] = _desiredOutputProperties[key];
                }
                // Make sure we can open our item
                newDesiredOutputProperties["open"] = true;
                if (newDesiredOutputProperties["contains"] != null) {
                    List<string> fillerArray = new List<string>(newDesiredOutputProperties["contains"] as List<string>);
                    fillerArray.Remove(fillerName);
                    if (fillerArray.Count == 0)
                        newDesiredOutputProperties.Remove("contains");
                    else
                        newDesiredOutputProperties["contains"] = fillerArray;
                }

                // Now try to generate the inputs
                Dictionary<string, object> innerItemProps = new Dictionary<string, object>();
                if (_desiredOutputProperties.ContainsKey("innerItemProps"))
                    innerItemProps = _desiredOutputProperties["innerItemProps"] as Dictionary<string, object>;
                PuzzleOutput possibleContainerInput = _containerInput.generatePuzzle(outputName, newDesiredOutputProperties);
                PuzzleOutput possibleFillerInput = _itemToInsertInput.generatePuzzle(fillerName, innerItemProps);
                if (possibleContainerInput == null || possibleFillerInput == null) {
                    if (_verbose) Debug.Log(string.Format("Failed to generate insertion puzzle with {0} as the container and {1} as the filler.", outputName, fillerName));
                    _containerInput.despawnItems();
                    _itemToInsertInput.despawnItems();
                    continue;
                }

                if (_verbose) Debug.Log(string.Format("Successfully generated insertion puzzle with {0} as container and {1} as the filler.", outputName, fillerName));
                _itemsToSpawn.AddRange(possibleContainerInput.Items);
                _itemsToSpawn.AddRange(possibleFillerInput.Items);
                _relationshipsToSpawn.AddRange(possibleContainerInput.Relationships);
                _relationshipsToSpawn.AddRange(possibleFillerInput.Relationships);

                // Add an insertion relationship here
                InsertionRelationship insertionRelationship = new InsertionRelationship(fillerName, _itemToInsertInput.outputSpawnIndex(), outputName, _containerInput.outputSpawnIndex());
                _relationshipsToSpawn.Add(insertionRelationship);

                return true;

            }

            if (_verbose) Debug.Log("Failed to generate insertion puzzle. No possible fillers worked.");
            return false;
        }
예제 #3
0
 public void accept(InsertionRelationship rel)
 {
     // Add the insertion relationship to the map
     if (!_relationshipMap.ContainsKey(rel.containerName))
         _relationshipMap[rel.containerName] = new Dictionary<string, IRelationship>();
     _relationshipMap[rel.containerName][rel.fillerName] = rel;
     if (!_relationshipMap.ContainsKey(rel.fillerName))
         _relationshipMap[rel.fillerName] = new Dictionary<string, IRelationship>();
     _relationshipMap[rel.fillerName][rel.containerName] = rel;
 }
예제 #4
0
 public void accept(InsertionRelationship rel)
 {
     // Insert one item in the other.
     SpawnedPuzzleItem box, filler;
     if (rel.containerName == _item1.itemName) {
         box = _item1;
         filler = _item2;
     }
     else {
         box = _item2;
         filler = _item1;
     }
     // If the box is empty, insert the filler item
     if (!box.containsItem) {
         filler.addToOtherItem(box);
         PlayState.instance.playAudio(PlayState.instance.pickupClip);
     }
     else {
         PlayState.instance.addPlayerText(string.Format("The {0} is full.", box.itemName));
     }
 }
예제 #5
0
    protected void addAuxiliaryRelationship(string name1, string name2)
    {
        IRelationship relToAdd = null;

        DBItem dbitem1 = Database.Instance.getItem(name1);
        DBItem dbitem2 = Database.Instance.getItem(name2);

        // Figure out if one of the items can be inserted in the other
        if (dbitem1.propertyExists("container") && (bool)dbitem1.getProperty("container")
            && dbitem1.propertyExists("filledby") && (dbitem1.getProperty("filledby") as List<string>).Contains(name2)) {
             	relToAdd = new InsertionRelationship(name2, 0, name1, 0);
        }
        if (relToAdd == null) {
            if (dbitem2.propertyExists("container") && (bool)dbitem2.getProperty("container")
                && dbitem2.propertyExists("filledby") && (dbitem2.getProperty("filledby") as List<string>).Contains(name1)) {
                 	relToAdd = new InsertionRelationship(name1, 0, name2, 0);
            }
        }
        // Next, try combine relationships
        if (relToAdd == null) {
            if (dbitem1.propertyExists("makes")) {
                List<KeyValuePair<string, string>> makes = new List<KeyValuePair<string, string>>((List<KeyValuePair<string, string>>)dbitem1.getProperty("makes"));
                Globals.shuffle(makes);
                foreach (KeyValuePair<string, string> recipe in makes) {
                    if (recipe.Key == name2) {
                        if (!Database.Instance.itemExists(recipe.Value))
                            continue;
                        DBItem dbResult = Database.Instance.getItem(recipe.Value);
                        if (dbResult.Spawned)
                            continue;
                        PuzzleItem resultItem = dbResult.spawnItem();
                        relToAdd = new CombineRelationship(name1, 0, name2, 0, resultItem);
                        break;
                    }
                }
            }
        }
        if (relToAdd == null) {
            if (dbitem2.propertyExists("makes")) {
                List<KeyValuePair<string, string>> makes = new List<KeyValuePair<string, string>>((List<KeyValuePair<string, string>>)dbitem2.getProperty("makes"));
                Globals.shuffle(makes);
                foreach (KeyValuePair<string, string> recipe in makes) {
                    if (recipe.Key == name1) {
                        if (!Database.Instance.itemExists(recipe.Value))
                            continue;
                        DBItem dbResult = Database.Instance.getItem(recipe.Value);
                        if (dbResult.Spawned)
                            continue;
                        PuzzleItem resultItem = dbResult.spawnItem();
                        relToAdd = new CombineRelationship(name1, 0, name2, 0, resultItem);
                        break;
                    }
                }
            }
        }
        // Finally try property change relationships
        if (relToAdd == null) {
            if (dbitem1.propertyExists("changes")) {
                List<KeyValuePair<string, string>> changes = new List<KeyValuePair<string, string>>();
                Dictionary<string, List<string>> changesDict = (Dictionary<string, List<string>>)dbitem1.getProperty("changes");
                foreach (string changeProp in changesDict.Keys) {
                    foreach (string changeVal in changesDict[changeProp]) {
                        changes.Add(new KeyValuePair<string, string>(changeProp, changeVal));
                    }
                }

                Globals.shuffle(changes);
                foreach (KeyValuePair<string, string> change in changes) {
                    // Check if the property is mutable and allows our value
                    if (!dbitem2.propertyExists("mutables") || !((List<string>)dbitem2.getProperty("mutables")).Contains(change.Key))
                        continue;
                    if (!dbitem2.propertyExists(change.Key) || !((List<string>)dbitem2.getProperty(change.Key)).Contains(change.Value))
                        continue;
                    relToAdd = new PropertyChangeRelationship(name2, 0, name1, 0, change.Key, change.Value);
                    break;
                }
            }
        }
        if (relToAdd == null) {
            if (dbitem2.propertyExists("changes")) {
                List<KeyValuePair<string, string>> changes = new List<KeyValuePair<string, string>>();
                Dictionary<string, List<string>> changesDict = (Dictionary<string, List<string>>)dbitem2.getProperty("changes");
                foreach (string changeProp in changesDict.Keys) {
                    foreach (string changeVal in changesDict[changeProp]) {
                        changes.Add(new KeyValuePair<string, string>(changeProp, changeVal));
                    }
                }
                Globals.shuffle(changes);
                foreach (KeyValuePair<string, string> change in changes) {
                    // Check if the property is mutable and allows our value
                    if (!dbitem1.propertyExists("mutables") || !((List<string>)dbitem1.getProperty("mutables")).Contains(change.Key))
                        continue;
                    if (!dbitem1.propertyExists(change.Key) || !((List<string>)dbitem1.getProperty(change.Key)).Contains(change.Value))
                        continue;
                    relToAdd = new PropertyChangeRelationship(name1, 0, name2, 0, change.Key, change.Value);
                    break;
                }
            }

        }

        if (relToAdd != null) {
            if (!_relationshipMap.ContainsKey(name1))
                _relationshipMap[name1] = new Dictionary<string, IRelationship>();
            _relationshipMap[name1][name2] = relToAdd;
            if (!_relationshipMap.ContainsKey(name2))
                _relationshipMap[name2] = new Dictionary<string, IRelationship>();
            _relationshipMap[name2][name1] = relToAdd;
        }
    }