コード例 #1
0
ファイル: Appliance.cs プロジェクト: Rachellie/Crecipe
    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);
            }
        }
    }
コード例 #2
0
    public void MouseDown(ref 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;
                    bool       fail = true;

                    for (int i = 0; i < PlayerData.player.GetLevel() && i < PlayerData.player.GetRecipeDB().Count; i++)
                    {
                        foreach (FoodObject match in PlayerData.player.GetRecipeDB()[i].Values)
                        {
                            if (match.getAppliance() == appName && foodSet.SetEquals(match.getIngNeeded()))
                            {
                                fail = false;
                                Debug.Log("Matching recipe!");
                                food = new FoodObject(match);
                                break;
                            }
                        }
                    }

                    if (fail)
                    {
                        Debug.Log("searching hidden db");
                        for (int i = 0; i < PlayerData.player.GetLevel() && i < PlayerData.player.GetHiddenDB().Count; i++)
                        {
                            foreach (FoodObject match in PlayerData.player.GetHiddenDB()[i].Values)
                            {
                                if (match.getAppliance() == appName && foodSet.SetEquals(match.getIngNeeded()))
                                {
                                    fail = false;
                                    Debug.Log("Matching HIDDEN recipe!");
                                    food = new FoodObject(match);
                                    PlayerData.database.transferRecipe(i, match.getName());
                                    break;
                                }
                            }
                        }
                    }

                    if (fail)
                    {
                        food = PlayerData.player.GetDB()[0]["Fail"];
                    }

                    foodSet.Clear();
                    PlayerData.player.SetCurrentFood(food);
                    bag.Refresh();

                    ClientSend.UpdateAppliance(appName, "Plate");
                }
                else
                {
                    ClientSend.UpdateAppliance(appName, PlayerData.player.GetCurrentFood().getName());                     //
                    addIngToApp(PlayerData.player.GetCurrentFood(), foodSet);
                    FindObjectOfType <AudioManager>().Play(sound);

                    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(ref foodSet);
            }
        }
    }