/// <summary>
		/// Tries to make the next bytes backward in the stream fit into an Chest object.
		/// If it fails sets the position back to where it was.
		/// This does nothing at all for the items in the chest, only the Chest itself.
		/// </summary>
		/// <returns>An Chest object.  Active will be true on any valid Chest.</returns>
		private Chest tryReadChestHeaderBackwards()
		{
			Int32 x, y;
			Int32 strictBool;
			Chest returnChest = new Chest();
			long oldPosition = stream.Position;
			Boolean validChest = false;

#if (DEBUG == false)
			try
			{
#endif
				y = backReader.ReadBackwardsInt32();
				x = backReader.ReadBackwardsInt32();

				returnChest.Coordinates = new Point(x, y);

				strictBool = backReader.ReadBackwardsByte();

				if (strictBool == 1)
					returnChest.Active = true;

				if (returnChest.Active == true && x > 0&& y > 0 && x < MaxX && y < MaxY)
					validChest = true;
#if (DEBUG == false)
			}
			catch (EndOfStreamException e)
			{
				e.GetType();
			}
#endif

			if (validChest == false)
			{
				stream.Seek(oldPosition, SeekOrigin.Begin);
				returnChest.Active = false;
			}

			return returnChest;
		}
Example #2
0
		private void ReadChests()
		{
			Int16 itemCount;
			Chest theChest = null;
			Item theItem;
			Int32 i, j;
			Int32 maxChests;
			int maxItems;
			chests = new List<Chest>();

			if (bw != null)
				bw.ReportProgress((Int32)(((Single)progressPosition / stream.Length) * readWorldPerc)
					, "Reading Chests");


			maxChests = reader.ReadInt16();
			maxItems = reader.ReadInt16();


			for (i = 0; i < maxChests; i++)
			{

				theChest = new Chest();
				theChest.ChestId = i;
				theChest.Active = true;

				theChest.Coordinates = new Point(reader.ReadInt32(), reader.ReadInt32());

				theChest.Name = reader.ReadString();


				if (chestTypeList != null)
				{
					if (chestTypeList.ContainsKey(theChest.Coordinates))
						theChest.Type = chestTypeList[theChest.Coordinates];
				}
				else
				{
					theChest.Type = ChestType.Chest;
				}

				for (j = 0; j < maxItems; j++)
				{
					if (header.ReleaseNumber > 68)
						itemCount = reader.ReadInt16();
					else
						itemCount = reader.ReadByte();

					if (itemCount > 0)
					{
						theItem = new Item();
						theItem.Id = j;
						theItem.Count = itemCount;

						if (header.ReleaseNumber >= 0x26)
						{
							theItem.Name = Global.Instance.Info.GetItemName(reader.ReadInt32());
						}
						else
						{
							theItem.Name = reader.ReadString();
						}

						if (header.ReleaseNumber >= 0x24)
							theItem.Prefix = reader.ReadByte();

						theChest.Items.Add(theItem);
					}
				}
				chests.Add(theChest);


				progressPosition = stream.Position;
			}

			posSigns = stream.Position;
		}
Example #3
0
        private void ReadChests(World world)
        {
            Boolean isChest;
            short itemCount;
            Chest theChest = null;
            Item theItem;
            Int32 i, j;
            
            var chests = new List<Chest>();

            for (i = 0; i < 1000; i++)
            {
                isChest = reader.ReadBoolean();

                if (isChest)
                {
                    theChest = new Chest();
                    theChest.ChestId = i;
                    theChest.Active = isChest;

                    theChest.Coordinates = new Point(reader.ReadInt32(), reader.ReadInt32());

                    if (world.ChestTypeList != null)
                    {
                        if (world.ChestTypeList.ContainsKey(theChest.Coordinates))
                            theChest.Type = world.ChestTypeList[theChest.Coordinates];
                    }
                    else
                    {
                        theChest.Type = ChestType.Chest;
                    }

                    for (j = 0; j < 40; j++)
                    {
                        itemCount = reader.ReadInt16();

                        if (itemCount > 0)
                        {
                            theItem = new Item();
                            theItem.Id = j;
                            theItem.Count = itemCount;

                            if (world.Header.ReleaseNumber >= 0x26)
                            {
                                theItem.Name = Global.Instance.Info.GetItemName(reader.ReadInt32());
                            }
                            else
                            {
                                theItem.Name = reader.ReadString();
                            }

                            if (world.Header.ReleaseNumber >= 0x24)
                                theItem.Prefix = reader.ReadByte();

                            theChest.Items.Add(theItem);
                        }
                    }
                    chests.Add(theChest);
                }

               // progressPosition = stream.Position;
            }
            world.Chests = chests;

        }