public Product CreateProduct(StoreObjectReference container, Box.PackagedBud bud)
    { // Create a container and put packaged bud into it
        GameObject newContainer = Instantiate(container.gameObject_);

        newContainer.transform.position = bud.parentBox.transform.position;
        ProductGO productGO = newContainer.GetComponent <ProductGO>();

        if (container.proType == StoreObjectReference.productType.jar)
        {
            StorageJar storageJar = new StorageJar(container, newContainer);
            storageJar.uniqueID = Dispensary.GetUniqueProductID();
            productGO.product   = storageJar;
            float      incrementValue = 1;
            List <Bud> newBuds        = new List <Bud>();
            while (bud.weight > 0)
            {
                if (bud.weight - 1 < 0)
                {
                    incrementValue = bud.weight;
                }
                GameObject budGO = new GameObject(bud.strain.name + " Nug");
                budGO.transform.SetParent(newContainer.transform);
                budGO.transform.localPosition = Vector3.zero;
                Bud newBud = budGO.AddComponent <Bud>();
                newBud.strain = bud.strain;
                newBud.weight = incrementValue;
                newBuds.Add(newBud);
                bud.weight -= incrementValue;
            }
            print("Adding buds");
            storageJar.AddBud(newBuds);
            return(storageJar);
        }
        return(null);
    }
Exemple #2
0
    public void AddStartJar()
    {
        List <StoreObjectReference> containerObjects = db.GetProducts(StoreObjectReference.productType.container);
        GameObject jar       = Instantiate(containerObjects[1].gameObject_);
        ProductGO  productGO = jar.GetComponent <ProductGO>();

        productGO.objectID = containerObjects[1].objectID;
        StorageJar storageJar = new StorageJar(containerObjects[1], jar);

        storageJar.uniqueID              = Dispensary.GetUniqueProductID();
        storageJar.objectID              = containerObjects[1].objectID;
        productGO.product                = storageJar;
        productGO.canHighlight           = true;
        jar.GetComponent <Jar>().product = storageJar;
        List <Bud> toAdd = new List <Bud>();
        Strain     toUse = db.GetRandomStrain();

        for (int i = 0; i < 28; i++)
        {
            GameObject bud    = new GameObject("Bud");
            Bud        newBud = bud.AddComponent <Bud>();
            newBud.strain = toUse;
            newBud.weight = UnityEngine.Random.Range(.65f, 1.35f);
            newBud.weight = Mathf.Round(newBud.weight * 100f) / 100f; // Round to 2 decimal places
            jar.GetComponent <Jar>().AddBud(bud);
            bud.transform.position = Vector3.zero;
            toAdd.Add(newBud);
        }
        storageJar.AddBud(toAdd);
        ShelfPosition jarPosition = dm.dispensary.Storage_cs[0].GetRandomStorageLocation(storageJar);

        jar.transform.position = jarPosition.transform.position;
        jar.transform.parent   = jarPosition.transform;
        jarPosition.shelf.parentShelf.AddProduct(storageJar);
    }