Ejemplo n.º 1
0
 internal override void Send()
 {
     if (!Config.IsServer && PendingPickups.Contains(GameObjectId))
     {
         return;
     }
     base.Send();
     PendingPickups.Add(GameObjectId);
 }
Ejemplo n.º 2
0
        internal override void Receive()
        {
            if (!Config.IsSinglePlayer)
            {
                lock (TcpClient)
                {
                    base.Receive();
                    var bytes = ReadStream(DataLength);
                    PlayerId     = BitConverter.ToInt32(bytes, 0);
                    GameObjectId = BitConverter.ToInt32(bytes, sizeof(int));
                }
            }

            //bm: the removal could be requested more than once as the player moves while waiting for a response. maybe this should be prevented client-side
            if (!WorldData.GameItems.ContainsKey(GameObjectId))
            {
                return;
            }

            var             blockItem = (BlockItem)WorldData.GameItems[GameObjectId];
            var             chunk     = WorldData.Chunks[blockItem.Coords];
            GameItemDynamic remove;

            chunk.GameItems.TryRemove(GameObjectId, out remove);
            WorldData.GameItems.TryRemove(GameObjectId, out remove);

            if (Config.IsServer)
            {
                foreach (var player in Server.Controller.Players.Values)
                {
                    if (player.Id == PlayerId)
                    {
                        //this player is picking it up, update their inventory and send a different packet so they do too
                        player.Inventory[(int)blockItem.BlockType]++;
                        new PickupBlockItem(PlayerId, GameObjectId)
                        {
                            ConnectedPlayer = player
                        }.Send();
                    }
                    else
                    {
                        //as far as this player knows it was destroyed (any reason to do otherwise?)
                        new RemoveBlockItem(GameObjectId, false)
                        {
                            ConnectedPlayer = player
                        }.Send();
                    }
                }
            }
            else
            {
                Game.Player.Inventory[(int)blockItem.BlockType]++;
                Sounds.Audio.PlaySound(Sounds.SoundType.ItemPickup, ref blockItem.Coords);
                PendingPickups.Remove(GameObjectId);
            }
        }