Warp() public method

Moves NPC to target location and adds it to the region. Returns false if region doesn't exist.
public Warp ( int regionId, int x, int y ) : bool
regionId int
x int
y int
return bool
Beispiel #1
0
		/// <summary>
		/// Spawns one creature based on this spawners settings.
		/// </summary>
		/// <returns></returns>
		private void SpawnOne()
		{
			// Create NPC
			var creature = new NPC(this.RaceId);

			// Warp to spawn point
			var pos = this.GetRandomPosition();
			if (!creature.Warp(this.RegionId, pos.X, pos.Y))
			{
				Log.Error("CreatureSpawner: Failed to spawn '{0}'s, region '{1}' doesn't exist.", this.RaceId, this.RegionId);
				return;
			}

			// Save spawn location
			creature.SpawnLocation = new Location(this.RegionId, pos.X, pos.Y);

			// Random title
			if (_titles != null && _titles.Length != 0)
			{
				var title = (ushort)(_titles[RandomProvider.Get().Next(_titles.Length)]);
				if (title != 0)
				{
					creature.Titles.Enable(title);
					creature.Titles.ChangeTitle(title, false);
				}
			}

			// Maintenance
			creature.SpawnId = this.Id;
			creature.Disappears += this.OnDisappears;

			// Add to list to keep track of all creatures
			lock (_creatures)
				_creatures.Add(creature);
		}
Beispiel #2
0
		/// <summary>
		/// Spawns a creature.
		/// </summary>
		/// <param name="raceId"></param>
		/// <param name="regionId"></param>
		/// <param name="x"></param>
		/// <param name="y"></param>
		/// <param name="spawnId"></param>
		/// <param name="active"></param>
		/// <param name="effect"></param>
		/// <returns></returns>
		public NPC Spawn(int raceId, int regionId, int x, int y, bool active, bool effect)
		{
			// Create NPC
			var npc = new NPC(raceId);

			// Warp to spawn point
			if (!npc.Warp(regionId, x, y))
			{
				Log.Error("Failed to spawn '{0}'s, region '{1}' doesn't exist.", raceId, regionId);
				return null;
			}

			// Save spawn location
			npc.SpawnLocation = new Location(regionId, x, y);

			// Activate AI at least once
			if (npc.AI != null && active)
				npc.AI.Activate(0);

			// Spawn effect
			if (effect)
				Send.SpawnEffect(SpawnEffect.Monster, npc.RegionId, x, y, npc, npc);

			return npc;
		}
Beispiel #3
0
        /// <summary>
        /// Spawns a creature.
        /// </summary>
        /// <param name="raceId"></param>
        /// <param name="regionId"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="spawnId"></param>
        /// <returns></returns>
        public Creature Spawn(int raceId, int regionId, int x, int y, int spawnId, bool active, bool effect)
        {
            // Create NPC
            var creature = new NPC();
            creature.Race = raceId;
            creature.LoadDefault();
            creature.SpawnId = spawnId;
            creature.Name = creature.RaceData.Name;
            creature.Color1 = creature.RaceData.Color1;
            creature.Color2 = creature.RaceData.Color2;
            creature.Color3 = creature.RaceData.Color3;
            creature.Height = creature.RaceData.Size;
            creature.Life = creature.LifeMaxBase = creature.RaceData.Life;
            creature.State = (CreatureStates)creature.RaceData.DefaultState;
            creature.Direction = (byte)RandomProvider.Get().Next(256);

            // Set drops
            creature.Drops.GoldMin = creature.RaceData.GoldMin;
            creature.Drops.GoldMax = creature.RaceData.GoldMax;
            creature.Drops.Add(creature.RaceData.Drops);

            // Give skills
            foreach (var skill in creature.RaceData.Skills)
                creature.Skills.Add((SkillId)skill.SkillId, (SkillRank)skill.Rank, creature.Race);

            // Set AI
            if (!string.IsNullOrWhiteSpace(creature.RaceData.AI) && creature.RaceData.AI != "none")
            {
                creature.AI = this.GetAi(creature.RaceData.AI, creature);
                if (creature.AI == null)
                    Log.Warning("Spawn: Missing AI '{0}' for '{1}'.", creature.RaceData.AI, raceId);
            }

            // Warp to spawn point
            if (!creature.Warp(regionId, x, y))
            {
                Log.Error("Failed to spawn '{0}'s.", raceId);
                return null;
            }

            // Activate AI at least once
            if (creature.AI != null && active)
                creature.AI.Activate(0);

            // Spawn effect
            if (effect)
                Send.SpawnEffect(SpawnEffect.Monster, creature.RegionId, x, y, creature, creature);

            return creature;
        }