Ejemplo n.º 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];
            _amount            = mapSpawnValues.Amount;
            _area = new MapSpawnRect(mapSpawnValues).ToRectangle(map);

            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();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the quests that this <see cref="NPC"/> should provide.
        /// </summary>
        /// <param name="charTemplate">The <see cref="CharacterTemplate"/> that this <see cref="NPC"/> was loaded from.</param>
        /// <returns>The quests that this <see cref="NPC"/> should provide. Return an empty or null collection to make
        /// this <see cref="NPC"/> not provide any quests.</returns>
        protected virtual IEnumerable <IQuest <User> > GetProvidedQuests(CharacterTemplate charTemplate)
        {
            if (charTemplate == null)
            {
                return(_emptyQuests);
            }

            return(charTemplate.Quests);
        }
Ejemplo n.º 4
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;
            }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NPC"/> class.
        /// </summary>
        /// <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="parent" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="template" /> is <c>null</c>.</exception>
        public NPC(World parent, CharacterTemplate template, Map map, Vector2 position) : base(parent, false)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (template == null)
            {
                throw new ArgumentNullException("template");
            }

            var v = template.TemplateTable;

            // Set the rest of the template stuff
            Load(template);
            _respawnSecs = v.Respawn;
            _giveExp     = v.GiveExp;
            _giveCash    = v.GiveCash;
            _quests      = GetProvidedQuests(template) ?? _emptyQuests;
            _chatDialog  = v.ChatDialog.HasValue ? _npcChatManager[v.ChatDialog.Value] : null;
            SetShopFromID(v.ShopID);

            // Set the respawn positions only if the map we set them on is not instanced
            if (!map.IsInstanced)
            {
                RespawnMapID    = map.ID;
                RespawnPosition = position;
            }
            else
            {
                RespawnMapID    = null;
                RespawnPosition = Vector2.Zero;
            }

            LoadSpawnState();

            // Done loading
            SetAsLoaded();

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Created NPC instance from template `{0}`.", template);
            }

            // Spawn
            Teleport(map, position);

            ((IRespawnable)this).Respawn();
        }
Ejemplo n.º 8
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;
            }
Ejemplo n.º 9
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;
            }
Ejemplo n.º 10
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;
            }
Ejemplo n.º 11
0
 /// <summary>
 /// Gets the quests that this <see cref="NPC"/> should provide.
 /// </summary>
 /// <param name="charTemplate">The <see cref="CharacterTemplate"/> that this <see cref="NPC"/> was loaded from.</param>
 /// <returns>
 /// The quests that this <see cref="NPC"/> should provide. Return an empty or null collection to make
 /// this <see cref="NPC"/> not provide any quests.
 /// </returns>
 protected override IEnumerable<IQuest<User>> GetProvidedQuests(CharacterTemplate charTemplate)
 {
     // Never use quests for a thralled NPC
     return null;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Gets the quests that this <see cref="NPC"/> should provide.
 /// </summary>
 /// <param name="charTemplate">The <see cref="CharacterTemplate"/> that this <see cref="NPC"/> was loaded from.</param>
 /// <returns>
 /// The quests that this <see cref="NPC"/> should provide. Return an empty or null collection to make
 /// this <see cref="NPC"/> not provide any quests.
 /// </returns>
 protected override IEnumerable <IQuest <User> > GetProvidedQuests(CharacterTemplate charTemplate)
 {
     // Never use quests for a thralled NPC
     return(null);
 }
Ejemplo n.º 13
0
        protected void Load(CharacterTemplate template)
        {
            var v = template.TemplateTable;

            Name = v.Name;
            Alliance = _allianceManager[v.AllianceID];
            BodyInfo = BodyInfoManager.Instance.GetBody(v.BodyID);
            CharacterTemplateID = v.ID;
            Resize(BodyInfo.Size);

            _level = v.Level;
            MoveSpeed = v.MoveSpeed;
            _exp = v.Exp;
            _statPoints = v.StatPoints;

            // Create the AI
            if (v.AIID.HasValue)
            {
                if (!SetAI(v.AIID.Value))
                {
                    const string errmsg = "Failed to set Character `{0}`'s AI to ID `{1}`.";
                    if (log.IsErrorEnabled)
                        log.ErrorFormat(errmsg, this, v.AIID.Value);
                    Debug.Fail(string.Format(errmsg, this, v.AIID.Value));
                    RemoveAI();
                }
            }

            // Set the base stats
            BaseStats.CopyValuesFrom(v.Stats);

            // Set known skills
            if (_knownSkills == null)
                _knownSkills = new KnownSkillsCollection(this);

            KnownSkills.SetValues(template.KnownSkills);
        }