Example #1
0
 public static void shootBlack()
 {
     world.Games.Remove(shootBlack);
     mode = GameMode.shootblack;
     GunModeOn();
     foreach (Player p in world.Players)
     {
         Vector3I block = new Vector3I(p.Position.X / 32, p.Position.Y / 32, (p.Position.Z / 32) + 8);
         if (world.Map.InBounds(block))
         {
             randomBlocks.TryAdd(block.ToString(), block);
             world.Map.QueueUpdate(new BlockUpdate(null, block, Block.BlackWool));
         }
     }
     world.Players.Message("&WYou have 20 seconds to shoot all &8BLACK &Wblocks.... &AGO!");
     wait(10000);
     world.Players.Message("&WYou have 10 seconds left to shoot all &8BLACK &Wblocks.");
     wait(10000);
     GunModeOff();
     scoreCounter();
     foreach (Vector3I block in platform.Values)
     {
         if (world.Map != null && world.IsLoaded)
         {
             world.Map.QueueUpdate(new BlockUpdate(null, block, Block.Air));
             Vector3I removed;
             platform.TryRemove(block.ToString(), out removed);
         }
     }
     interval();
     gamePicker();
 }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/createroid\s+(?<X>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Y>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Z>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Size>(\d+?))\s+(?<Name>.+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var position = new Vector3D(
                    double.Parse(match.Groups["X"].Value, CultureInfo.InvariantCulture),
                    double.Parse(match.Groups["Y"].Value, CultureInfo.InvariantCulture),
                    double.Parse(match.Groups["Z"].Value, CultureInfo.InvariantCulture));

                var length = int.Parse(match.Groups["Size"].Value, CultureInfo.InvariantCulture);
                if (length < 1 || length % 64 != 0)
                {
                    MyAPIGateway.Utilities.ShowMessage("Invalid", "Size specified.");
                    return true;
                }

                var size = new Vector3I(length, length, length);
                var name = match.Groups["Name"].Value;

                if (position.IsValid() && ((Vector3D)size).IsValid())
                {
                    MyAPIGateway.Utilities.ShowMessage("Size", size.ToString());
                    var newName = Support.CreateUniqueStorageName(name);

                    // MyAPIGateway.Session.VoxelMaps.CreateVoxelMap will always create a square shaped asteroid.
                    // This is by design within the API itself and cannot be altered.
                    var newVoxelMap = Support.CreateNewAsteroid(newName, size, position);
                    return true;
                }
            }

            return false;
        }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/createroid\s+(?<X>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Y>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Z>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s+(?<Size>(\d+?))\s+(?<Name>.+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var position = new Vector3D(
                    double.Parse(match.Groups["X"].Value, CultureInfo.InvariantCulture),
                    double.Parse(match.Groups["Y"].Value, CultureInfo.InvariantCulture),
                    double.Parse(match.Groups["Z"].Value, CultureInfo.InvariantCulture));

                var length = int.Parse(match.Groups["Size"].Value, CultureInfo.InvariantCulture);
                if (length < 1 || length % 64 != 0)
                {
                    MyAPIGateway.Utilities.ShowMessage("Invalid", "Size specified.");
                    return(true);
                }

                var size = new Vector3I(length, length, length);
                var name = match.Groups["Name"].Value;

                if (position.IsValid() && ((Vector3D)size).IsValid())
                {
                    MyAPIGateway.Utilities.ShowMessage("Size", size.ToString());
                    var newName = Support.CreateUniqueStorageName(name);

                    // MyAPIGateway.Session.VoxelMaps.CreateVoxelMap will always create a square shaped asteroid.
                    // This is by design within the API itself and cannot be altered.
                    var newVoxelMap = Support.CreateNewAsteroid(newName, size, position);
                    return(true);
                }
            }

            return(false);
        }
Example #4
0
        private void set_cursor_position(string name)
        {
            //find a block by name and point to it on the screen
            Echo("CURSING");
            IMyTerminalBlock block = GridTerminalSystem.GetBlockWithName(name);

            cursor_vec = block.Position;
            Echo("Found at:" + cursor_vec.ToString());
        }
Example #5
0
        public Vector3B(Vector3I vec)
        {
            Debug.Assert(vec.X >= sbyte.MinValue && vec.X <= sbyte.MaxValue
                && vec.Y >= sbyte.MinValue && vec.Y <= sbyte.MaxValue
                && vec.Z >= sbyte.MinValue && vec.Z <= sbyte.MaxValue, "This Vector3I does not fit Vector3B: " + vec.ToString());

            X = (sbyte)vec.X;
            Y = (sbyte)vec.Y;
            Z = (sbyte)vec.Z;
        }
Example #6
0
        public static void towerInit(object sender, Events.PlayerPlacedBlockEventArgs e)
        {
            World world = e.Player.World;

            if (e.Player.towerMode)
            {
                if (world.Map != null && world.IsLoaded)
                {
                    if (e.Context == BlockChangeContext.Manual)
                    {
                        if (e.NewBlock == Block.Iron)
                        {
                            waterThread = new Thread(new ThreadStart(delegate
                            {
                                if (e.Player.TowerCache != null)
                                {
                                    world.Map.QueueUpdate(new BlockUpdate(null, e.Player.towerOrigin, Block.Air));
                                    e.Player.towerOrigin = e.Coords;
                                    foreach (Vector3I block in e.Player.TowerCache.Values)
                                    {
                                        e.Player.Send(PacketWriter.MakeSetBlock(block, Block.Air));
                                    }
                                    e.Player.TowerCache.Clear();
                                }
                                e.Player.towerOrigin = e.Coords;
                                e.Player.TowerCache  = new System.Collections.Concurrent.ConcurrentDictionary <string, Vector3I>();
                                for (int z = e.Coords.Z; z <= world.Map.Height; z++)
                                {
                                    Thread.Sleep(250);
                                    if (world.Map != null && world.IsLoaded)
                                    {
                                        if (world.Map.GetBlock(e.Coords.X, e.Coords.Y, z + 1) != Block.Air ||
                                            world.Map.GetBlock(e.Coords) != Block.Iron ||
                                            e.Player.towerOrigin != e.Coords ||
                                            !e.Player.towerMode)
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            Vector3I tower = new Vector3I(e.Coords.X, e.Coords.Y, z + 1);
                                            e.Player.TowerCache.TryAdd(tower.ToString(), tower);
                                            e.Player.Send(PacketWriter.MakeSetBlock(tower, Block.Water));
                                        }
                                    }
                                }
                            })); waterThread.Start();
                        }
                    }
                }
            }
        }
        internal MyCubeGridRenderCell GetCell(Vector3 pos)
        {
            Vector3I             cellPos = Vector3I.Round((pos - m_basePos) / (SplitCellCubeCount * m_gridRender.GridSize));
            MyCubeGridRenderCell result;

            if (!m_cells.TryGetValue(cellPos, out result))
            {
                result           = new MyCubeGridRenderCell(m_gridRender);
                result.DebugName = cellPos.ToString();
                m_cells[cellPos] = result;
            }
            return(result);
        }
Example #8
0
        public static void GunMove( Player player )
        {
            World world = player.World;
            if ( null == world )
                return;
            try {
                if ( null == world.Map )
                    return;
                if ( player.IsOnline ) {
                    Position p = player.Position;
                    double ksi = 2.0 * Math.PI * ( -player.Position.L ) / 256.0;
                    double phi = 2.0 * Math.PI * ( player.Position.R - 64 ) / 256.0;
                    double sphi = Math.Sin( phi );
                    double cphi = Math.Cos( phi );
                    double sksi = Math.Sin( ksi );
                    double cksi = Math.Cos( ksi );

                    if ( player.GunCache.Values.Count > 0 ) {
                        foreach ( Vector3I block in player.GunCache.Values ) {
                            if ( player.IsOnline ) {
                                player.Send( PacketWriter.MakeSetBlock( block.X, block.Y, block.Z, world.Map.GetBlock( block ) ) );
                                Vector3I removed;
                                player.GunCache.TryRemove( block.ToString(), out removed );
                            }
                        }
                    }

                    for ( int y = -1; y < 2; ++y ) {
                        for ( int z = -1; z < 2; ++z ) {
                            if ( player.IsOnline ) {
                                //4 is the distance betwen the player and the glass wall
                                Vector3I glassBlockPos = new Vector3I( ( int )( cphi * cksi * 4 - sphi * ( 0.5 + y ) - cphi * sksi * ( 0.5 + z ) ),
                                      ( int )( sphi * cksi * 4 + cphi * ( 0.5 + y ) - sphi * sksi * ( 0.5 + z ) ),
                                      ( int )( sksi * 4 + cksi * ( 0.5 + z ) ) );
                                glassBlockPos += p.ToBlockCoords();
                                if ( world.Map.GetBlock( glassBlockPos ) == Block.Air ) {
                                    player.Send( PacketWriter.MakeSetBlock( glassBlockPos.X, glassBlockPos.Y, glassBlockPos.Z, Block.Glass ) );
                                    player.GunCache.TryAdd( glassBlockPos.ToString(), glassBlockPos );
                                }
                            }
                        }
                    }
                }
            } catch ( Exception ex ) {
                Logger.Log( LogType.SeriousError, "GunGlass: " + ex );
            }
        }
Example #9
0
        private static void HandleEmitters(byte[] data)
        {
            byte lengh = data[1];

            var emitters = new List <Emitter>();

            for (var i = 2; i < data.Length; i += lengh)
            {
                var em = new byte[lengh];
                Array.Copy(data, i, em, 0, lengh);

                var emitter = MyAPIGateway.Utilities.SerializeFromBinary <Emitter>(em);
                emitters.Add(emitter);
            }

            var emitterDic = new Dictionary <IMySlimBlock, int>();

            foreach (Emitter emitter in emitters)
            {
                IMyEntity entity;
                MyAPIGateway.Entities.TryGetEntityById(emitter.GridId, out entity);

                if (entity == null)
                {
                    MyAPIGateway.Utilities.ShowMessage(emitter.GridId.ToString(), "NULL GRID");
                }
                var          pos   = new Vector3I(emitter.PosX, emitter.PosY, emitter.PosZ);
                IMySlimBlock block = (entity as IMyCubeGrid)?.GetCubeBlock(pos);

                if (block == null)
                {
                    MyAPIGateway.Utilities.ShowMessage(pos.ToString(), "NULL BLOCK");
                    continue;
                }

                emitterDic.Add(block, emitter.EffectId);
            }

            DamageCore.CheckAndRemoveEmitters(emitterDic);
            DamageCore.AddNewEmitters(emitterDic);
        }
Example #10
0
 private static void SetUpMines()
 {
     for (short i = 0; i <= _map.Width; ++i)
     {
         for (short j = 0; j <= _map.Length; ++j)
         {
             if (_map.GetBlock(i, j, _ground) != Block.Red &&
                 _map.GetBlock(i, j, _ground) != Block.Green &&
                 _map.GetBlock(i, j, _ground) != Block.Water)
             {
                 _map.SetBlock(i, j, _ground, Block.Dirt);
                 _map.SetBlock(i, j, _ground - 1, Block.Dirt);
                 if (_rand.Next(1, 100) > 96)
                 {
                     Vector3I vec = new Vector3I(i, j, _ground);
                     Mines.TryAdd(vec.ToString(), vec);
                     //_map.SetBlock(vec, Block.Red);//
                 }
             }
         }
     }
 }
Example #11
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            _chunkManager.ChunkSystem.Renderer.RenderAll();

            lock (_physicsMutex)
            {
                if (drawPhysics)
                {
                    modelDrawer.Draw(MathConverter.Convert(cam.View), MathConverter.Convert(cam.Projection));
                }
            }

            if (pickedPos != Vector3I.One * -1)
            {
                BoundingBox picked = new BoundingBox(pickedPos.ToVector3() - 0.55f * Vector3.One, pickedPos.ToVector3() + 0.55f * Vector3.One);
                BoundingBoxRenderer.Render(GraphicsDevice, picked, camManager.MainCamera);

                BoundingBox sidePicked = new BoundingBox(sidePickedPos.ToVector3() - 0.55f * Vector3.One, sidePickedPos.ToVector3() + 0.55f * Vector3.One);
                BoundingBoxRenderer.Render(GraphicsDevice, sidePicked, Color.Blue, camManager.MainCamera);

                BoundingBox b1 = new BoundingBox(pickedPos.ToVector3(), pickedPos.ToVector3() + Vector3.One);
                BoundingBox b2 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left, pickedPos.ToVector3() + Vector3.Up + Vector3.Backward);
                BoundingBox b3 = new BoundingBox(pickedPos.ToVector3() + Vector3.Forward, pickedPos.ToVector3() + Vector3.Up + Vector3.Right);
                BoundingBox b4 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left + Vector3.Forward, pickedPos.ToVector3() + Vector3.Up);

                BoundingBox b5 = new BoundingBox(pickedPos.ToVector3() + Vector3.Down, pickedPos.ToVector3() + Vector3.Right + Vector3.Backward);
                BoundingBox b6 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left + Vector3.Down, pickedPos.ToVector3() + Vector3.Backward);
                BoundingBox b7 = new BoundingBox(pickedPos.ToVector3() + Vector3.Forward + Vector3.Down, pickedPos.ToVector3() + Vector3.Right);
                BoundingBox b8 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left + Vector3.Forward + Vector3.Down, pickedPos.ToVector3());
            }

            spriteBatch.Begin();

            spriteBatch.DrawString(font, "Target: " + cam.Target, Vector2.One * 2f, Color.White);
            spriteBatch.DrawString(font, "Position: " + cam.Position, new Vector2(2, 2 + font.LineSpacing + 2), Color.White);
            spriteBatch.DrawString(font, "Selected: " + ((pickedPos == Vector3I.One * -1) ? "None" : pickedPos.ToString()), new Vector2(2, 2 + 2 * font.LineSpacing + 2), Color.White);

            if (_paused)
            {
                Vector2 dim = font.MeasureString("Paused");

                spriteBatch.DrawString(font, "Paused", new Vector2(GraphicsDevice.Viewport.Width - dim.X - 2, 2), Color.White);
            }

            spriteBatch.Draw(contentLibrary.DummyPixel, new Rectangle(GraphicsDevice.Viewport.Width / 2 - 1, GraphicsDevice.Viewport.Height / 2 - 1, 2, 2), Color.White);

            spriteBatch.End();

            _fpsCounter.Draw();

            base.Draw(gameTime);
        }
Example #12
0
 public static void towerInit(object sender, Events.PlayerPlacedBlockEventArgs e)
 {
     World world = e.Player.World;
     if (e.Player.towerMode)
     {
         if (world.Map != null && world.IsLoaded)
         {
             if (e.Context == BlockChangeContext.Manual)
             {
                 if (e.NewBlock == Block.Iron)
                 {
                     waterThread = new Thread(new ThreadStart(delegate
                     {
                         if (e.Player.TowerCache != null)
                         {
                             world.Map.QueueUpdate(new BlockUpdate(null, e.Player.towerOrigin, Block.Air));
                             e.Player.towerOrigin = e.Coords;
                             foreach (Vector3I block in e.Player.TowerCache.Values)
                             {
                                 e.Player.Send(PacketWriter.MakeSetBlock(block, Block.Air));
                             }
                             e.Player.TowerCache.Clear();
                         }
                         e.Player.towerOrigin = e.Coords;
                         e.Player.TowerCache = new System.Collections.Concurrent.ConcurrentDictionary<string, Vector3I>();
                         for (int z = e.Coords.Z; z <= world.Map.Height; z++)
                         {
                             Thread.Sleep(250);
                             if (world.Map != null && world.IsLoaded)
                             {
                                 if (world.Map.GetBlock(e.Coords.X, e.Coords.Y, z + 1) != Block.Air
                                     || world.Map.GetBlock(e.Coords) != Block.Iron
                                     || e.Player.towerOrigin != e.Coords
                                     || !e.Player.towerMode)
                                 {
                                     break;
                                 }
                                 else
                                 {
                                     Vector3I tower = new Vector3I(e.Coords.X, e.Coords.Y, z + 1);
                                     e.Player.TowerCache.TryAdd(tower.ToString(), tower);
                                     e.Player.Send(PacketWriter.MakeSetBlock(tower, Block.Water));
                                 }
                             }
                         }
                     })); waterThread.Start();
                 }
             }
         }
     }
 }
Example #13
0
        public override void Received(ref RelayMode relay)
        {
            if (Main.IsServer && !Main.IgnoreAmmoConsumption) // ammo consumption, only needed server side
            {
                IMyInventory inv = Utils.GetCharacterInventoryOrError(this, Utils.GetCharacterOrError(this, Utils.GetPlayerOrError(this, OriginalSenderSteamId)));
                if (inv != null)
                {
                    inv.RemoveItemsOfType(1, Main.Constants.PAINT_MAG_ITEM, false);
                }
            }

            MyCubeGrid grid = Utils.GetEntityOrError <MyCubeGrid>(this, GridEntId, Constants.NETWORK_DESYNC_ERROR_LOGGING);

            if (grid == null)
            {
                return;
            }

            if (Main.IsServer)
            {
                // ensure server side if safezone permissions are respected
                if (!Utils.SafeZoneCanPaint(grid.GetCubeBlock(BlockPosition), OriginalSenderSteamId))
                {
                    if (Constants.NETWORK_DESYNC_ERROR_LOGGING)
                    {
                        IMySlimBlock block = (IMySlimBlock)grid.GetCubeBlock(BlockPosition);
                        Log.Error($"{GetType().Name} :: Can't paint inside no-build safe zone! Sender={OriginalSenderSteamId.ToString()}; Grid={grid} ({grid.EntityId.ToString()}); block={block.BlockDefinition.Id.ToString()} ({block.Position.ToString()})", Log.PRINT_MESSAGE);
                    }

                    Main.NetworkLibHandler.PacketWarningMessage.Send(OriginalSenderSteamId, "Failed to paint server side, denied by safe zone.");
                    return;
                }

                long identity = MyAPIGateway.Players.TryGetIdentityId(OriginalSenderSteamId);
                if (!Utils.AllowedToPaintGrid(grid, identity))
                {
                    if (Constants.NETWORK_DESYNC_ERROR_LOGGING)
                    {
                        Log.Error($"{GetType().Name} :: Can't paint non-allied grids! Sender={OriginalSenderSteamId.ToString()}; Grid={grid} ({grid.EntityId.ToString()})", Log.PRINT_MESSAGE);
                    }

                    Main.NetworkLibHandler.PacketWarningMessage.Send(OriginalSenderSteamId, "Failed to paint server side, ship not allied.");
                    return;
                }

                if (!grid.CubeExists(BlockPosition))
                {
                    if (Constants.NETWORK_DESYNC_ERROR_LOGGING)
                    {
                        Log.Error($"{GetType().Name} :: Can't paint inexistent blocks! Sender={OriginalSenderSteamId.ToString()}; Grid={grid} ({grid.EntityId.ToString()}) at GridPosition={BlockPosition.ToString()}", Log.PRINT_MESSAGE);
                    }

                    Main.NetworkLibHandler.PacketWarningMessage.Send(OriginalSenderSteamId, "Failed to paint server side, block no longer exists.");
                    return;
                }
            }

            if (DoAction(grid))
            {
                relay = RelayMode.RelayWithChanges;
            }
        }
        void ProcessMovementPacket()
        {
            BytesReceived += 10;
            reader.ReadByte();
            Position newPos = new Position {
                X = IPAddress.NetworkToHostOrder( reader.ReadInt16() ),
                Z = IPAddress.NetworkToHostOrder( reader.ReadInt16() ),
                Y = IPAddress.NetworkToHostOrder( reader.ReadInt16() ),
                R = reader.ReadByte(),
                L = reader.ReadByte()
            };

            Position oldPos = Position;

            // calculate difference between old and new positions
            Position delta = new Position {
                X = ( short )( newPos.X - oldPos.X ),
                Y = ( short )( newPos.Y - oldPos.Y ),
                Z = ( short )( newPos.Z - oldPos.Z ),
                R = ( byte )Math.Abs( newPos.R - oldPos.R ),
                L = ( byte )Math.Abs( newPos.L - oldPos.L )
            };

            // skip everything if player hasn't moved
            if ( delta.IsZero ) return;

            bool rotChanged = ( delta.R != 0 ) || ( delta.L != 0 );

            // only reset the timer if player rotated
            // if player is just pushed around, rotation does not change (and timer should not reset)
            if ( rotChanged ) ResetIdleTimer();

            if ( Info.IsFrozen ) {
                // special handling for frozen players
                if ( delta.X * delta.X + delta.Y * delta.Y > AntiSpeedMaxDistanceSquared ||
                    Math.Abs( delta.Z ) > 40 ) {
                    SendNow( PacketWriter.MakeSelfTeleport( Position ) );
                }
                newPos.X = Position.X;
                newPos.Y = Position.Y;
                newPos.Z = Position.Z;

                // recalculate deltas
                delta.X = 0;
                delta.Y = 0;
                delta.Z = 0;

            }
            if ( IsFlying ) {
                Vector3I oldPosi = new Vector3I( oldPos.X / 32, oldPos.Y / 32, oldPos.Z / 32 );
                Vector3I newPosi = new Vector3I( newPos.X / 32, newPos.Y / 32, newPos.Z / 32 );
                //Checking e.Old vs e.New increases accuracy, checking old vs new uses a lot less updates
                if ( ( oldPosi.X != newPosi.X ) || ( oldPosi.Y != newPosi.Y ) || ( oldPosi.Z != newPosi.Z ) ) {
                    //finally, /fly decends
                    if ( ( oldPos.Z > newPos.Z ) ) {
                        foreach ( Vector3I block in FlyCache.Values ) {
                            SendNow( PacketWriter.MakeSetBlock( block, Block.Air ) );
                            Vector3I removed;
                            FlyCache.TryRemove( block.ToString(), out removed );
                        }
                    }
                    // Create new block parts
                    for ( int i = -1; i <= 1; i++ ) //reduced width and length by 1
                    {
                        for ( int j = -1; j <= 1; j++ ) {
                            for ( int k = 2; k <= 3; k++ ) //added a 2nd layer
                            {
                                Vector3I layer = new Vector3I( newPosi.X + i, newPosi.Y + j, newPosi.Z - k );
                                if ( World.Map.GetBlock( layer ) == Block.Air ) {
                                    SendNow( PacketWriter.MakeSetBlock( layer, Block.Glass ) );
                                    FlyCache.TryAdd( layer.ToString(), layer );
                                }
                            }
                        }
                    }

                    // Remove old blocks
                    foreach ( Vector3I block in FlyCache.Values ) {
                        if ( fCraft.Utils.FlyHandler.CanRemoveBlock( this, block, newPosi ) ) {
                            SendNow( PacketWriter.MakeSetBlock( block, Block.Air ) );
                            Vector3I removed;
                            FlyCache.TryRemove( block.ToString(), out removed );
                        }
                    }
                }
            } else if ( !Can( Permission.UseSpeedHack ) ) {
                int distSquared = delta.X * delta.X + delta.Y * delta.Y + delta.Z * delta.Z;
                // speedhack detection
                if ( DetectMovementPacketSpam() ) {
                    return;

                } else if ( ( distSquared - delta.Z * delta.Z > AntiSpeedMaxDistanceSquared || delta.Z > AntiSpeedMaxJumpDelta ) &&
                           speedHackDetectionCounter >= 0 ) {

                    if ( speedHackDetectionCounter == 0 ) {
                        lastValidPosition = Position;
                    } else if ( speedHackDetectionCounter > 1 ) {
                        DenyMovement();
                        speedHackDetectionCounter = 0;
                        return;
                    }
                    speedHackDetectionCounter++;

                } else {
                    speedHackDetectionCounter = 0;
                }
            }

            if ( RaisePlayerMovingEvent( this, newPos ) ) {
                DenyMovement();
                return;
            }

            Position = newPos;
            RaisePlayerMovedEvent( this, oldPos );
        }
Example #15
0
        private static void Player_Moved(object sender, Events.PlayerMovedEventArgs e)
        {
            try
            {
                if (e.Player.IsFlying)
                {
                    Vector3I oldPos = new Vector3I(e.OldPosition.X / 32, e.OldPosition.Y / 32, e.OldPosition.Z / 32);
                    Vector3I newPos = new Vector3I(e.NewPosition.X / 32, e.NewPosition.Y / 32, e.NewPosition.Z / 32);
                    //Checking e.Old vs e.New increases accuracy, checking old vs new uses a lot less updates
                    if ((oldPos.X != newPos.X) || (oldPos.Y != newPos.Y) || (oldPos.Z != newPos.Z))
                    {
                        //finally, /fly decends
                        if((e.OldPosition.Z > e.NewPosition.Z))
                        {
                            foreach (Vector3I block in e.Player.FlyCache.Values)
                            {
                                e.Player.Send(PacketWriter.MakeSetBlock(block, Block.Air));
                                Vector3I removed;
                                e.Player.FlyCache.TryRemove(block.ToString(), out removed);
                            }
                        }
                        // Create new block parts
                        for (int i = -1; i <= 1; i++) //reduced width and length by 1
                        {
                            for (int j = -1; j <= 1; j++)
                            {
                                for (int k = 2; k <= 3; k++) //added a 2nd layer
                                {
                                    Vector3I layer = new Vector3I(newPos.X + i, newPos.Y + j, newPos.Z - k);
                                    if (e.Player.World.Map.GetBlock(layer) == Block.Air)
                                    {
                                        e.Player.Send(PacketWriter.MakeSetBlock(layer, Block.Glass));
                                        e.Player.FlyCache.TryAdd(layer.ToString(), layer);
                                    }
                                }
                            }
                        }

                        // Remove old blocks
                        foreach (Vector3I block in e.Player.FlyCache.Values)
                        {
                            if (CanRemoveBlock(e.Player, block, newPos))
                            {
                                e.Player.Send(PacketWriter.MakeSetBlock(block, Block.Air));
                                Vector3I removed;
                                e.Player.FlyCache.TryRemove(block.ToString(), out removed);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogType.Error, "FlyHandler.Player_Moved: " + ex);
            }
        }
Example #16
0
 public static void shootBlack()
 {
     world.Games.Remove(shootBlack);
     mode = GameMode.shootblack;
     GunModeOn();
     foreach (Player p in world.Players)
     {
         Vector3I block = new Vector3I(p.Position.X / 32, p.Position.Y /32, (p.Position.Z /32) + 8);
         if (world.Map.InBounds(block))
         {
             randomBlocks.TryAdd(block.ToString(), block);
             world.Map.QueueUpdate(new BlockUpdate(null, block, Block.Black));
         }
     }
     world.Players.Message("&WYou have 20 seconds to shoot all &8BLACK &Wblocks.... &AGO!");
     wait(10000);
     world.Players.Message("&WYou have 10 seconds left to shoot all &8BLACK &Wblocks.");
     wait(10000);
     GunModeOff();
     scoreCounter();
     foreach (Vector3I block in platform.Values)
     {
         if (world.Map != null && world.IsLoaded)
         {
             world.Map.QueueUpdate(new BlockUpdate(null, block, Block.Air));
             Vector3I removed;
             platform.TryRemove(block.ToString(), out removed);
         }
     }
     interval();
     gamePicker();
 }
Example #17
0
        /// <summary>
        /// инициализация логики нашего мода
        /// </summary>
        private void MyInit()
        {
            Log.init("debug.log");
            Log.writeLine("<CoreBlock> Logging started.");
            ShowMessageInGame("dbg", "first init");
            SetUpDefaultLimits();
            m_block = (IMyCubeBlock)Entity;
            m_block.NeedsWorldMatrix = true;

            (m_block as IMyTerminalBlock).CustomName = "Core Status: Loading";

            (m_block as IMyTerminalBlock).ShowOnHUD = true;

            m_mycubegrid = m_block.CubeGrid as MyCubeGrid;

            // m_grid = m_block.CubeGrid;
            m_mycubegrid.OnBlockAdded   += OnblockEvent;
            m_mycubegrid.OnBlockRemoved += OnblockEvent;

            //   m_block.IsWorkingChanged
            LOOP_soundEmitter = new MyEntity3DSoundEmitter(Container.Entity as VRage.Game.Entity.MyEntity);
            ShowMessageInGame("dbg", "init end!");
            Vector3I corepos = m_block.Position;

            ShowMessageInGame("dbgcorepos", corepos.ToString());

            Matrix mmatrix;

            m_block.Orientation.GetMatrix(out mmatrix);
            addonsPositions = new List <Vector3I>()       //слева справа сверху снизу ссади
            {
                new Vector3I(corepos + mmatrix.Left),     //слева
                new Vector3I(corepos + mmatrix.Right),    //справа
                new Vector3I(corepos + mmatrix.Up),       //сверху
                new Vector3I(corepos + mmatrix.Down),     //снизу
                new Vector3I(corepos + mmatrix.Backward), //ссади
            };



            string tmp = "";

            foreach (var str in addonsPositions)
            {
                tmp += str.ToString();
            }
            ShowMessageInGame("dbg", tmp);



            DetectAddons();

            (m_block as IMyTerminalBlock).ShowOnHUD = true;
            _init = true;

            MyAPIGateway.TerminalControls.CustomControlGetter += TerminalControls_CustomControlGetter;
            mycore = Container.Entity as IMyBatteryBlock;
            mycore.AppendingCustomInfo += Tool_AppendingCustomInfo;
            CheckAndReplaceOwner();
            CreateWeirdLabels();
        }
Example #18
0
 public void LogCellAddition(MyVoxelNavigationMesh navMesh, Vector3I cell)
 {
     m_log.WriteLine("NMOP: " + navMesh.ToString() + " ADD " + cell.ToString());
 }
 public override string ToString()
 {
     return("(" + A.ToString() + ", " + B.ToString() + ")");
 }
Example #20
0
        private static void Player_Moved(object sender, Events.PlayerMovedEventArgs e)
        {
            try
            {
                if (e.Player.IsFlying)
                {
                    // We need to have block positions, so we divide by 32
                    Vector3I oldPos = new Vector3I(e.OldPosition.X / 32, e.OldPosition.Y / 32, e.OldPosition.Z / 32);
                    Vector3I newPos = new Vector3I(e.NewPosition.X / 32, e.NewPosition.Y / 32, e.NewPosition.Z / 32);

                    // Check if the player actually moved and not just rotated
                    if ((oldPos.X != newPos.X) || (oldPos.Y != newPos.Y) || (oldPos.Z != newPos.Z))
                    {
                        // Create new blocks part
                        for (int i = -2; i <= 2; i++)
                        {
                            for (int j = -2; j <= 2; j++)
                            {
                                Vector3I carpet = new Vector3I(newPos.X + i, newPos.Y + j, newPos.Z - 2);

                                if (e.Player.World.Map.GetBlock(carpet) == Block.Air)
                                {
                                    e.Player.Send(PacketWriter.MakeSetBlock(carpet, Block.Glass));
                                    e.Player.FlyCache.TryAdd(carpet.ToString(), carpet);
                                }
                            }
                        }

                        // Remove old blocks
                        foreach(Vector3I block in e.Player.FlyCache.Values)
                        {
                            if (CanRemoveBlock(e.Player, block, newPos))
                            {
                                e.Player.Send(PacketWriter.MakeSetBlock(block, Block.Air));
                                Vector3I removed;
                                e.Player.FlyCache.TryRemove(block.ToString(), out removed);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log( LogType.Error, "FlyHandler.Player_Moved: " + ex);
            }
        }
Example #21
0
 //processess one blockupdate
 public void sendWorldBlock( int index, byte type )
 {
     if ( world.Map == null ) {
         started = false;
         return;
     }
     if ( world.IsLoaded ) {
         int x = 0, y = 0, z = 0;
         switch ( direction ) {
             case Direction.one:
                 x = ( int )( index / 8 ) + EndPos.X;
                 y = StartPos.Y;
                 z = StartPos.Z + ( index % 8 );
                 if ( world.map.InBounds( x, y, z ) ) {
                     if ( x >= StartPos.X && x <= FinishPos.X ) {
                         if ( ( Block )type != Block.Air ) {
                             Vector3I Pos = new Vector3I( x, y, z );
                             world.map.QueueUpdate( new BlockUpdate( null, Pos, ( Block )type ) );
                             Blocks.TryAdd( Pos.ToString(), Pos );
                         }
                     }
                 }
                 break;
             case Direction.two:
                 x = ( short )( EndPos.X - ( index / 8 ) );
                 y = ( short )StartPos.Y;
                 z = ( short )( StartPos.Z + ( index % 8 ) );
                 if ( world.map.InBounds( x, y, z ) ) {
                     if ( x <= StartPos.X && x >= FinishPos.X ) {
                         if ( ( Block )type != Block.Air ) {
                             Vector3I Pos = new Vector3I( x, y, z );
                             world.map.QueueUpdate( new BlockUpdate( null, Pos, ( Block )type ) );
                             Blocks.TryAdd( Pos.ToString(), Pos );
                         }
                     }
                 }
                 break;
             case Direction.three:
                 x = ( short )StartPos.X;
                 y = ( short )( EndPos.Y + ( index / 8 ) );
                 z = ( short )( StartPos.Z + ( index % 8 ) );
                 if ( world.map.InBounds( x, y, z ) ) {
                     if ( y >= StartPos.Y && y <= FinishPos.Y ) {
                         if ( ( Block )type != Block.Air ) {
                             Vector3I Pos = new Vector3I( x, y, z );
                             world.map.QueueUpdate( new BlockUpdate( null, Pos, ( Block )type ) );
                             Blocks.TryAdd( Pos.ToString(), Pos );
                         }
                     }
                 }
                 break;
             case Direction.four:
                 x = ( short )StartPos.X;
                 y = ( short )( EndPos.Y - ( index / 8 ) );
                 z = ( short )( StartPos.Z + ( index % 8 ) );
                 if ( world.map.InBounds( x, y, z ) ) {
                     if ( y <= StartPos.Y && y >= FinishPos.Y ) {
                         if ( ( Block )type != Block.Air ) {
                             Vector3I Pos = new Vector3I( x, y, z );
                             world.map.QueueUpdate( new BlockUpdate( null, Pos, ( Block )type ) );
                             Blocks.TryAdd( Pos.ToString(), Pos );
                         }
                     }
                 }
                 break;
             default:
                 break;
         }
     }
 }
Example #22
0
 public override string ToString()
 {
     return(LocalGridPosition.ToString() + " -> " + Direction.ToString());
 }
 private FileSystemPath GetChunkFilePath(Vector3I chunkOffset)
 {
     return(FileSystemPath.Combine(worldDataPathRoot,
                                   FileSystemPath.CombineFileName(chunkOffset.ToString(),
                                                                  ChunkFileExtension)));
 }
Example #24
0
 private static void SetUpMines()
 {
     for ( short i = 0; i <= _map.Width; ++i ) {
         for ( short j = 0; j <= _map.Length; ++j ) {
             if ( _map.GetBlock( i, j, _ground ) != Block.Red &&
                 _map.GetBlock( i, j, _ground ) != Block.Green &&
                 _map.GetBlock( i, j, _ground ) != Block.Water ) {
                 _map.SetBlock( i, j, _ground, Block.Dirt );
                 _map.SetBlock( i, j, _ground - 1, Block.Dirt );
                 if ( _rand.Next( 1, 100 ) > 96 ) {
                     Vector3I vec = new Vector3I( i, j, _ground );
                     Mines.TryAdd( vec.ToString(), vec );
                     //_map.SetBlock(vec, Block.Red);//
                 }
             }
         }
     }
 }
Example #25
0
 public override string ToString()
 {
     return(vector.ToString());
 }
Example #26
0
 public void LogCellRemoval(MyVoxelNavigationMesh navMesh, Vector3I cell)
 {
     m_log.WriteLine("NMOP: " + navMesh.ToString() + " REM " + cell.ToString());
 }
 public void LogCellAddition(MyVoxelNavigationMesh navMesh, Vector3I cell)
 {
     m_log.WriteLine("NMOP: " + navMesh.ToString() + " ADD " + cell.ToString());
 }
Example #28
0
        public static void GunMove(Player player)
        {
            World world = player.World;

            if (null == world)
            {
                return;
            }
            try
            {
                lock (world.SyncRoot)
                {
                    if (null == world.Map)
                    {
                        return;
                    }
                    if (!player.IsOnline)
                    {
                        return;
                    }
                    Position p    = player.Position;
                    double   ksi  = 2.0 * Math.PI * (-player.Position.L) / 256.0;
                    double   phi  = 2.0 * Math.PI * (player.Position.R - 64) / 256.0;
                    double   sphi = Math.Sin(phi);
                    double   cphi = Math.Cos(phi);
                    double   sksi = Math.Sin(ksi);
                    double   cksi = Math.Cos(ksi);

                    if (player.IsOnline)
                    {
                        if (player.GunCache.Values.Count > 0)
                        {
                            foreach (Vector3I block in player.GunCache.Values)
                            {
                                if (!player.IsOnline)
                                {
                                    continue;
                                }
                                player.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, world.Map.GetBlock(block)));
                                player.GunCache.TryRemove(block.ToString(), out _);
                            }
                        }
                    }

                    for (int y = -1; y < 2; ++y)
                    {
                        for (int z = -1; z < 2; ++z)
                        {
                            if (!player.IsOnline)
                            {
                                continue;
                            }
                            //4 is the distance betwen the player and the glass wall
                            Vector3I glassBlockPos = new Vector3I((int)(cphi * cksi * 4 - sphi * (0.5 + y) - cphi * sksi * (0.5 + z)),
                                                                  (int)(sphi * cksi * 4 + cphi * (0.5 + y) - sphi * sksi * (0.5 + z)),
                                                                  (int)(sksi * 4 + cksi * (0.5 + z)));
                            glassBlockPos += p.ToBlockCoords();
                            if (world.Map.GetBlock(glassBlockPos) != Block.Air)
                            {
                                continue;
                            }
                            player.Send(PacketWriter.MakeSetBlock(glassBlockPos, Block.Glass));
                            player.GunCache.TryAdd(glassBlockPos.ToString(), glassBlockPos);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogType.SeriousError, "GunGlass: " + ex);
            }
        }
 public void LogCellRemoval(MyVoxelNavigationMesh navMesh, Vector3I cell)
 {
     m_log.WriteLine("NMOP: " + navMesh.ToString() + " REM " + cell.ToString());
 }
        protected bool TestGridPlacementOnGrid(MyCubeGrid previewGrid, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid)
        {
            bool retval = true;

            Vector3I gridOffset = hitGrid.WorldToGridInteger(m_pastePosition);
            MatrixI  transform  = hitGrid.CalculateMergeTransform(previewGrid, gridOffset);

            if (MyDebugDrawSettings.DEBUG_DRAW_COPY_PASTE)
            {
                MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, 60.0f), "First grid offset: " + gridOffset.ToString(), Color.Red, 1.0f);
            }
            retval = retval && hitGrid.GridSizeEnum == previewGrid.GridSizeEnum && hitGrid.CanMergeCubes(previewGrid, gridOffset);
            retval = retval && MyCubeGrid.CheckMergeConnectivity(hitGrid, previewGrid, gridOffset);

            // Check if any block connects to hit grid
            if (retval)
            {
                bool connected = false;

                foreach (var block in previewGrid.CubeBlocks)
                {
                    if (block.FatBlock is MyCompoundCubeBlock)
                    {
                        MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                        foreach (var blockInCompound in compoundBlock.GetBlocks())
                        {
                            connected |= CheckConnectivityOnGrid(blockInCompound, ref transform, ref settings, hitGrid);
                            if (connected)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        connected |= CheckConnectivityOnGrid(block, ref transform, ref settings, hitGrid);
                    }

                    if (connected)
                    {
                        break;
                    }
                }

                retval &= connected;
            }

            if (retval)
            {
                foreach (var block in previewGrid.CubeBlocks)
                {
                    if (block.FatBlock is MyCompoundCubeBlock)
                    {
                        MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                        foreach (var blockInCompound in compoundBlock.GetBlocks())
                        {
                            retval = retval && TestBlockPlacementOnGrid(blockInCompound, ref transform, ref settings, hitGrid);
                            if (!retval)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        retval = retval && TestBlockPlacementOnGrid(block, ref transform, ref settings, hitGrid);
                    }

                    if (!retval)
                    {
                        break;
                    }
                }
            }

            return(retval);
        }
Example #31
0
 public void TestToString()
 {
     CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
     try
     {
         Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
         Vector3I a = new Vector3I(1, 2, 3);
         Assert.AreEqual("(1, 2, 3)", a.ToString());
     }
     finally
     {
         Thread.CurrentThread.CurrentCulture = originalCulture;
     }
 }