Exemple #1
0
        public override void LoadCustomData(BinaryReader reader)
        {
            int           count          = reader.ReadInt32();
            List <ushort> canRestore     = new List <ushort>();
            bool          canRestoreFlag = false;

            for (int k = 0; k < count; k++)
            {
                MysteryTileInfo info;
                string          modName = reader.ReadString();
                if (modName.Length == 0)
                {
                    infos.Add(null);
                    canRestore.Add(0);
                }
                else
                {
                    string name           = reader.ReadString();
                    bool   frameImportant = reader.ReadBoolean();
                    if (frameImportant)
                    {
                        info = new MysteryTileInfo(modName, name, reader.ReadInt16(), reader.ReadInt16());
                    }
                    else
                    {
                        info = new MysteryTileInfo(modName, name);
                    }
                    infos.Add(info);
                    Mod    mod  = ModLoader.GetMod(modName);
                    ushort type = (ushort)(mod == null ? 0 : mod.TileType(name));
                    canRestore.Add(type);
                    if (type != 0)
                    {
                        canRestoreFlag = true;
                    }
                }
            }
            if (canRestoreFlag)
            {
                RestoreTiles(canRestore);
                for (int k = 0; k < count; k++)
                {
                    if (canRestore[k] > 0)
                    {
                        infos[k] = null;
                    }
                }
            }
            if (pendingInfos.Count > 0)
            {
                ConfirmPendingInfo();
            }
        }
		public override void LoadCustomData(BinaryReader reader)
		{
			int count = reader.ReadInt32();
			List<ushort> canRestore = new List<ushort>();
			bool canRestoreFlag = false;
			for (int k = 0; k < count; k++)
			{
				MysteryTileInfo info;
				string modName = reader.ReadString();
				if (modName.Length == 0)
				{
					infos.Add(null);
					canRestore.Add(0);
				}
				else
				{
					string name = reader.ReadString();
					bool frameImportant = reader.ReadBoolean();
					if (frameImportant)
					{
						info = new MysteryTileInfo(modName, name, reader.ReadInt16(), reader.ReadInt16());
					}
					else
					{
						info = new MysteryTileInfo(modName, name);
					}
					infos.Add(info);
					Mod mod = ModLoader.GetMod(modName);
					ushort type = (ushort)(mod == null ? 0 : mod.TileType(name));
					canRestore.Add(type);
					if (type != 0)
					{
						canRestoreFlag = true;
					}
				}
			}
			if (canRestoreFlag)
			{
				RestoreTiles(canRestore);
				for (int k = 0; k < count; k++)
				{
					if (canRestore[k] > 0)
					{
						infos[k] = null;
					}
				}
			}
			if (pendingInfos.Count > 0)
			{
				ConfirmPendingInfo();
			}
		}
        public override bool Equals(object obj)
        {
            MysteryTileInfo other = obj as MysteryTileInfo;

            if (other == null)
            {
                return(false);
            }
            if (modName != other.modName || name != other.name || frameImportant != other.frameImportant)
            {
                return(false);
            }
            return(!frameImportant || (frameX == other.frameX && frameY == other.frameY));
        }
        private void RestoreTiles(List <ushort> canRestore)
        {
            ushort mysteryType = (ushort)ModLoader.GetMod("ModLoader").TileType("MysteryTile");

            for (int x = 0; x < Main.maxTilesX; x++)
            {
                for (int y = 0; y < Main.maxTilesY; y++)
                {
                    if (Main.tile[x, y].type == mysteryType)
                    {
                        Tile             tile  = Main.tile[x, y];
                        MysteryTileFrame frame = new MysteryTileFrame(tile.frameX, tile.frameY);
                        int frameID            = frame.FrameID;
                        if (canRestore[frameID] > 0)
                        {
                            MysteryTileInfo info = infos[frameID];
                            tile.type   = canRestore[frameID];
                            tile.frameX = info.frameX;
                            tile.frameY = info.frameY;
                        }
                    }
                }
            }
        }
Exemple #5
0
		internal static void ReadModTile(ref int i, ref int j, TileTables tables, BinaryReader reader, ref bool nextModTile)
		{
			byte flags;
			flags = reader.ReadByte();
			Tile tile = Main.tile[i, j];
			if ((flags & 1) == 1)
			{
				tile.active(true);
				ushort saveType = reader.ReadUInt16();
				tile.type = tables.tiles[saveType];
				if (tables.frameImportant[saveType])
				{
					if ((flags & 2) == 2)
					{
						tile.frameX = reader.ReadInt16();
					}
					else
					{
						tile.frameX = reader.ReadByte();
					}
					if ((flags & 4) == 4)
					{
						tile.frameY = reader.ReadInt16();
					}
					else
					{
						tile.frameY = reader.ReadByte();
					}
				}
				else
				{
					tile.frameX = -1;
					tile.frameY = -1;
				}
				if (tile.type == ModLoader.GetMod("ModLoader").TileType("PendingMysteryTile")
					&& tables.tileNames.ContainsKey(saveType))
				{
					MysteryTileInfo info;
					if (tables.frameImportant[saveType])
					{
						info = new MysteryTileInfo(tables.tileModNames[saveType], tables.tileNames[saveType],
							tile.frameX, tile.frameY);
					}
					else
					{
						info = new MysteryTileInfo(tables.tileModNames[saveType], tables.tileNames[saveType]);
					}
					MysteryTilesWorld modWorld = (MysteryTilesWorld)ModLoader.GetMod("ModLoader").GetModWorld("MysteryTilesWorld");
					int pendingFrameID = modWorld.pendingInfos.IndexOf(info);
					if (pendingFrameID < 0)
					{
						pendingFrameID = modWorld.pendingInfos.Count;
						modWorld.pendingInfos.Add(info);
					}
					MysteryTileFrame pendingFrame = new MysteryTileFrame(pendingFrameID);
					tile.frameX = pendingFrame.FrameX;
					tile.frameY = pendingFrame.FrameY;
				}
				if ((flags & 8) == 8)
				{
					tile.color(reader.ReadByte());
				}
				WorldGen.tileCounts[tile.type] += j <= Main.worldSurface ? 5 : 1;
			}
			if ((flags & 16) == 16)
			{
				tile.wall = tables.walls[reader.ReadUInt16()];
				if ((flags & 32) == 32)
				{
					tile.wallColor(reader.ReadByte());
				}
			}
			if ((flags & 64) == 64)
			{
				byte sameCount = reader.ReadByte();
				for (byte k = 0; k < sameCount; k++)
				{
					NextTile(ref i, ref j);
					Main.tile[i, j].CopyFrom(tile);
					WorldGen.tileCounts[tile.type] += j <= Main.worldSurface ? 5 : 1;
				}
			}
			if ((flags & 128) == 128)
			{
				nextModTile = true;
			}
		}