Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NPCSpawner"/> class.
        /// </summary>
        /// <param name="mapSpawnValues">The MapSpawnValues containing the values to use to create this NPCSpawner.</param>
        /// <param name="map">The Map instance to do the spawning on. The <see cref="MapID"/> of this Map must be equal to the
        /// <see cref="MapID"/> of the <paramref name="mapSpawnValues"/>.</param>
        /// <exception cref="ArgumentException">The <paramref name="map"/>'s <see cref="MapID"/> does not match the
        /// <paramref name="mapSpawnValues"/>'s <see cref="MapID"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="map" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="mapSpawnValues" /> is <c>null</c>.</exception>
        public NPCSpawner(IMapSpawnTable mapSpawnValues, Map map)
        {
            if (map == null)
                throw new ArgumentNullException("map");
            if (mapSpawnValues == null)
                throw new ArgumentNullException("mapSpawnValues");

            if (map.ID != mapSpawnValues.MapID)
                throw new ArgumentException("The map's MapID and mapSpawnValues's MapID do not match.", "map");

            _map = map;
            _characterTemplate = _characterTemplateManager[mapSpawnValues.CharacterTemplateID];
            _characterTemplateBody = BodyInfoManager.Instance.GetBody(_characterTemplate.TemplateTable.BodyID);
            _amount = mapSpawnValues.Amount;
            _area = new MapSpawnRect(mapSpawnValues).ToRectangle(map);
            _spawnDirection = mapSpawnValues.DirectionId;
            _respawn = mapSpawnValues.Respawn;

            if (_characterTemplate == null)
            {
                const string errmsg = "Failed to find the CharacterTemplate for CharacterTemplateID `{0}`.";
                var err = string.Format(errmsg, mapSpawnValues.CharacterTemplateID);
                if (log.IsFatalEnabled)
                    log.Fatal(err);
                Debug.Fail(err);
                throw new ArgumentException(err);
            }

            SpawnNPCs();
        }
Beispiel #2
0
        public ThralledNPC(World parent, CharacterTemplate template, Map map, Vector2 position)
            : base(parent, template, map, position)
        {
            // This NPC should never respawn. Once it's dead, that should be it!
            RespawnMapID = null;
            RespawnPosition = Vector2.Zero;

            if (log.IsDebugEnabled)
                log.DebugFormat("Created ThralledNPC `{0}` on map `{1}` at `{2}` with template `{3}`.", this, Map, Position,
                    template);
        }
        static bool TryGetMap(Character user, out Map map)
        {
            // Check for a valid user
            if (user == null)
            {
                const string errmsg = "user is null.";
                if (log.IsErrorEnabled)
                    log.Error(errmsg);
                Debug.Fail(errmsg);
                map = null;
                return false;
            }

            // Get the map
            map = user.Map;
            if (map == null)
            {
                // Invalid map
                const string errorMsg = "Received UseWorld from user `{0}`, but their map is null.";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errorMsg, user);
                Debug.Fail(string.Format(errorMsg, user));
                return false;
            }

            // Valid map
            return true;
        }
        /// <summary>
        /// Tries to get the <see cref="Map"/> and <see cref="User"/> from an <see cref="IIPSocket"/>.
        /// </summary>
        /// <param name="conn">The <see cref="IIPSocket"/> to get the <see cref="Map"/> and <see cref="User"/> from.</param>
        /// <param name="user">When this method returns true, contains the <see cref="User"/>.</param>
        /// <param name="map">When this method returns true, contains the <see cref="Map"/>.</param>
        /// <returns>True if the <paramref name="user"/> and <paramref name="map"/> were successfully found; otherwise
        /// false.</returns>
        static bool TryGetMap(IIPSocket conn, out User user, out Map map)
        {
            if ((user = TryGetUser(conn)) == null)
            {
                map = null;
                return false;
            }

            return TryGetMap(user, out map);
        }
Beispiel #5
0
            /// <summary>
            /// Initializes a new instance of the <see cref="NPCSpawnerNPC"/> class.
            /// </summary>
            /// <param name="spawner">The spawner.</param>
            /// <param name="parent">World that the NPC belongs to.</param>
            /// <param name="template">NPCTemplate used to create the NPC.</param>
            /// <param name="map">The map.</param>
            /// <param name="position">The position.</param>
            /// <param name="spawnDirection">The direction to spawn in</param>
            /// <exception cref="ArgumentNullException"><paramref name="spawner" /> is <c>null</c>.</exception>
            public NPCSpawnerNPC(NPCSpawner spawner, World parent, CharacterTemplate template, Map map, Vector2 position, Direction spawnDirection, ushort respawn)
                : base(parent, template, map, position)
            {
                if (spawner == null)
                    throw new ArgumentNullException("spawner");

                // Set the heading for this NPC
                Heading = spawnDirection;
                // Set the amount of seconds before respawning
                RespawnSecs = respawn;

                _spawner = spawner;
            }
Beispiel #6
0
        /// <summary>
        /// Loads the NPCSpawners for a Map.
        /// </summary>
        /// <param name="map">Map to load the spawners for.</param>
        /// <returns>IEnumerable of the <see cref="NPCSpawner"/>s that were loaded.</returns>
        public static IEnumerable<NPCSpawner> LoadSpawners(Map map)
        {
            var queryValues = MapSpawnValues.Load(map.DbController, map.ID);
            var ret = new List<NPCSpawner>();

            foreach (var queryValue in queryValues)
            {
                var spawner = new NPCSpawner(queryValue, map);
                ret.Add(spawner);
            }

            return ret;
        }
Beispiel #7
0
            /// <summary>
            /// Initializes a new instance of the <see cref="NPCSpawnerNPC"/> class.
            /// </summary>
            /// <param name="spawner">The spawner.</param>
            /// <param name="parent">World that the NPC belongs to.</param>
            /// <param name="template">NPCTemplate used to create the NPC.</param>
            /// <param name="map">The map.</param>
            /// <param name="position">The position.</param>
            /// <exception cref="ArgumentNullException"><paramref name="spawner" /> is <c>null</c>.</exception>
            public NPCSpawnerNPC(NPCSpawner spawner, World parent, CharacterTemplate template, Map map, Vector2 position)
                : base(parent, template, map, position)
            {
                if (spawner == null)
                    throw new ArgumentNullException("spawner");

                _spawner = spawner;
            }
Beispiel #8
0
        /// <summary>
        /// Teleports the character to a new position and informs clients in the area of
        /// interest that the character has teleported.
        /// </summary>
        /// <param name="newMap">The new map to teleport to.</param>
        /// <param name="position">Position to teleport to.</param>
        public void Teleport(MapBase newMap, Vector2 position)
        {
            if (newMap != Map)
            {
                // Take the character off the old map, teleport, then put them on the new map
                if (Map != null)
                    Map.RemoveEntity(this);

                _map = null;

                Teleport(position);

                if (newMap != null)
                {
                    newMap.AddEntity(this);
                    _spSync.ForceSynchronize();
                }
            }
            else
            {
                // Just teleport since the map didn't change
                Teleport(position);
            }

            Debug.Assert(Map == newMap);
        }
Beispiel #9
0
 /// <summary>
 /// When overridden in the derived class, allows for additional handling of the
 /// <see cref="Character.MapChanged"/> event. It is recommended you override this method instead of
 /// using the corresponding event when possible.
 /// </summary>
 /// <param name="oldMap">The old map.</param>
 /// <param name="newMap">The new map.</param>
 protected virtual void OnMapChanged(Map oldMap, Map newMap)
 {
 }