Beispiel #1
0
    private bool ConsumeItem(Item item, int numInInventory)
    {
        int type = item.stats["Consumable Type"];

        if (type == 0)
        {
            //This type is being deprecated
            int          recipeID = item.stats["Recipe ID"];
            FoundRecipes r        = player.GetComponent <FoundRecipes>();
            if (!r.CheckIfFound(recipeID))
            {
                r.AddRecipe(recipeID);
                List <string> displayText = new List <string>();
                displayText.Add("You now know how to make " + item.name);
                player.GetComponent <TextController>().TriggerTextEvent(displayText);
            }
            else
            {
                return(false);
            }
        }
        item.stats["Current Count"]--;
        if (item.stats["Current Count"] == 0)
        {
            RemoveFromHotbar(numInInventory);
            return(true);
        }
        UpdateInventoryText(numInInventory, item.stats["Current Count"]);
        return(true);
    }
Beispiel #2
0
    public static void SavePlayer(UseItem u, FoundRecipes cm)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/player.inv";
        FileStream      stream    = new FileStream(path, FileMode.Create);
        PlayerData      pd        = new PlayerData(u, cm);

        formatter.Serialize(stream, pd);
        stream.Close();
    }
Beispiel #3
0
    public PlayerData(UseItem u, FoundRecipes cm)
    {
        // int currentSpot = 0;

        for (int i = 0; i < 50; i++)
        {
            inventoryItems[i] = -1;
        }
        for (int i = 0; i < 100; i++)
        {
            unlockedRecipes[i] = -1;
        }
        foreach (KeyValuePair <int, Item> pair in u.inventoryItems)
        {
            inventoryItems[pair.Key]      = pair.Value.id;
            inventoryItemCounts[pair.Key] = pair.Value.stats["Current Count"];
        }
        // currentSpot = 0;
        foreach (KeyValuePair <int, Recipe> pair in cm.GetRecipes())
        {
            unlockedRecipes[pair.Key] = pair.Value.id;
        }
    }