Ejemplo n.º 1
0
    public void MouseDown(HashSet <FoodObject> foodSet, string appName, string sound)
    {
        float distance = Vector3.Distance(player.transform.position, gameObject.transform.position);

        if (distance <= range)
        {
            if (PlayerData.player.GetCurrentFood() != null)
            {
                if (PlayerData.player.GetCurrentFood().getName() == "Plate")
                {
                    FoodObject food = null;
                    FoodObject recipe;
                    List <List <FoodObject> > recipeTable = PlayerData.player.GetRecipeTable();
                    bool fail = true;

                    for (int i = 0; i < recipeTable.Count; ++i)
                    {
                        for (int j = 0; j < recipeTable[i].Count; ++j)
                        {
                            recipe = recipeTable[i][j];

                            if (recipe.getAppliance() == appName && foodSet.SetEquals(recipe.getIngNeeded()))
                            {
                                fail = false;
                                Debug.Log("matching recipe!");
                                food = new FoodObject(recipe);
                                food.setPlate(true);
                                break;
                            }
                        }
                    }

                    if (fail)
                    {
                        food = new FoodObject("FAIL", "Sprites/temp2", "Models/salmon", h: -5, plate: true);
                    }

                    foodSet.Clear();
                    PlayerData.player.SetCurrentFood(food);
                    bag.Refresh();
                }
                else
                {
                    addIngToApp(PlayerData.player.GetCurrentFood(), foodSet);
                    FindObjectOfType <AudioManager>().Play(sound);
                    if (PlayerData.player.GetCurrentFood().getQuantity() <= 0)
                    {
                        PlayerData.player.SetCurrentFood(null);
                    }

                    bag.Refresh();

                    // debug
                    foreach (FoodObject ing in foodSet)
                    {
                        Debug.Log(ing.getName() + " x" + ing.getQuantity());
                    }
                }
            }
            else             // open popup to show set of ingredients inside
            {
                if (appIng.gameObject.activeInHierarchy)
                {
                    appIng.gameObject.SetActive(false);
                }
                else
                {
                    appIng.gameObject.SetActive(true);
                }

                AppIng appIngScript = appIng.GetComponent <AppIng>();
                appIngScript.SetContents(foodSet);
            }
        }
    }