Esempio n. 1
0
    public void accept(PropertyChangeRelationship rel)
    {
        // Change a property of an item
        SpawnedPuzzleItem changer, changee;

        if (rel.changerName == _item1.itemName)
        {
            changer = _item1;
            changee = _item2;
        }
        else
        {
            changer = _item2;
            changee = _item1;
        }
        if (!changee.propertyExists(rel.propertyName) || changee.getProperty(rel.propertyName) != rel.propertyVal)
        {
            PlayState.instance.playAudio(PlayState.instance.pickupClip);
            PlayState.instance.addPlayerText(string.Format("The {0} is now {1}", changee.itemName, rel.propertyVal));
            changee.setProperty(rel.propertyName, rel.propertyVal);
        }
        else
        {
            PlayState.instance.addPlayerText("Nothing happened.");
        }
        if (changer.propertyExists("destroyonpropchange") && (bool)changer.getProperty("destroyonprochange"))
        {
            if (changer.inInventory)
            {
                changer.currentSlot.removeItem();
            }
            changer.die();
        }
    }
Esempio n. 2
0
 public void accept(PropertyChangeRelationship rel)
 {
     // Add the property change relationship to the map
     if (!_relationshipMap.ContainsKey(rel.changerName))
     {
         _relationshipMap[rel.changerName] = new Dictionary <string, IRelationship>();
     }
     _relationshipMap[rel.changerName][rel.changeeName] = rel;
     if (!_relationshipMap.ContainsKey(rel.changeeName))
     {
         _relationshipMap[rel.changeeName] = new Dictionary <string, IRelationship>();
     }
     _relationshipMap[rel.changeeName][rel.changerName] = rel;
 }
Esempio n. 3
0
        // The function that's called when we actually generate the puzzle.
        protected void onSuccess(string changeeName, string changerName, PuzzleOutput changeeInput, PuzzleOutput changerInput, string propertyName, object propertyVal)
        {
            if (_verbose)
            {
                Debug.Log(string.Format("Successfully generated property change puzzle with {0} as changer and {1} as changee", changerName, changeeName));
            }
            _itemsToSpawn.AddRange(changeeInput.Items);
            _itemsToSpawn.AddRange(changerInput.Items);
            _relationshipsToSpawn.AddRange(changeeInput.Relationships);
            _relationshipsToSpawn.AddRange(changerInput.Relationships);
            PropertyChangeRelationship changeRelationship = new PropertyChangeRelationship(changeeName, _changeeInput.outputSpawnIndex(), changerName, _changerInput.outputSpawnIndex(), propertyName, propertyVal);

            _relationshipsToSpawn.Add(changeRelationship);
        }
Esempio n. 4
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;
        }
    }