Пример #1
0
        private void Actual_OnBlockAdded(IMySlimBlock obj)
        {
            SeenHolo sh;

            if (!m_holoEntities.TryGetValue(obj.CubeGrid.EntityId, out sh))
            {
                Log.DebugLog("failed lookup of grid: " + obj.CubeGrid.DisplayName, Logger.severity.ERROR);
                obj.CubeGrid.OnBlockAdded   -= Actual_OnBlockAdded;
                obj.CubeGrid.OnBlockRemoved -= Actual_OnBlockRemoved;
                return;
            }

            IMyCubeGrid holo = (IMyCubeGrid)sh.Holo;
            MyObjectBuilder_CubeBlock objBuilder = obj.GetObjectBuilder();

            objBuilder.EntityId = 0L;
            holo.AddBlock(objBuilder, false);

            IMyCubeBlock cubeBlock = holo.GetCubeBlock(obj.Position).FatBlock;

            if (cubeBlock != null)
            {
                SetupProjection(cubeBlock);
            }
        }
Пример #2
0
        public static void Received(ushort id, byte[] data, ulong sender, bool isArrivedFromServer)
        {
            AddBlockPacket temp = MyAPIGateway.Utilities.SerializeFromBinary <AddBlockPacket>(data);

            if (temp != null)
            {
                MyObjectBuilder_PistonTop newTop = temp.newTop;
                IMyCubeGrid grid = MyAPIGateway.Entities.GetEntityById(temp.gridId) as IMyCubeGrid;
                if (newTop != null && grid != null)
                {
                    grid.AddBlock(newTop, false);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Updates the appearance of the block if the integrity has changed. Only used for welding/griding.
        /// </summary>
        private static void UpdateBlockModel(IMySlimBlock realBlock, IMyCubeGrid holoGrid)
        {
            IMySlimBlock holoBlock = holoGrid.GetCubeBlock(realBlock.Position);

            Logger.DebugLog("holoBlock == null", Logger.severity.FATAL, condition: holoBlock == null);

            float realIntegrityRatio = (realBlock.BuildIntegrity - realBlock.CurrentDamage) / realBlock.MaxIntegrity;
            float holoIntegrityRatio = (holoBlock.BuildIntegrity - holoBlock.CurrentDamage) / holoBlock.MaxIntegrity;

            if (realIntegrityRatio == holoIntegrityRatio)
            {
                return;
            }

            float min, max;

            if (realIntegrityRatio > holoIntegrityRatio)
            {
                max = realIntegrityRatio;
                min = holoIntegrityRatio;
            }
            else
            {
                max = holoIntegrityRatio;
                min = realIntegrityRatio;
            }

            if (((MyCubeBlockDefinition)realBlock.BlockDefinition).ModelChangeIsNeeded(min, max))
            {
                holoGrid.RemoveBlock(holoBlock);

                MyObjectBuilder_CubeBlock objBuilder = realBlock.GetObjectBuilder();
                objBuilder.EntityId = 0L;
                holoGrid.AddBlock(objBuilder, false);

                IMyCubeBlock cubeBlock = holoGrid.GetCubeBlock(realBlock.Position).FatBlock;
                if (cubeBlock != null)
                {
                    SetupProjection(cubeBlock);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Updates the appearance of the block if the integrity has changed. Only used for welding/griding.
        /// </summary>
        private static void UpdateBlockModel(IMySlimBlock realBlock, IMyCubeGrid holoGrid)
        {
            IMySlimBlock holoBlock = holoGrid.GetCubeBlock(realBlock.Position);
            Static.logger.debugLog(holoBlock == null, "holoBlock == null", Logger.severity.FATAL);

            float realIntegrityRatio = (realBlock.BuildIntegrity - realBlock.CurrentDamage) / realBlock.MaxIntegrity;
            float holoIntegrityRatio = (holoBlock.BuildIntegrity - holoBlock.CurrentDamage) / holoBlock.MaxIntegrity;

            if (realIntegrityRatio == holoIntegrityRatio)
                return;

            float min, max;
            if (realIntegrityRatio > holoIntegrityRatio)
            {
                max = realIntegrityRatio;
                min = holoIntegrityRatio;
            }
            else
            {
                max = holoIntegrityRatio;
                min = realIntegrityRatio;
            }

            if (((MyCubeBlockDefinition)realBlock.BlockDefinition).ModelChangeIsNeeded(min, max))
            {
                holoGrid.RemoveBlock(holoBlock);

                MyObjectBuilder_CubeBlock objBuilder = realBlock.GetObjectBuilder();
                objBuilder.EntityId = 0L;
                holoGrid.AddBlock(objBuilder, false);

                IMyCubeBlock cubeBlock = holoGrid.GetCubeBlock(realBlock.Position).FatBlock;
                if (cubeBlock != null)
                    SetupProjection(cubeBlock);
            }
        }
        private bool CommonProcess(ulong steamId, long entityId, bool redAxis, bool greenAxis, bool blueAxis, bool xSymmetryOdd, SerializableVector3I?xSymmetryPlane, bool ySymmetryOdd, SerializableVector3I?ySymmetryPlane, bool zSymmetryOdd, SerializableVector3I?zSymmetryPlane, Vector3I cubePosition, bool oneWay)
        {
            if (!MyAPIGateway.Entities.EntityExists(entityId))
            {
                return(false);
            }

            IMyCubeGrid shipEntity = (IMyCubeGrid)MyAPIGateway.Entities.GetEntityById(entityId);

            int count = 0;

            //MyCubeGrid shipGrid = (MyCubeGrid)shipEntity;

            // TODO: use cubePosition with oneWay.

            if (redAxis && xSymmetryPlane.HasValue)
            {
                MirrorDirection xMirror = xSymmetryOdd ? MirrorDirection.EvenDown : MirrorDirection.Odd;
                int             xAxis   = xSymmetryPlane.Value.X;
                var             cubes   = MirrorCubes(shipEntity, true, xMirror, xAxis, MirrorDirection.None, 0, MirrorDirection.None, 0).ToArray();
                foreach (MyObjectBuilder_CubeBlock cube in cubes)
                {
                    IMySlimBlock block = shipEntity.AddBlock(cube, false);
                    // TODO: WTF do I need to do to get this to Sync from Server to Clients?  ***KEEN!!!***
                }
                count += cubes.Length;

                // TODO: mirror BlockGroups
            }
            if (greenAxis && ySymmetryPlane.HasValue)
            {
                MirrorDirection yMirror = ySymmetryOdd ? MirrorDirection.EvenDown : MirrorDirection.Odd;
                int             yAxis   = ySymmetryPlane.Value.Y;
                var             cubes   = MirrorCubes(shipEntity, true, MirrorDirection.None, 0, yMirror, yAxis, MirrorDirection.None, 0).ToArray();
                foreach (var cube in cubes)
                {
                    IMySlimBlock block = shipEntity.AddBlock(cube, false);
                    // TODO: WTF do I need to do to get this to Sync from Server to Clients?  ***KEEN!!!***
                }
                count += cubes.Length;

                // TODO: mirror BlockGroups
            }
            if (blueAxis && zSymmetryPlane.HasValue)
            {
                MirrorDirection zMirror = zSymmetryOdd ? MirrorDirection.EvenUp : MirrorDirection.Odd;
                int             zAxis   = zSymmetryPlane.Value.Z;
                var             cubes   = MirrorCubes(shipEntity, true, MirrorDirection.None, 0, MirrorDirection.None, 0, zMirror, zAxis).ToArray();
                foreach (var cube in cubes)
                {
                    IMySlimBlock block = shipEntity.AddBlock(cube, false);
                    // TODO: WTF do I need to do to get this to Sync from Server to Clients?  ***KEEN!!!***
                }
                count += cubes.Length;

                // TODO: mirror BlockGroups
            }

            //shipEntity.Synchronized = false;
            //shipGrid.IsReadyForReplication = true;
            //Sandbox.Game.Entities.MyEntities.RaiseEntityAdd((MyEntity)shipEntity);
            //Sandbox.Game.Entities.MyEntities.RaiseEntityCreated((MyEntity)shipEntity);

            //shipGrid.SyncFlag = true;
            ////shipGrid.rep

            MyAPIGateway.Utilities.SendMessage(steamId, "Server", $"Mirror has added {count} new blocks.");

            return(true);
        }