예제 #1
0
        internal override void Receive()
        {
            if (!Config.IsSinglePlayer)
            {
                lock (TcpClient)
                {
                    base.Receive();
                    var bytes = ReadStream(DataLength);
                    Position = new Position(bytes, 0);
                }
            }

            var existingBlock = Position.GetBlock(); //store the existing block before we overwrite it
            WorldData.PlaceBlock(Position, Block.BlockType.Air);

            //if destroying a block, create an item
            BlockItem newBlockItem = null;
            if ((Config.IsSinglePlayer && !Config.CreativeMode) || (Config.IsServer && !ConnectedPlayer.IsCreative))
            {
                if (!existingBlock.IsTransparent)
                {
                    var temp = Position.ToCoords();
                    newBlockItem = new BlockItem(ref temp, existingBlock.Type);
                }
            }

            if (Config.IsServer)
            {
                foreach (var player in Server.Controller.Players.Values)
                {
                    new RemoveBlock(ref Position) { ConnectedPlayer = player }.Send();
                    if (newBlockItem != null) new AddBlockItem(ref newBlockItem.Coords, ref newBlockItem.Velocity, newBlockItem.BlockType, newBlockItem.Id) {ConnectedPlayer = player}.Send();
                }
            }
        }
예제 #2
0
        internal override void Receive()
        {
            if (!Config.IsSinglePlayer)
            {
                lock (TcpClient)
                {
                    base.Receive();
                    var bytes = ReadStream(DataLength);
                    Coords = new Coords(bytes, 0);
                    Velocity = new Vector3(BitConverter.ToSingle(bytes, sizeof(float) * 5),
                                           BitConverter.ToSingle(bytes, sizeof(float) * 6),
                                           BitConverter.ToSingle(bytes, sizeof(float) * 7));
                    BlockType = (Block.BlockType)BitConverter.ToUInt16(bytes, Coords.SIZE + Vector3.SizeInBytes);
                    GameObjectId = BitConverter.ToInt32(bytes, Coords.SIZE + Vector3.SizeInBytes + sizeof(ushort));
                }
            }

            //add the new block item to the chunk game items (note: constructor adds the item to the collection)
            var newBlockItem = new BlockItem(ref Coords, BlockType, Velocity, GameObjectId);

            if (Config.IsServer)
            {
                foreach (var player in Server.Controller.Players.Values)
                {
                    new AddBlockItem(ref newBlockItem.Coords, ref newBlockItem.Velocity, newBlockItem.BlockType, newBlockItem.Id) { ConnectedPlayer = player }.Send();
                }
            }
        }
예제 #3
0
        }                                                                //projectiles decay as soon as they stop

        /// <summary>Projectile explodes on decay.</summary>
        internal void OnItemDecay(FrameEventArgs e)
        {
            if (Config.IsServer || Config.IsSinglePlayer)
            {
                var positions     = Coords.AdjacentPositions;
                var removeBlocks  = new List <RemoveBlock>();
                var addBlockItems = new List <AddBlockItem>();
                Settings.ChunkUpdatesDisabled = true;
                foreach (var position in positions)
                {
                    var block = position.GetBlock();
                    if (block.Type != Block.BlockType.Air && block.Type != Block.BlockType.Water)
                    {
                        WorldData.PlaceBlock(position, Block.BlockType.Air);
                        var tempPosition = position;                         //copy to pass by ref
                        removeBlocks.Add(new RemoveBlock(ref tempPosition));

                        if (!block.IsTransparent && position.IsValidItemLocation)
                        {
                            var tempCoords   = position.ToCoords();                           //copy to pass by ref
                            var newBlockItem = new BlockItem(ref tempCoords, block.Type);
                            addBlockItems.Add(new AddBlockItem(ref newBlockItem.Coords, ref newBlockItem.Velocity, newBlockItem.BlockType, newBlockItem.Id));
                        }
                    }
                }
                Settings.ChunkUpdatesDisabled = false;

                if (Config.IsServer && removeBlocks.Count > 0)
                {
                    foreach (var player in Server.Controller.Players.Values)
                    {
                        var removeBlockMulti = new RemoveBlockMulti {
                            ConnectedPlayer = player
                        };
                        removeBlockMulti.Blocks.AddRange(removeBlocks);
                        removeBlockMulti.BlockItems.AddRange(addBlockItems);
                        removeBlockMulti.Send();
                    }
                }
            }
        }
예제 #4
0
        /// <summary>Projectile explodes on decay.</summary>
        internal void OnItemDecay(FrameEventArgs e)
        {
            if (Config.IsServer || Config.IsSinglePlayer)
            {
                var positions = Coords.AdjacentPositions;
                var removeBlocks = new List<RemoveBlock>();
                var addBlockItems = new List<AddBlockItem>();
                Settings.ChunkUpdatesDisabled = true;
                foreach (var position in positions)
                {
                    var block = position.GetBlock();
                    if (block.Type != Block.BlockType.Air && block.Type != Block.BlockType.Water)
                    {
                        WorldData.PlaceBlock(position, Block.BlockType.Air);
                        var tempPosition = position; //copy to pass by ref
                        removeBlocks.Add(new RemoveBlock(ref tempPosition));

                        if (!block.IsTransparent && position.IsValidItemLocation)
                        {
                            var tempCoords = position.ToCoords(); //copy to pass by ref
                            var newBlockItem = new BlockItem(ref tempCoords, block.Type);
                            addBlockItems.Add(new AddBlockItem(ref newBlockItem.Coords, ref newBlockItem.Velocity, newBlockItem.BlockType, newBlockItem.Id));
                        }
                    }
                }
                Settings.ChunkUpdatesDisabled = false;

                if (Config.IsServer && removeBlocks.Count > 0)
                {
                    foreach (var player in Server.Controller.Players.Values)
                    {
                        var removeBlockMulti = new RemoveBlockMulti {ConnectedPlayer = player};
                        removeBlockMulti.Blocks.AddRange(removeBlocks);
                        removeBlockMulti.BlockItems.AddRange(addBlockItems);
                        removeBlockMulti.Send();
                    }
                }
            }
        }