private void SendNetworkAddition(Entity entity)
        {
            var packet = new EntityAddPacket(entity);

            // Get all interested clients
            var characters = MapSimulator.EntityCollection.Filter<CharacterComponent>();

            // Send to all interested parties
            foreach (var character in characters.Entities)
            {
                var characterComponent = character.GetComponent<CharacterComponent>();
                ClientNetworkManager.Instance.SendPacket(packet, characterComponent.Connection);
            }
        }
        private void EntityChangeEvent(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs)
        {
            switch (notifyCollectionChangedEventArgs.Action)
            {
                case NotifyCollectionChangedAction.Add:

                    foreach (Entity o in notifyCollectionChangedEventArgs.NewItems)
                    {

                        // Send the new addition to everyone
                        SendNetworkAddition(o);

                        var characterComponent = o.GetComponent<CharacterComponent>();
                        if (characterComponent != null)
                        {
                            // If this is a player, send them all current entities, too
                            foreach (var entity in MapSimulator.EntityCollection.Entities)
                            {
                                if (entity == o)
                                    continue;

                                var packet = new EntityAddPacket(entity);
                                ClientNetworkManager.Instance.SendPacket(packet, characterComponent.Connection);
                            }
                        }

                        Logger.Instance.Log(Level.Debug, "Entity with ID " + o.ID + " was added to a map.");
                    }

                    break;
                case NotifyCollectionChangedAction.Remove:
                    foreach (var o in notifyCollectionChangedEventArgs.NewItems)
                        SendNetworkSubtraction((Entity)o);
                    break;
                case NotifyCollectionChangedAction.Reset:
                    throw new Exception("Clearing the entity list is not supported. This is a dangerous operation.");
            }
        }
 private void EntityRecieved(EntityAddPacket entityAddPacket)
 {
     // Add the entity
     ServiceManager.AddEntity(entityAddPacket.Entity);
 }
 public static new Packet FromNetBuffer(NetIncomingMessage incomingMessage)
 {
     var o = (Shared.Components.Entity)SerializationHelper.ByteArrayToObject(incomingMessage.ReadBytes(incomingMessage.ReadInt32()));
     var packet = new EntityAddPacket(o);
     return packet;
 }