Ejemplo n.º 1
0
        public override void PreUpdate()
        {
            if (quickSwitch)
            {
                count++;
                if (count >= 100)
                {
                    count = 0;
                    //Main.NewText(Liquid.numLiquid +","+ LiquidBuffer.numLiquidBuffer +","+ Liquid2.numLiquid);
                }

                Liquid.cycles       = 1;
                Liquid.panicCounter = 0;
                Liquid.UpdateLiquid();

                while (LiquidBuffer.numLiquidBuffer > 0 && Liquid2.numLiquid != 1000000 - 1)
                {
                    //Liquid2.AddWater(Main.liquidBuffer[LiquidBuffer.numLiquidBuffer -1].x,Main.liquidBuffer[LiquidBuffer.numLiquidBuffer -1].y);
                    //LiquidBuffer.DelBuffer(LiquidBuffer.numLiquidBuffer -1);
                    Main.tile[Main.liquidBuffer[0].x, Main.liquidBuffer[0].y].checkingLiquid(false);
                    Liquid2.AddWater(Main.liquidBuffer[0].x, Main.liquidBuffer[0].y);
                    LiquidBuffer.DelBuffer(0);
                }
                Liquid2.cycles       = 1;
                Liquid2.panicCounter = 0;
                Liquid2.UpdateLiquid();
            }
        }
Ejemplo n.º 2
0
        public override void PreUpdate()
        {
            /*
             * count++;
             * if(count >= 100)
             * {
             *      count = 0;
             *      Main.NewText(Liquid.numLiquid +","+ LiquidBuffer.numLiquidBuffer + "," + LiquidBuffer2.numLiquidBuffer);
             * }
             */

            if (quickSwitch)
            {
                Liquid.cycles       = 1;
                Liquid.panicCounter = 0;

                while (LiquidBuffer.numLiquidBuffer > 5000 && LiquidBuffer2.numLiquidBuffer != 100000 - 1)
                {
                    LiquidBuffer2.AddBuffer(Main.liquidBuffer[LiquidBuffer.numLiquidBuffer - 1].x, Main.liquidBuffer[LiquidBuffer.numLiquidBuffer - 1].y);
                    LiquidBuffer.DelBuffer(LiquidBuffer.numLiquidBuffer - 1);
                }
                while (LiquidBuffer.numLiquidBuffer < 5000 && LiquidBuffer2.numLiquidBuffer != 0)
                {
                    //LiquidBuffer.AddBuffer(liquidBuffer2[LiquidBuffer2.numLiquidBuffer].x,liquidBuffer2[LiquidBuffer2.numLiquidBuffer].y);
                    Main.liquidBuffer[LiquidBuffer.numLiquidBuffer].x = liquidBuffer2[LiquidBuffer2.numLiquidBuffer - 1].x;
                    Main.liquidBuffer[LiquidBuffer.numLiquidBuffer].y = liquidBuffer2[LiquidBuffer2.numLiquidBuffer - 1].y;
                    LiquidBuffer.numLiquidBuffer++;

                    LiquidBuffer2.DelBuffer(LiquidBuffer2.numLiquidBuffer - 1);
                }

                Liquid.UpdateLiquid();
            }
        }
Ejemplo n.º 3
0
 public override void PreUpdate()
 {
     /*
      *          while (0 < Main.maxTilesX * Main.maxTilesY * (3E-05f * Main.worldRate))
      *          {
      *                  int tileX = WorldGen.genRand.Next(10, Main.maxTilesX - 10); //a random x tile
      *                  int tileY = WorldGen.genRand.Next(10, (int)Main.worldSurface - 1); //a psuedo random y tile based on the world surface
      *
      *                  int tileYAbovetileY = tileY - 1 < 10 ? 10 : tileY - 1; //the tile above the psuedo random tile y position
      *
      *                  Tile groundTile = Framing.GetTileSafely(tileX, tileY); //the ground tile that the new tile will be placed on
      *
      *                  //an array of all the tiles that will need to be free
      *                  Tile[] spaceRequired = new Tile[]
      *                  {
      *                          Framing.GetTileSafely(tileX, tileYAbovetileY), //bottom left
      *                          Framing.GetTileSafely(tileX, tileYAbovetileY - 1), //top left
      *                          Framing.GetTileSafely(tileX + 1, tileYAbovetileY), //bottom right
      *                          Framing.GetTileSafely(tileX + 1, tileYAbovetileY - 1) //top right
      *                  };
      *
      *                  //if the ground tile isnt null and its grass
      *                  if (groundTile != null && groundTile.type == TileID.Grass)
      *                  {
      *                          //loop through every required tile
      *                          foreach (Tile tile in spaceRequired)
      *                          {
      *                                  //if the tile isnt active; there is space for the new tile
      *                                  if (!tile.active())
      *                                  {
      *                                          if (WorldGen.genRand.NextBool(50)) //Random amount to slow down growing
      *                                          {
      *                                                  //place the 2x2 strawberry multitile
      *                                                  WorldGen.Place2x2(tileX, tileYAbovetileY - 1, (ushort)ModContent.TileType<StrawberryPlantTile>(), 0);
      *
      *                                                  //if its still active
      *                                                  if (tile.active())
      *                                                  {
      *                                                          //set the paint color to the ground tiles paint color
      *                                                          tile.color(groundTile.color());
      *
      *                                                          //Synce the multitile placement
      *                                                          if (Main.netMode == NetmodeID.Server)
      *                                                                  NetMessage.SendTileRange(-1, tileX, tileYAbovetileY - 1, 2, 2);
      *                                                  }
      *                                          }
      *                                  }
      *                          }
      *                  }
      *          }*/
     if (Subworld.IsActive <Dimensions.PlasmaDesert>())
     {
         if (++Liquid.skipCount > 1)
         {
             Liquid.UpdateLiquid();
             Liquid.skipCount = 0;
         }
     }
 }
Ejemplo n.º 4
0
        public void settleLiquid(GenerationProgress progress)
        {
            progress.Message = Lang.gen[27].Value;
            Liquid.QuickWater(3, -1, -1);
            WorldGen.WaterCheck();
            int k = 0;

            Liquid.quickSettle = true;
            while (k < 10)
            {
                int num = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                k++;
                float num2 = 0f;
                while (Liquid.numLiquid > 0)
                {
                    float num3 = (float)(num - (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer)) / (float)num;
                    if (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer > num)
                    {
                        num = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                    }
                    if (num3 > num2)
                    {
                        num2 = num3;
                    }
                    else
                    {
                        num3 = num2;
                    }
                    if (k == 1)
                    {
                        progress.Set(num3 / 3f + 0.33f);
                    }
                    int num4 = 10;
                    if (k > num4)
                    {
                    }
                    Liquid.UpdateLiquid();
                }
                WorldGen.WaterCheck();
                progress.Set((float)k * 0.1f / 3f + 0.66f);
            }
            Liquid.quickSettle  = false;
            Main.tileSolid[190] = true;
        }
Ejemplo n.º 5
0
        public static void LoadWorld(string LoadPath)
        {
            using (FileStream fileStream = new FileStream(LoadPath, FileMode.Open))
            {
                using (BinaryReader binaryReader = new BinaryReader(fileStream))
                {
                    try
                    {
                        WorldModify.loadFailed  = false;
                        WorldModify.loadSuccess = false;
                        int Terraria_Release = binaryReader.ReadInt32();
                        if (Terraria_Release > Statics.CURRENT_TERRARIA_RELEASE)
                        {
                            WorldModify.loadFailed  = true;
                            WorldModify.loadSuccess = false;
                            try
                            {
                                binaryReader.Close();
                                fileStream.Close();
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            Main.worldName    = binaryReader.ReadString();
                            Main.worldID      = binaryReader.ReadInt32();
                            Main.leftWorld    = (float)binaryReader.ReadInt32();
                            Main.rightWorld   = (float)binaryReader.ReadInt32();
                            Main.topWorld     = (float)binaryReader.ReadInt32();
                            Main.bottomWorld  = (float)binaryReader.ReadInt32();
                            Main.maxTilesY    = binaryReader.ReadInt32();
                            Main.maxTilesX    = binaryReader.ReadInt32();
                            Main.maxSectionsX = Main.maxTilesX / 200;
                            Main.maxSectionsY = Main.maxTilesY / 150;
                            clearWorld();
                            Main.spawnTileX   = binaryReader.ReadInt32();
                            Main.spawnTileY   = binaryReader.ReadInt32();
                            Main.worldSurface = binaryReader.ReadDouble();
                            Main.rockLayer    = binaryReader.ReadDouble();
                            tempTime          = binaryReader.ReadDouble();
                            tempDayTime       = binaryReader.ReadBoolean();
                            tempMoonPhase     = binaryReader.ReadInt32();
                            tempBloodMoon     = binaryReader.ReadBoolean();
                            Main.dungeonX     = binaryReader.ReadInt32();
                            Main.dungeonY     = binaryReader.ReadInt32();
                            NPC.downedBoss1   = binaryReader.ReadBoolean();
                            NPC.downedBoss2   = binaryReader.ReadBoolean();
                            NPC.downedBoss3   = binaryReader.ReadBoolean();
                            if (Terraria_Release >= 29)
                            {
                                NPC.savedGoblin = binaryReader.ReadBoolean();
                                NPC.savedWizard = binaryReader.ReadBoolean();
                                if (Terraria_Release >= 34)
                                {
                                    NPC.savedMech = binaryReader.ReadBoolean();
                                }
                                NPC.downedGoblins = binaryReader.ReadBoolean();
                            }
                            if (Terraria_Release >= 32)
                            {
                                NPC.downedClown = binaryReader.ReadBoolean();
                            }
                            WorldModify.shadowOrbSmashed = binaryReader.ReadBoolean();
                            WorldModify.spawnMeteor      = binaryReader.ReadBoolean();
                            WorldModify.shadowOrbCount   = (int)binaryReader.ReadByte();
                            if (Terraria_Release >= 23)
                            {
                                WorldModify.altarCount = binaryReader.ReadInt32();
                                Main.hardMode          = binaryReader.ReadBoolean();
                            }
                            Main.invasionDelay = binaryReader.ReadInt32();
                            Main.invasionSize  = binaryReader.ReadInt32();
                            Main.invasionType  = binaryReader.ReadInt32();
                            Main.invasionX     = binaryReader.ReadDouble();

                            using (var prog = new ProgressLogger(Main.maxTilesX - 1, "Loading world tiles"))
                            {
                                for (int j = 0; j < Main.maxTilesX; j++)
                                {
                                    prog.Value = j;

                                    for (int k = 0; k < Main.maxTilesY; k++)
                                    {
                                        Main.tile.At(j, k).SetActive(binaryReader.ReadBoolean());
                                        if (Main.tile.At(j, k).Active)
                                        {
                                            Main.tile.At(j, k).SetType(binaryReader.ReadByte());
                                            if (Main.tileFrameImportant[(int)Main.tile.At(j, k).Type])
                                            {
                                                Main.tile.At(j, k).SetFrameX(binaryReader.ReadInt16());
                                                Main.tile.At(j, k).SetFrameY(binaryReader.ReadInt16());
                                            }
                                            else
                                            {
                                                Main.tile.At(j, k).SetFrameX(-1);
                                                Main.tile.At(j, k).SetFrameY(-1);
                                            }
                                        }
                                        if (Terraria_Release <= 25)
                                        {
                                            Main.tile.At(j, k).SetLighted(binaryReader.ReadBoolean());
                                        }
                                        if (binaryReader.ReadBoolean())
                                        {
                                            Main.tile.At(j, k).SetWall(binaryReader.ReadByte());
//											if (Main.tile.At(j, k).Wall == 7)
//												Main.tile.At(j, k).SetWall (17);
                                        }
                                        if (binaryReader.ReadBoolean())
                                        {
                                            Main.tile.At(j, k).SetLiquid(binaryReader.ReadByte());
                                            Main.tile.At(j, k).SetLava(binaryReader.ReadBoolean());
                                        }
                                        if (Terraria_Release >= 33)
                                        {
                                            Main.tile.At(j, k).SetWire(binaryReader.ReadBoolean());
                                        }
                                        if (Terraria_Release >= 25)
                                        {
                                            int num3 = (int)binaryReader.ReadInt16();
                                            if (num3 > 0)
                                            {
                                                for (int l = k + 1; l < k + num3 + 1; l++)
                                                {
                                                    Main.tile.At(j, l).SetActive(Main.tile.At(j, k).Active);
                                                    Main.tile.At(j, l).SetType(Main.tile.At(j, k).Type);
                                                    Main.tile.At(j, l).SetWall(Main.tile.At(j, k).Wall);
                                                    Main.tile.At(j, l).SetFrameX(Main.tile.At(j, k).FrameX);
                                                    Main.tile.At(j, l).SetFrameY(Main.tile.At(j, k).FrameY);
                                                    Main.tile.At(j, l).SetLiquid(Main.tile.At(j, k).Liquid);
                                                    Main.tile.At(j, l).SetLava(Main.tile.At(j, k).Lava);
                                                    Main.tile.At(j, l).SetWire(Main.tile.At(j, k).Wire);
                                                }
                                                k += num3;
                                            }
                                        }
                                    }
                                }
                            }

                            for (int l = 0; l < 1000; l++)
                            {
                                if (binaryReader.ReadBoolean())
                                {
                                    Main.chest[l]   = new Chest();
                                    Main.chest[l].x = binaryReader.ReadInt32();
                                    Main.chest[l].y = binaryReader.ReadInt32();
                                    for (int m = 0; m < Chest.MAX_ITEMS; m++)
                                    {
                                        Main.chest[l].contents[m] = new Item();
                                        int stack = binaryReader.ReadByte();
                                        if (stack > 0)
                                        {
                                            string defaults = Item.VersionName(binaryReader.ReadString(), Terraria_Release);
                                            Main.chest[l].contents[m]       = Registries.Item.Create(defaults, stack);
                                            Main.chest[m].contents[m].Stack = (int)stack;
                                            if (Terraria_Release >= 36)
                                            {
                                                Main.chest[m].contents[m].SetPrefix((int)binaryReader.ReadByte());
                                            }
                                        }
                                    }
                                }
                            }
                            for (int n = 0; n < 1000; n++)
                            {
                                if (binaryReader.ReadBoolean())
                                {
                                    string text = binaryReader.ReadString();
                                    int    num3 = binaryReader.ReadInt32();
                                    int    num4 = binaryReader.ReadInt32();
                                    if (Main.tile.At(num3, num4).Active&& (Main.tile.At(num3, num4).Type == 55 || Main.tile.At(num3, num4).Type == 85))
                                    {
                                        Main.sign[n]      = new Sign();
                                        Main.sign[n].x    = num3;
                                        Main.sign[n].y    = num4;
                                        Main.sign[n].text = text;
                                    }
                                }
                            }
                            bool flag = binaryReader.ReadBoolean();
                            int  num5 = 0;
                            while (flag)
                            {
                                string NPCName = binaryReader.ReadString();
                                Main.npcs[num5]            = Registries.NPC.Create(NPCName);
                                Main.npcs[num5].Position.X = binaryReader.ReadSingle();
                                Main.npcs[num5].Position.Y = binaryReader.ReadSingle();
                                Main.npcs[num5].homeless   = binaryReader.ReadBoolean();
                                Main.npcs[num5].homeTileX  = binaryReader.ReadInt32();
                                Main.npcs[num5].homeTileY  = binaryReader.ReadInt32();
                                flag = binaryReader.ReadBoolean();
                                num5++;
                            }
                            if (Terraria_Release >= 31)
                            {
                                Main.chrName[17]  = binaryReader.ReadString();
                                Main.chrName[18]  = binaryReader.ReadString();
                                Main.chrName[19]  = binaryReader.ReadString();
                                Main.chrName[20]  = binaryReader.ReadString();
                                Main.chrName[22]  = binaryReader.ReadString();
                                Main.chrName[54]  = binaryReader.ReadString();
                                Main.chrName[38]  = binaryReader.ReadString();
                                Main.chrName[107] = binaryReader.ReadString();
                                Main.chrName[108] = binaryReader.ReadString();
                                if (Terraria_Release >= 35)
                                {
                                    Main.chrName[124] = binaryReader.ReadString();
                                }
                            }
                            if (Terraria_Release >= 7)
                            {
                                bool   flag2 = binaryReader.ReadBoolean();
                                string a     = binaryReader.ReadString();
                                int    num6  = binaryReader.ReadInt32();
                                if (!flag2 || !(a == Main.worldName) || num6 != Main.worldID)
                                {
                                    WorldModify.loadSuccess = false;
                                    WorldModify.loadFailed  = true;
                                    binaryReader.Close();
                                    fileStream.Close();
                                    return;
                                }
                                WorldModify.loadSuccess = true;
                            }
                            else
                            {
                                WorldModify.loadSuccess = true;
                            }
                            binaryReader.Close();
                            fileStream.Close();

                            if (!WorldModify.loadFailed && WorldModify.loadSuccess)
                            {
                                WorldModify.gen = true;
                                for (int num9 = 0; num9 < Main.maxTilesX; num9++)
                                {
                                    float num10 = (float)num9 / (float)Main.maxTilesX;
                                    WorldModify.statusText = "Checking tile alignment: " + (int)(num10 * 100f + 1f) + "%";
                                    WorldModify.CountTiles(num9);
                                }
                                WorldModify.waterLine = Main.maxTilesY;
                                NPC.SetNames();
                                Liquid.QuickWater(2, -1, -1);
                                WorldModify.WaterCheck();
                                int num11 = 0;
                                Liquid.quickSettle = true;
                                int   num12 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                                float num13 = 0f;

                                using (var prog = new ProgressLogger(100, "Settling liquids"))
                                    while (Liquid.numLiquid > 0 && num11 < 100000)
                                    {
                                        num11++;
                                        float num14 = (float)(num12 - (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer)) / (float)num12;
                                        if (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer > num12)
                                        {
                                            num12 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                                        }
                                        if (num14 > num13)
                                        {
                                            num13 = num14;
                                        }
                                        else
                                        {
                                            num14 = num13;
                                        }

                                        prog.Value = (int)(num14 * 50f + 50f);

                                        Liquid.UpdateLiquid();
                                    }
                                Liquid.quickSettle = false;

                                ProgramLog.Log("Performing Water Check");
                                WorldModify.WaterCheck();
                                WorldModify.gen = false;
                            }
                        }
                    }
                    catch
                    {
                        WorldModify.loadFailed  = true;
                        WorldModify.loadSuccess = false;
                        try
                        {
                            binaryReader.Close();
                            fileStream.Close();
                        }
                        catch
                        {
                        }
                        return;
                    }
                }
            }

            if (Main.worldName == null || Main.worldName == "")
            {
                Main.worldName = System.IO.Path.GetFileNameWithoutExtension(LoadPath);
            }

            Statics.WorldLoaded = true;

            PluginManager.NotifyWorldLoaded();

            var ctx = new HookContext
            {
            };

            var args = new HookArgs.WorldLoaded
            {
                Height = Main.maxTilesY,
                Width  = Main.maxTilesX,
            };

            HookPoints.WorldLoaded.Invoke(ref ctx, ref args);
        }
        public static void loadWorld(bool loadFromCloud)
        {
            MainCallback.WorldLoadBegin();
            WorldFile.IsWorldOnCloud = loadFromCloud;
            Main.checkXMas();
            Main.checkHalloween();
            bool flag = loadFromCloud && SocialAPI.Cloud != null;

            if (!FileUtilities.Exists(Main.worldPathName, flag) && Main.autoGen)
            {
                if (!flag)
                {
                    for (int i = Main.worldPathName.Length - 1; i >= 0; i--)
                    {
                        if (Main.worldPathName.Substring(i, 1) == string.Concat(Path.DirectorySeparatorChar))
                        {
                            string path = Main.worldPathName.Substring(0, i);
                            Directory.CreateDirectory(path);
                            break;
                        }
                    }
                }
                WorldGen.clearWorld();
                WorldGen.generateWorld(-1, Main.AutogenProgress);
                WorldFile.saveWorld();
            }
            if (WorldGen.genRand == null)
            {
                WorldGen.genRand = new Random((int)DateTime.Now.Ticks);
            }
            byte[] buffer = FileUtilities.ReadAllBytes(Main.worldPathName, flag);
            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                using (BinaryReader binaryReader = new BinaryReader(memoryStream))
                {
                    try
                    {
                        WorldGen.loadFailed  = false;
                        WorldGen.loadSuccess = false;
                        int num = binaryReader.ReadInt32();
                        WorldFile.versionNumber = num;
                        int num2;
                        if (num <= 87)
                        {
                            num2 = WorldFile.LoadWorld_Version1(binaryReader);
                        }
                        else
                        {
                            num2 = WorldFile.LoadWorld_Version2(binaryReader);
                        }
                        if (num < 141)
                        {
                            if (!loadFromCloud)
                            {
                                Main.ActiveWorldFileData.CreationTime = File.GetCreationTime(Main.worldPathName);
                            }
                            else
                            {
                                Main.ActiveWorldFileData.CreationTime = DateTime.Now;
                            }
                        }
                        binaryReader.Close();
                        memoryStream.Close();
                        if (num2 != 0)
                        {
                            WorldGen.loadFailed = true;
                        }
                        else
                        {
                            WorldGen.loadSuccess = true;
                        }
                        if (WorldGen.loadFailed || !WorldGen.loadSuccess)
                        {
                            return;
                        }
                        WorldGen.gen       = true;
                        WorldGen.waterLine = Main.maxTilesY;
                        Liquid.QuickWater(2, -1, -1);
                        WorldGen.WaterCheck();
                        int num3 = 0;
                        Liquid.quickSettle = true;
                        int   num4 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                        float num5 = 0;
                        while (Liquid.numLiquid > 0 && num3 < 100000)
                        {
                            num3++;
                            float num6 = (float)(num4 - (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer)) / (float)num4;
                            if (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer > num4)
                            {
                                num4 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                            }
                            if (num6 > num5)
                            {
                                num5 = num6;
                            }
                            else
                            {
                                num6 = num5;
                            }
                            Main.statusText = string.Concat(new object[]
                            {
                                Lang.gen[27],
                                " ",
                                (int)(num6 * 100 / 2 + 50),
                                "%"
                            });
                            Liquid.UpdateLiquid();
                        }
                        Liquid.quickSettle  = false;
                        Main.weatherCounter = WorldGen.genRand.Next(3600, 18000);
                        Cloud.resetClouds();
                        WorldGen.WaterCheck();
                        WorldGen.gen = false;
                        NPC.setFireFlyChance();
                        MainCallback.WorldLoadEnd();
                        Main.InitLifeBytes();
                        if (Main.slimeRainTime > 0)
                        {
                            Main.StartSlimeRain(false);
                        }
                        NPC.setWorldMonsters();
                    }
                    catch (Exception e)
                    {
                        WorldGen.loadFailed  = true;
                        WorldGen.loadSuccess = false;
                        try
                        {
                            binaryReader.Close();
                            memoryStream.Close();
                        }
                        catch
                        {
                        }
                        Console.WriteLine(e);
                        return;
                    }
                }
            }
//            if (WorldFile.OnWorldLoad != null)
//            {
//                WorldFile.OnWorldLoad.Invoke();
//            }
        }
        public static void MuddifyShrines()
        {
            Liquid.QuickWater(3);
            WorldGen.WaterCheck();
            int num78 = 0;

            Liquid.quickSettle = true;
            while (num78 < 10)
            {
                int num79 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                num78++;
                float num80 = 0f;
                while (Liquid.numLiquid > 0)
                {
                    float num81 = (float)(num79 - (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer)) / (float)num79;
                    if (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer > num79)
                    {
                        num79 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                    }
                    if (num81 > num80)
                    {
                        num80 = num81;
                    }
                    else
                    {
                        num81 = num80;
                    }
                    if (num78 == 1)
                    {
                        //progress.Set(num81 / 3f + 0.33f);
                    }
                    int num82 = 10;
                    if (num78 > num82)
                    {
                        num82 = num78;
                    }
                    Liquid.UpdateLiquid();
                }
                WorldGen.WaterCheck();
            }
            Liquid.quickSettle = false;



            foreach (List <Point> waterPoints in eachShrineWater)
            {
                int indexWaterTile = 0;
                foreach (Point floodedTilePoint in waterPoints.Distinct().Where(testby => Main.tile[testby.X, testby.Y].liquid > 250).OrderBy(testby => 100000 - testby.Y + WorldGen.genRand.Next(-4, 4)))
                {
                    if (indexWaterTile < waterPoints.Count / 2)
                    {
                        Tile tileAbove = Framing.GetTileSafely(floodedTilePoint.X, floodedTilePoint.Y - WorldGen.genRand.Next(2, 5));
                        if (tileAbove.liquid > 250)
                        {
                            Tile tile = Framing.GetTileSafely(floodedTilePoint.X, floodedTilePoint.Y);
                            if (!tile.active() || Main.tileCut[tile.type])
                            {
                                WorldGen.PlaceTile(floodedTilePoint.X, floodedTilePoint.Y, ModContent.TileType <MoistSand>(), false, true);
                            }
                        }
                    }
                    //indexWaterTile += 1;
                }
            }
        }
Ejemplo n.º 8
0
        private static void LoadWorldDirect(bool loadFromCloud)
        {
            WorldFile.IsWorldOnCloud = loadFromCloud;
            Main.checkXMas();
            Main.checkHalloween();
            bool flag = loadFromCloud && SocialAPI.Cloud != null;

            if (!FileUtilities.Exists(Main.worldPathName, flag) && Main.autoGen)
            {
                if (!flag)
                {
                    for (int i = Main.worldPathName.Length - 1; i >= 0; i--)
                    {
                        if (Main.worldPathName.Substring(i, 1) == (Path.DirectorySeparatorChar.ToString() ?? ""))
                        {
                            Directory.CreateDirectory(Main.worldPathName.Substring(0, i));
                            break;
                        }
                    }
                }
                WorldGen.clearWorld();
                Main.ActiveWorldFileData = WorldFile.CreateMetadata((Main.worldName == "") ? "World" : Main.worldName, flag, Main.expertMode);
                string text = (Main.AutogenSeedName ?? "").Trim();
                if (text.Length == 0)
                {
                    Main.ActiveWorldFileData.SetSeedToRandom();
                }
                else
                {
                    Main.ActiveWorldFileData.SetSeed(text);
                }
                WorldGen.generateWorld(Main.ActiveWorldFileData.Seed, Main.AutogenProgress);
                WorldFile.saveWorld();
            }
            using (MemoryStream memoryStream = new MemoryStream(FileUtilities.ReadAllBytes(Main.worldPathName, flag)))
            {
                using (BinaryReader binaryReader = new BinaryReader(memoryStream))
                {
                    try
                    {
                        WorldGen.loadFailed  = false;
                        WorldGen.loadSuccess = false;
                        int num = WorldFile.versionNumber = binaryReader.ReadInt32();
                        int num2;
                        if (num <= 87)
                        {
                            // Not supported
                            num2 = WorldFile.LoadWorld_Version1(binaryReader);
                        }
                        else
                        {
                            num2 = LoadWorld_Version2(binaryReader);
                        }
                        if (num < 141)
                        {
                            if (!loadFromCloud)
                            {
                                Main.ActiveWorldFileData.CreationTime = File.GetCreationTime(Main.worldPathName);
                            }
                            else
                            {
                                Main.ActiveWorldFileData.CreationTime = DateTime.Now;
                            }
                        }
                        binaryReader.Close();
                        memoryStream.Close();
                        if (num2 != 0)
                        {
                            WorldGen.loadFailed = true;
                        }
                        else
                        {
                            WorldGen.loadSuccess = true;
                        }
                        if (WorldGen.loadFailed || !WorldGen.loadSuccess)
                        {
                            return;
                        }
                        WorldGen.gen       = true;
                        WorldGen.waterLine = Main.maxTilesY;
                        Liquid.QuickWater(2, -1, -1);
                        WorldGen.WaterCheck();
                        int num3 = 0;
                        Liquid.quickSettle = true;
                        int   num4 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                        float num5 = 0f;
                        while (Liquid.numLiquid > 0 && num3 < 100000)
                        {
                            num3++;
                            float num6 = (float)(num4 - (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer)) / (float)num4;
                            if (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer > num4)
                            {
                                num4 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                            }
                            if (num6 > num5)
                            {
                                num5 = num6;
                            }
                            else
                            {
                                num6 = num5;
                            }

                            SetStatusText(string.Concat(new object[]
                            {
                                Lang.gen[27].Value,
                                " ",
                                (int)(num6 * 100f / 2f + 50f),
                                "%"
                            }));
                            Liquid.UpdateLiquid();
                        }
                        Liquid.quickSettle  = false;
                        Main.weatherCounter = WorldGen.genRand.Next(3600, 18000);
                        Cloud.resetClouds();
                        WorldGen.WaterCheck();
                        WorldGen.gen = false;
                        NPC.setFireFlyChance();
                        Main.InitLifeBytes();
                        if (Main.slimeRainTime > 0.0)
                        {
                            Main.StartSlimeRain(false);
                        }
                        NPC.setWorldMonsters();
                    }
                    catch (Exception value)
                    {
                        WorldGen.loadFailed  = true;
                        WorldGen.loadSuccess = false;
                        System.Console.WriteLine(value);
                        try
                        {
                            binaryReader.Close();
                            memoryStream.Close();
                        }
                        catch
                        {
                        }
                        return;
                    }
                }
            }

            EventInfo eventOnWorldLoad = typeof(WorldFile).GetEvent("OnWorldLoad", BindingFlags.Public | BindingFlags.Static);

            eventOnWorldLoad.GetRaiseMethod()?.Invoke(null, new object[] { });
            //if (WorldFile.OnWorldLoad != null)
            //WorldFile.OnWorldLoad();
        }
        public static void LoadWorld(Func <Int32, Int32, ITile> TileRefs, ISandbox sandbox, string LoadPath)
        {
            if (TileRefs == null)
            {
                TileRefs = TileCollection.ITileAt;
            }

            Main.checkXmas();

            using (FileStream fileStream = new FileStream(LoadPath, FileMode.Open))
            {
                using (BinaryReader binaryReader = new BinaryReader(fileStream))
                {
                    try
                    {
                        WorldModify.loadFailed  = false;
                        WorldModify.loadSuccess = false;
                        int Terraria_Release = binaryReader.ReadInt32();
                        if (Terraria_Release > Statics.CURRENT_TERRARIA_RELEASE)
                        {
                            WorldModify.loadFailed  = true;
                            WorldModify.loadSuccess = false;
                            try
                            {
                                binaryReader.Close();
                                fileStream.Close();
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            Main.worldName    = binaryReader.ReadString();
                            Main.worldID      = binaryReader.ReadInt32();
                            Main.leftWorld    = (float)binaryReader.ReadInt32();
                            Main.rightWorld   = (float)binaryReader.ReadInt32();
                            Main.topWorld     = (float)binaryReader.ReadInt32();
                            Main.bottomWorld  = (float)binaryReader.ReadInt32();
                            Main.maxTilesY    = binaryReader.ReadInt32();
                            Main.maxTilesX    = binaryReader.ReadInt32();
                            Main.maxSectionsX = Main.maxTilesX / 200;
                            Main.maxSectionsY = Main.maxTilesY / 150;
                            ClearWorld();
                            Main.spawnTileX   = binaryReader.ReadInt32();
                            Main.spawnTileY   = binaryReader.ReadInt32();
                            Main.worldSurface = binaryReader.ReadDouble();
                            Main.rockLayer    = binaryReader.ReadDouble();
                            tempTime          = binaryReader.ReadDouble();
                            tempDayTime       = binaryReader.ReadBoolean();
                            tempMoonPhase     = binaryReader.ReadInt32();
                            tempBloodMoon     = binaryReader.ReadBoolean();
                            Main.dungeonX     = binaryReader.ReadInt32();
                            Main.dungeonY     = binaryReader.ReadInt32();
                            NPC.downedBoss1   = binaryReader.ReadBoolean();
                            NPC.downedBoss2   = binaryReader.ReadBoolean();
                            NPC.downedBoss3   = binaryReader.ReadBoolean();
                            if (Terraria_Release >= 29)
                            {
                                NPC.savedGoblin = binaryReader.ReadBoolean();
                                NPC.savedWizard = binaryReader.ReadBoolean();
                                if (Terraria_Release >= 34)
                                {
                                    NPC.savedMech = binaryReader.ReadBoolean();
                                }
                                NPC.downedGoblins = binaryReader.ReadBoolean();
                            }
                            if (Terraria_Release >= 32)
                            {
                                NPC.downedClown = binaryReader.ReadBoolean();
                            }
                            if (Terraria_Release >= 37)
                            {
                                NPC.downedFrost = binaryReader.ReadBoolean();
                            }
                            WorldModify.shadowOrbSmashed = binaryReader.ReadBoolean();
                            WorldModify.spawnMeteor      = binaryReader.ReadBoolean();
                            WorldModify.shadowOrbCount   = (int)binaryReader.ReadByte();
                            if (Terraria_Release >= 23)
                            {
                                WorldModify.altarCount = binaryReader.ReadInt32();
                                Main.hardMode          = binaryReader.ReadBoolean();
                            }
                            Main.invasionDelay = binaryReader.ReadInt32();
                            Main.invasionSize  = binaryReader.ReadInt32();
                            Main.invasionType  = (InvasionType)binaryReader.ReadInt32();
                            Main.invasionX     = binaryReader.ReadDouble();

                            using (var prog = new ProgressLogger(Main.maxTilesX - 1, Languages.LoadingWorldTiles))
                            {
                                for (int j = 0; j < Main.maxTilesX; j++)
                                {
                                    prog.Value = j;

                                    for (int k = 0; k < Main.maxTilesY; k++)
                                    {
                                        Main.tile.At(j, k).SetActive(binaryReader.ReadBoolean());
                                        if (Main.tile.At(j, k).Active)
                                        {
                                            Main.tile.At(j, k).SetType(binaryReader.ReadByte());

                                            if (Main.tile.At(j, k).Type == 127)
                                            {
                                                Main.tile.At(j, k).SetActive(false);
                                            }

                                            if (Main.tileFrameImportant[(int)Main.tile.At(j, k).Type])
                                            {
                                                if (Terraria_Release < 28 && Main.tile.At(j, k).Type == 4)
                                                {
                                                    Main.tile.At(j, k).SetFrameX(0);
                                                    Main.tile.At(j, k).SetFrameY(0);
                                                }
                                                else
                                                {
                                                    Main.tile.At(j, k).SetFrameX(binaryReader.ReadInt16());
                                                    Main.tile.At(j, k).SetFrameY(binaryReader.ReadInt16());
                                                    if (Main.tile.At(j, k).Type == 144)
                                                    {
                                                        Main.tile.At(j, k).SetFrameY(0);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                Main.tile.At(j, k).SetFrameX(-1);
                                                Main.tile.At(j, k).SetFrameY(-1);
                                            }
                                        }
                                        if (Terraria_Release <= 25)
                                        {
                                            /*Main.tile.At(j, k).SetLighted(*/
                                            binaryReader.ReadBoolean();
                                            /*);*/
                                        }
                                        if (binaryReader.ReadBoolean())
                                        {
                                            Main.tile.At(j, k).SetWall(binaryReader.ReadByte());
                                            //											if (Main.tile.At(j, k).Wall == 7)
                                            //												Main.tile.At(j, k).SetWall (17);
                                        }
                                        if (binaryReader.ReadBoolean())
                                        {
                                            Main.tile.At(j, k).SetLiquid(binaryReader.ReadByte());
                                            Main.tile.At(j, k).SetLava(binaryReader.ReadBoolean());
                                        }
                                        if (Terraria_Release >= 33)
                                        {
                                            Main.tile.At(j, k).SetWire(binaryReader.ReadBoolean());
                                        }
                                        if (Terraria_Release >= 25)
                                        {
                                            int num3 = (int)binaryReader.ReadInt16();
                                            if (num3 > 0)
                                            {
                                                for (int l = k + 1; l < k + num3 + 1; l++)
                                                {
                                                    Main.tile.At(j, l).SetActive(Main.tile.At(j, k).Active);
                                                    Main.tile.At(j, l).SetType(Main.tile.At(j, k).Type);
                                                    Main.tile.At(j, l).SetWall(Main.tile.At(j, k).Wall);
                                                    Main.tile.At(j, l).SetFrameX(Main.tile.At(j, k).FrameX);
                                                    Main.tile.At(j, l).SetFrameY(Main.tile.At(j, k).FrameY);
                                                    Main.tile.At(j, l).SetLiquid(Main.tile.At(j, k).Liquid);
                                                    Main.tile.At(j, l).SetLava(Main.tile.At(j, k).Lava);
                                                    Main.tile.At(j, l).SetWire(Main.tile.At(j, k).Wire);
                                                }
                                                k += num3;
                                            }
                                        }
                                    }
                                }
                            }

                            for (int l = 0; l < Main.MAX_CHESTS; l++)
                            {
                                if (binaryReader.ReadBoolean())
                                {
                                    var x = binaryReader.ReadInt32();
                                    var y = binaryReader.ReadInt32();
                                    Main.chest[l] = Chest.InitializeChest(x, y);
                                    for (int m = 0; m < Chest.MAX_ITEMS; m++)
                                    {
                                        //Main.chest[l].contents[m] = new Item();
                                        int stack = binaryReader.ReadByte();
                                        if (stack > 0)
                                        {
                                            if (Terraria_Release >= 38)
                                            {
                                                Main.chest[l].contents[m]       = Item.netDefaults(binaryReader.ReadInt32());
                                                Main.chest[l].contents[m].Stack = stack;
                                            }
                                            else
                                            {
                                                string defaults = Item.VersionName(binaryReader.ReadString(), Terraria_Release);
                                                Main.chest[l].contents[m] = Registries.Item.Create(defaults, stack);
                                            }

                                            if (Terraria_Release >= 36)
                                            {
                                                Main.chest[l].contents[m].SetPrefix((int)binaryReader.ReadByte());
                                            }
                                        }
                                    }
                                }
                            }
                            for (int n = 0; n < Main.MAX_SIGNS; n++)
                            {
                                if (binaryReader.ReadBoolean())
                                {
                                    string text = binaryReader.ReadString();
                                    int    x    = binaryReader.ReadInt32();
                                    int    y    = binaryReader.ReadInt32();
                                    if (Main.tile.At(x, y).Active&& (Main.tile.At(x, y).Type == 55 || Main.tile.At(x, y).Type == 85))
                                    {
                                        Main.sign[n]      = new Sign();
                                        Main.sign[n].x    = x;
                                        Main.sign[n].y    = y;
                                        Main.sign[n].text = text;
                                    }
                                }
                            }
                            bool flag = binaryReader.ReadBoolean();
                            int  num5 = 0;
                            while (flag)
                            {
                                string NPCName = binaryReader.ReadString();
                                Main.npcs[num5]            = Registries.NPC.Create(NPCName);
                                Main.npcs[num5].Position.X = binaryReader.ReadSingle();
                                Main.npcs[num5].Position.Y = binaryReader.ReadSingle();
                                Main.npcs[num5].homeless   = binaryReader.ReadBoolean();
                                Main.npcs[num5].homeTileX  = binaryReader.ReadInt32();
                                Main.npcs[num5].homeTileY  = binaryReader.ReadInt32();
                                flag = binaryReader.ReadBoolean();
                                num5++;
                            }
                            if (Terraria_Release >= 31)
                            {
                                Main.chrName[17]  = binaryReader.ReadString();
                                Main.chrName[18]  = binaryReader.ReadString();
                                Main.chrName[19]  = binaryReader.ReadString();
                                Main.chrName[20]  = binaryReader.ReadString();
                                Main.chrName[22]  = binaryReader.ReadString();
                                Main.chrName[54]  = binaryReader.ReadString();
                                Main.chrName[38]  = binaryReader.ReadString();
                                Main.chrName[107] = binaryReader.ReadString();
                                Main.chrName[108] = binaryReader.ReadString();
                                if (Terraria_Release >= 35)
                                {
                                    Main.chrName[124] = binaryReader.ReadString();
                                }
                            }
                            if (Terraria_Release >= 7)
                            {
                                bool   flag2     = binaryReader.ReadBoolean();
                                string worldName = binaryReader.ReadString();
                                int    num6      = binaryReader.ReadInt32();
                                if (!flag2 || !(worldName == Main.worldName) || num6 != Main.worldID)
                                {
                                    WorldModify.loadSuccess = false;
                                    WorldModify.loadFailed  = true;
                                    binaryReader.Close();
                                    fileStream.Close();
                                    return;
                                }
                                WorldModify.loadSuccess = true;
                            }
                            else
                            {
                                WorldModify.loadSuccess = true;
                            }
                            binaryReader.Close();
                            fileStream.Close();

                            if (!WorldModify.loadFailed && WorldModify.loadSuccess)
                            {
                                WorldModify.gen = true;
                                using (var prog = new ProgressLogger(Main.maxTilesX, Languages.CheckingTileAlignment))
                                {
                                    for (int num9 = 0; num9 < Main.maxTilesX; num9++)
                                    {
                                        float num10 = (float)num9 / (float)Main.maxTilesX;
                                        //WorldModify.statusText = "Checking tile alignment: " + (int)(num10 * 100f + 1f) + "%";
                                        WorldModify.CountTiles(TileRefs, num9);
                                        prog.Value++;
                                    }
                                }

                                //ProgramLog.Log("Loading NPC Names...");
                                //NPC.SetNames();

                                ProgramLog.Log(Languages.Water_PreparingLiquids);
                                WorldModify.waterLine = Main.maxTilesY;
                                Liquid.QuickWater(TileRefs, sandbox, 2, -1, -1);
                                WorldModify.WaterCheck(TileRefs, sandbox);

                                int num11 = 0;
                                Liquid.quickSettle = true;
                                int   num12 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                                float num13 = 0f;

                                var pres = Liquid.numLiquid;
                                using (var prog = new ProgressLogger(Liquid.maxLiquid, Languages.Generation_SettlingLiquids))
                                {
                                    while (Liquid.numLiquid > 0 && num11 < 100000)
                                    {
                                        num11++;
                                        float num14 = (float)(num12 - (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer)) / (float)num12;
                                        if (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer > num12)
                                        {
                                            num12 = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                                        }
                                        if (num14 > num13)
                                        {
                                            num13 = num14;
                                        }
                                        else
                                        {
                                            num14 = num13;
                                        }

                                        prog.Value = Liquid.numLiquid;

                                        Liquid.UpdateLiquid(TileRefs, sandbox);
                                    }
                                }

                                Liquid.quickSettle = false;

                                ProgramLog.Log(Languages.Water_PerformingWaterCheck);
                                WorldModify.WaterCheck(TileRefs, sandbox);
                                WorldModify.gen = false;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        WorldModify.loadFailed  = true;
                        WorldModify.loadSuccess = false;
                        try
                        {
                            binaryReader.Close();
                            fileStream.Close();
                        }
                        catch { }

                        ProgramLog.Error.Log(
                            String.Format("Error Loading world:\n{0}\nStack Trace: {1}", e, e.StackTrace)
                            );

                        return;
                    }
                }
            }

            if (String.IsNullOrEmpty(Main.worldName))
            {
                Main.worldName = System.IO.Path.GetFileNameWithoutExtension(LoadPath);
            }

            Statics.WorldLoaded = true;

            PluginManager.NotifyWorldLoaded();

            var ctx = new HookContext
            {
            };

            var args = new HookArgs.WorldLoaded
            {
                Height = Main.maxTilesY,
                Width  = Main.maxTilesX,
            };

            HookPoints.WorldLoaded.Invoke(ref ctx, ref args);
        }