示例#1
0
        /// <summary>
        /// When overridden in the derived class, allows for additional processing on Entities removed from the map.
        /// This is called after the Entity has finished being removed from the map.
        /// </summary>
        /// <param name="entity">Entity that was removed from the map.</param>
        protected override void EntityRemoved(Entity entity)
        {
            base.EntityRemoved(entity);

            // Handle the different types of entities
            DynamicEntity dynamicEntity;

            if ((dynamicEntity = entity as DynamicEntity) != null)
            {
                var character = entity as Character;
                if (character != null)
                {
                    CharacterRemoved(character);
                }

                // Destroy the DynamicEntity for everyone on the map
                if (_users.Count > 0)
                {
                    using (var pw = ServerPacket.RemoveDynamicEntity(dynamicEntity.MapEntityIndex))
                    {
                        Send(pw, ServerMessageType.Map);
                    }
                }
            }

            // Remove items to the MapItemsCleaner
            var item = entity as ItemEntityBase;

            if (item != null)
            {
                _mapItemsCleaner.Remove(item);
            }
        }
示例#2
0
        void RecvRequestMapEntityIndex(IIPSocket conn, BitStream r)
        {
            var index = r.ReadMapEntityIndex();

            // Get the user and their map
            User user;

            if ((user = TryGetUser(conn)) == null)
            {
                return;
            }

            Map map;

            if (!TryGetMap(user, out map))
            {
                return;
            }

            // Get the DynamicEntity
            var de = map.GetDynamicEntity(index);

            if (de == null)
            {
                // The DynamicEntity for the index was null, so tell the client to delete whatever is at that index
                using (var pw = ServerPacket.RemoveDynamicEntity(index))
                {
                    conn.Send(pw, ServerMessageType.Map);
                }
            }
            else
            {
                // A DynamicEntity does exist at that index, so tell the client to create it
                using (var pw = ServerPacket.CreateDynamicEntity(de))
                {
                    conn.Send(pw, ServerMessageType.Map);
                }
            }
        }