コード例 #1
0
        public void MoveFirstItemToConstructionStockpile(IMyComponentInventory fromInventory)
        {
            if (MySession.Static.CreativeMode)
            {
                return;
            }

            EnsureConstructionStockpileExists();

            MyComponentStack.GroupInfo info = ComponentStack.GetGroupInfo(0);
            m_stockpile.ClearSyncList();
            if ((int)fromInventory.GetItemAmount(info.Component.Id) >= 1)
            {
                //Other player cant move your inventory and you also when trying to cosntruct so its safe already after check above ^^
                fromInventory.RemoveItemsOfType(1, info.Component.Id, MyItemFlags.None);
                //Debug.Assert(removed, "Item not found, but reported available few lines above");
                m_stockpile.AddItems(1, info.Component.Id);
            }
            CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
            m_stockpile.ClearSyncList();
        }
コード例 #2
0
        public void MoveItemsToConstructionStockpile(IMyComponentInventory fromInventory)
        {
            if (MySession.Static.CreativeMode || MySession.Static.SimpleSurvival)
                return;

            m_tmpComponents.Clear();
            GetMissingComponents(m_tmpComponents);

            if (m_tmpComponents.Count() != 0)
            {
                EnsureConstructionStockpileExists();

                m_stockpile.ClearSyncList();
                foreach (var kv in m_tmpComponents)
                {
                    var id = new MyDefinitionId(typeof(MyObjectBuilder_Component), kv.Key);
                    int amountAvailable = (int)fromInventory.GetItemAmount(id);
                    int moveAmount = Math.Min(kv.Value, amountAvailable);
                    if (moveAmount > 0)
                    {
                        fromInventory.RemoveItemsOfType(moveAmount, id);
                        m_stockpile.AddItems(moveAmount, new MyDefinitionId(typeof(MyObjectBuilder_Component), kv.Key));
                    }
                }
                CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
                m_stockpile.ClearSyncList();
            }
        }
コード例 #3
0
        private bool PasteInternal(IMyComponentInventory buildInventory, bool missingDefinitions, bool deactivate, List<MyObjectBuilder_CubeGrid> pastedBuilders = null, List<MyCubeGrid> touchingGrids = null,
            UpdateAfterPasteCallback updateAfterPasteCallback = null)
        {
            MyGuiAudio.PlaySound(MyGuiSounds.HudPlaceBlock);

            MyEntities.RemapObjectBuilderCollection(m_copiedGrids);

            m_tmpPastedBuilders.Clear();
            m_tmpPastedBuilders.Capacity = m_copiedGrids.Count;
            MyCubeGrid firstPastedGrid = null;

            bool forceDynamicGrid = IsForcedDynamic() && !m_gridChangeToDynamicDisabled;

            int i = 0;
            bool retVal = false;
            List<MyCubeGrid> pastedGrids = new List<MyCubeGrid>();

            foreach (var gridBuilder in m_copiedGrids)
               {
                gridBuilder.CreatePhysics = true;
                gridBuilder.EnableSmallToLargeConnections = true;
                bool savedStaticFlag = gridBuilder.IsStatic;

                if (forceDynamicGrid)
                {
                    gridBuilder.IsStatic = false;
                }

                var previousPos = gridBuilder.PositionAndOrientation;
                gridBuilder.PositionAndOrientation = new MyPositionAndOrientation(m_previewGrids[i].WorldMatrix);

                var pastedGrid = MyEntities.CreateFromObjectBuilder(gridBuilder) as MyCubeGrid;

                if (pastedGrid == null)
                {
                    retVal = true;
                    continue;
                }

                if (MySession.Static.EnableStationVoxelSupport && pastedGrid.IsStatic)
                {
                    pastedGrid.TestDynamic = true;
                }

                //pastedGrid.PositionComp.SetPosition(MySector.MainCamera.Position);
                MyEntities.Add(pastedGrid);
                if (i == 0) firstPastedGrid = pastedGrid;

               
                if (missingDefinitions)
                    pastedGrid.DetectDisconnectsAfterFrame();

                //pastedGrid.PositionComp.SetWorldMatrix(m_previewGrids[i].WorldMatrix);
                i++;

                if (!pastedGrid.IsStatic && (!MyFakes.ENABLE_BATTLE_SYSTEM || !MySession.Static.Battle))
                    pastedGrid.Physics.LinearVelocity = m_objectVelocity;

                if (!pastedGrid.IsStatic && MySession.ControlledEntity != null && MySession.ControlledEntity.Entity.Physics != null && m_calculateVelocity
                    && (!MyFakes.ENABLE_BATTLE_SYSTEM || !MySession.Static.Battle))
                {
                    pastedGrid.Physics.AngularVelocity = MySession.ControlledEntity.Entity.Physics.AngularVelocity;
                }

                pastedGrids.Add(pastedGrid);

                gridBuilder.IsStatic = savedStaticFlag;

                retVal = true;
            }

            //Because blocks fills SubBlocks in this method..
            //TODO: Create LoadPhase2
            MyEntities.UpdateOnceBeforeFrame();

            foreach (var pastedGrid in pastedGrids)
            {
                var builder = pastedGrid.GetObjectBuilder();
                m_tmpPastedBuilders.Add(builder);

                if (pastedBuilders != null)
                    pastedBuilders.Add((MyObjectBuilder_CubeGrid)builder);
            }

            if (IsSnapped && SnapMode == MyGridPlacementSettings.SnapMode.Base6Directions && m_hitEntity is MyCubeGrid && firstPastedGrid != null && ((MyCubeGrid)m_hitEntity).GridSizeEnum == firstPastedGrid.GridSizeEnum)
            {
                var hitGrid = m_hitEntity as MyCubeGrid;

                MatrixI mergingTransform = hitGrid.CalculateMergeTransform(firstPastedGrid, hitGrid.WorldToGridInteger(firstPastedGrid.PositionComp.GetPosition()));
                MySyncCreate.RequestMergingCopyPaste(m_tmpPastedBuilders, m_hitEntity.EntityId, mergingTransform);
            }
            else if (touchingGrids != null && touchingGrids.Count > 0)
            {
                // Currently only first grid is supported for merging.
                MyCubeGrid touchingGrid = touchingGrids[0];

                if (touchingGrid != null)
                {
                    MatrixI mergingTransform = touchingGrid.CalculateMergeTransform(firstPastedGrid, touchingGrid.WorldToGridInteger(firstPastedGrid.PositionComp.GetPosition()));
                    MySyncCreate.RequestMergingCopyPaste(m_tmpPastedBuilders, touchingGrid.EntityId, mergingTransform);
                }
                else
                {
                    //MySyncCreate.RequestEntitiesCreate(m_tmpPastedBuilders);
                    MySyncCreate.SendEntitiesCreated(m_tmpPastedBuilders);
                }
            }
            else
            {
                // CH:TODO: This would probably be safer if it was requested from the server as well
                MySyncCreate.SendEntitiesCreated(m_tmpPastedBuilders);
            }

            // CH:TODO: Use only items for grids that were really added to not screw with players
            if (buildInventory != null)
            {
                foreach (var item in m_buildComponents.TotalMaterials)
                {
                    buildInventory.RemoveItemsOfType(item.Value, item.Key);
                }
            }

            if (deactivate)
                Deactivate();

            if (retVal && updateAfterPasteCallback != null)
            {
                updateAfterPasteCallback(pastedBuilders);
            }

            return retVal;
        }