Exemple #1
0
        /// <summary>
        /// Sends the data to the specified user of all existing content on the map.
        /// </summary>
        /// <param name="user">User to send the map data to.</param>
        void SendMapData(User user)
        {
            using (var pw = ServerPacket.GetWriter())
            {
                // Tell the user to change the map
                ServerPacket.SetMap(pw, ID);
                user.Send(pw, ServerMessageType.Map);

                // Send dynamic entities
                foreach (var dynamicEntity in DynamicEntities)
                {
                    pw.Reset();
                    ServerPacket.CreateDynamicEntity(pw, dynamicEntity);
                    user.Send(pw, ServerMessageType.Map);

                    // Perform special synchronizations for Characters
                    var character = dynamicEntity as Character;
                    if (character != null)
                    {
                        character.SynchronizeSPTo(user);
                        character.SynchronizePaperdollTo(user);
                    }
                }

                // Now that the user know about the Map and every Entity on it, tell them which one is theirs
                pw.Reset();
                ServerPacket.SetUserChar(pw, user.MapEntityIndex);
                user.Send(pw, ServerMessageType.Map);
            }
        }
Exemple #2
0
        /// <summary>
        /// When overridden in the derived class, allows for additional processing on Entities added to the map.
        /// This is called after the Entity has finished being added to the map.
        /// </summary>
        /// <param name="entity">Entity that was added to the map.</param>
        protected override void EntityAdded(Entity entity)
        {
            base.EntityAdded(entity);

            // When a User enters the Map, reset the inactivity counter
            if (entity is User)
            {
                _inactiveCounter = _emptyMapNoUpdateDelay;
            }

            // Create the DynamicEntity for everyone on the map
            if (_users.Count > 0)
            {
                var de = entity as DynamicEntity;
                if (de != null)
                {
                    using (var pw = ServerPacket.CreateDynamicEntity(de))
                    {
                        Send(pw, ServerMessageType.Map);
                    }
                }
            }

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

            if (item != null)
            {
                if (item is ItemEntity)
                {
                    ((ItemEntity)item).IsPersistent = false;
                }

                EventCounterManager.Map.Increment(ID, MapEventCounterType.ItemAdded, item.Amount);

                _mapItemsCleaner.Add(item, GetTime());
            }

            // Handle the different types of entities
            var character = entity as Character;

            if (character != null)
            {
                CharacterAdded(character);
            }
        }
Exemple #3
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);
                }
            }
        }