Server.VendorGenerator.Process C# (CSharp) Méthode

Process() private static méthode

private static Process ( Server.Map map, Server.Rectangle2D regions ) : void
map Server.Map
regions Server.Rectangle2D
Résultat void
		private static void Process( Map map, Rectangle2D[] regions )
		{
			m_ShopTable = new Hashtable();
			m_ShopList = new ArrayList();

			World.Broadcast( 0x35, true, "Generating vendor spawns for {0}, please wait.", map );
			
			for ( int i = 0; i < regions.Length; ++i )
				for ( int x = 0; x < map.Width; ++x )
					for ( int y = 0; y < map.Height; ++y )
						CheckPoint( map, regions[i].X + x, regions[i].Y + y );

			for ( int i = 0; i < m_ShopList.Count; ++i )
			{
				ShopInfo si = (ShopInfo)m_ShopList[i];

				int xTotal = 0;
				int yTotal = 0;

				bool hasSpawner = false;

				for ( int j = 0; !hasSpawner && j < si.m_Floor.Count; ++j )
				{
					Point2D fp = (Point2D)si.m_Floor[j];

					xTotal += fp.X;
					yTotal += fp.Y;

					IPooledEnumerable eable = map.GetItemsInRange( new Point3D( fp.X, fp.Y, 0 ), 0 );

					foreach ( Item item in eable )
					{
						if ( item is Spawner )
						{
							hasSpawner = true;
							break;
						}
					}

					eable.Free();

					if ( hasSpawner )
						break;
				}

				if ( hasSpawner )
					continue;

				int xAvg = xTotal / si.m_Floor.Count;
				int yAvg = yTotal / si.m_Floor.Count;

				ArrayList names = new ArrayList();
				ShopFlags flags = si.m_Flags;

				if ( (flags & ShopFlags.Armor) != 0 )
					names.Add( "armorer" );

				if ( (flags & ShopFlags.MetalWeapon) != 0 )
					names.Add( "weaponsmith" );

				if ( (flags & ShopFlags.ArcheryWeapon) != 0 )
					names.Add( "bowyer" );

				if ( (flags & ShopFlags.Scroll) != 0 )
					names.Add( "mage" );

				if ( (flags & ShopFlags.Spellbook) != 0 )
					names.Add( "mage" );

				if ( (flags & ShopFlags.Bread) != 0 )
					names.Add( "baker" );

				if ( (flags & ShopFlags.Jewel) != 0 )
					names.Add( "jeweler" );

				if ( (flags & ShopFlags.Potion) != 0 )
				{
					names.Add( "herbalist" );
					names.Add( "alchemist" );
					names.Add( "mage" );
				}

				if ( (flags & ShopFlags.Reagent) != 0 )
				{
					names.Add( "mage" );
					names.Add( "herbalist" );
				}

				if ( (flags & ShopFlags.Clothes) != 0 )
				{
					names.Add( "tailor" );
					names.Add( "weaver" );
				}

				for ( int j = 0; j < names.Count; ++j )
				{
					Point2D cp = Point2D.Zero;
					int dist = 100000;
					int tz;

					for ( int k = 0; k < si.m_Floor.Count; ++k )
					{
						Point2D fp = (Point2D)si.m_Floor[k];

						int rx = fp.X - xAvg;
						int ry = fp.Y - yAvg;
						int fd = (int)Math.Sqrt( rx*rx + ry*ry );

						if ( fd > 0 && fd < 5 )
							fd -= Utility.Random( 10 );

						if ( fd < dist && GetFloorZ( map, fp.X, fp.Y, out tz ) )
						{
							dist = fd;
							cp = fp;
						}
					}

					if ( cp == Point2D.Zero )
						continue;

					int z;

					if ( !GetFloorZ( map, cp.X, cp.Y, out z ) )
						continue;

					new Spawner( 1, 1, 1, 0, 4, (string)names[j] ).MoveToWorld( new Point3D( cp.X, cp.Y, z ), map );
				}
			}

			World.Broadcast( 0x35, true, "Generation complete. {0} spawners generated.", m_ShopList.Count );
		}