Beispiel #1
0
    void Awake()
    {
        GlobalContentProvider contentProvider = GlobalContentProvider.Instance;

        foodObject = contentProvider.foods[foodObjectIndex];
        variants   = foodObject.variants;
    }
Beispiel #2
0
    public static void UpdateCounter(Packet _packet)
    {
        int    num      = _packet.ReadInt();
        string name     = _packet.ReadString();
        int    quantity = _packet.ReadInt();

        if (name != "null")
        {
            FoodObject food = new FoodObject(FindFood(name));
            food.setQuantity(quantity);
            PlayerData.player.GetCounters()[num] = food;
        }
        else
        {
            PlayerData.player.GetCounters()[num] = null;
        }

        if (SceneManager.GetActiveScene().name == "KitchenScene")
        {
            GameObject counters = GameObject.Find("Counters");

            foreach (Transform counter in counters.transform)
            {
                if (counter.GetComponent <Counter>().counterNum == num)
                {
                    counter.GetComponent <Counter>().Refresh();
                    return;
                }
            }
        }
    }
Beispiel #3
0
    public void SwapInventoryItems(int indexFrom, int indexTo)
    {
        if (indexFrom == indexTo)
        {
            return;
        }

        if (playerInfo.fridge[indexFrom] != null && playerInfo.fridge[indexTo] != null)
        {
            if (playerInfo.fridge[indexFrom].getName() == playerInfo.fridge[indexTo].getName())
            {
                playerInfo.fridge[indexTo].setQuantity(playerInfo.fridge[indexTo].getQuantity() + playerInfo.fridge[indexFrom].getQuantity());
                playerInfo.fridge[indexFrom] = null;
                return;
            }
        }

        FoodObject temp = playerInfo.fridge[indexFrom];

        playerInfo.fridge[indexFrom] = playerInfo.fridge[indexTo];
        playerInfo.fridge[indexTo]   = temp;

        ClientSend.UpdateFridge(indexFrom);
        ClientSend.UpdateFridge(indexTo);
    }
    /// <summary>
    /// Where should the pet move in this update?
    /// </summary>
    /// <returns></returns>
    public override Vector3 GetMovement()
    {
        if (!_interactor.isHoldingObject)
        {
            _target = _observer.GetClosestFood(false);
            if (_target == null)
            {
                return(Vector3.zero);
            }

            float distanceToFood = (_target.transform.position - _pet.transform.position).magnitude;

            if (distanceToFood > _interactor.interactionDistance)
            {
                return((_target.transform.position - _pet.transform.position).normalized);
            }
            else
            {
                _isNearby = true;
            }
        }
        else
        {
            return((_observer.stockpileArea.transform.position - _pet.transform.position).normalized);
        }

        return(Vector3.zero);
    }
Beispiel #5
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);
    }
Beispiel #6
0
    //adds and ingredient into the appliance
    public void addIngToApp(FoodObject food, HashSet <FoodObject> foodSet)
    {
        Transform onHead = player.GetChild(2);

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

        food.subOneQ();
        PlayerData.player.SetCurrentFood(food);

        food = new FoodObject(food);
        food.setQuantity(1);

        foreach (FoodObject ing in foodSet)
        {
            if (ing.getName() == food.getName())
            {
                Debug.Log("match");
                ing.addOneQ();
                prevIng = food.getName();
                return;
            }
        }
        foodSet.Add(food);
        prevIng = food.getName();
    }
Beispiel #7
0
 protected virtual void ArrivedAtTargetLocation()
 {
     if (isServer && myMoM != null)
     {
         if (IsCarryingFood() && Vector3.Distance(myMoM.Location, Location) > 1)
         {
             StartCoroutine(ReturnToHome());
         }
         if (IsTargetingFood() && Vector3.Distance(targetedFood.Location, Location) > 1)
         {
             MoveTo(targetedFood.Location);
         }
         if (CanTargetFood())
         {
             targetedFood = TargetNearest();
             if (targetedFood != null)
             {
                 MoveTo(targetedFood.Location);
             }
             else
             {
                 MoveRandomly();
             }
         }
     }
 }
Beispiel #8
0
    /// <summary>
    /// Where should the pet move in this update?
    /// </summary>
    /// <returns></returns>
    public override Vector3 GetMovement()
    {
        if (!_interactor.isHoldingObject)
        {
            _target = _observer.GetClosestFood(true);
            if (_target == null)
            {
                return(Vector3.zero);
            }

            float distanceToFood = (_target.transform.position - _pet.transform.position).magnitude;

            if (distanceToFood > _interactor.interactionDistance)
            {
                return((_target.transform.position - _pet.transform.position).normalized);
            }
            else
            {
                _isNearby = true;
            }
        }
        else
        {
            return(_petMovement.Wander()); // wander around for  abit when holding food
        }

        return(Vector3.zero);
    }
Beispiel #9
0
    /// <summary>
    /// Given the Pet GO, calculate a score for this behaviour. The top scoring behaviour will be picked for that tick
    /// </summary>
    /// <param name="pet">Pet GO</param>
    /// <returns></returns>
    public override int GetScore()
    {
        // we can't move food if there is none
        if (_foodSpawner.foodInScene.Count == 0)
        {
            return(-100);
        }

        FoodObject closestFood = _observer.GetClosestFood(true);

        // if all our food is in stockpile, don't move anything
        if (closestFood == null)
        {
            return(-100);
        }

        // more likely to play with food when bored
        int score = (int)Mathf.Lerp(30, 0, _stats.fun);

        float distanceToFood = (closestFood.transform.position - _pet.transform.position).magnitude;

        if (distanceToFood < 1f)
        {
            score += 10;                      // if we're near food, more likely to play with it
        }
        return(score);
    }
    /// <summary>
    /// Given the Pet GO, calculate a score for this behaviour. The top scoring behaviour will be picked for that tick
    /// </summary>
    /// <param name="pet">Pet GO</param>
    /// <returns></returns>
    public override int GetScore()
    {
        // we can't move food if there is none
        if (_foodSpawner.foodInScene.Count == 0)
        {
            return(-100);
        }

        FoodObject closestFoodNotInStockpile = _observer.GetClosestFood(false);

        // if all our food is in stockpile, don't move anything
        if (closestFoodNotInStockpile == null)
        {
            return(-100);
        }

        int score = 25;

        float distanceToFood = (closestFoodNotInStockpile.transform.position - _pet.transform.position).magnitude;

        if (distanceToFood < 1f)
        {
            score += 25;                      // if we're near food, more likely to start stockpiling
        }
        return(score);
    }
Beispiel #11
0
    public GameObject SpawnFood()
    {
        GameObject go = Instantiate(spawnableFood, SceneManager.instance.GetFoodSpawnPos(), Quaternion.identity);
        FoodObject fs = go.GetComponent <FoodObject>();

        fs.InitFood();

        return(go);
    }
    void Update()
    {
        if (!canMove)
        {
            return;
        }

        //Get the vector from the pet to the target
        Vector3 movementDirection = currentMovementTarget.transform.position - transform.position;

        //Cache the real distance to use for checking distance to food
        float realDistanceToTarget = movementDirection.magnitude;

        //Convert the vector into a direction vector
        movementDirection.y = 0.0f; //zero out the vertical coordinate to keep movement horizontal

        //Cache the distance to target excluding height difference, to use for checking distance to camera
        float horizontalDistanceToTarget = movementDirection.magnitude;

        movementDirection.Normalize();

        //Calculate the new pet location by generating a translation vector from the speed * direction, then adding it to the pet's current location
        Vector3 translationVector = movementSpeed * movementDirection * Time.deltaTime;
        Vector3 newPosition       = transform.position + translationVector;

        //Determine if we're in range of our movement target
        //Assumption: the only types of targets are the camera or a food object
        bool inRangeOfTarget = (currentMovementTarget == Camera.main.gameObject) ? horizontalDistanceToTarget <= acceptableDistanceToCamera : realDistanceToTarget <= acceptableDistanceToFood;

        //If we're outside of our acceptable distance, move closer to the target.  If not, and the target is food, consume the food
        bool hasMoved = false;

        if (!inRangeOfTarget)
        {
            transform.forward  = movementDirection;
            transform.position = newPosition;

            hasMoved = true;
        }
        else
        {
            FoodObject foodObject = currentMovementTarget.GetComponent <FoodObject>();
            if (foodObject != null)
            {
                canMove = false;

                animator.Play("Eating", -1);
                StartCoroutine("WaitForEatingToFinish");
            }
        }

        //Update the animation state to reflect whether the pet moved or not this frame
        if (animator != null)
        {
            animator.SetBool("IsMoving", hasMoved);
        }
    }
Beispiel #13
0
 public IActionResult UpdateForm(FoodObject food)
 {
     if (food == null)
     {
         return(NotFound("Something went wrong"));
     }
     _foodRepo.Update(food);
     _foodRepo.Save();
     return(RedirectToAction("Index", "Home"));
 }
Beispiel #14
0
 protected override void Death()
 {
     base.Death();
     myMoM.farmers -= 1;
     if (IsCarryingFood())
     {
         carriedFood.Detach();
         carriedFood = null;
     }
 }
Beispiel #15
0
 // copy constructor
 public FoodObject(FoodObject other)
 {
     foodName          = other.foodName;
     icon              = other.icon;
     model             = other.model;
     appliance         = other.appliance;
     price             = other.price;
     quantity          = other.quantity;
     happiness         = other.happiness;
     ingredientsNeeded = other.ingredientsNeeded;
 }
Beispiel #16
0
        public IActionResult Details(FoodObject foodObject)
        {
            FoodObject food = _foodRepo.NameExists(foodObject.Name);

            if (food == null)
            {
                return(NotFound("Something went wrong"));
            }

            return(View(food));
        }
Beispiel #17
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();
    }
Beispiel #18
0
    /// <summary>
    /// Start eating the food with a sequence of picking up the food, taking bites until finished, and dropping it
    /// </summary>
    /// <param name="food"></param>
    /// <returns>true if started eating food, false if already eating a food</returns>
    public bool EatFood(FoodObject food)
    {
        if (_eatFoodCoroutine != null)
        {
            return(false);
        }

        _eatFoodCoroutine = StartCoroutine(EatFoodCoroutine(food));

        return(true);
    }
Beispiel #19
0
    public void DropObject()
    {
        isHoldingObject = false;
        if (currentHeldObject == null)
        {
            return;
        }

        currentHeldObject.GetComponent <Rigidbody>().drag = _prevObjectDrag;
        currentHeldObject = null;
    }
Beispiel #20
0
    public bool SetSceneFood(FoodObject food)
    {
        if (!currentScene.canSpawn || currentScene.currentObject != null)
        {
            return(false);
        }

        currentScene.currentObject = food;
        currentScene.currentObject.InitFood();
        currentScene.currentObject.InitFoodState(currentScene.ID);
        return(true);
    }
Beispiel #21
0
    public bool SetSceneFood(FoodObject food, int index)
    {
        if (!scenes[index].canSpawn || scenes[index].currentObject != null)
        {
            return(false);
        }

        scenes[index].currentObject = food;
        scenes[index].currentObject.InitFood();
        scenes[index].currentObject.InitFoodState(index);
        return(true);
    }
Beispiel #22
0
    private void AddButtons()
    {
        for (int i = 0; i < foodList.Count; ++i)
        {
            FoodObject food      = foodList[i];
            GameObject newButton = buttonObjectPool.GetObject();
            newButton.transform.SetParent(contentPanel, false);             // add false

            ShopButton shopButton = newButton.GetComponent <ShopButton>();
            shopButton.Setup(food, this);
        }
    }
Beispiel #23
0
    public FoodInstruction(Type type, FoodObject target, FoodObject tool)
    {
        this.type = type;
        this.target = target;
        this.tool = tool;

        switch (type)
        {
            case Type.SliceFood:
                _triggerCount = 2;
                break;
        }
    }
Beispiel #24
0
        public IActionResult Delete1(int id)
        {
            FoodObject food = _foodRepo.GetFoodById(id);

            if (food == null)
            {
                return(NotFound("Something went wrong"));
            }
            _foodRepo.Delete(food);
            _foodRepo.Save();

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #25
0
 public void Initialize(FoodObject p, float speed)
 {
     parent = p;
     transform.SetParent(parent.transform);
     speedOfDecay = 10.0f / speed;
     buttons      = new PressureButton[2];
     buttons[0]   = transform.GetChild(2).GetComponent <PressureButton>();
     buttons[0].Init(this);
     buttons[1] = transform.GetChild(3).GetComponent <PressureButton>();
     buttons[1].Init(this);
     currentPressure = 14.7f;
     OnPressureChange();
 }
Beispiel #26
0
        public IActionResult Create(FoodObject food)
        {
            _foodRepo.NameExists(food.Name);

            if (food == null)
            {
                return(NotFound("Could not create object."));
            }

            _foodRepo.Create(food);
            _foodRepo.Save();

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #27
0
    public void eat(GameObject obj, FoodObject food)
    {
        food.onEat();
        hunger -= food.HUNGER_VALUE;
        thirst -= food.THIRST_VALUE;

        checkValueLimits();

        StartCoroutine(DestroyObjectAfterTime(1, obj));

        Debug.Log("Eat");
        Debug.Log(hunger);
        Debug.Log(thirst);
    }
Beispiel #28
0
    public void DisplayFloatingInfoAboutFoosUsing(FoodObject food)
    {
        var playerInstance = GameObject.Find("Player").GetComponent <Player>();

        StartCoroutine(ActivationRoutine(floatingWindow, 1));
        if (playerInstance.Health < playerInstance.MaxPlayerHealth())
        {
            floatingWindow.GetComponentInChildren <TextMeshProUGUI>().SetText($"You eat a <{food.name}> and restored {food.restoreHealthValue}hp.");
        }
        else
        {
            floatingWindow.GetComponentInChildren <TextMeshProUGUI>().SetText($"You eat a <{food.name}>, <b>Your HP is full.</b>");
        }
    }
Beispiel #29
0
    public FoodInstruction(Type type, FoodObject target)
    {
        this.type = type;
        this.target = target;

        switch (type)
        {
            case Type.MoveFood:
            case Type.PickKnife:
                _triggerCount = 1;
                target.OnClicked += _Trigger;
                break;
        }
    }
Beispiel #30
0
 protected virtual void ArrivedAtTargetLocation()
 {
     if (isServer)
     {
         targetedFood = TargetNearest();
         if (targetedFood != null)
         {
             MoveTo(targetedFood.Location);
         }
         else
         {
             MoveRandomly();
         }
     }
 }
Beispiel #31
0
    IEnumerator EatFoodCoroutine(FoodObject food)
    {
        PickUpObject(food);

        _holdDistance = 0.3f;

        yield return(new WaitForSeconds(0.5f));

        yield return(new WaitUntil(() => _petMovement.IsSettled()));


        while (food.bitesLeft > 0)
        {
            _holdDistance = 0.3f;
            yield return(new WaitForSeconds(1f));

            _sounds.PlayOpenMouthSound();

            yield return(new WaitForSeconds(UnityEngine.Random.Range(0.3f, 0.8f)));

            _holdDistance = 0.2f;
            yield return(new WaitForSeconds(UnityEngine.Random.Range(0.1f, 0.3f)));

            // calculate plane to use for slicing the food
            Vector3 planePosition = this.transform.position + _holdDirection * (_holdDistance + 0.05f);
            food.Bite(planePosition, _holdDirection);
            _sounds.PlayCrunchSound();

            if (food.bitesLeft == 0)
            {
                _holdDistance = 0f;                      // when food is finished, absorb completely
            }
            yield return(new WaitForSeconds(0.8f));

            _sounds.PlayMunchSounds();

            gameObject.SendMessage("FoodBitten", food);
        }

        DropObject();

        if (food.bitesLeft == 0)
        {
            gameObject.SendMessage("FoodEaten", food);
        }

        _eatFoodCoroutine = null;
    }
Beispiel #32
0
    //produces FoodObject product
    public FoodObject execute()
    {
        //TEMPORARY
        FoodObject food = new FoodObject();
        //TEMPORARY

        //find if this recipe exists
        List <FoodObject> foodList = PlayerData.player.GetTable()[ingredientSet.Count];

        //reset the set and prevIng and usage
        ingredientSet.Clear();
        prevIng = "";
        inUse   = false;

        return(food);
    }
Beispiel #33
0
 public void Use()
 {
     dragAndDrop = ItemUI.gameObject.GetComponent <DragAndDrop>();
     if (item.type == ItemType.Food)
     {
         FoodObject food = (FoodObject)item;
         playerInfo.AddHp(food.HealthRestore);
         playerInfo.AddMana(food.ManaRestore);
         playerInfo.AddStanima(food.HungerRestore);
         dragAndDrop.IfSetSlotsOccupied(false, false);
         inventoryData.RemoveItem(item);
         Destroy(ItemUI.gameObject);
         Debug.Log("Used");
         Destroy(gameObject);
     }
 }
Beispiel #34
0
    public override void Build()
    {
        Vector3 __appleSpawnPos = new Vector3(-4f, 2f, 0f);
        _apple = (
            (GameObject)Instantiate(
                _foodHandler.apple.gameObject,
                __appleSpawnPos,
                Quaternion.identity
            )
        ).GetComponent<FoodObject>();
        var moveFood = new FoodInstruction(FoodInstruction.Type.MoveFood, _apple);
        _AddInstruction(moveFood);

        // Initialize knife
        Vector3 __knifeSpawnPos = new Vector3(-2.73f, -0.74f, 0f);
        _knife = (
            (GameObject)Instantiate(
                _foodHandler.knife.gameObject,
                __knifeSpawnPos,
                Quaternion.identity
            )
        ).GetComponent<FoodObject>();
        var pickKnife = new FoodInstruction(FoodInstruction.Type.PickKnife, _knife);
        _AddInstruction(pickKnife);

        // Initialize animation
        Vector3 __animPos = new Vector3(0f, -2.75f, 0f);
        _anim = (
            (GameObject)Instantiate(
                _foodHandler.appleSliceAnimation.gameObject,
                __animPos,
                Quaternion.identity
            )
        ).GetComponent<FoodAnimation>();
        _anim.gameObject.SetActive(false);
        var sliceAppleWithKnife = new FoodInstruction(FoodInstruction.Type.SliceFood, _apple, _knife);
        sliceAppleWithKnife.AddAnimation(_anim);
        _AddInstruction(sliceAppleWithKnife);
    }
Beispiel #35
0
    private void _VisualAction()
    {
        // Visual action only lasts for x amount of time
        _frame++;

        if (type == Type.MoveFood)
        {
            // Move object to destination
            Vector3 __p = target.transform.position;
            target.transform.position = Vector3.Lerp(__p, new Vector3(0f, -2.75f, 0f), _frame / 60f);

            if (_frame > 60)
            {
                // When visual action is done, trigger Recipe to pull out new instruction
                _runningVisualAction = false;
                OnInstructionDone();
            }
        }
        else if (type == Type.SliceFood)
        {
            if (target != null)
            {
                target.SelfDestruct();
                target = null;
            }

            if (_anim != null)
                _anim.Begin();

            if (_frame > 120)
            {
                _runningVisualAction = false;
                OnInstructionDone();
            }
        }
        else if (type == Type.PickKnife)
        {
            _runningVisualAction = false;
            OnInstructionDone();
        }
    }