コード例 #1
0
        public void CheckProductionNeed(ref List <ControlObject> controlObjectList, ref FinalContainer finalContainer)
        {
            IMyGridTerminalSystem myGridTerminalSystem = null;
            IMyCargoContainer     finalContainerUnico  = null;

            foreach (ControlObject controlObject in controlObjectList)
            {
                MyItemType item = new MyItemType(controlObject.getComponentIDValue(), "");

                for (int i = 0; i < finalContainer.getContainerName().Count(); i++)
                {
                    finalContainerUnico = (IMyCargoContainer)myGridTerminalSystem.GetBlockWithName(finalContainer.getContainerName()[i]);
                    if (finalContainerUnico != null)
                    {
                        MyInventoryItem myInventoryItem = (MyInventoryItem)finalContainerUnico.GetInventory().FindItem(item);

                        if (myInventoryItem != null)
                        {
                            controlObject.setComponentsAmountProduced((int)myInventoryItem.Amount);
                            controlObject.setComponentsAmountToProduce(controlObject.getComponetAmountKeepStorage() - controlObject.getComponentsAmountProduced());
                        }
                        else
                        {
                            controlObject.setComponentsAmountProduced(controlObject.getComponetAmountKeepStorage());
                            controlObject.setComponentsAmountToProduce(controlObject.getComponetAmountKeepStorage());
                        }
                    }
                }
            }
        }
コード例 #2
0
        public bool CreateFinalContainer(ref FinalContainer finalContainer)
        {
            VRage.MyFixedPoint currentVolume = 0;
            VRage.MyFixedPoint maxVolume     = 0;

            IMyGridTerminalSystem GridTerminalSystem = null;

            if (finalContainer.getContainerName().Count() > 1)
            {
                List <IMyTerminalBlock> myCargoContainers  = null;
                List <IMyInventory>     containerInventory = null;

                var isExistCount = 0;
                var isFullCount  = 0;

                for (int i = 0; i < finalContainer.getContainerName().Count(); i++)
                {
                    myCargoContainers.Add(GridTerminalSystem.GetBlockWithName(finalContainer.getContainerName()[i]));
                }

                for (int i = 0; i < myCargoContainers.Count(); i++)
                {
                    if (myCargoContainers[i] == null)
                    {
                        finalContainer.setContainerExist(false);
                    }
                }

                for (int i = 0; i < finalContainer.getContainerExist().Count(); i++)
                {
                    if (finalContainer.getContainerExist()[i] == false)
                    {
                        isExistCount += 1;
                    }
                }

                if (isExistCount == finalContainer.getContainerExist().Count())
                {
                    return(false);
                }

                for (int i = 0; i < myCargoContainers.Count(); i++)
                {
                    containerInventory.Add(myCargoContainers[i].GetInventory(0));
                }

                for (int i = 0; i < containerInventory.Count(); i++)
                {
                    if (containerInventory[i].IsFull)
                    {
                        isFullCount += 1;
                        if (finalContainer.getMensagemContainerIsFull()[i] == "")
                        {
                            finalContainer.setMensagemContainerIsFull("Container " + finalContainer.getContainerName()[i] + " está cheio");
                        }
                        else
                        {
                            finalContainer.setMensagemContainerIsFull(finalContainer.getMensagemContainerIsFull() + " - Container " + finalContainer.getContainerName()[i] + " está cheio");
                        }
                    }
                }

                if (isFullCount == containerInventory.Count())
                {
                    finalContainer.setContainerIsFull(true);
                }

                for (int i = 0; i < containerInventory.Count(); i++)
                {
                    currentVolume += containerInventory[i].CurrentVolume;
                    maxVolume     += containerInventory[i].MaxVolume;
                    finalContainer.setPercentage(((double)currentVolume / (double)maxVolume) * 100);
                    finalContainer.setContainerCapacityUsed((double)currentVolume);
                    finalContainer.setContainerCapacity((double)maxVolume);
                }
            }
            else
            {
                IMyTerminalBlock myCargoContainers = GridTerminalSystem.GetBlockWithName(finalContainer.getContainerName()[0]);

                if (myCargoContainers != null)
                {
                    finalContainer.setContainerExist(true);
                }
                else
                {
                    finalContainer.setContainerExist(false);
                }

                if (!finalContainer.getContainerExist()[1])
                {
                    return(false);
                }

                IMyInventory containerInventory = myCargoContainers.GetInventory(0);
                currentVolume += containerInventory.CurrentVolume;
                maxVolume     += containerInventory.MaxVolume;
                finalContainer.setPercentage(((double)currentVolume / (double)maxVolume) * 100);
                finalContainer.setContainerCapacityUsed((double)currentVolume);
                finalContainer.setContainerCapacity((double)maxVolume);

                if (containerInventory.IsFull == true)
                {
                    finalContainer.setMensagemContainerIsFull("Container " + finalContainer.getContainerName()[0] + " está cheio");
                    return(false);
                }
                currentVolume += containerInventory.CurrentVolume;
            }
            return(true);
        }