void CreateCargoBoxWithDroppedItems(IEnumerable<int> droppedItemIDs, MySmallShip dropper)
        {
            var worldMatrix = Matrix.CreateWorld(
                dropper.WorldVolume.Center, 
                dropper.GetForward(), 
                dropper.GetUp());

            var items = new List<MyMwcObjectBuilder_InventoryItem>();
            foreach (var droppedItemID in droppedItemIDs)
            {
                var inventoryItem = m_itemsRepository.GetItem(droppedItemID);
                items.Add(new MyMwcObjectBuilder_InventoryItem(inventoryItem.GetInventoryItemObjectBuilder(false), inventoryItem.Amount));
            }
            var inventory = new MyMwcObjectBuilder_Inventory(items, MyInventory.DEFAULT_MAX_ITEMS);

            var cargoBoxBuilder = new MyMwcObjectBuilder_CargoBox(inventory)
                {
                    CargoBoxType = MyMwcObjectBuilder_CargoBox_TypesEnum.DroppedItems
                };
            cargoBoxBuilder.PersistentFlags |= MyPersistentEntityFlags.ActivatedOnAllDifficulties;

            var cargoBox = MyEntities.CreateFromObjectBuilderAndAdd(null, cargoBoxBuilder, worldMatrix);

            var matrix = cargoBox.WorldMatrix;
            matrix.Translation += 0.8f * dropper.WorldVolume.Radius * dropper.GetForward();
            matrix.Translation -= 0.5f * dropper.WorldVolume.Radius * dropper.GetUp();
            cargoBox.WorldMatrix = matrix;

            cargoBoxBuilder.EntityId = cargoBox.EntityId.ToNullableUInt();
            if (MyMultiplayerGameplay.IsRunning)
            {
                MyMultiplayerGameplay.Static.NewEntity(cargoBoxBuilder, cargoBox.WorldMatrix);
                MyMultiplayerGameplay.Static.HookEntity(cargoBox);
            }
        }
Exemple #2
0
        public void Init(string hudLabelText, MyMwcObjectBuilder_CargoBox objectBuilder, Matrix matrix)
        {
            Flags |= EntityFlags.EditableInEditor;

            StringBuilder hudLabelTextSb = (hudLabelText == null) ? MyTextsWrapper.Get(MyTextsWrapperEnum.CargoBox) : new StringBuilder(hudLabelText);

            // We want to make cargo box "lazy" to prevent rapid movement
            const float cargoBoxMass = 5000.0f;
            const float cargoAngularDamping = 0.5f;

            var modelLod0Enum = GetModelLod0EnumFromType(objectBuilder.CargoBoxType);

            base.Init(hudLabelTextSb, modelLod0Enum, null, null, null, objectBuilder);
            base.InitBoxPhysics(MyMaterialType.METAL, ModelLod0, cargoBoxMass, cargoAngularDamping, MyConstants.COLLISION_LAYER_DEFAULT, RigidBodyFlag.RBF_RBO_STATIC);
            this.Physics.LinearDamping = 0.7f;
            this.Physics.MaxLinearVelocity = 350;
            this.Physics.MaxAngularVelocity = 5;

            m_inventoryTemplate = objectBuilder.Inventory;
            if (m_inventoryTemplate != null)
            {
                Inventory.Init(m_inventoryTemplate);
            }
            CargoBoxType = objectBuilder.CargoBoxType;

            SetWorldMatrix(matrix);

            Save = true;
            this.Physics.Enabled = true;
            UpdateState();
        }