Esempio n. 1
0
        /// <summary>
        /// Overrides Buffer with incoming ReagentMix.
        /// Used with GetBufferMix() to return reagents from temporary ReagentMix
        /// </summary>
        /// <param name="overridingMix">ReagentMix to override Buffer with</param>
        private void TransferMixToBuffer(ReagentMix overridingMix)
        {
            //seperate back to slots
            if (BufferslotOne)
            {
                BufferslotOne.CurrentReagentMix.Clear();
                if (overridingMix.Total <= BufferslotOne.MaxCapacity)
                {
                    overridingMix.TransferTo(BufferslotOne.CurrentReagentMix, overridingMix.Total);
                }
                else
                {
                    overridingMix.TransferTo(BufferslotOne.CurrentReagentMix, BufferslotOne.MaxCapacity);
                }

                Logger.LogTrace($"ChemMaster: {gameObject} " +
                                $"Reagentmix buffer one after: {BufferslotOne.CurrentReagentMix}", Category.Chemistry);
            }

            if (BufferslotTwo)
            {
                BufferslotTwo.CurrentReagentMix.Clear();
                //Only two containers, and previous math confirms
                // that tempTransfer amount won't be larger than last buffer
                overridingMix.TransferTo(BufferslotTwo.CurrentReagentMix, overridingMix.Total);
                Logger.LogTrace($"ChemMaster: {gameObject} " +
                                $"reagentmix buffer two after: {BufferslotTwo.CurrentReagentMix}", Category.Chemistry);
            }
        }
Esempio n. 2
0
        public void DispenseProduct(int productId, int numberOfProduct, string newName)
        {
            ReagentMix temp = GetBufferMix();
            //Do Math
            float maxProductAmount    = ChemMasterProducts[productId].GetComponent <ReagentContainer>().MaxCapacity;
            float maxTotalAllProducts = maxProductAmount * numberOfProduct;
            float amountPerProduct    = ((maxTotalAllProducts > temp.Total) ? temp.Total : maxTotalAllProducts)
                                        / numberOfProduct;

            for (int i = 0; i < numberOfProduct; i++)
            {
                //Spawn Object
                var product = Spawn.ServerPrefab(ChemMasterProducts[productId], gameObject.WorldPosServer(),
                                                 transform.parent).GameObject;

                //Fill Product
                ReagentContainer productContainer = product.GetComponent <ReagentContainer>();
                if (amountPerProduct <= productContainer.MaxCapacity)
                {
                    temp.TransferTo(productContainer.CurrentReagentMix, amountPerProduct);
                }
                else
                {
                    temp.TransferTo(productContainer.CurrentReagentMix, productContainer.MaxCapacity);
                }

                //Give it some color
                productContainer.OnReagentMixChanged?.Invoke();

                //Give it some love
                product.GetComponent <ItemAttributesV2>().ServerSetArticleName($"{newName}" +
                                                                               $" {product.GetComponent<ItemAttributesV2>().InitialName}");
            }

            ClearBuffer();
            TransferMixToBuffer(temp);
            UpdateGui();
        }
Esempio n. 3
0
        /// <summary>
        /// Retreive Buffer contents as one ReagentMix
        /// </summary>
        /// <returns> Buffer's mix of reagents </returns>
        public ReagentMix GetBufferMix()
        {
            ReagentMix emptyMix = new ReagentMix();

            if (BufferslotOne)
            {
                ReagentMix temp = BufferslotOne.CurrentReagentMix.Clone();
                temp.TransferTo(emptyMix, temp.Total);
            }

            if (BufferslotTwo)
            {
                ReagentMix temp = BufferslotTwo.CurrentReagentMix.Clone();
                temp.TransferTo(emptyMix, temp.Total);
            }

            return(emptyMix);
        }