Esempio n. 1
0
    public bool AddFoodItem(FoodObject food)
    {
        List <FoodObject> location = playerInfo.bag;

        // find if foodItem exists
        for (int i = 0; i < 15; ++i)
        {
            if (location[i] != null && food.getName() == location[i].getName())
            {
                location[i].setQuantity(location[i].getQuantity() + food.getQuantity());
                return(true);
            }
        }
        // if foodItem does not exist create new copy of foodItem and add to first null slot
        for (int i = 0; i < 15; ++i)
        {
            if (location[i] == null)
            {
                location[i] = new FoodObject(food);
                return(true);
            }
        }

        return(false);
    }
Esempio n. 2
0
    public void Setup(FoodObject currentFood, Canvas newCanvas, Bag bag, int indx)
    {
        food = currentFood;

        image.sprite      = Resources.Load <Sprite>(food.getIcon());
        quantityText.text = food.getQuantity().ToString();
        canvas            = newCanvas;
        bagScript         = bag;
        index             = indx;
        model             = food.getModel();
    }
Esempio n. 3
0
    public void Setup(FoodObject currentFood, ShopScrollList currentScrollList)
    {
        food             = currentFood;
        nameLabel.text   = food.getName();
        priceLabel.text  = food.getPrice().ToString();
        iconImage.sprite = Resources.Load <Sprite>(food.getIcon());

        scrollList = currentScrollList;
        if (scrollList.isPlayer)
        {
            quantityLabel.text = "x" + food.getQuantity().ToString();
        }
        else
        {
            quantityLabel.text = "";             // blank
        }
    }
Esempio n. 4
0
    public void SetCurrentFood(FoodObject food)
    {
        GameObject player    = GameObject.FindWithTag("Player");
        GameObject buttonEat = GameObject.Find("/Canvas/ButtonEat");

        if (food == null || food.getQuantity() <= 0)
        {
            playerInfo.currentFood = null;
            playerInfo.bag[15]     = null;

            if (player != null)
            {
                for (int i = player.transform.childCount - 1; i >= 2; --i)
                {
                    Destroy(player.transform.GetChild(i).gameObject);                     // third child is hat
                }
            }
            Debug.Log("you currently have NOTHING");
            buttonEat.GetComponent <Image>().enabled = false;
            ClientSend.PlayerFood("null");
            return;
        }

        playerInfo.currentFood = new FoodObject(food);
        playerInfo.bag[15]     = food;

        if (player != null)
        {
            for (int i = player.transform.childCount - 1; i >= 2; --i)
            {
                Destroy(player.transform.GetChild(i).gameObject);                 // third child is hat
            }

            Instantiate(Resources.Load(playerInfo.currentFood.getModel()), player.transform);
        }
        Debug.Log("you currently have " + playerInfo.currentFood.getName());
        ClientSend.PlayerFood(food.getName());

        if (playerInfo.currentFood.getName() != "Plate")
        {
            buttonEat.GetComponent <Image>().enabled = true;
        }
    }
Esempio n. 5
0
    public static void UpdateCounter(int num)
    {
        using (Packet _packet = new Packet((int)ClientPackets.updateCounter))
        {
            _packet.Write(num);

            FoodObject food = PlayerData.player.GetCounterFood(num);
            if (food != null)
            {
                _packet.Write(food.getName());
                _packet.Write(food.getQuantity());
            }
            else
            {
                _packet.Write("null");
                _packet.Write(0);
            }

            SendTCPData(_packet);
        }
    }
Esempio n. 6
0
    public static void UpdateFridge(int slot)
    {
        using (Packet _packet = new Packet((int)ClientPackets.updateFridge))
        {
            _packet.Write(slot);

            FoodObject food = PlayerData.player.GetFridge()[slot];
            if (food != null)
            {
                _packet.Write(food.getName());
                _packet.Write(food.getQuantity());
            }
            else
            {
                _packet.Write("null");
                _packet.Write(0);
            }

            SendTCPData(_packet);
        }
    }
Esempio n. 7
0
    public static void AddToApp(HashSet <FoodObject> foodSet, FoodObject food)
    {
        Debug.Log(food.getQuantity());
        bool notFound = true;

        food.setQuantity(1);

        if (food.getName() != "Plate")
        {
            foreach (FoodObject ing in foodSet)
            {
                if (ing.getName() == food.getName())
                {
                    ing.addOneQ();
                    notFound = false;
                    break;
                }
            }
            if (notFound)
            {
                foodSet.Add(food);
            }
        }
        else
        {
            foodSet.Clear();
        }

        if (SceneManager.GetActiveScene().name == "KitchenScene")
        {
            GameObject appIng = GameObject.Find("AppIng");

            if (appIng != null)
            {
                appIng.GetComponent <AppIng>().Refresh();
            }
        }
    }
Esempio n. 8
0
    public void EatFood()
    {
        Transform onHead = GameObject.FindWithTag("Player").transform.GetChild(2);

        onHead.SetParent(null, true);
        StartCoroutine(Slerp(onHead));

        FoodObject toEat = PlayerData.player.GetCurrentFood();

        PlayerData.player.SetHappiness(PlayerData.player.GetHappiness() + toEat.getHappiness());
        if (toEat.getHappiness() > 0)
        {
            PlayerData.player.SetXP(PlayerData.player.GetXP() + toEat.getHappiness());
        }

        toEat.subOneQ();

        if (toEat.getQuantity() <= 0)
        {
            toEat = null;
        }

        PlayerData.player.SetCurrentFood(toEat);
    }
Esempio n. 9
0
 public void Setup(FoodObject currentFood)
 {
     nameLabel.text   = currentFood.getName() + " x" + currentFood.getQuantity().ToString();;
     iconImage.sprite = Resources.Load <Sprite>(currentFood.getIcon());
 }