private void AttachOwner(IMyInventoryOwner owner)
        {
            if (owner == null)
            {
                return;
            }

            m_nameLabel.Text = owner.DisplayNameText.ToString();

            for (int i = 0; i < owner.InventoryCount; ++i)
            {
                var inventory = owner.GetInventory(i);
                inventory.UserData         = this;
                inventory.ContentsChanged += inventory_OnContentsChanged;

                var massLabel = MakeMassLabel(inventory);
                Elements.Add(massLabel);
                m_massLabels.Add(massLabel);

                var volumeLabel = MakeVolumeLabel(inventory);
                Elements.Add(volumeLabel);
                m_volumeLabels.Add(volumeLabel);

                var inventoryGrid = MakeInventoryGrid(inventory);
                Elements.Add(inventoryGrid);
                m_inventoryGrids.Add(inventoryGrid);
            }

            m_inventoryOwner = owner;

            RefreshInventoryContents();
        }
示例#2
0
        static void OnRemoveItemsSuccess(ref RemoveItemsMsg msg, MyNetworkClient sender)
        {
            if (!MyEntities.EntityExists(msg.OwnerEntityId))
            {
                return;
            }
            IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner;
            MyInventory       inv   = null;

            if (owner != null)
            {
                inv = owner.GetInventory(msg.InventoryIndex);
            }
            else
            {
                // NOTE: this should be the default code after we get rid of the inventory owner and should be searched by it's id
                MyEntity        entity = MyEntities.GetEntityById(msg.OwnerEntityId);
                MyInventoryBase baseInventory;
                if (entity.Components.TryGet <MyInventoryBase>(out baseInventory))
                {
                    inv = baseInventory as MyInventory;
                }
            }

            if (inv != null)
            {
                inv.RemoveItemsInternal(msg.itemId, msg.Amount);
            }
            else
            {
                Debug.Fail("Inventory was not found!");
            }
        }
示例#3
0
        public static ulong GetBattlePoints(MySlimBlock slimBlock)
        {
            Debug.Assert(slimBlock.BlockDefinition.Points > 0);
            ulong pts = (ulong)(slimBlock.BlockDefinition.Points > 0 ? slimBlock.BlockDefinition.Points : 1);

            if (slimBlock.BlockDefinition.IsGeneratedBlock)
            {
                pts = 0;
            }

            // Get points from container items
            IMyInventoryOwner inventoryOwner = slimBlock.FatBlock as IMyInventoryOwner;

            if (inventoryOwner != null)
            {
                var inventory = inventoryOwner.GetInventory(0);
                if (inventory != null)
                {
                    foreach (var item in inventory.GetItems())
                    {
                        if (item.Content is MyObjectBuilder_BlockItem)
                        {
                            MyObjectBuilder_BlockItem blockItem = item.Content as MyObjectBuilder_BlockItem;
                            pts += GetBattlePoints(blockItem.BlockDefId);
                        }
                    }
                }
            }

            return(pts);
        }
示例#4
0
        static void OnRemoveItemsRequest(ref RemoveItemsMsg msg, MyNetworkClient sender)
        {
            if (!MyEntities.EntityExists(msg.OwnerEntityId))
            {
                return;
            }

            IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner;
            MyInventory       inv   = null;

            if (owner != null)
            {
                inv = owner.GetInventory(msg.InventoryIndex);
            }
            else
            {
                // NOTE: this should be the default code after we get rid of the inventory owner and should be searched by it's id
                MyEntity        entity = MyEntities.GetEntityById(msg.OwnerEntityId);
                MyInventoryBase baseInventory;
                if (entity.Components.TryGet <MyInventoryBase>(out baseInventory))
                {
                    inv = baseInventory as MyInventory;
                }
            }
            var item = inv.GetItemByID(msg.itemId);

            if (!item.HasValue)
            {
                return;
            }
            inv.RemoveItems(msg.itemId, msg.Amount, spawn: msg.Spawn);
        }
示例#5
0
        private static void AddItemsInternal(AddItemsMsg msg)
        {
            IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner;
            MyInventory       inv   = owner.GetInventory(msg.InventoryIndex);

            inv.AddItemsInternal(msg.Amount, msg.Item, msg.itemIdx);
        }
示例#6
0
        static void OnAddItemsRequest(ref AddItemsMsg msg, MyNetworkClient sender)
        {
            if (!MyEntities.EntityExists(msg.OwnerEntityId))
            {
                return;
            }
            IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner;

            owner.GetInventory(msg.InventoryIndex).AddItems(msg.Amount, msg.Item, msg.itemIdx);
        }
示例#7
0
        static void OnRemoveItemsSuccess(ref RemoveItemsMsg msg, MyNetworkClient sender)
        {
            if (!MyEntities.EntityExists(msg.OwnerEntityId))
            {
                return;
            }
            IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner;
            MyInventory       inv   = owner.GetInventory(msg.InventoryIndex);

            inv.RemoveItemsInternal(msg.itemId, msg.Amount);
        }
示例#8
0
        static void OnTransferItemsRequest(ref TransferItemsMsg msg, MyNetworkClient sender)
        {
            if (!MyEntities.EntityExists(msg.OwnerEntityId) || !MyEntities.EntityExists(msg.DestOwnerEntityId))
            {
                return;
            }

            IMyInventoryOwner srcOwner  = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner;
            IMyInventoryOwner destOwner = MyEntities.GetEntityById(msg.DestOwnerEntityId) as IMyInventoryOwner;
            MyInventory       src       = srcOwner.GetInventory(msg.InventoryIndex);
            MyInventory       dst       = destOwner.GetInventory(msg.DestInventoryIndex);

            TransferItemsInternal(src, dst, msg.itemId, msg.Spawn, msg.DestItemIndex, msg.Amount);
        }
        private void EmptyBlockInventories(IMyInventoryOwner block)
        {
            for (int i = 0; i < block.InventoryCount; ++i)
            {
                var blockInventory = block.GetInventory(i);
                if (blockInventory.Empty()) continue;

                m_tmpItemList.Clear();
                m_tmpItemList.AddList(blockInventory.GetItems());

                foreach (var item in m_tmpItemList)
                {
                    MyInventory.Transfer(blockInventory, Inventory, item.ItemId);
                }
            }
        }
        private static bool FillInventoryWithIron()
        {
            IMyInventoryOwner invObject = MySession.ControlledEntity as IMyInventoryOwner;

            if (invObject != null)
            {
                MyFixedPoint amount = 20000;

                var         oreBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>("Iron");
                MyInventory inventory  = invObject.GetInventory(0);
                amount = inventory.ComputeAmountThatFits(oreBuilder.GetId());

                inventory.AddItems(amount, oreBuilder);
            }

            return(true);
        }
示例#11
0
        static void OnRemoveItemsRequest(ref RemoveItemsMsg msg, MyNetworkClient sender)
        {
            if (!MyEntities.EntityExists(msg.OwnerEntityId))
            {
                return;
            }

            IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner;
            MyInventory       inv   = owner.GetInventory(msg.InventoryIndex);
            var item = inv.GetItemByID(msg.itemId);

            if (!item.HasValue)
            {
                return;
            }
            inv.RemoveItems(msg.itemId, msg.Amount, spawn: msg.Spawn);
        }
示例#12
0
        private void EmptyBlockInventories(IMyInventoryOwner block)
        {
            for (int i = 0; i < block.InventoryCount; ++i)
            {
                var blockInventory = block.GetInventory(i);
                if (blockInventory.Empty())
                {
                    continue;
                }

                m_tmpItemList.Clear();
                m_tmpItemList.AddList(blockInventory.GetItems());

                foreach (var item in m_tmpItemList)
                {
                    MyInventory.Transfer(blockInventory, Inventory, item.ItemId);
                }
            }
        }
示例#13
0
        private static void OnUpdateOxygenLevel(ref UpdateOxygenLevelMsg msg, MyNetworkClient sender)
        {
            if (!MyEntities.EntityExists(msg.OwnerEntityId))
            {
                return;
            }

            IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner;
            MyInventory       inv   = null;

            if (owner != null)
            {
                inv = owner.GetInventory(msg.InventoryIndex);
            }
            else
            {
                // NOTE: this should be the default code after we get rid of the inventory owner and should be searched by it's id
                MyEntity        entity = MyEntities.GetEntityById(msg.OwnerEntityId);
                MyInventoryBase baseInventory;
                if (entity.Components.TryGet <MyInventoryBase>(out baseInventory))
                {
                    inv = baseInventory as MyInventory;
                }
            }

            var item = inv.GetItemByID(msg.ItemId);

            if (!item.HasValue)
            {
                return;
            }

            var oxygenContainer = item.Value.Content as MyObjectBuilder_OxygenContainerObject;

            if (oxygenContainer != null)
            {
                oxygenContainer.OxygenLevel = msg.OxygenLevel;
                inv.UpdateOxygenAmount();
            }
        }
示例#14
0
        protected override void OnLoad(BitStream stream, Action <MyInventory> loadingDoneHandler)
        {
            long entityId;

            VRage.Serialization.MySerializer.CreateAndRead(stream, out entityId);

            int inventoryId;

            VRage.Serialization.MySerializer.CreateAndRead(stream, out inventoryId);
            MyEntity entity;

            MyEntities.TryGetEntityById(entityId, out entity);

            IMyInventoryOwner owner = entity as IMyInventoryOwner;

            MyInventory inventory = null;

            if (owner != null)
            {
                inventory = owner.GetInventory(inventoryId);

                m_items.Clear();
                int numItems;
                VRage.Serialization.MySerializer.CreateAndRead(stream, out numItems);
                for (int i = 0; i < numItems; ++i)
                {
                    MyPhysicalInventoryItem item;
                    VRage.Serialization.MySerializer.CreateAndRead(stream, out item, MyObjectBuilderSerializer.Dynamic);
                    m_items.Add(item);
                }

                inventory.SetItems(m_items);
            }
            Debug.Assert(inventory != null, "Dusan, we should fix this, try to find out what is that EntityId of owner on server: " + entityId);
            loadingDoneHandler(inventory);
        }
示例#15
0
        private static void OnUpdateOxygenLevel(ref UpdateOxygenLevelMsg msg, MyNetworkClient sender)
        {
            if (!MyEntities.EntityExists(msg.OwnerEntityId))
            {
                return;
            }

            IMyInventoryOwner owner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner;
            MyInventory       inv   = owner.GetInventory(msg.InventoryIndex);
            var item = inv.GetItemByID(msg.ItemId);

            if (!item.HasValue)
            {
                return;
            }

            var oxygenContainer = item.Value.Content as MyObjectBuilder_OxygenContainerObject;

            if (oxygenContainer != null)
            {
                oxygenContainer.OxygenLevel = msg.OxygenLevel;
                inv.UpdateOxygenAmount();
            }
        }
        void confirmButton_OnButtonClick(MyGuiControlButton sender)
        {
            IMyInventoryOwner invObject = MySession.ControlledEntity as IMyInventoryOwner;

            if (invObject != null)
            {
                double amountDec = 0;
                double.TryParse(m_amountTextbox.Text, out amountDec);

                MyFixedPoint amount = (MyFixedPoint)amountDec;

                var         itemId    = m_physicalItemDefinitions[(int)m_items.GetSelectedKey()].Id;
                MyInventory inventory = invObject.GetInventory(0);
                if (!MySession.Static.CreativeMode)
                {
                    amount = MyFixedPoint.Min(inventory.ComputeAmountThatFits(itemId), amount);
                }

                var builder = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(itemId);
                inventory.DebugAddItems(amount, builder);
            }

            CloseScreen();
        }
        private void AddItemsToInventory(int variant)
        {
            bool overrideCheck   = variant != 0;
            bool spawnNonfitting = variant != 0;
            bool componentsOnly  = variant == 2;

            IMyInventoryOwner invObject = MySession.ControlledEntity as IMyInventoryOwner;

            if (invObject != null)
            {
                MyInventory inventory = invObject.GetInventory(0);
                //inventory.Clear();

                if (!componentsOnly)
                {
                    MyObjectBuilder_AmmoMagazine ammoMag = new MyObjectBuilder_AmmoMagazine();
                    ammoMag.SubtypeName      = "NATO_5p56x45mm";
                    ammoMag.ProjectilesCount = 50;
                    AddItems(inventory, ammoMag, false, 5);

                    MyObjectBuilder_AmmoMagazine ammoMag2 = new MyObjectBuilder_AmmoMagazine();
                    ammoMag2.SubtypeName      = "NATO_25x184mm";
                    ammoMag2.ProjectilesCount = 50;
                    AddItems(inventory, ammoMag2, false);

                    MyObjectBuilder_AmmoMagazine ammoMag3 = new MyObjectBuilder_AmmoMagazine();
                    ammoMag3.SubtypeName      = "Missile200mm";
                    ammoMag3.ProjectilesCount = 50;
                    AddItems(inventory, ammoMag3, false);


                    AddItems(inventory, CreateGunContent("AutomaticRifleItem"), false);
                    AddItems(inventory, CreateGunContent("WelderItem"), false);
                    AddItems(inventory, CreateGunContent("AngleGrinderItem"), false);
                    AddItems(inventory, CreateGunContent("HandDrillItem"), false);
                }

                // Add all components
                foreach (var definition in MyDefinitionManager.Static.GetAllDefinitions())
                {
                    if (definition.Id.TypeId != typeof(MyObjectBuilder_Component) &&
                        definition.Id.TypeId != typeof(MyObjectBuilder_Ingot))
                    {
                        continue;
                    }

                    if (componentsOnly && definition.Id.TypeId != typeof(MyObjectBuilder_Component))
                    {
                        continue;
                    }

                    if (componentsOnly && ((MyComponentDefinition)definition).Volume > 0.05f)
                    {
                        continue;
                    }

                    var component = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definition.Id.TypeId);
                    component.SubtypeName = definition.Id.SubtypeName;
                    if (!AddItems(inventory, component, overrideCheck, 1) && spawnNonfitting)
                    {
                        Matrix headMatrix = MySession.ControlledEntity.GetHeadMatrix(true);
                        MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(1, component), headMatrix.Translation + headMatrix.Forward * 0.2f, headMatrix.Forward, headMatrix.Up, MySession.ControlledEntity.Entity.Physics);
                    }
                }

                if (!componentsOnly)
                {
                    string[] ores;
                    MyDefinitionManager.Static.GetOreTypeNames(out ores);
                    foreach (var ore in ores)
                    {
                        var oreBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>(ore);
                        if (!AddItems(inventory, oreBuilder, overrideCheck, 1) && spawnNonfitting)
                        {
                            Matrix headMatrix = MySession.ControlledEntity.GetHeadMatrix(true);
                            MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(1, oreBuilder), headMatrix.Translation + headMatrix.Forward * 0.2f, headMatrix.Forward, headMatrix.Up, MySession.ControlledEntity.Entity.Physics);
                        }
                    }
                }
            }
        }
示例#18
0
        public static void ItemPullRequest(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyDefinitionId itemId, MyFixedPoint?amount = null)
        {
            using (var invertedConductivity = new MyConveyorLine.InvertedConductivity())
            {
                if (amount.HasValue)
                {
                    Debug.Assert(itemId.TypeId == typeof(MyObjectBuilder_Ore) ||
                                 itemId.TypeId == typeof(MyObjectBuilder_Ingot) ||
                                 MyFixedPoint.Floor(amount.Value) == amount.Value);
                }

                SetTraversalPlayerId(playerId);
                SetTraversalInventoryItemDefinitionId(itemId);

                PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, NeedsLargeTube(itemId) ? IsConveyorLargePredicate : null);
                foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding)
                {
                    IMyInventoryOwner owner = conveyorEndpoint.CubeBlock as IMyInventoryOwner;
                    if (owner == null)
                    {
                        continue;
                    }

                    for (int i = 0; i < owner.InventoryCount; ++i)
                    {
                        var inventory = owner.GetInventory(i);
                        if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0)
                        {
                            continue;
                        }

                        if (inventory == destinationInventory)
                        {
                            continue;
                        }

                        if (amount.HasValue)
                        {
                            var availableAmount = inventory.GetItemAmount(itemId);
                            availableAmount = amount.HasValue ? MyFixedPoint.Min(availableAmount, amount.Value) : availableAmount;
                            if (availableAmount == 0)
                            {
                                continue;
                            }

                            MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None, availableAmount);

                            amount -= availableAmount;
                            if (amount.Value == 0)
                            {
                                return;
                            }
                        }
                        else
                        {
                            MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None);
                        }
                    }
                }
            }
        }
        public override bool HandleInput()
        {
            bool handled = false;

            if (m_gridDebugInfo)
            {
                LineD      line = new LineD(MySector.MainCamera.Position, MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 1000);
                MyCubeGrid grid;
                Vector3I   cubePos;
                double     distance;
                if (MyCubeGrid.GetLineIntersection(ref line, out grid, out cubePos, out distance))
                {
                    var gridMatrix = grid.WorldMatrix;
                    var boxMatrix  = Matrix.CreateTranslation(cubePos * grid.GridSize) * gridMatrix;
                    var block      = grid.GetCubeBlock(cubePos);

                    MyRenderProxy.DebugDrawText2D(new Vector2(), cubePos.ToString(), Color.White, 0.7f);
                    MyRenderProxy.DebugDrawOBB(Matrix.CreateScale(new Vector3(grid.GridSize) + new Vector3(0.15f)) * boxMatrix, Color.Red.ToVector3(), 0.2f, true, true);

                    //int[, ,] bones = grid.Skeleton.AddCubeBones(cubePos);

                    //Vector3 closestBone = Vector3.Zero;
                    //Vector3I closestPoint = Vector3I.Zero;
                    //float closestPointDist = float.MaxValue;
                    //int closestBoneIndex = 0;

                    //for (int x = -1; x <= 1; x += 1)
                    //{
                    //    for (int y = -1; y <= 1; y += 1)
                    //    {
                    //        for (int z = -1; z <= 1; z += 1)
                    //        {
                    //            int boneIndex = bones[x + 1, y + 1, z + 1];
                    //            Vector3 bone = grid.Skeleton[boneIndex];

                    //            var pos = boxMatrix.Translation + new Vector3(grid.GridSize / 2) * new Vector3(x, y, z);
                    //            //MyRenderProxy.DebugDrawSphere(pos, 0.2f, Color.Blue.ToVector3(), 1.0f, false);
                    //            MyRenderProxy.DebugDrawText3D(pos, String.Format("{0:G2}, {1:G2}, {2:G2}", bone.X, bone.Y, bone.Z), Color.White, 0.5f, false);

                    //            var dist = MyUtils.GetPointLineDistance(ref line, ref pos);
                    //            if (dist < closestPointDist)
                    //            {
                    //                closestPointDist = dist;
                    //                closestPoint = new Vector3I(x, y, z);
                    //                closestBoneIndex = boneIndex;
                    //                closestBone = bone;

                    //            }
                    //        }
                    //    }
                    //}

                    //MyRenderProxy.DebugDrawText3D(boxMatrix.Translation + new Vector3(grid.GridSize / 2) * closestPoint * 1.0f, String.Format("{0:G2}, {1:G2}, {2:G2}", closestBone.X, closestBone.Y, closestBone.Z), Color.Red, 0.5f, false);
                    //var bonePos = grid.Skeleton[bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]];
                    //MyRenderProxy.DebugDrawSphere(boxMatrix.Translation + new Vector3(grid.GridSize / 2) * closestPoint * 1.0f + bonePos, 0.5f, Color.Red.ToVector3(), 0.4f, true, true);

                    //if (input.IsNewKeyPressed(Keys.P) && block != null)
                    //{
                    //    if (input.IsAnyShiftKeyPressed())
                    //    {
                    //        grid.ResetBlockSkeleton(block);
                    //    }
                    //    else
                    //    {
                    //        grid.Skeleton[bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]] = Vector3.Zero;
                    //        grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One);
                    //        //grid.SetBlockDirty(block);
                    //    }
                    //    handled = true;
                    //}

                    //// Move bones to center by 0.1f
                    //if (input.IsNewKeyPressed(Keys.OemOpenBrackets))
                    //{
                    //    int index = bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1];
                    //    grid.Skeleton[index] -= Vector3.Sign(grid.Skeleton[index]) * 0.1f;
                    //    grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One);
                    //    //grid.SetBlockDirty(block);
                    //    handled = true;
                    //}

                    //// Reduce max offset by 0.1f
                    //if (input.IsNewKeyPressed(Keys.OemCloseBrackets))
                    //{
                    //    int index = bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1];
                    //    var old = Vector3.Abs(grid.Skeleton[index]);
                    //    var max = new Vector3(Math.Max(Math.Max(old.X, old.Y), old.Z));
                    //    if (max.X > 0.1f)
                    //    {
                    //        grid.Skeleton[index] = Vector3.Clamp(grid.Skeleton[index], -max + 0.1f, max - 0.1f);
                    //    }
                    //    else
                    //    {
                    //        grid.Skeleton[index] = Vector3.Zero;
                    //    }
                    //    grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One);
                    //    //grid.SetBlockDirty(block);
                    //    handled = true;
                    //}
                }
            }

            if (MyInput.Static.IsAnyAltKeyPressed())
            {
                return(handled);
            }

            bool shift = MyInput.Static.IsAnyShiftKeyPressed();
            bool ctrl  = MyInput.Static.IsAnyCtrlKeyPressed();

            //if (input.IsNewKeyPressed(Keys.I))
            //{
            //    foreach (var grid in MyEntities.GetEntities().OfType<MyCubeGrid>())
            //    {
            //        foreach (var block in grid.GetBlocks().ToArray())
            //        {
            //            grid.DetectMerge(block.Min, block.Max);
            //        }
            //    }
            //    handled = true;
            //}

            // Disabled since it is common to have normal control bound to O key.
            // If you ever need this again, bind it to something more complicated, like key combination.
            //if (input.IsNewKeyPressed(Keys.O))
            //{
            //    m_gridDebugInfo = !m_gridDebugInfo;
            //    handled = true;
            //}

            //for (int i = 0; i <= 9; i++)
            //{
            //    if (MyInput.Static.IsNewKeyPressed((Keys)(((int)Keys.D0) + i)))
            //    {
            //        string name = "Slot" + i.ToString();
            //        if (ctrl)
            //        {
            //            MySession.Static.Name = name;
            //            MySession.Static.WorldID = MySession.GetNewWorldId();
            //            MySession.Static.Save(name);
            //        }
            //        else if (shift)
            //        {
            //            var path = MyLocalCache.GetSessionSavesPath(name, false, false);
            //            if (System.IO.Directory.Exists(path))
            //            {
            //                MySession.Static.Unload();
            //                MySession.Load(path);
            //            }
            //        }
            //        handled = true;
            //    }
            //}

            //if (MyInput.Static.IsNewKeyPressed(Keys.End))
            //{
            //    MyMeteorShower.MeteorWave(null);
            //}

            // Disabled for god sake!
            //if (MyInput.Static.IsNewKeyPressed(Keys.PageUp) && MyInput.Static.IsAnyCtrlKeyPressed())
            //{
            //    MyReloadTestComponent.Enabled = true;
            //}
            //if (MyInput.Static.IsNewKeyPressed(Keys.PageDown) && MyInput.Static.IsAnyCtrlKeyPressed())
            //{
            //    MyReloadTestComponent.Enabled = false;
            //}

            if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad6))
            {
                var view = MySession.Static.CameraController.GetViewMatrix();
                var inv  = Matrix.Invert(view);

                //MyPhysicalInventoryItem item = new MyPhysicalInventoryItem(100,
                var oreBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>("Stone");
                var item       = new MyPhysicalInventoryItem(1, oreBuilder);
                var obj        = MyFloatingObjects.Spawn(item, inv.Translation + inv.Forward * 1.0f, inv.Forward, inv.Up);
                obj.Physics.LinearVelocity = inv.Forward * 50;
            }

            if (false && MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9))
            {
                List <HkShape>       trShapes = new List <HkShape>();
                List <HkConvexShape> shapes   = new List <HkConvexShape>();
                List <Matrix>        matrices = new List <Matrix>();

                var         grid = new HkGridShape(2.5f, HkReferencePolicy.None);
                const short size = 50;
                for (short x = 0; x < size; x++)
                {
                    for (short y = 0; y < size; y++)
                    {
                        for (short z = 0; z < size; z++)
                        {
                            var box = new HkBoxShape(Vector3.One);
                            grid.AddShapes(new System.Collections.Generic.List <HkShape>()
                            {
                                box
                            }, new Vector3S(x, y, z), new Vector3S(x, y, z));
                            trShapes.Add(new HkConvexTranslateShape(box, new Vector3(x, y, z), HkReferencePolicy.None));
                            shapes.Add(box);
                            matrices.Add(Matrix.CreateTranslation(new Vector3(x, y, z)));
                        }
                    }
                }

                var emptyGeom = new HkGeometry(new List <Vector3>(), new List <int>());

                var list         = new HkListShape(trShapes.ToArray(), trShapes.Count, HkReferencePolicy.None);
                var compressedBv = new HkBvCompressedMeshShape(emptyGeom, shapes, matrices, HkWeldingType.None);
                var mopp         = new HkMoppBvTreeShape(list, HkReferencePolicy.None);

                HkShapeBuffer buf = new HkShapeBuffer();

                //HkShapeContainerIterator i = compressedBv.GetIterator(buf);
                //int count = 0; // will be 125000
                //while (i.IsValid)
                //{
                //    count++;
                //    i.Next();
                //}

                buf.Dispose();
                var info = new HkRigidBodyCinfo();
                info.Mass = 10;
                info.CalculateBoxInertiaTensor(Vector3.One, 10);
                info.MotionType  = HkMotionType.Dynamic;
                info.QualityType = HkCollidableQualityType.Moving;
                info.Shape       = compressedBv;
                var body = new HkRigidBody(info);

                //MyPhysics.HavokWorld.AddRigidBody(body);
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad7))
            {
                foreach (var g in MyEntities.GetEntities().OfType <MyCubeGrid>())
                {
                    foreach (var s in g.CubeBlocks.Select(s => s.FatBlock).Where(s => s != null).OfType <MyMotorStator>())
                    {
                        if (s.Rotor != null)
                        {
                            var q = Quaternion.CreateFromAxisAngle(s.Rotor.WorldMatrix.Up, MathHelper.ToRadians(45));
                            s.Rotor.CubeGrid.WorldMatrix = MatrixD.CreateFromQuaternion(q) * s.Rotor.CubeGrid.WorldMatrix;
                        }
                    }
                }
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad8))
            {
                var view = MySession.Static.CameraController.GetViewMatrix();
                var inv  = Matrix.Invert(view);

                var oreBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>("Stone");
                var obj        = new MyObjectBuilder_FloatingObject()
                {
                    Item = new MyObjectBuilder_InventoryItem()
                    {
                        Content = oreBuilder, Amount = 1000
                    }
                };
                obj.PositionAndOrientation = new MyPositionAndOrientation(inv.Translation + 2.0f * inv.Forward, inv.Forward, inv.Up);
                obj.PersistentFlags        = MyPersistentEntityFlags2.InScene;
                var e = MyEntities.CreateFromObjectBuilderAndAdd(obj);
                e.Physics.LinearVelocity = Vector3.Normalize(inv.Forward) * 50.0f;
            }


            if (MyInput.Static.IsNewKeyPressed(MyKeys.Divide))
            {
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.Multiply))
            {
                MyDebugDrawSettings.ENABLE_DEBUG_DRAW = !MyDebugDrawSettings.ENABLE_DEBUG_DRAW;
                MyStructuralIntegrity.Enabled         = true;
                MyDebugDrawSettings.DEBUG_DRAW_STRUCTURAL_INTEGRITY = true;

                var grids = MyEntities.GetEntities().OfType <MyCubeGrid>();
                foreach (var g in grids)
                {
                    if (!g.IsStatic)// || g.GetBlocks().Count < 800) //to compute only castle
                    {
                        continue;
                    }

                    g.CreateStructuralIntegrity();
                }
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad1))
            {
                var e = MyEntities.GetEntities().OfType <MyCubeGrid>().FirstOrDefault();
                if (e != null)
                {
                    e.Physics.RigidBody.MaxLinearVelocity = 1000;
                    if (e.Physics.RigidBody2 != null)
                    {
                        e.Physics.RigidBody2.MaxLinearVelocity = 1000;
                    }

                    e.Physics.LinearVelocity = new Vector3(1000, 0, 0);
                }
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.Decimal))
            {
                MyPrefabManager.Static.SpawnPrefab("respawnship", MySector.MainCamera.Position, MySector.MainCamera.ForwardVector, MySector.MainCamera.UpVector);
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.Multiply) && MyInput.Static.IsAnyShiftKeyPressed())
            {
                GC.Collect(2);
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad5))
            {
                Thread.Sleep(250);
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9))
            {
                var obj = MySession.ControlledEntity != null ? MySession.ControlledEntity.Entity : null;
                if (obj != null)
                {
                    const float dist = 5.0f;
                    obj.PositionComp.SetPosition(obj.PositionComp.GetPosition() + obj.WorldMatrix.Forward * dist);
                }
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad4))
            {
                IMyInventoryOwner invObject = MySession.ControlledEntity as IMyInventoryOwner;
                if (invObject != null)
                {
                    MyFixedPoint amount = 20000;

                    var         oreBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>("Stone");
                    MyInventory inventory  = invObject.GetInventory(0);
                    inventory.AddItems(amount, oreBuilder);
                }

                handled = true;
            }

            //if (MyInput.Static.IsNewKeyPressed(Keys.NumPad8))
            //{
            //    var pos = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 2;
            //    var grid = (MyObjectBuilder_CubeGrid)MyObjectBuilderSerializer.CreateNewObject(MyObjectBuilderTypeEnum.CubeGrid);
            //    grid.PositionAndOrientation = new MyPositionAndOrientation(pos, Vector3.Forward, Vector3.Up);
            //    grid.CubeBlocks = new List<MyObjectBuilder_CubeBlock>();
            //    grid.GridSizeEnum = MyCubeSize.Large;

            //    var block = new MyObjectBuilder_CubeBlock();
            //    block.BlockOrientation = MyBlockOrientation.Identity;
            //    block.Min = Vector3I.Zero;
            //    //var blockDefinition = Sandbox.Game.Managers.MyDefinitionManager.Static.GetCubeBlockDefinition(new CommonLib.ObjectBuilders.Definitions.MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock"));
            //    block.SubtypeName = "LargeBlockArmorBlock";
            //    grid.CubeBlocks.Add(block);
            //    grid.LinearVelocity = MySector.MainCamera.ForwardVector * 20;
            //    grid.PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene;

            //    var x = MyEntities.CreateFromObjectBuilderAndAdd(grid);
            //}

            //if (MyInput.Static.IsNewKeyPressed(Keys.NumPad9))
            //{
            //    var pos = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 2;
            //    var grid =  (MyObjectBuilder_CubeGrid)MyObjectBuilderSerializer.CreateNewObject(MyObjectBuilderTypeEnum.CubeGrid);
            //    grid.PositionAndOrientation = new MyPositionAndOrientation(pos, Vector3.Forward, Vector3.Up);
            //    grid.CubeBlocks = new List<MyObjectBuilder_CubeBlock>();
            //    grid.GridSizeEnum = MyCubeSize.Large;

            //    var block = new MyObjectBuilder_CubeBlock();
            //    block.BlockOrientation = MyBlockOrientation.Identity;
            //    block.Min = Vector3I.Zero;
            //    //var blockDefinition = Sandbox.Game.Managers.MyDefinitionManager.Static.GetCubeBlockDefinition(new CommonLib.ObjectBuilders.Definitions.MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock"));
            //    block.SubtypeName = "LargeBlockGyro";
            //    grid.CubeBlocks.Add(block);
            //    grid.LinearVelocity = MySector.MainCamera.ForwardVector * 20;
            //    grid.PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene;

            //    var x = MyEntities.CreateFromObjectBuilderAndAdd(grid);
            //}

            if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.Delete))
            {
                int count = MyEntities.GetEntities().OfType <MyFloatingObject>().Count();
                foreach (var obj in MyEntities.GetEntities().OfType <MyFloatingObject>())
                {
                    if (obj == MySession.ControlledEntity)
                    {
                        MySession.SetCameraController(MyCameraControllerEnum.Spectator);
                    }
                    obj.Close();
                }
                handled = true;
            }

            if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.Decimal))
            {
                foreach (var obj in MyEntities.GetEntities())
                {
                    if (obj != MySession.ControlledEntity && (MySession.ControlledEntity == null || obj != MySession.ControlledEntity.Entity.Parent) && obj != MyCubeBuilder.Static.FindClosestGrid())
                    {
                        obj.Close();
                    }
                }
                handled = true;
            }

            if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9) || MyInput.Static.IsNewKeyPressed(MyKeys.NumPad5))
            {
                //MyCubeGrid.UserCollisions = input.IsNewKeyPressed(Keys.NumPad9);

                var body = MySession.ControlledEntity.Entity.GetTopMostParent().Physics;
                if (body.RigidBody != null)
                {
                    //body.AddForce(Engine.Physics.MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, new Vector3(0, 0, 10 * body.Mass), null, null);
                    body.RigidBody.ApplyLinearImpulse(body.Entity.WorldMatrix.Forward * body.Mass * 2);
                }
                handled = true;
            }

            //if (input.IsNewKeyPressed(Keys.J) && input.IsAnyCtrlKeyPressed())
            //{
            //    MyGlobalInputComponent.CopyCurrentGridToClipboard();

            //    MyEntity addedEntity = MyGlobalInputComponent.PasteEntityFromClipboard();

            //    if (addedEntity != null)
            //    {
            //        Vector3 pos = addedEntity.GetPosition();
            //        pos.Z += addedEntity.WorldVolume.Radius * 1.5f;
            //        addedEntity.SetPosition(pos);
            //    }
            //    handled = true;
            //}

            if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.OemComma))
            {
                foreach (var e in MyEntities.GetEntities().OfType <MyFloatingObject>().ToArray())
                {
                    e.Close();
                }
            }

            return(handled);
        }
示例#20
0
        public static bool ItemPushRequest(IMyConveyorEndpointBlock start, MyInventory srcInventory, long playerId, MyPhysicalInventoryItem toSend, MyFixedPoint?amount = null)
        {
            var itemBuilder = toSend.Content;

            if (amount.HasValue)
            {
                Debug.Assert(toSend.Content.TypeId == typeof(MyObjectBuilder_Ore) ||
                             toSend.Content.TypeId == typeof(MyObjectBuilder_Ingot) ||
                             MyFixedPoint.Floor(amount.Value) == amount.Value);
            }

            MyFixedPoint remainingAmount = toSend.Amount;

            if (amount.HasValue)
            {
                remainingAmount = amount.Value;
            }

            SetTraversalPlayerId(playerId);

            var toSendContentId = toSend.Content.GetId();

            SetTraversalInventoryItemDefinitionId(toSendContentId);

            if (NeedsLargeTube(toSendContentId))
            {
                PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, IsConveyorLargePredicate);
            }
            else
            {
                PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate);
            }

            bool success = false;

            foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding)
            {
                IMyInventoryOwner owner = conveyorEndpoint.CubeBlock as IMyInventoryOwner;
                if (owner == null)
                {
                    continue;
                }

                for (int i = 0; i < owner.InventoryCount; ++i)
                {
                    var inventory = owner.GetInventory(i);
                    if ((inventory.GetFlags() & MyInventoryFlags.CanReceive) == 0)
                    {
                        continue;
                    }

                    if (inventory == srcInventory)
                    {
                        continue;
                    }

                    var fittingAmount = inventory.ComputeAmountThatFits(toSendContentId);
                    fittingAmount = MyFixedPoint.Min(fittingAmount, remainingAmount);
                    if (!inventory.CheckConstraint(toSendContentId))
                    {
                        continue;
                    }
                    if (fittingAmount == 0)
                    {
                        continue;
                    }

                    MyInventory.Transfer(srcInventory, inventory, toSend.ItemId, -1, fittingAmount);
                    success = true;
                }
            }
            return(success);
        }
示例#21
0
        private static void ItemPullAllInternal(MyInventory destinationInventory, PullRequestItemSet requestedTypeIds, bool onlySmall)
        {
            SetTraversalInventoryItemDefinitionId();
            Debug.Assert(m_tmpPullRequests.Count == 0, "m_tmpPullRequests is not empty!");
            using (var invertedConductivity = new MyConveyorLine.InvertedConductivity())
            {
                foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding)
                {
                    IMyInventoryOwner owner = conveyorEndpoint.CubeBlock as IMyInventoryOwner;
                    if (owner == null)
                    {
                        continue;
                    }

                    for (int i = 0; i < owner.InventoryCount; ++i)
                    {
                        var inventory = owner.GetInventory(i);
                        if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0)
                        {
                            continue;
                        }

                        if (inventory == destinationInventory)
                        {
                            continue;
                        }

                        m_tmpInventoryItems.Clear();
                        foreach (var item in inventory.GetItems())
                        {
                            m_tmpInventoryItems.Add(item);
                        }

                        foreach (var item in m_tmpInventoryItems)
                        {
                            if (destinationInventory.VolumeFillFactor >= 1.0f)
                            {
                                m_tmpInventoryItems.Clear();
                                return;
                            }

                            var itemId = item.Content.GetId();

                            if (requestedTypeIds != null && !requestedTypeIds.Contains(itemId))
                            {
                                continue;
                            }

                            if (onlySmall && NeedsLargeTube(itemId))
                            {
                                continue;
                            }

                            var transferedAmount = item.Amount;

                            var oxygenBottle = item.Content as Sandbox.Common.ObjectBuilders.Definitions.MyObjectBuilder_GasContainerObject;
                            if (oxygenBottle != null && oxygenBottle.GasLevel == 1f)
                            {
                                continue;
                            }

                            if (!MySession.Static.CreativeMode)
                            {
                                var fittingAmount = destinationInventory.ComputeAmountThatFits(item.Content.GetId());
                                if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) &&
                                    item.Content.TypeId != typeof(MyObjectBuilder_Ingot))
                                {
                                    fittingAmount = MyFixedPoint.Floor(fittingAmount);
                                }
                                transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount);
                            }
                            if (transferedAmount == 0)
                            {
                                continue;
                            }

                            // SK: this is mental
                            m_tmpPullRequests.Add(new MyTuple <IMyConveyorEndpointBlock, MyPhysicalInventoryItem>(m_startingEndpoint.CubeBlock as IMyConveyorEndpointBlock, item));
                            //MyInventory.Transfer(inventory, destinationInventory, item.Content.GetId(), MyItemFlags.None, transferedAmount);
                        }
                    }
                }
            }

            foreach (var tuple in m_tmpPullRequests)
            {
                if (destinationInventory.VolumeFillFactor >= 1.0f)
                {
                    m_tmpPullRequests.Clear();
                    return;
                }

                var start = tuple.Item1;
                var item  = tuple.Item2;

                var transferedAmount = item.Amount;
                var fittingAmount    = destinationInventory.ComputeAmountThatFits(item.Content.GetId());
                if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) &&
                    item.Content.TypeId != typeof(MyObjectBuilder_Ingot))
                {
                    fittingAmount = MyFixedPoint.Floor(fittingAmount);
                }
                transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount);

                if (transferedAmount == 0)
                {
                    continue;
                }

                var itemId = item.Content.GetId();

                SetTraversalInventoryItemDefinitionId(itemId);
                ItemPullRequest(start, destinationInventory, m_playerIdForAccessiblePredicate, itemId, transferedAmount);
            }

            m_tmpPullRequests.Clear();
        }
        private void RefreshInventoryContents()
        {
            Debug.Assert(m_inventoryOwner.InventoryCount == m_inventoryGrids.Count);
            Debug.Assert(m_inventoryOwner.InventoryCount == m_massLabels.Count);
            Debug.Assert(m_inventoryOwner.InventoryCount == m_volumeLabels.Count);
            for (int i = 0; i < m_inventoryOwner.InventoryCount; ++i)
            {
                var inventory     = m_inventoryOwner.GetInventory(i);
                var inventoryGrid = m_inventoryGrids[i];
                var massLabel     = m_massLabels[i];
                var volumeLabel   = m_volumeLabels[i];
                int?selectedIndex = inventoryGrid.SelectedIndex;
                inventoryGrid.Clear();

                massLabel.UpdateFormatParams(((double)inventory.CurrentMass).ToString(MyInventoryConstants.GUI_DISPLAY_FORMAT, CultureInfo.InvariantCulture));

                string volume = ((double)(inventory.CurrentVolume * 1000)).ToString(MyInventoryConstants.GUI_DISPLAY_FORMAT, CultureInfo.InvariantCulture);
                if (MySession.Static.SurvivalMode)
                {
                    volume += " / " + ((double)(inventory.MaxVolume * 1000)).ToString(MyInventoryConstants.GUI_DISPLAY_FORMAT, CultureInfo.InvariantCulture);
                }
                volumeLabel.UpdateFormatParams(volume);

                //RefreshInventoryGridSize(inventory, inventoryGrid);
                if (inventory.Constraint != null)
                {
                    inventoryGrid.EmptyItemIcon = inventory.Constraint.Icon;
                    inventoryGrid.SetEmptyItemToolTip(inventory.Constraint.Description);
                }
                else
                {
                    inventoryGrid.EmptyItemIcon = null;
                    inventoryGrid.SetEmptyItemToolTip(null);
                }

                foreach (var item in inventory.GetItems())
                {
                    inventoryGrid.Add(CreateInventoryGridItem(item));
                }

                if (selectedIndex.HasValue)
                {
                    if (inventoryGrid.IsValidIndex(selectedIndex.Value))
                    {
                        inventoryGrid.SelectedIndex = selectedIndex;
                    }
                    else
                    {
                        inventoryGrid.SelectLastItem();
                    }
                }
                else
                {
                    inventoryGrid.SelectedIndex = null;
                }
            }

            RefreshInventoryGridSizes();
            Size = ComputeControlSize();
            RefreshInternals();
        }
示例#23
0
        public bool Drill(bool collectOre = true, bool performCutout = true)
        {
            ProfilerShort.Begin("MyDrillBase::Drill()");

            bool drillingSuccess = false;

            MySoundPair sound = null;

            if ((m_drillEntity.Parent != null) && (m_drillEntity.Parent.Physics != null) && !m_drillEntity.Parent.Physics.Enabled)
            {
                return(false);
            }

            if (performCutout)
            {
                var entitiesInRange = m_sensor.EntitiesInRange;
                foreach (var entry in entitiesInRange)
                {
                    drillingSuccess = false;
                    var entity = entry.Value.Entity;
                    if (entity.MarkedForClose)
                    {
                        continue;
                    }
                    if (entity is MyCubeGrid)
                    {
                        var grid = entity as MyCubeGrid;
                        if (grid.Physics != null && grid.Physics.Enabled)
                        {
                            drillingSuccess = TryDrillBlocks(grid, entry.Value.DetectionPoint, !Sync.IsServer);
                        }
                        if (drillingSuccess)
                        {
                            m_initialHeatup = false;
                            sound           = m_sounds.MetalLoop;
                            CreateParticles(entry.Value.DetectionPoint, false, true, false);
                        }
                    }
                    else if (entity is MyVoxelBase)
                    {
                        ProfilerShort.Begin("Drill voxel map");
                        var voxels = entity as MyVoxelBase;
                        drillingSuccess = TryDrillVoxels(voxels, entry.Value.DetectionPoint, collectOre, !Sync.IsServer);
                        ProfilerShort.BeginNextBlock("Create particles");
                        if (drillingSuccess)
                        {
                            sound = m_sounds.RockLoop;
                            CreateParticles(entry.Value.DetectionPoint, true, false, true);
                        }
                        ProfilerShort.End();
                    }
                    else if (entity is MyFloatingObject)
                    {
                        var sphere = (BoundingSphereD)m_cutOut.Sphere;
                        sphere.Radius *= 1.33f;
                        if (entity.GetIntersectionWithSphere(ref sphere))
                        {
                            MyFloatingObject flObj = entity as MyFloatingObject;
                            if (Sync.IsServer)
                            {
                                if (flObj.Item.Content.TypeId == typeof(MyObjectBuilder_Ore))
                                {
                                    IMyInventoryOwner invOwn = m_drillEntity as IMyInventoryOwner;
                                    if (invOwn == null)
                                    {
                                        invOwn = (m_drillEntity as MyHandDrill).Owner as IMyInventoryOwner;
                                    }
                                    invOwn.GetInventory(0).TakeFloatingObject(flObj);
                                }
                                else
                                {
                                    (entity as MyFloatingObject).DoDamage(70, MyDamageType.Drill, true, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0);
                                }
                            }
                            drillingSuccess = true;
                        }
                    }
                    else if (entity is MyCharacter)
                    {
                        var sphere = (BoundingSphereD)m_cutOut.Sphere;
                        sphere.Radius *= (4 / 5f);
                        var character = entity as MyCharacter;
                        if (entity.GetIntersectionWithSphere(ref sphere))
                        {
                            //MyRenderProxy.DebugDrawSphere(sphere.Center, sphere.Radius, Color.Green.ToVector3(), 1, true);
                            if (Sync.IsServer)
                            {
                                character.DoDamage(20, MyDamageType.Drill, true, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0);
                            }
                            drillingSuccess = true;
                        }
                        else
                        {
                            BoundingSphereD headSphere = new BoundingSphereD(character.PositionComp.WorldMatrix.Translation + character.WorldMatrix.Up * 1.25f, 0.6f);
                            //MyRenderProxy.DebugDrawSphere(headSphere.Center, headSphere.Radius, Color.Red.ToVector3(), 1, false);
                            if (headSphere.Intersects(sphere))
                            {
                                //MyRenderProxy.DebugDrawSphere(sphere.Center, sphere.Radius, Color.Green.ToVector3(), 1, true);
                                if (Sync.IsServer)
                                {
                                    character.DoDamage(20, MyDamageType.Drill, true, attackerId: m_drillEntity != null ? m_drillEntity.EntityId : 0);
                                }
                                drillingSuccess = true;
                            }
                        }
                    }
                    if (drillingSuccess)
                    {
                        m_lastContactTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                    }
                }
            }

            if (sound != null)
            {
                StartLoopSound(sound);
            }
            else
            {
                StartIdleSound(m_sounds.IdleLoop);
            }

            IsDrilling = true;

            m_animationLastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            ProfilerShort.End();
            return(drillingSuccess);
        }
        private void AttachOwner(IMyInventoryOwner owner)
        {
            if (owner == null)
                return;

            m_nameLabel.Text = owner.DisplayNameText.ToString();

            for (int i = 0; i < owner.InventoryCount; ++i)
            {
                var inventory = owner.GetInventory(i);
                inventory.UserData = this;
                inventory.ContentsChanged += inventory_OnContentsChanged;

                var massLabel = MakeMassLabel(inventory);
                Elements.Add(massLabel);
                m_massLabels.Add(massLabel);

                var volumeLabel = MakeVolumeLabel(inventory);
                Elements.Add(volumeLabel);
                m_volumeLabels.Add(volumeLabel);

                var inventoryGrid = MakeInventoryGrid(inventory);
                Elements.Add(inventoryGrid);
                m_inventoryGrids.Add(inventoryGrid);
            }

            m_inventoryOwner = owner;

            RefreshInventoryContents();
        }
        void Main(string argument)
        {
            // initialize
            Dictionary <MyDefinitionId, VRage.MyFixedPoint> inventory = new Dictionary <MyDefinitionId, VRage.MyFixedPoint>();

            var blocks = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyInventoryOwner>(blocks);
            VRage.ObjectBuilders.MyObjectBuilderType type = null;
            if (!nameTypes.TryGetValue(argument, out type))
            {
                for (int i = 0; i < nameTypes.Count; i++)
                {
                }
                return;
            }
            debug.Append(argument).Append('=').AppendLine(type.ToString() ?? "null");


            if (blocks.Count == 0)
            {
                throw new Exception("Did not find any cargo container.");
            }

            for (int i = 0; i < blocks.Count; ++i)
            {
                IMyInventoryOwner invOwner = blocks[i] as IMyInventoryOwner;
                for (int j = 0; j < invOwner.InventoryCount; ++j)
                {
                    IMyInventory            inv   = invOwner.GetInventory(j);
                    List <IMyInventoryItem> items = inv.GetItems();
                    for (int k = 0; k < items.Count; ++k)
                    {
                        IMyInventoryItem item = items[k];
                        var key = new MyDefinitionId(item.Content.TypeId, item.Content.SubtypeName);
                        //contents.Add(key);
                        if (!inventory.ContainsKey(key))
                        {
                            inventory[key] = item.Amount;
                        }
                        else
                        {
                            inventory[key] = inventory[key] + item.Amount;
                        }
                    }
                }
            }
            debug.AppendLine();
            var enumerator = inventory.Keys.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var key = enumerator.Current;
                if (key.TypeId != ItemTypes.INGOT)
                {
                    continue;
                }
                debug.Append(typeNames[key.TypeId]).Append(key.SubtypeName).Append(" = ").Append(inventory[key]).AppendLine();
            }

            Echo(debug.ToString());
            debug.Clear();
        }