public int AddCrate(StockCrate crate)
    {
        int remainingStock = crate.SetQuantity(AddStock(crate.GetQuantity(), crate.GetStockType()));

        if (remainingStock < 0)
        {
            remainingStock = 0;
        }

        crate.UnclaimItem(gameObject);

        return(remainingStock);
    }
Пример #2
0
    protected virtual void OnCollisionEnter_UE(Collision collision)
    {
        ContactPoint contact = collision.GetContact(0);

        GameObject other = contact.otherCollider.transform.root.gameObject;

        //Debug.Log(collision.relativeVelocity.magnitude);

        // Add products to the shelf if it hits it hard enough
        if (collision.relativeVelocity.magnitude < stateMachine.collisionSensitivity)
        {
            return;
        }

        StockItem stock = other.GetComponent <StockItem>();

        switch (other.tag)
        {
        case "Product":
        {
            // Double check if StockItem exists
            stock = other.GetComponent <StockItem>();
            if (stock)
            {
                // Check if stock matches the current wanted product
                if (stock.GetStockType() == stateMachine.currentWantedProduct)
                {
                    // Equip cought product
                    stateMachine.EquipItem(other.transform);
                }
            }
            break;
        }

        case "StockCrate":
        {
            // Double check if StockCrate exists
            StockCrate crate = stock as StockCrate;
            if (crate)
            {
                // Claim crate
                crate.ClaimItem(stateMachine.gameObject);

                /* Check if stock in crate matches the current wanted
                 * product and if there is enough in the crate to take one
                 */
                if (crate.GetStockType() == stateMachine.currentWantedProduct && crate.GetQuantity() >= 1)
                {
                    // Deduct one stock from the crate
                    crate.SetQuantity(crate.GetQuantity() - 1);

                    // Make new stock and add to customer
                    GameObject newStock = Object.Instantiate(stateMachine.mapManager.GetStockTypePrefab(stateMachine.currentWantedProduct)) as GameObject;

                    // Equip the new stock
                    stateMachine.EquipItem(newStock.transform);
                }

                // Unclaim crate
                crate.UnclaimItem(stateMachine.gameObject);
            }
            break;
        }
        }
    }