Aura.Channel.World.Entities.NPC.Spawn C# (CSharp) Метод

Spawn() публичный Метод

Sets SpawnLocation and places NPC in region.
public Spawn ( int regionId, int x, int y ) : bool
regionId int
x int
y int
Результат bool
		public bool Spawn(int regionId, int x, int y)
		{
			// Already spawned
			if (this.Region != Region.Limbo)
			{
				Log.Error("NPC.Spawn: Failed to spawn '{0}', it was spawned already.", this.RaceId, this.RegionId);
				return false;
			}

			// Save spawn location
			this.SpawnLocation = new Location(this.RegionId, x, y);

			// Warp to spawn point
			if (!this.Warp(regionId, x, y))
			{
				Log.Error("NPC.Spawn: Failed to spawn '{0}', region '{1}' doesn't exist.", this.RaceId, this.RegionId);
				return false;
			}

			return true;
		}

Usage Example

Пример #1
0
		/// <summary>
		/// Adds boss to list of bosses to spawn.
		/// </summary>
		/// <param name="raceId"></param>
		/// <param name="amount"></param>
		public void AddBoss(int raceId, int amount = 1)
		{
			var rnd = RandomProvider.Get();
			var end = this.Generator.Floors.Last().MazeGenerator.EndPos;
			var endX = end.X * TileSize + TileSize / 2;
			var endY = end.Y * TileSize + TileSize / 2;
			var regionId = this.Regions.Last().Id;

			for (int i = 0; i < amount; ++i)
			{
				var pos = new Position(endX, endY + TileSize / 2);
				pos = pos.GetRandomInRange(TileSize / 2, rnd);

				var npc = new NPC(raceId);
				npc.Death += this.OnBossDeath;
				npc.Spawn(regionId, pos.X, pos.Y);
				Send.SpawnEffect(SpawnEffect.Monster, regionId, pos.X, pos.Y, npc, npc);
				if (npc.AI != null)
					npc.AI.Activate(0);
			}

			Interlocked.Add(ref _bossesRemaining, amount);
		}