Ejemplo n.º 1
0
        public void GenerateContent(MyContainerTypeDefinition containerDefinition)
        {
            int itemNumber = MyUtils.GetRandomInt(containerDefinition.CountMin, containerDefinition.CountMax);
            for (int i = 0; i < itemNumber; ++i)
            {
                MyContainerTypeDefinition.ContainerTypeItem item = containerDefinition.SelectNextRandomItem();
                MyFixedPoint amount = (MyFixedPoint)MyRandom.Instance.NextFloat((float)item.AmountMin, (float)item.AmountMax);

                if (ContainItems(1, item.DefinitionId))
                {
                    var currentAmount = GetItemAmount(item.DefinitionId);
                    amount -= currentAmount;
                    if (amount <= 0)
                    {
                        continue;
                    }
                }

                if (MyDefinitionManager.Static.GetPhysicalItemDefinition(item.DefinitionId).HasIntegralAmounts)
                {
                    amount = MyFixedPoint.Ceiling(amount); // Use ceiling to avoid amounts equal to 0
                }

                amount = MyFixedPoint.Min(ComputeAmountThatFits(item.DefinitionId), amount);
                if (amount > 0)
                {
                    var inventoryItem = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(item.DefinitionId);
                    AddItems(amount, inventoryItem);
                }
            }
            containerDefinition.DeselectAll();
        }
Ejemplo n.º 2
0
        public void SpawnRandomCargo()
        {
            if (m_containerType == null)
            {
                return;
            }

            MyContainerTypeDefinition containerDefinition = MyDefinitionManager.Static.GetContainerTypeDefinition(m_containerType);

            if (containerDefinition != null && containerDefinition.Items.Count() > 0)
            {
                int itemNumber = MyUtils.GetRandomInt(containerDefinition.CountMin, containerDefinition.CountMax);
                for (int i = 0; i < itemNumber; ++i)
                {
                    MyContainerTypeDefinition.ContainerTypeItem item = containerDefinition.SelectNextRandomItem();
                    MyFixedPoint amount = (MyFixedPoint)MyRandom.Instance.NextFloat((float)item.AmountMin, (float)item.AmountMax);

                    if (MyDefinitionManager.Static.GetPhysicalItemDefinition(item.DefinitionId).HasIntegralAmounts)
                    {
                        amount = MyFixedPoint.Ceiling(amount); // Use ceiling to avoid amounts equal to 0
                    }

                    amount = MyFixedPoint.Min(m_inventory.ComputeAmountThatFits(item.DefinitionId), amount);
                    if (amount > 0)
                    {
                        var inventoryItem = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(item.DefinitionId);
                        m_inventory.AddItems(amount, inventoryItem);
                    }
                }
                containerDefinition.DeselectAll();
            }
        }