예제 #1
0
        public void LoadChests()
        {
            string path = Path.Combine(Main.ActiveWorldFileData.Path.Replace(".wld", ""), ActiveDimensionName.Split(':')[1]) + "\\chest.data";

            using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open)))
            {
                int num  = (int)reader.ReadInt16();
                int num2 = (int)reader.ReadInt16();
                int num3;
                int num4;
                if (num2 < 40)
                {
                    num3 = num2;
                    num4 = 0;
                }
                else
                {
                    num3 = 40;
                    num4 = num2 - 40;
                }
                int i;
                for (i = 0; i < num; i++)
                {
                    Chest chest = new Chest(false);
                    chest.x    = reader.ReadInt32();
                    chest.y    = reader.ReadInt32();
                    chest.name = reader.ReadString();
                    for (int j = 0; j < num3; j++)
                    {
                        short num5 = reader.ReadInt16();
                        Item  item = new Item();
                        if (num5 > 0)
                        {
                            item.netDefaults(reader.ReadInt32());
                            item.stack = (int)num5;
                            item.Prefix((int)reader.ReadByte());
                        }
                        else if (num5 < 0)
                        {
                            item.netDefaults(reader.ReadInt32());
                            item.Prefix((int)reader.ReadByte());
                            item.stack = 1;
                        }
                        chest.item[j] = item;
                    }
                    for (int j = 0; j < num4; j++)
                    {
                        short num5 = reader.ReadInt16();
                        if (num5 > 0)
                        {
                            reader.ReadInt32();
                            reader.ReadByte();
                        }
                    }
                    Main.chest[i] = chest;
                }
                List <Point16> list = new List <Point16>();
                for (int k = 0; k < i; k++)
                {
                    if (Main.chest[k] != null)
                    {
                        Point16 item2 = new Point16(Main.chest[k].x, Main.chest[k].y);
                        if (list.Contains(item2))
                        {
                            Main.chest[k] = null;
                        }
                        else
                        {
                            list.Add(item2);
                        }
                    }
                }
                while (i < 1000)
                {
                    Main.chest[i] = null;
                    i++;
                }
                if (WorldFile.versionNumber < 115)
                {
                    WorldFile.FixDresserChests();
                }
            }
        }