Ejemplo n.º 1
0
 public override void AddItems(MyCharacter character)
 {
     character.GetInventory(0).Clear(true);
     if (this.InventoryContentGenerated)
     {
         MyContainerTypeDefinition containerTypeDefinition = MyDefinitionManager.Static.GetContainerTypeDefinition(this.InventoryContainerTypeId.SubtypeName);
         if (containerTypeDefinition != null)
         {
             character.GetInventory(0).GenerateContent(containerTypeDefinition);
         }
     }
 }
Ejemplo n.º 2
0
        public override void AddItems(Sandbox.Game.Entities.Character.MyCharacter character)
        {
            System.Diagnostics.Debug.Assert((character.GetInventory(0) as MyInventory) != null, "Null or unexpected inventory type returned!");
            (character.GetInventory(0) as MyInventory).Clear();

            if (InventoryContentGenerated)
            {
                MyContainerTypeDefinition cargoContainerDefinition = MyDefinitionManager.Static.GetContainerTypeDefinition(InventoryContainerTypeId.SubtypeName);
                if (cargoContainerDefinition != null)
                {
                    (character.GetInventory(0) as MyInventory).GenerateContent(cargoContainerDefinition);
                }
                else
                {
                    System.Diagnostics.Debug.Fail("CargoContainer type definition " + InventoryContainerTypeId + " wasn't found.");
                }
            }
        }
Ejemplo n.º 3
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();
        }