Esempio n. 1
0
        private static void ConcealEntity(IMyEntity entity)
        {
            int pos = 0;

            try
            {
                if (!entity.InScene)
                {
                    return;
                }

                MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity);
                if (builder == null)
                {
                    return;
                }

                pos = 1;
                IMyCubeGrid grid      = (IMyCubeGrid)entity;
                long        ownerId   = 0;
                string      ownerName = "";
                if (CubeGrids.GetOwner(builder, out ownerId))
                {
                    //ownerId = grid.BigOwners.First();
                    ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name;
                }

                pos = 2;
                if (entity.Physics != null)
                {
                    entity.Physics.LinearVelocity  = Vector3.Zero;
                    entity.Physics.AngularVelocity = Vector3.Zero;
                }

                /*
                 * entity.InScene = false;
                 * entity.CastShadows = false;
                 * entity.Visible = false;
                 */

                builder.PersistentFlags = MyPersistentEntityFlags2.None;
                MyAPIGateway.Entities.RemapObjectBuilder(builder);

                pos = 3;
                if (RemovedGrids.Contains(entity.EntityId))
                {
                    Logging.WriteLineAndConsole("Conceal", string.Format("Concealing - Id: {0} DUPE FOUND - Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId));
                    BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
                }
                else
                {
                    if (!PluginSettings.Instance.DynamicConcealServerOnly)
                    {
                        /*
                         * if (PluginSettings.Instance.DynamicBlockManagementEnabled)
                         * {
                         *      bool enable = false;
                         *      lock (BlockManagement.Instance.GridDisabled)
                         *      {
                         *              if(BlockManagement.Instance.GridDisabled.Contains(entity.EntityId))
                         *                      enable = true;
                         *      }
                         *
                         *      if(enable)
                         *              BlockManagement.Instance.EnableGrid((IMyCubeGrid)entity);
                         * }
                         */
                        IMyEntity newEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(builder);
                        Logging.WriteLineAndConsole("Conceal", string.Format("Start Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, newEntity.EntityId));
                        if (newEntity == null)
                        {
                            Logging.WriteLineAndConsole("Conceal", string.Format("Issue - CreateFromObjectBuilder failed: {0}", newEntity.EntityId));
                            return;
                        }

                        RemovedGrids.Add(entity.EntityId);
                        BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
                        MyAPIGateway.Entities.AddEntity(newEntity, false);
                        Logging.WriteLineAndConsole("Conceal", string.Format("End Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, newEntity.EntityId));
                    }
                    else
                    {
                        Logging.WriteLineAndConsole("Conceal", string.Format("Start Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId));
                        entity.InScene = false;
                        Logging.WriteLineAndConsole("Conceal", string.Format("End Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId));
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.WriteLineAndConsole(string.Format("ConcealEntity({1}): {0}", ex.ToString(), pos));
            }
        }