Server.Statics.DoUnfreeze C# (CSharp) Méthode

DoUnfreeze() private static méthode

private static DoUnfreeze ( Server.Map map, Server.Point2D start, Server.Point2D end, bool &badDataFile, int &totalUnfrozen ) : void
map Server.Map
start Server.Point2D
end Server.Point2D
badDataFile bool
totalUnfrozen int
Résultat void
		private static void DoUnfreeze( Map map, Point2D start, Point2D end, ref bool badDataFile, ref int totalUnfrozen )
		{
			start = map.Bound( start );
			end = map.Bound( end );

			int xStartBlock = start.X >> 3;
			int yStartBlock = start.Y >> 3;
			int xEndBlock = end.X >> 3;
			int yEndBlock = end.Y >> 3;

			int xTileStart = start.X, yTileStart = start.Y;
			int xTileWidth = end.X - start.X + 1, yTileHeight = end.Y - start.Y + 1;

			TileMatrix matrix = map.Tiles;

			using ( FileStream idxStream = OpenWrite( matrix.IndexStream ) )
			{
				using ( FileStream mulStream = OpenWrite( matrix.DataStream ) )
				{
					if ( idxStream == null || mulStream == null )
					{
						badDataFile = true;
						return;
					}

					BinaryReader idxReader = new BinaryReader( idxStream );

					BinaryWriter idxWriter = new BinaryWriter( idxStream );
					BinaryWriter mulWriter = new BinaryWriter( mulStream );

					for ( int x = xStartBlock; x <= xEndBlock; ++x )
					{
						for ( int y = yStartBlock; y <= yEndBlock; ++y )
						{
							int oldTileCount;
							StaticTile[] oldTiles = ReadStaticBlock( idxReader, mulStream, x, y, matrix.BlockWidth, matrix.BlockHeight, out oldTileCount );

							if ( oldTileCount < 0 )
								continue;

							int newTileCount = 0;
							StaticTile[] newTiles = new StaticTile[oldTileCount];

							int baseX = (x << 3) - xTileStart, baseY = (y << 3) - yTileStart;

							for ( int i = 0; i < oldTileCount; ++i )
							{
								StaticTile oldTile = oldTiles[i];

								int px = baseX + oldTile.X;
								int py = baseY + oldTile.Y;

								if ( px < 0 || px >= xTileWidth || py < 0 || py >= yTileHeight )
								{
									newTiles[newTileCount++] = oldTile;
								}
								else
								{
									++totalUnfrozen;

									Item item = new Static( oldTile.ID );

									item.Hue = oldTile.Hue;

									item.MoveToWorld( new Point3D( px + xTileStart, py + yTileStart, oldTile.Z ), map );
								}
							}

							int mulPos = -1;
							int length = -1;
							int extra = 0;

							if ( newTileCount > 0 )
							{
								mulWriter.Seek( 0, SeekOrigin.End );

								mulPos = (int)mulWriter.BaseStream.Position;
								length = newTileCount * 7;
								extra = 1;

								for ( int i = 0; i < newTileCount; ++i )
								{
									StaticTile toWrite = newTiles[i];

									mulWriter.Write( (ushort) toWrite.ID );
									mulWriter.Write( (byte) toWrite.X );
									mulWriter.Write( (byte) toWrite.Y );
									mulWriter.Write( (sbyte) toWrite.Z );
									mulWriter.Write( (short) toWrite.Hue );
								}

								mulWriter.Flush();
							}

							int idxPos = ((x * matrix.BlockHeight) + y) * 12;

							idxWriter.Seek( idxPos, SeekOrigin.Begin );
							idxWriter.Write( mulPos );
							idxWriter.Write( length );
							idxWriter.Write( extra );

							idxWriter.Flush();

							matrix.SetStaticBlock( x, y, null );
						}
					}
				}
			}
		}

Same methods

Statics::DoUnfreeze ( Server.Map map, bool &badDataFile, int &totalUnfrozen ) : void