public void accept(ItemRequestRelationship rel) { // Give one item to another. SpawnedPuzzleItem requested, requester; if (rel.requestedName == _item1.itemName) { requested = _item1; requester = _item2; } else { requested = _item2; requester = _item1; } // If the requester is inside something, have to remove it first if (requester.insideItem) { PlayState.instance.addPlayerText(string.Format("Have to remove the {0} first.", requester.itemName)); return; } // Check to see if the item has the requested property if (rel.requestedPropertyName != null && (!requested.propertyExists(rel.requestedPropertyName) || requested.getProperty(rel.requestedPropertyName) != rel.requestedPropertyValue)) { requester.activateText(requester.npcWrongPropertyText()); return; } requester.requestFulfilled = true; PlayState.instance.playAudio(PlayState.instance.pickupClip); // On success, destroy the old item and spawn the new one. if (requested.inInventory) { requested.currentSlot.removeItem(); } if (requested.insideItem) { requested.removeFromOtherItem(); } requested.die(); SpawnedPuzzleItem itemToSpawn = spawnItem(rel.rewardItem); if (itemToSpawn.carryable) { itemToSpawn.init(); itemToSpawn.addToInventory(); } else { _currentRoom.addPiece(itemToSpawn); } // Display the fulfilled text. requester.activateText(requester.npcFulfilledText()); }
protected void onSuccess(string outputName, string giverName, string requestName, PuzzleOutput giverInput, PuzzleOutput requestInput, string propertyName, object propertyVal) { if (_verbose) { Debug.Log(string.Format("Successfully generated item request puzzle with {0} as giver and {1} as requested item and {2} as reward.", giverName, requestName, outputName)); } _itemsToSpawn.AddRange(giverInput.Items); _itemsToSpawn.AddRange(requestInput.Items); _relationshipsToSpawn.AddRange(giverInput.Relationships); _relationshipsToSpawn.AddRange(requestInput.Relationships); ItemRequestRelationship requestRelationship = new ItemRequestRelationship(giverName, _requesterInput.outputSpawnIndex(), requestName, _requestedInput.outputSpawnIndex(), _spawnedOutput, propertyName, propertyVal); _relationshipsToSpawn.Add(requestRelationship); }
public void accept(ItemRequestRelationship rel) { // First, add this to our list of requests _requests[rel.requesterName] = rel; // Add the item request relationship to the map if (!_relationshipMap.ContainsKey(rel.requesterName)) { _relationshipMap[rel.requesterName] = new Dictionary <string, IRelationship>(); } _relationshipMap[rel.requesterName][rel.requestedName] = rel; if (!_relationshipMap.ContainsKey(rel.requestedName)) { _relationshipMap[rel.requestedName] = new Dictionary <string, IRelationship>(); } _relationshipMap[rel.requestedName][rel.requesterName] = rel; // Make sure the reward item is included in the list of item names _itemNames.Add(rel.rewardItem.Name); }