Esempio n. 1
0
 public void areaDespawnItems(BuildingBlock possibleBind)
 {
     if (_verbose)
     {
         Debug.Log("Despawning Door Unlock Puzzle");
     }
     _keyInput.despawnItems();
     _connectingArea.areaDespawnItems(this);
 }
Esempio n. 2
0
 public override void despawnItems()
 {
     if (_spawnedOption != null)
     {
         _spawnedOption.despawnItems();
     }
     _spawnedOption = null;
 }
Esempio n. 3
0
 public override void despawnItems()
 {
     _outputPuzzleMap.despawnItems();
 }
Esempio n. 4
0
        protected override bool spawnFilteredInputs(string outputName)
        {
            DBItem rewardDBItem = Database.Instance.getItem(outputName);

            if (!rewardDBItem.propertyExists("givenby"))
            {
                if (_verbose)
                {
                    Debug.Log("Failed to generate item request puzzle: Reward could not be result of item request");
                }
                return(false);
            }
            List <string> workingQuestgivers  = rewardDBItem.getProperty("givenby") as List <string>;
            List <string> filteredQuestgivers = filterQuestgivers(workingQuestgivers);

            if (filteredQuestgivers.Count == 0)
            {
                if (_verbose)
                {
                    Debug.Log(string.Format("Failed to generate item request puzzle: no questgivers met constraints"));
                }
                return(false);
            }

            BuildingBlock.shuffle(filteredQuestgivers);
            foreach (string giverName in filteredQuestgivers)
            {
                PuzzleOutput possibleGiverInput = _requesterInput.generatePuzzle(giverName);
                if (possibleGiverInput == null)
                {
                    if (_verbose)
                    {
                        Debug.Log(string.Format("Failed to generate item request puzzle using {0} as requester", giverName));
                    }
                    _requesterInput.despawnItems();
                    continue;
                }
                DBItem giverDBItem = Database.Instance.getItem(giverName);
                if (!giverDBItem.propertyExists("requests"))
                {
                    if (_verbose)
                    {
                        Debug.Log(string.Format("Failed to generate item request puzzle: requester {0} had no requests", giverName));
                    }
                    _requesterInput.despawnItems();
                    continue;
                }
                List <string> requests = new List <string>(giverDBItem.getProperty("requests") as List <string>);
                BuildingBlock.shuffle(requests);
                foreach (string requestName in requests)
                {
                    if (!areCarryable(new List <string>()
                    {
                        giverName, requestName
                    }, new List <BuildingBlock>()
                    {
                        _requesterInput, _requestedInput
                    }))
                    {
                        continue;
                    }

                    DBItem dbRequestItem = Database.Instance.getItem(requestName);
                    if (dbRequestItem == null)
                    {
                        if (_verbose)
                        {
                            Debug.Log(string.Format("WARNING: tried to access item in database that doesn't exist: {0}", requestName));
                        }
                        continue;
                    }
                    else if (dbRequestItem.Spawned)
                    {
                        if (_verbose)
                        {
                            Debug.Log(string.Format("failed to use {0} as a requested item. Item already spawned.", requestName));
                        }
                        continue;
                    }
                    // Now we need to iterate through the mutable properties of the requested item
                    List <string> propertyNames = dbRequestItem.getProperty("mutables") as List <string>;
                    // If we don't have any mutable properties, then just go ahead and generate a normal request
                    if (propertyNames == null || propertyNames.Count == 0)
                    {
                        PuzzleOutput possibleRequestInput = _requestedInput.generatePuzzle(requestName);
                        if (possibleRequestInput == null)
                        {
                            if (_verbose)
                            {
                                Debug.Log(string.Format("Failed to generate item request puzzle with {0} as the requested item.", requestName));
                            }
                            _requestedInput.despawnItems();
                        }
                        else
                        {
                            onSuccess(outputName, giverName, requestName, possibleGiverInput, possibleRequestInput);
                            return(true);
                        }
                    }
                    else
                    {
                        BuildingBlock.shuffle(propertyNames);
                        foreach (string propertyName in propertyNames)
                        {
                            List <string> values = dbRequestItem.getProperty(propertyName) as List <string>;
                            if (values == null)
                            {
                                values = new List <string>()
                                {
                                    null
                                }
                            }
                            ;
                            values = new List <string>(values);
                            BuildingBlock.shuffle(values);
                            foreach (object val in values)
                            {
                                Dictionary <string, object> inputDesiredProps = new Dictionary <string, object>();
                                inputDesiredProps[propertyName] = val;
                                PuzzleOutput possibleRequestInput = _requestedInput.generatePuzzle(requestName, inputDesiredProps);
                                if (possibleRequestInput == null)
                                {
                                    _requestedInput.despawnItems();
                                    if (_verbose)
                                    {
                                        Debug.Log(string.Format("Failed to generate item request puzzle with {0} as the requested item", requestName));
                                    }
                                }
                                else
                                {
                                    onSuccess(outputName, giverName, requestName, possibleGiverInput, possibleRequestInput, propertyName, val);
                                    return(true);
                                }
                            }
                        }
                    }
                }
                if (_verbose)
                {
                    Debug.Log(string.Format("failed to generate item request puzzle with {0} as the giver. No requests worked", giverName));
                }
                _requesterInput.despawnItems();
            }
            if (_verbose)
            {
                Debug.Log("Failed to generate item request puzzle: No working combinations of quest giver and request worked");
            }
            return(false);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        protected bool tryToGeneratePuzzles(string changeeName, string propertyName, object propertyVal, object startingVal)
        {
            if (!Database.Instance.itemExists(changeeName))
            {
                if (_verbose)
                {
                    Debug.Log("Failed to generate property change puzzle.");
                    Debug.Log(string.Format("WARNING: tried to generate puzzle with item that does not exist in database: {0}", changeeName));
                }
                return(false);
            }

            DBItem dbChangee = Database.Instance.getItem(changeeName);

            if (!dbChangee.propertyExists(propertyName))
            {
                if (_verbose)
                {
                    Debug.Log(string.Format("Failed to generate property change puzzle. Attempted property: {0} did not exist for {1}", propertyName, changeeName));
                }
                return(false);
            }

            List <string> possibleVals = new List <string>(dbChangee.getProperty(propertyName) as List <string>);

            // Now we need to iterate through all of the values instead of just a random choice.
            // this ensures we try all options
            if (propertyVal == null)
            {
                // shuffle our values
                BuildingBlock.shuffle(possibleVals);
                foreach (string maybeVal in possibleVals)
                {
                    bool maybeGood = tryToGeneratePuzzles(changeeName, propertyName, maybeVal, startingVal);
                    if (maybeGood)
                    {
                        return(true);
                    }
                }
                if (_verbose)
                {
                    Debug.Log(string.Format("Failed to generate property change puzzle: No desired value for property {0} worked.", propertyName));
                }
                return(false);
            }

            // Now we need to remove the desired property from the list of posible values so we can effectively
            // choose a different starting value
            possibleVals.Remove(propertyVal as string);

            // Iterate through possible starting values if we don't already have on e
            if (startingVal == null)
            {
                if (possibleVals.Count == 0)
                {
                    return(false);
                }
                BuildingBlock.shuffle(possibleVals);
                foreach (string maybeStartingVal in possibleVals)
                {
                    bool maybeGood = tryToGeneratePuzzles(changeeName, propertyName, propertyVal, maybeStartingVal);
                    if (maybeGood)
                    {
                        return(true);
                    }
                }
                if (_verbose)
                {
                    Debug.Log(string.Format("Failed to generate property change puzzle: No possible starting value for property {0} worked.", propertyName));
                }
                return(false);
            }

            // Since we've reached this point in the function, we can assume that we have a valid changee name, property name, property value, and starting property value
            Dictionary <string, object> changeeStartingProp = new Dictionary <string, object>();

            // Make sure all the other properties we desire are taken care of
            foreach (string otherName in _desiredOutputProperties.Keys)
            {
                changeeStartingProp[otherName] = _desiredOutputProperties[otherName];
            }
            changeeStartingProp[propertyName] = startingVal;
            PuzzleOutput possibleChangeeInput = _changeeInput.generatePuzzle(changeeName, changeeStartingProp);

            if (possibleChangeeInput == null)
            {
                if (_verbose)
                {
                    Debug.Log(string.Format("Failed to generate property change puzzle with {0} as the changee.", changeeName));
                }
                _changeeInput.despawnItems();
                return(false);
            }

            if (!dbChangee.propertyExists("changedby"))
            {
                if (_verbose)
                {
                    Debug.Log(string.Format("Failed to generate property change puzzle with {0} as the changee. Does not possess the changedby property."));
                }
                return(false);
            }

            // Now we choose a random changer
            List <string> filteredChangers = dbChangee.getProperty("changedby") as List <string>;

            filteredChangers = getRelevantChangers(filteredChangers, propertyName, propertyVal);
            // Randomly shuffle our changers
            BuildingBlock.shuffle(filteredChangers);
            foreach (string changerName in filteredChangers)
            {
                if (!areCarryable(new List <string>()
                {
                    changeeName, changerName
                }, new List <BuildingBlock>()
                {
                    _changeeInput, _changerInput
                }))
                {
                    continue;
                }

                PuzzleOutput possibleChangerInput = _changerInput.generatePuzzle(changerName);
                if (possibleChangerInput == null)
                {
                    if (_verbose)
                    {
                        Debug.Log(string.Format("Failed to generate property change puzzle with {0} as the changer", changerName));
                    }
                    _changerInput.despawnItems();
                }
                else
                {
                    onSuccess(changeeName, changerName, possibleChangeeInput, possibleChangerInput, propertyName, propertyVal);
                    return(true);
                }
            }
            if (_verbose)
            {
                Debug.Log(string.Format("Failed to generate property change puzzle with {0} as the changee. No changers worked.", changeeName));
            }
            _changeeInput.despawnItems();
            return(false);
        }
Esempio n. 7
0
        protected override bool spawnFilteredInputs(string outputName)
        {
            DBItem rewardDBItem = Database.Instance.getItem(outputName);

            if (!rewardDBItem.propertyExists("madeby"))
            {
                if (_verbose)
                {
                    Debug.Log("Failed to generate combine puzzle: Reward could not be the result of combination");
                }
                return(false);
            }
            List <KeyValuePair <string, string> > workingCombinations  = rewardDBItem.getProperty("madeby") as List <KeyValuePair <string, string> >;
            List <KeyValuePair <string, string> > filteredCombinations = filterWorkingCombinations(workingCombinations);

            if (filteredCombinations.Count == 0)
            {
                if (_verbose)
                {
                    Debug.Log("Failed to generate combine puzzle: No working combinations fit constraints");
                }
                return(false);
            }

            // Randomly shuffle our working combinations
            BuildingBlock.shuffle(filteredCombinations);
            // and try each combination
            foreach (KeyValuePair <string, string> itemPair in filteredCombinations)
            {
                // Unpack the "Tuples"
                string itemName1 = itemPair.Key;
                string itemName2 = itemPair.Value;

                PuzzleOutput possibleInput1 = _input1.generatePuzzle(itemName1);
                PuzzleOutput possibleInput2 = _input2.generatePuzzle(itemName2);

                if (possibleInput1 == null || possibleInput2 == null)
                {
                    if (_verbose)
                    {
                        Debug.Log("Failed to generate combine puzzle using " + itemName1 + " and " + itemName2);
                    }
                    Debug.Log(string.Format("input1: {0}, input2: {1}", possibleInput1, possibleInput2));
                    _input1.despawnItems();
                    _input2.despawnItems();
                    continue;
                }
                else if (!BuildingBlock.areCarryable(new List <string>()
                {
                    itemName1, itemName2
                }, new List <BuildingBlock>()
                {
                    _input1, _input2
                }))
                {
                    if (_verbose)
                    {
                        Debug.Log("Failed to generate combine puzzle using " + itemName1 + " and " + itemName2 + " because neither item is carryable to the other item.");
                    }
                    _input1.despawnItems();
                    _input2.despawnItems();
                    continue;
                }
                // Success!
                else
                {
                    if (_verbose)
                    {
                        Debug.Log("Successfully generated combine puzzle for " + outputName + " with  " + itemName1 + " and " + itemName2);
                    }
                    // Add all the items spawned by our inputs
                    _itemsToSpawn.AddRange(possibleInput1.Items);
                    _itemsToSpawn.AddRange(possibleInput2.Items);
                    _relationshipsToSpawn.AddRange(possibleInput1.Relationships);
                    _relationshipsToSpawn.AddRange(possibleInput2.Relationships);

                    // Generate the essential combine relationship
                    CombineRelationship combine = new CombineRelationship(itemName1, _input1.outputSpawnIndex(), itemName2, _input2.outputSpawnIndex(), _spawnedOutput as PuzzleItem);
                    _relationshipsToSpawn.Add(combine);

                    return(true);
                }
            }
            if (_verbose)
            {
                Debug.Log("Failed to generate combine puzzle: no working combinations worked!");
            }

            return(false);
        }