public void areaDespawnItems(BuildingBlock possibleBind) { if (_verbose) { Debug.Log(string.Format("Attempting to despawn items for area {0}", _name)); } if (possibleBind == _boundBuildingBlock) { if (_verbose) { Debug.Log(string.Format("Successfully despawning items for area {0}", _name)); } _input.areaDespawnItems(this); _boundBuildingBlock = null; } }
protected override bool spawnFilteredInputs(string outputName) { // If we don't have a specific property we're trying to change if (_desiredPropertyName == null) { // Need to first find out whether our desired properties dictionary actually has any elements List <string> desiredPropertyKeys = new List <string>(_desiredOutputProperties.Keys); List <string> possiblePropertyNames = new List <string>(); if (desiredPropertyKeys.Count == 0) { possiblePropertyNames = new List <string>(Database.Instance.getItem(outputName).getProperty("mutables") as List <string>); } else { possiblePropertyNames = new List <string>(desiredPropertyKeys); } // Shuffle up our property names BuildingBlock.shuffle(possiblePropertyNames); foreach (string propertyName in possiblePropertyNames) { object tryPropertyVal = _desiredPropertyVal; if (_desiredOutputProperties.ContainsKey(propertyName)) { tryPropertyVal = _desiredOutputProperties[propertyName]; } bool maybeSuccess = tryToGeneratePuzzles(outputName, propertyName, tryPropertyVal, null); if (maybeSuccess) { return(true); } } } else { bool maybeSuccess = tryToGeneratePuzzles(outputName, _desiredPropertyName, _desiredPropertyVal, null); if (maybeSuccess) { return(true); } } if (_verbose) { Debug.Log("Failed to generate property change puzzle: No combinations worked"); } return(false); }
protected static PropertyChangePuzzle parsePropertyChangePuzzle(XmlElement elem, XmlDocument xmlDoc) { BuildingBlock changer = findAndParsePuzzleBlock(elem.GetAttribute("changer"), xmlDoc); BuildingBlock changee = findAndParsePuzzleBlock(elem.GetAttribute("changee"), xmlDoc); if (changer != null && changee != null) { string propertyName = elem.GetAttribute("propertyName"); if (propertyName == "") { propertyName = null; } string propertyValue = elem.GetAttribute("propertyValue"); if (propertyValue == "") { propertyValue = null; } return(new PropertyChangePuzzle(changer, changee, propertyName, parseSimplePropertyVal(propertyValue))); } return(null); }
public CombineContainerPuzzle(BuildingBlock containerInput, BuildingBlock carryableInput, BuildingBlock nonCarryableInput) : base(new List <BuildingBlock>() { }) { // Filter to generate a carryable container Dictionary <string, object> containerFilterProps = new Dictionary <string, object>(); containerFilterProps["carryable"] = true; FilterBlock containerFilter = new FilterBlock(containerInput, containerFilterProps); // Filter to make sure the item in the container is not carryable Dictionary <string, object> carryableFilterProps = new Dictionary <string, object>(); carryableFilterProps["carryable"] = false; FilterBlock carryableFilter = new FilterBlock(carryableInput, carryableFilterProps); // Filter to make sure the item not in the container is not carryable Dictionary <string, object> nonCarryableFilterProps = new Dictionary <string, object>(); nonCarryableFilterProps["carryable"] = false; FilterBlock nonCarryableFilter = new FilterBlock(nonCarryableInput, nonCarryableFilterProps); InsertionPuzzle insertStep = new InsertionPuzzle(containerFilter, carryableFilter); _outputPuzzleMap = new CombinePuzzle(nonCarryableFilter, new UnboxingPuzzle(insertStep)); }
public PuzzleOutput areaGeneratePuzzle(BuildingBlock buildingBlockToBind) { if (_verbose) { Debug.Log("spawning Area: " + _name); } if (_boundBuildingBlock != null) { if (_verbose) { Debug.Log("Area already bound to another building block!"); } return(new PuzzleOutput()); } else { BuildingBlock.shuffle(_inputs); foreach (IAreaConnector input in _inputs) { PuzzleOutput possibleInput = input.areaGeneratePuzzle(this); if (possibleInput == null) { continue; } _input = input; _boundBuildingBlock = buildingBlockToBind; PuzzleOutput result = new PuzzleOutput(); result.Items.AddRange(possibleInput.Items); result.Relationships.AddRange(possibleInput.Relationships); // Add an area connection relationship here AreaConnectionRelationship connectionRelationship = input.makeConnection(this); result.Relationships.Add(connectionRelationship); return(result); } return(null); } }
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); }
public InsertionPuzzle(BuildingBlock containerInput, BuildingBlock itemToInsertInput) : base(new List <BuildingBlock>() { containerInput, itemToInsertInput }) { _containerInput = containerInput; _itemToInsertInput = itemToInsertInput; }
public static bool isCarryable(string itemName, BuildingBlock input) { return((bool)Database.Instance.getItem(itemName).getProperty("carryable") || input.outputHasContainer()); }
public ORBlock(BuildingBlock option1, BuildingBlock option2) : base(new List <BuildingBlock> () { option1, option2 }) { _option1 = option1; _option2 = option2; }
public PuzzleOutput areaGeneratePuzzle(BuildingBlock buildingBlockToBind) { return(generatePuzzle((buildingBlockToBind as Area).name, new Dictionary <string, object>())); }
public DoorUnlockPuzzle(BuildingBlock keyInput, Area connectingArea) : base(new List <BuildingBlock>() { keyInput }) { _keyInput = keyInput; _connectingArea = connectingArea; }
public PropertyChangePuzzle(BuildingBlock changerInput, BuildingBlock changeeInput) : this(changerInput, changeeInput, null, null) { }
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); }
public FilterBlock(BuildingBlock input, Dictionary <string, object> propertiesToFilter) : base(new List <BuildingBlock>() { input }) { _input = input; _propertiesToFilter = propertiesToFilter; }
public ItemRequestPuzzle(BuildingBlock requester, BuildingBlock requested) : base(new List <BuildingBlock>() { requester, requested }) { _requesterInput = requester; _requestedInput = requested; }
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); }
public PuzzleOutput areaGeneratePuzzle(BuildingBlock buildingBlockToBind) { return(new PuzzleOutput()); }
public UnboxingPuzzle(BuildingBlock containerInput) : base(new List <BuildingBlock>() { containerInput }) { _containerInput = containerInput; }
public void areaDespawnItems(BuildingBlock possibleBind) { }
public Area(string name, List <IAreaConnector> inputs) : base(new List <BuildingBlock>()) { _name = name; _boundBuildingBlock = null; _inputs = inputs; }
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); }