diff --git a/Items/LabFinders/OnyxSeekingMechanism.cs b/Items/LabFinders/OnyxSeekingMechanism.cs new file mode 100644 index 0000000000..b0f54b1e88 --- /dev/null +++ b/Items/LabFinders/OnyxSeekingMechanism.cs @@ -0,0 +1,46 @@ +using CalamityMod.Projectiles.Typeless; +using CalamityMod.Rarities; +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.LabFinders +{ + public class OnyxSeekingMechanism : ModItem + { + public override void SetStaticDefaults() + { + SacrificeTotal = 1; + DisplayName.SetDefault("Onyx Seeking Mechanism"); + Tooltip.SetDefault("Moves swiftly towards a lab within the caverns"); + } + + public override void SetDefaults() + { + Item.width = 24; + Item.height = 26; + Item.noUseGraphic = true; + Item.useStyle = ItemUseStyleID.Swing; + Item.useTime = Item.useAnimation = 36; + Item.shoot = ModContent.ProjectileType(); + Item.Calamity().MaxCharge = 100; + Item.Calamity().ChargePerUse = 10; + Item.Calamity().UsesCharge = true; + Item.rare = ModContent.RarityType(); + } + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0 && CalamityWorld.CavernLabCenter != Vector2.Zero; + + public override void AddRecipes() + { + //Temporary recipe probably + CreateRecipe(). + AddIngredient(). + AddIngredient(ItemID.Obsidian, 25). + AddTile(TileID.Anvils). + Register(); + } + } +} diff --git a/Items/LabFinders/OnyxSeekingMechanism.png b/Items/LabFinders/OnyxSeekingMechanism.png new file mode 100644 index 0000000000..1eb3900463 Binary files /dev/null and b/Items/LabFinders/OnyxSeekingMechanism.png differ diff --git a/Projectiles/Typeless/OnyxLabSeeker.cs b/Projectiles/Typeless/OnyxLabSeeker.cs new file mode 100644 index 0000000000..c85aa109e8 --- /dev/null +++ b/Projectiles/Typeless/OnyxLabSeeker.cs @@ -0,0 +1,63 @@ +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Typeless +{ + public class OnyxLabSeeker : ModProjectile + { + public ref float Time => ref Projectile.ai[0]; + public override string Texture => "CalamityMod/Items/LabFinders/OnyxSeekingMechanism"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Seeking Mechanism"); + ProjectileID.Sets.TrailingMode[Projectile.type] = 1; + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20; + } + + public override void SetDefaults() + { + Projectile.width = Projectile.height = 24; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + Projectile.timeLeft = 300; + } + + public override void AI() => RedLabSeeker.Behavior(Projectile, CalamityWorld.CavernLabCenter, Color.Magenta, ref Time); + + public override void Kill(int timeLeft) + { + for (int i = 0; i < 8; i++) + { + Dust dust = Dust.NewDustPerfect(Projectile.Center + Main.rand.NextVector2Circular(16f, 16f), 267); + dust.color = Color.Magenta; + dust.scale = Main.rand.NextFloat(0.95f, 1.25f); + dust.velocity = Main.rand.NextVector2Circular(2.5f, 2.5f); + dust.velocity.Y -= 1.5f; + dust.fadeIn = 1.2f; + dust.noGravity = true; + } + } + + public override bool? CanCutTiles() => false; + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = ModContent.Request(Texture).Value; + if (Time > 80f && Projectile.ai[1] == 0f) + { + for (int i = 0; i < 24; i += 2) + { + Vector2 drawPosition = Projectile.Center - Projectile.velocity.SafeNormalize(Vector2.Zero) * i * Utils.GetLerpValue(80f, 125f, Time, true) * 25f - Main.screenPosition; + Main.EntitySpriteDraw(texture, drawPosition, null, Projectile.GetAlpha(lightColor) * (1f - i / 24f), Projectile.rotation, texture.Size() * 0.5f, Projectile.scale, SpriteEffects.None, 0); + } + } + return true; + } + } +} diff --git a/Schematics/DraedonsLab_Cavern.csch b/Schematics/DraedonsLab_Cavern.csch new file mode 100644 index 0000000000..f5358d0878 Binary files /dev/null and b/Schematics/DraedonsLab_Cavern.csch differ diff --git a/Schematics/DraedonsLab_CavernWorkshop.csch b/Schematics/DraedonsLab_CavernWorkshop.csch deleted file mode 100644 index d5f8e44c6b..0000000000 Binary files a/Schematics/DraedonsLab_CavernWorkshop.csch and /dev/null differ diff --git a/Schematics/DungeonArena.csch b/Schematics/DungeonArena.csch index 29364a0099..738055f6e6 100644 Binary files a/Schematics/DungeonArena.csch and b/Schematics/DungeonArena.csch differ diff --git a/Schematics/SchematicManager.cs b/Schematics/SchematicManager.cs index fb4db262ff..cc442fe462 100644 --- a/Schematics/SchematicManager.cs +++ b/Schematics/SchematicManager.cs @@ -34,6 +34,34 @@ namespace CalamityMod.Schematics internal const string IceLabKey = "Ice Laboratory"; internal const string IceLabFilename = "Schematics/DraedonsLab_Ice.csch"; + internal const string CavernLabKey = "Cavern Laboratory"; + internal const string CavernLabFilename = "Schematics/DraedonsLab_Cavern.csch"; + + internal const string CorruptionShrineKey = "Corruption Shrine"; + internal const string CorruptionShrineFilename = "Schematics/Shrine_Corruption.csch"; + + internal const string CrimsonShrineKey = "Crimson Shrine"; + internal const string CrimsonShrineFilename = "Schematics/Shrine_Crimson.csch"; + + internal const string DesertShrineKey = "Desert Shrine"; + internal const string DesertShrineFilename = "Schematics/Shrine_Desert.csch"; + + internal const string GraniteShrineKey = "Granite Shrine"; + internal const string GraniteShrineFilename = "Schematics/Shrine_Granite.csch"; + + internal const string IceShrineKey = "Ice Shrine"; + internal const string IceShrineFilename = "Schematics/Shrine_Ice.csch"; + + internal const string MarbleShrineKey = "Marble Shrine"; + internal const string MarbleShrineFilename = "Schematics/Shrine_Marble.csch"; + + internal const string MushroomShrineKey = "Mushroom Shrine"; + internal const string MushroomShrineFilename = "Schematics/Shrine_Mushroom.csch"; + + internal const string SurfaceShrineKey = "Surface Shrine"; + internal const string SurfaceShrineFilename = "Schematics/Shrine_Surface.csch"; + + internal const string AstralBeaconKey = "Astral Beacon"; internal const string AstralBeaconFilename = "Schematics/AstralBeacon.csch"; @@ -55,6 +83,17 @@ namespace CalamityMod.Schematics [PlagueLabKey] = CalamitySchematicIO.LoadSchematic(PlagueLabFilename), [HellLabKey] = CalamitySchematicIO.LoadSchematic(HellLabFilename), [IceLabKey] = CalamitySchematicIO.LoadSchematic(IceLabFilename), + [CavernLabKey] = CalamitySchematicIO.LoadSchematic(CavernLabFilename), + + // Shrine world gen structures + [CorruptionShrineKey] = CalamitySchematicIO.LoadSchematic(CorruptionShrineFilename), + [CrimsonShrineKey] = CalamitySchematicIO.LoadSchematic(CrimsonShrineFilename), + [DesertShrineKey] = CalamitySchematicIO.LoadSchematic(DesertShrineFilename), + [GraniteShrineKey] = CalamitySchematicIO.LoadSchematic(GraniteShrineFilename), + [IceShrineKey] = CalamitySchematicIO.LoadSchematic(IceShrineFilename), + [MarbleShrineKey] = CalamitySchematicIO.LoadSchematic(MarbleShrineFilename), + [MushroomShrineKey] = CalamitySchematicIO.LoadSchematic(MushroomShrineFilename), + [SurfaceShrineKey] = CalamitySchematicIO.LoadSchematic(SurfaceShrineFilename), // Astral world gen structures [AstralBeaconKey] = CalamitySchematicIO.LoadSchematic(AstralBeaconFilename), diff --git a/Schematics/Shrine_Corruption.csch b/Schematics/Shrine_Corruption.csch new file mode 100644 index 0000000000..1543395aa7 Binary files /dev/null and b/Schematics/Shrine_Corruption.csch differ diff --git a/Schematics/Shrine_Crimson.csch b/Schematics/Shrine_Crimson.csch index 48567cda53..998ec79a19 100644 Binary files a/Schematics/Shrine_Crimson.csch and b/Schematics/Shrine_Crimson.csch differ diff --git a/Schematics/Shrine_Desert.csch b/Schematics/Shrine_Desert.csch index 3fb5b215c8..37205a4d91 100644 Binary files a/Schematics/Shrine_Desert.csch and b/Schematics/Shrine_Desert.csch differ diff --git a/Schematics/Shrine_Granite.csch b/Schematics/Shrine_Granite.csch index 86a5596ceb..16c10690a2 100644 Binary files a/Schematics/Shrine_Granite.csch and b/Schematics/Shrine_Granite.csch differ diff --git a/Schematics/Shrine_Ice.csch b/Schematics/Shrine_Ice.csch new file mode 100644 index 0000000000..ad7c0cfb7d Binary files /dev/null and b/Schematics/Shrine_Ice.csch differ diff --git a/Schematics/Shrine_Marble.csch b/Schematics/Shrine_Marble.csch index 9268d43f24..98b301fda3 100644 Binary files a/Schematics/Shrine_Marble.csch and b/Schematics/Shrine_Marble.csch differ diff --git a/Schematics/Shrine_Mushroom.csch b/Schematics/Shrine_Mushroom.csch index ef2cb11c2f..c5444008c2 100644 Binary files a/Schematics/Shrine_Mushroom.csch and b/Schematics/Shrine_Mushroom.csch differ diff --git a/Schematics/Shrine_Snow.csch b/Schematics/Shrine_Snow.csch deleted file mode 100644 index 64b7d77797..0000000000 Binary files a/Schematics/Shrine_Snow.csch and /dev/null differ diff --git a/Schematics/Shrine_Surface.csch b/Schematics/Shrine_Surface.csch new file mode 100644 index 0000000000..3010472517 Binary files /dev/null and b/Schematics/Shrine_Surface.csch differ diff --git a/Schematics/SurfaceHouse_Snow_Mechanic.csch b/Schematics/SurfaceHouse_Snow_Mechanic.csch index 2ab500a194..8e66175a34 100644 Binary files a/Schematics/SurfaceHouse_Snow_Mechanic.csch and b/Schematics/SurfaceHouse_Snow_Mechanic.csch differ diff --git a/Systems/WorldgenManagementSystem.cs b/Systems/WorldgenManagementSystem.cs index b044664f6b..ac46cd156c 100644 --- a/Systems/WorldgenManagementSystem.cs +++ b/Systems/WorldgenManagementSystem.cs @@ -157,13 +157,6 @@ namespace CalamityMod.Systems })); } - tasks.Insert(++currentFinalIndex, new PassLegacy("Special Shrines", (progress, config) => - { - progress.Message = "Placing hidden shrines"; - UndergroundShrines.PlaceShrines(); - })); - - tasks.Insert(++currentFinalIndex, new PassLegacy("Draedon Structures", (progress, config) => { progress.Message = "Rust and Dust"; @@ -189,6 +182,9 @@ namespace CalamityMod.Systems DraedonStructures.PlacePlagueLab(out Point plaguePlacementPosition, workshopPositions, WorldGen.structures); workshopPositions.Add(plaguePlacementPosition); + DraedonStructures.PlaceCavernLab(out Point cavernPlacementPosition, workshopPositions, WorldGen.structures); + workshopPositions.Add(cavernPlacementPosition); + for (int i = 0; i < workshopCount; i++) { DraedonStructures.PlaceWorkshop(out Point placementPosition, workshopPositions, WorldGen.structures); @@ -200,6 +196,20 @@ namespace CalamityMod.Systems workshopPositions.Add(placementPosition); } })); + + tasks.Insert(++currentFinalIndex, new PassLegacy("Special Shrines", (progress, config) => + { + progress.Message = "Placing hidden shrines"; + + UndergroundShrines.PlaceCorruptionShrine(WorldGen.structures); + UndergroundShrines.PlaceCrimsonShrine(WorldGen.structures); + UndergroundShrines.PlaceDesertShrine(WorldGen.structures); + UndergroundShrines.PlaceGraniteShrine(WorldGen.structures); + UndergroundShrines.PlaceIceShrine(WorldGen.structures); + UndergroundShrines.PlaceMarbleShrine(WorldGen.structures); + UndergroundShrines.PlaceMushroomShrine(WorldGen.structures); + UndergroundShrines.PlaceSurfaceShrine(WorldGen.structures); + })); tasks.Insert(++currentFinalIndex, new PassLegacy("Abyss", (progress, config) => { diff --git a/Tiles/DraedonStructures/OnyxExcavatorTile.cs b/Tiles/DraedonStructures/OnyxExcavatorTile.cs new file mode 100644 index 0000000000..49025f1347 --- /dev/null +++ b/Tiles/DraedonStructures/OnyxExcavatorTile.cs @@ -0,0 +1,33 @@ +using CalamityMod.Items.Mounts; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ObjectData; + +namespace CalamityMod.Tiles.DraedonStructures +{ + public class OnyxExcavatorTile : ModTile + { + public override void SetStaticDefaults() + { + Main.tileFrameImportant[Type] = true; + Main.tileNoAttach[Type] = true; + Main.tileSpelunker[Type] = true; + TileObjectData.newTile.CopyFrom(TileObjectData.Style3x4); + TileObjectData.newTile.Width = 8; + TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16, 16 }; + TileObjectData.addTile(Type); + ModTranslation name = CreateMapEntryName(); + name.SetDefault("Onyx Excavator"); + AddMapEntry(new Color(128, 0, 128), name); + TileID.Sets.DisableSmartCursor[Type] = true; + } + + public override void KillMultiTile(int i, int j, int frameX, int frameY) + { + Item.NewItem(new EntitySource_TileBreak(i, j), i * 16, j * 16, 32, 16, ModContent.ItemType()); + } + } +} diff --git a/Tiles/DraedonStructures/OnyxExcavatorAmbient.png b/Tiles/DraedonStructures/OnyxExcavatorTile.png similarity index 100% rename from Tiles/DraedonStructures/OnyxExcavatorAmbient.png rename to Tiles/DraedonStructures/OnyxExcavatorTile.png diff --git a/World/CalamityWorld.cs b/World/CalamityWorld.cs index fceed6d708..c39aec4b13 100644 --- a/World/CalamityWorld.cs +++ b/World/CalamityWorld.cs @@ -83,6 +83,7 @@ namespace CalamityMod.World public static Vector2 JungleLabCenter; public static Vector2 HellLabCenter; public static Vector2 IceLabCenter; + public static Vector2 CavernLabCenter; #endregion } diff --git a/World/DraedonStructures.cs b/World/DraedonStructures.cs index 5535a192ef..ec53b825f5 100644 --- a/World/DraedonStructures.cs +++ b/World/DraedonStructures.cs @@ -15,7 +15,6 @@ using Terraria.ModLoader; using Terraria.WorldBuilding; using static CalamityMod.Schematics.SchematicManager; -using CalamityMod.Items.Potions.Alcohol; namespace CalamityMod.World { @@ -371,7 +370,6 @@ namespace CalamityMod.World placementPositionX = WorldGen.genRand.Next(ugDesert.Right - 10, ugDesert.Right + 20) - labWidth; int sunkenSeaY = 0; - bool foundPosition = false; //copied the desert position code from the sunken sea's generation so the lab always generates within the sunken sea properly for (int y = Main.maxTilesY - 200; y >= (Main.maxTilesY / 2) - 45; y--) @@ -388,10 +386,11 @@ namespace CalamityMod.World placementPoint = new Point(placementPositionX, placementPositionY); Vector2 schematicSize = new Vector2(schematic.GetLength(0), schematic.GetLength(1)); - int xCheckArea = 25; + /* //Disabled this specifically for the sunken sea lab, not sure if it's even needed since the lab now always places based on where the sunken sea is //this seems to work fine, but i dont want to delete it just in case + int xCheckArea = 25; bool shouldAvoidArea = false; float totalTiles = (schematicSize.X + xCheckArea * 2) * schematicSize.Y; @@ -646,5 +645,81 @@ namespace CalamityMod.World } } #endregion + + #region Cavern Lab + public static void FillCavernLaboratoryChest(Chest chest) + { + int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.EndurancePotion, ItemID.GravitationPotion, ItemID.HeartreachPotion, ItemID.LifeforcePotion); + List contents = new List() + { + new ChestItem(ModContent.ItemType(), WorldGen.genRand.Next(10, 17 + 1)), + new ChestItem(ModContent.ItemType(), WorldGen.genRand.Next(10, 15 + 1)), + new ChestItem(ItemID.Torch, WorldGen.genRand.Next(20, 40 + 1)), + new ChestItem(ItemID.GoldCoin, WorldGen.genRand.Next(8, 16 + 1)), + new ChestItem(ItemID.HealingPotion, WorldGen.genRand.Next(7, 10 + 1)), + new ChestItem(ItemID.Dynamite, WorldGen.genRand.Next(4, 6 + 1)), + new ChestItem(potionType, WorldGen.genRand.Next(4, 7 + 1)), + new ChestItem(ModContent.ItemType(), 1), + }; + + for (int i = 0; i < contents.Count; i++) + { + chest.item[i].SetDefaults(contents[i].Type); + chest.item[i].stack = contents[i].Stack; + } + } + public static void PlaceCavernLab(out Point placementPoint, List workshopPoints, StructureMap structures) + { + int tries = 0; + string mapKey = CavernLabKey; + + do + { + int placementPositionX = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.3f), (int)(Main.maxTilesX * 0.7f)); + int placementPositionY = WorldGen.genRand.Next((int)(Main.maxTilesY * 0.55f), (int)(Main.maxTilesY * 0.8f)); + + placementPoint = new Point(placementPositionX, placementPositionY); + Vector2 schematicSize = new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)); + int plainTilesInArea = 0; + int xCheckArea = 30; + bool canGenerateInLocation = true; + + // new Vector2 is used here since a lambda expression cannot capture a ref, out, or in parameter. + bool nearbyOtherWorkshop = workshopPoints.Any(point => Vector2.Distance(point.ToVector2(), new Vector2(placementPositionX, placementPositionY)) < 240f); + float totalTiles = (schematicSize.X + xCheckArea * 2) * schematicSize.Y; + for (int x = placementPoint.X - xCheckArea; x < placementPoint.X + schematicSize.X + xCheckArea; x++) + { + for (int y = placementPoint.Y; y < placementPoint.Y + schematicSize.Y; y++) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + if (ShouldAvoidLocation(new Point(x, y))) + canGenerateInLocation = false; + + if (tile.HasTile) + { + //Only spawn on normal cave tiles. Some special seeds are weeping rn. + if (tile.TileType == TileID.Dirt || tile.TileType == TileID.Stone || tile.TileType == TileID.Mud || TileID.Sets.Conversion.Moss[tile.TileType]) + plainTilesInArea++; + + //Letting it spawn in natural mud means avoiding every other mud biome at all costs + if (tile.TileType == TileID.JungleGrass || tile.TileType == TileID.MushroomGrass) + plainTilesInArea -= 1000; + } + } + } + if (!canGenerateInLocation || nearbyOtherWorkshop || plainTilesInArea < totalTiles * 0.3f || !structures.CanPlace(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y))) + tries++; + else + { + bool _ = true; + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action(FillCavernLaboratoryChest)); + structures.AddProtectedStructure(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y), 4); + CalamityWorld.CavernLabCenter = placementPoint.ToWorldCoordinates() + new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)) * 8f; + break; + } + } + while (tries <= 50000); + } + #endregion } } diff --git a/World/SunkenSea.cs b/World/SunkenSea.cs index 40f322ead3..1fd678ffa7 100644 --- a/World/SunkenSea.cs +++ b/World/SunkenSea.cs @@ -670,7 +670,7 @@ namespace CalamityMod.World //note: the stalactites and stalagmites only use their first frame for now //this is because the previous tile frame randomizer code i had was janky and bad, ill make sure to fix it eventually //stalactites - if (WorldGen.genRand.Next(5) == 0) + /*if (WorldGen.genRand.Next(5) == 0) { WorldGen.PlaceTile(num5, num6 + 2, (ushort)ModContent.TileType(), true, false, -1, 0); } diff --git a/World/UndergroundShrines.cs b/World/UndergroundShrines.cs index 41a93a6de1..02bbb09e08 100644 --- a/World/UndergroundShrines.cs +++ b/World/UndergroundShrines.cs @@ -1,15 +1,626 @@ -using CalamityMod.Items.Accessories; +using CalamityMod.Items.Accessories; using CalamityMod.Items.Mounts; using CalamityMod.Items.Placeables.Furniture; using CalamityMod.Items.SummonItems; +using CalamityMod.Tiles.DraedonStructures; +using CalamityMod.Tiles.SunkenSea; +using CalamityMod.Walls; +using CalamityMod.Schematics; +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; using Terraria; using Terraria.ID; using Terraria.ModLoader; +using Terraria.WorldBuilding; + +using static CalamityMod.Schematics.SchematicManager; namespace CalamityMod.World { public class UndergroundShrines { + public static bool ShouldAvoidLocation(Point placementPoint, bool careAboutLiquids = true) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(placementPoint.X, placementPoint.Y); + if (tile.LiquidAmount > 0 && careAboutLiquids) + return true; + if (tile.TileType == TileID.BlueDungeonBrick || + tile.TileType == TileID.GreenDungeonBrick || + tile.TileType == TileID.PinkDungeonBrick) + { + return true; + } + if (tile.TileType == TileID.LihzahrdBrick || + tile.WallType == WallID.LihzahrdBrickUnsafe) + { + return true; + } + if (tile.TileType == ModContent.TileType() || + tile.TileType == ModContent.TileType() || + tile.WallType == ModContent.WallType() || + tile.WallType == ModContent.WallType()) + { + return true; + } + if (tile.TileType == ModContent.TileType() || + tile.TileType == ModContent.TileType() || + tile.TileType == ModContent.TileType() || + tile.TileType == ModContent.TileType() || + tile.TileType == ModContent.TileType() || + tile.TileType == ModContent.TileType()) + { + return true; + } + + return false; + } + + #region Corruption Shrine + public static void FillCorruptionShrineChest(Chest chest) + { + int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.BattlePotion, ItemID.HunterPotion, ItemID.TrapsightPotion); + List contents = new List() + { + new ChestItem(ModContent.ItemType(), 1), + new ChestItem(ItemID.RottenChunk, WorldGen.genRand.Next(24, 28 + 1)), + new ChestItem(ItemID.CorruptionKey, 1), + new ChestItem(ItemID.CorruptTorch, WorldGen.genRand.Next(100, 110 + 1)), + new ChestItem(ItemID.GoldCoin, WorldGen.genRand.Next(20, 24 + 1)), + new ChestItem(ItemID.HealingPotion, WorldGen.genRand.Next(10, 12 + 1)), + new ChestItem(potionType, WorldGen.genRand.Next(10, 12 + 1)), + }; + + for (int i = 0; i < contents.Count; i++) + { + chest.item[i].SetDefaults(contents[i].Type); + chest.item[i].stack = contents[i].Stack; + } + } + public static void PlaceCorruptionShrine(StructureMap structures) + { + int tries = 0; + string mapKey = CorruptionShrineKey; + + do + { + int placementPositionX = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.1f), (int)(Main.maxTilesX * 0.9f)); + int placementPositionY = WorldGen.genRand.Next((int)(Main.maxTilesY * 0.2f), (int)(Main.maxTilesY * 0.35f)); + Point placementPoint = new Point(placementPositionX, placementPositionY); + + Vector2 schematicSize = new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)); + int corruptStuffInArea = 0; + bool canGenerateInLocation = true; + + float totalTiles = schematicSize.X * schematicSize.Y; + for (int x = placementPoint.X; x < placementPoint.X + schematicSize.X; x++) + { + for (int y = placementPoint.Y; y < placementPoint.Y + schematicSize.Y; y++) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + if (ShouldAvoidLocation(new Point(x, y))) + canGenerateInLocation = false; + + //Should generate within the bounds of the walls. + if (tile.TileType == TileID.Ebonstone || tile.WallType == WallID.EbonstoneUnsafe) + corruptStuffInArea++; + + //Do not cut into the altars + if (tile.TileType == TileID.DemonAltar) + canGenerateInLocation = false; + } + } + if (!canGenerateInLocation || corruptStuffInArea < totalTiles * 0.6f || !structures.CanPlace(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y))) + tries++; + else + { + bool _ = true; + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action(FillCorruptionShrineChest)); + structures.AddProtectedStructure(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y), 4); + break; + } + + } while (tries <= 50000); + } + #endregion + + #region Crimson Shrine + public static void FillCrimsonShrineChest(Chest chest) + { + int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.BattlePotion, ItemID.HunterPotion, ItemID.TrapsightPotion); + List contents = new List() + { + new ChestItem(ModContent.ItemType(), 1), + new ChestItem(ItemID.Vertebrae, WorldGen.genRand.Next(24, 28 + 1)), + new ChestItem(ItemID.CrimsonKey, 1), + new ChestItem(ItemID.CrimsonTorch, WorldGen.genRand.Next(100, 110 + 1)), + new ChestItem(ItemID.GoldCoin, WorldGen.genRand.Next(20, 24 + 1)), + new ChestItem(ItemID.HealingPotion, WorldGen.genRand.Next(10, 12 + 1)), + new ChestItem(potionType, WorldGen.genRand.Next(10, 12 + 1)), + }; + + for (int i = 0; i < contents.Count; i++) + { + chest.item[i].SetDefaults(contents[i].Type); + chest.item[i].stack = contents[i].Stack; + } + } + public static void PlaceCrimsonShrine(StructureMap structures) + { + int tries = 0; + string mapKey = CrimsonShrineKey; + + do + { + int placementPositionX = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.1f), (int)(Main.maxTilesX * 0.9f)); + int placementPositionY = WorldGen.genRand.Next((int)(Main.maxTilesY * 0.2f), (int)(Main.maxTilesY * 0.35f)); + Point placementPoint = new Point(placementPositionX, placementPositionY); + + Vector2 schematicSize = new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)); + int crimsonTilesInGround = 0; + int crimsonStuffInArea = 0; + bool canGenerateInLocation = true; + + float groundThreshold = schematicSize.Y * 0.4f; + float groundTiles = schematicSize.X * groundThreshold; + float totalTiles = schematicSize.X * schematicSize.Y; + for (int x = placementPoint.X; x < placementPoint.X + schematicSize.X; x++) + { + for (int y = placementPoint.Y; y < placementPoint.Y + schematicSize.Y; y++) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + if (ShouldAvoidLocation(new Point(x, y))) + canGenerateInLocation = false; + + //The structure is made to embed within the blocks + //The bottom half should have a lot of tiles. + if (y >= placementPoint.Y + schematicSize.Y - groundThreshold && tile.TileType == TileID.Crimstone) + crimsonTilesInGround++; + + //Crimson does not generate walls in blocks very much, so both walls and tiles are grouped + if (tile.TileType == TileID.Crimstone || tile.WallType == WallID.CrimstoneUnsafe) + crimsonStuffInArea++; + + //Do not cut into the altars + if (tile.TileType == TileID.DemonAltar) + canGenerateInLocation = false; + } + } + if (!canGenerateInLocation || crimsonTilesInGround < groundTiles * 0.5f || crimsonStuffInArea < totalTiles * 0.8f || !structures.CanPlace(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y))) + tries++; + else + { + bool _ = true; + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action(FillCrimsonShrineChest)); + structures.AddProtectedStructure(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y), 4); + break; + } + + } while (tries <= 50000); + } + #endregion + + #region Desert Shrine + public static void FillDesertShrineChest(Chest chest) + { + int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.SpelunkerPotion, ItemID.MiningPotion, ItemID.BuilderPotion); + List contents = new List() + { + new ChestItem(ModContent.ItemType(), 1), + new ChestItem(ModContent.ItemType(), WorldGen.genRand.Next(6, 8 + 1)), + new ChestItem(ItemID.DungeonDesertKey, 1), + new ChestItem(ItemID.DesertTorch, WorldGen.genRand.Next(100, 110 + 1)), + new ChestItem(ItemID.GoldCoin, WorldGen.genRand.Next(20, 24 + 1)), + new ChestItem(ItemID.HealingPotion, WorldGen.genRand.Next(10, 12 + 1)), + new ChestItem(potionType, WorldGen.genRand.Next(10, 12 + 1)), + }; + + for (int i = 0; i < contents.Count; i++) + { + chest.item[i].SetDefaults(contents[i].Type); + chest.item[i].stack = contents[i].Stack; + } + } + public static void PlaceDesertShrine(StructureMap structures) + { + int tries = 0; + string mapKey = DesertShrineKey; + + do + { + int placementPositionX = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.35f), (int)(Main.maxTilesX * 0.65f)); + int placementPositionY = WorldGen.genRand.Next((int)(Main.maxTilesY * 0.3f), (int)(Main.maxTilesY * 0.6f)); + Point placementPoint = new Point(placementPositionX, placementPositionY); + + Vector2 schematicSize = new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)); + int desertTilesInArea = 0; + int desertWallsInArea = 0; + int xCheckArea = 50; + bool canGenerateInLocation = true; + + float totalTiles = (schematicSize.X + xCheckArea * 2) * schematicSize.Y; + for (int x = placementPoint.X - xCheckArea; x < placementPoint.X + schematicSize.X + xCheckArea; x++) + { + for (int y = placementPoint.Y; y < placementPoint.Y + schematicSize.Y; y++) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + if (ShouldAvoidLocation(new Point(x, y))) + canGenerateInLocation = false; + + if (tile.TileType == TileID.DesertFossil || tile.TileType == TileID.Sand || tile.TileType == TileID.HardenedSand || tile.TileType == TileID.Sandstone) + desertTilesInArea++; + + //The desert is absolutely covered with walls. This prevents it from generating in random sand patches. + if (tile.WallType == WallID.HardenedSand || tile.WallType == WallID.Sandstone) + desertWallsInArea++; + } + } + if (!canGenerateInLocation || desertTilesInArea < totalTiles * 0.3f || desertWallsInArea < totalTiles * 0.95f || !structures.CanPlace(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y))) + tries++; + else + { + bool _ = true; + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action(FillDesertShrineChest)); + structures.AddProtectedStructure(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y), 4); + break; + } + + } while (tries <= 50000); + } + #endregion + + #region Granite Shrine + public static void FillGraniteShrineChest(Chest chest) + { + int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.EndurancePotion, ItemID.HeartreachPotion, ItemID.LifeforcePotion); + List contents = new List() + { + new ChestItem(ModContent.ItemType(), 1), + new ChestItem(ItemID.Geode, WorldGen.genRand.Next(6, 8 + 1)), + new ChestItem(ItemID.BlueTorch, WorldGen.genRand.Next(100, 110 + 1)), + new ChestItem(ItemID.GoldCoin, WorldGen.genRand.Next(20, 24 + 1)), + new ChestItem(ItemID.HealingPotion, WorldGen.genRand.Next(10, 12 + 1)), + new ChestItem(potionType, WorldGen.genRand.Next(10, 12 + 1)), + }; + + for (int i = 0; i < contents.Count; i++) + { + chest.item[i].SetDefaults(contents[i].Type); + chest.item[i].stack = contents[i].Stack; + } + } + public static void PlaceGraniteShrine(StructureMap structures) + { + int tries = 0; + string mapKey = GraniteShrineKey; + + do + { + int placementPositionX = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.1f), (int)(Main.maxTilesX * 0.9f)); + int placementPositionY = WorldGen.genRand.Next((int)(Main.maxTilesY * 0.55f), (int)(Main.maxTilesY * 0.85f)); + Point placementPoint = new Point(placementPositionX, placementPositionY); + + Vector2 schematicSize = new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)); + int graniteWallsInArea = 0; + bool canGenerateInLocation = true; + + float totalTiles = schematicSize.X * schematicSize.Y; + for (int x = placementPoint.X; x < placementPoint.X + schematicSize.X; x++) + { + for (int y = placementPoint.Y; y < placementPoint.Y + schematicSize.Y; y++) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + if (ShouldAvoidLocation(new Point(x, y))) + canGenerateInLocation = false; + + //The granite geode is supposed to fully float in free air. No tile replacements + if (tile.WallType == WallID.GraniteUnsafe && !tile.HasTile) + graniteWallsInArea++; + } + } + if (!canGenerateInLocation || graniteWallsInArea < totalTiles * 0.95f || !structures.CanPlace(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y))) + tries++; + else + { + bool _ = true; + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action(FillGraniteShrineChest)); + structures.AddProtectedStructure(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y), 4); + break; + } + + } while (tries <= 50000); + } + #endregion + + #region Ice Shrine + public static void FillIceShrineChest(Chest chest) + { + int foodType = Utils.SelectRandom(WorldGen.genRand, ItemID.ChristmasPudding, ItemID.SugarCookie, ItemID.GingerbreadCookie); + List contents = new List() + { + new ChestItem(ModContent.ItemType(), 1), + new ChestItem(ItemID.FlinxFur, WorldGen.genRand.Next(6, 8 + 1)), + new ChestItem(ItemID.FrozenKey, 1), + new ChestItem(ItemID.IceTorch, WorldGen.genRand.Next(100, 110 + 1)), + new ChestItem(ItemID.GoldCoin, WorldGen.genRand.Next(20, 24 + 1)), + new ChestItem(ItemID.HealingPotion, WorldGen.genRand.Next(10, 12 + 1)), + new ChestItem(foodType, WorldGen.genRand.Next(10, 12 + 1)), + }; + + for (int i = 0; i < contents.Count; i++) + { + chest.item[i].SetDefaults(contents[i].Type); + chest.item[i].stack = contents[i].Stack; + } + } + public static void PlaceIceShrine(StructureMap structures) + { + int tries = 0; + string mapKey = IceShrineKey; + + do + { + int placementPositionX = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.25f), (int)(Main.maxTilesX * 0.75f)); + int placementPositionY = WorldGen.genRand.Next((int)(Main.maxTilesY * 0.35f), (int)(Main.maxTilesY * 0.7f)); + Point placementPoint = new Point(placementPositionX, placementPositionY); + + Vector2 schematicSize = new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)); + int iceTilesInArea = 0; + int xCheckArea = 80; + int yCheckArea = 20; + bool canGenerateInLocation = true; + + float totalTiles = (schematicSize.X + xCheckArea * 2) * (schematicSize.Y + yCheckArea * 2); + for (int x = placementPoint.X - xCheckArea; x < placementPoint.X + schematicSize.X + xCheckArea; x++) + { + for (int y = placementPoint.Y - yCheckArea; y < placementPoint.Y + schematicSize.Y + yCheckArea; y++) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + //Ice biomes obviously have a lot of water + if (ShouldAvoidLocation(new Point(x, y), false)) + canGenerateInLocation = false; + + if (tile.TileType == TileID.SnowBlock || tile.TileType == TileID.IceBlock) + iceTilesInArea++; + } + } + if (!canGenerateInLocation || iceTilesInArea < totalTiles * 0.5f || !structures.CanPlace(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y))) + tries++; + else + { + bool _ = true; + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action(FillIceShrineChest)); + structures.AddProtectedStructure(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y), 4); + break; + } + + } while (tries <= 50000); + } + #endregion + + #region Marble Shrine + public static void FillMarbleShrineChest(Chest chest) + { + int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.EndurancePotion, ItemID.HeartreachPotion, ItemID.LifeforcePotion); + List contents = new List() + { + new ChestItem(ModContent.ItemType(), 1), + new ChestItem(WorldGen.goldBar == TileID.Gold ? ItemID.GoldBar : ItemID.PlatinumBar, WorldGen.genRand.Next(12, 15 + 1)), + new ChestItem(ItemID.WhiteTorch, WorldGen.genRand.Next(100, 110 + 1)), + new ChestItem(ItemID.GoldCoin, WorldGen.genRand.Next(20, 24 + 1)), + new ChestItem(ItemID.HealingPotion, WorldGen.genRand.Next(10, 12 + 1)), + new ChestItem(potionType, WorldGen.genRand.Next(10, 12 + 1)), + }; + + for (int i = 0; i < contents.Count; i++) + { + chest.item[i].SetDefaults(contents[i].Type); + chest.item[i].stack = contents[i].Stack; + } + } + public static void PlaceMarbleShrine(StructureMap structures) + { + int tries = 0; + string mapKey = MarbleShrineKey; + + do + { + int placementPositionX = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.1f), (int)(Main.maxTilesX * 0.9f)); + int placementPositionY = WorldGen.genRand.Next((int)(Main.maxTilesY * 0.55f), (int)(Main.maxTilesY * 0.85f)); + Point placementPoint = new Point(placementPositionX, placementPositionY); + + Vector2 schematicSize = new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)); + int marbleStuffInArea = 0; + int airTilesBetweenPillar = 0; + bool canGenerateInLocation = true; + + float totalTiles = schematicSize.X * schematicSize.Y; + for (int x = placementPoint.X; x < placementPoint.X + schematicSize.X; x++) + { + for (int y = placementPoint.Y; y < placementPoint.Y + schematicSize.Y; y++) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + if (ShouldAvoidLocation(new Point(x, y))) + canGenerateInLocation = false; + + //Marble biomes either have blocks or walls, occasionally both + //This should be near maximum to prevent the structure from overextending + if (tile.TileType == TileID.Marble || tile.WallType == WallID.MarbleUnsafe) + marbleStuffInArea++; + + //There should be some space between the pillars so it doesn't make pillars in the middle of nowhere zone + float pillarFoundationBound = schematicSize.Y * 0.2f; + bool pillarSpace = y <= placementPoint.Y + schematicSize.Y - pillarFoundationBound && y >= placementPoint.Y + pillarFoundationBound; + if (pillarSpace && !tile.HasTile) + airTilesBetweenPillar++; + } + } + + if (!canGenerateInLocation || marbleStuffInArea < totalTiles * 0.9f || airTilesBetweenPillar < totalTiles * 0.3f || !structures.CanPlace(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y))) + tries++; + else + { + bool _ = true; + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action(FillMarbleShrineChest)); + structures.AddProtectedStructure(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y), 4); + break; + } + + } while (tries <= 50000); + } + #endregion + + #region Mushroom Shrine + public static void FillMushroomShrineChest(Chest chest) + { + int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.SpelunkerPotion, ItemID.MiningPotion, ItemID.BuilderPotion); + List contents = new List() + { + new ChestItem(ModContent.ItemType(), 1), + new ChestItem(ItemID.TruffleWorm, 3), + //TODO -- Mushroom Torches are 1.4.4. exclusive + //new ChestItem(ItemID.MushroomTorch, WorldGen.genRand.Next(100, 110 + 1)), + new ChestItem(ItemID.GoldCoin, WorldGen.genRand.Next(20, 24 + 1)), + new ChestItem(ItemID.HealingPotion, WorldGen.genRand.Next(10, 12 + 1)), + new ChestItem(potionType, WorldGen.genRand.Next(10, 12 + 1)), + }; + + for (int i = 0; i < contents.Count; i++) + { + chest.item[i].SetDefaults(contents[i].Type); + chest.item[i].stack = contents[i].Stack; + } + } + public static void PlaceMushroomShrine(StructureMap structures) + { + int tries = 0; + string mapKey = MushroomShrineKey; + + do + { + int placementPositionX = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.3f), (int)(Main.maxTilesX * 0.7f)); + int placementPositionY = WorldGen.genRand.Next((int)(Main.maxTilesY * 0.5f), (int)(Main.maxTilesY * 0.8f)); + Point placementPoint = new Point(placementPositionX, placementPositionY); + + Vector2 schematicSize = new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)); + int realMushroomsInArea = 0; + int xCheckArea = 50; + bool canGenerateInLocation = true; + + float totalTiles = (schematicSize.X + xCheckArea * 2) * schematicSize.Y; + for (int x = placementPoint.X - xCheckArea; x < placementPoint.X + schematicSize.X + xCheckArea; x++) + { + for (int y = placementPoint.Y; y < placementPoint.Y + schematicSize.Y; y++) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + //For some reason, mushroom biomes are very wet + //It gets way too difficult to generate if it doesn't ignore water + if (ShouldAvoidLocation(new Point(x, y), false)) + canGenerateInLocation = false; + + if (tile.TileType == TileID.Mud) + realMushroomsInArea++; + + //Mushroom grass are the main tiles in the mushroom. + if (tile.TileType == TileID.MushroomGrass) + realMushroomsInArea += 3; + + //This will help make it generate within the "mushroom space". It's intended to generate as an island. + //Just in case though, the schematic makes some room so that it never gets stuck in the mud. + if (tile.TileType == TileID.MushroomPlants || tile.TileType == TileID.MushroomVines) + realMushroomsInArea += 30; + + //This will never spawn in the jungle + if (tile.TileType == TileID.JungleGrass) + canGenerateInLocation = false; + } + } + if (!canGenerateInLocation || realMushroomsInArea < totalTiles || !structures.CanPlace(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y))) + tries++; + else + { + bool _ = true; + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action(FillMushroomShrineChest)); + structures.AddProtectedStructure(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y), 4); + break; + } + + } while (tries <= 50000); + } + #endregion + + #region Surface Shrine + public static void FillSurfaceShrineChest(Chest chest) + { + int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.TeleportationPotion, ItemID.CalmingPotion, ItemID.SwiftnessPotion); + List contents = new List() + { + new ChestItem(ModContent.ItemType(), 1), + new ChestItem(ItemID.PinkGel, WorldGen.genRand.Next(24, 28 + 1)), + new ChestItem(ItemID.Torch, WorldGen.genRand.Next(100, 110 + 1)), + new ChestItem(ItemID.GoldCoin, WorldGen.genRand.Next(20, 24 + 1)), + new ChestItem(ItemID.HealingPotion, WorldGen.genRand.Next(10, 12 + 1)), + new ChestItem(potionType, WorldGen.genRand.Next(10, 12 + 1)), + }; + + for (int i = 0; i < contents.Count; i++) + { + chest.item[i].SetDefaults(contents[i].Type); + chest.item[i].stack = contents[i].Stack; + } + } + public static void PlaceSurfaceShrine(StructureMap structures) + { + int tries = 0; + string mapKey = SurfaceShrineKey; + + do + { + int placementPositionX = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.2f), (int)(Main.maxTilesX * 0.8f)); + int placementPositionY = WorldGen.genRand.Next((int)(Main.maxTilesY * 0.25f), (int)(Main.maxTilesY * 0.3f)); + Point placementPoint = new Point(placementPositionX, placementPositionY); + + Vector2 schematicSize = new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)); + int normalTilesInArea = 0; + int activeTilesInArea = 0; + bool canGenerateInLocation = true; + + for (int x = placementPoint.X; x < placementPoint.X + schematicSize.X; x++) + { + for (int y = placementPoint.Y; y < placementPoint.Y + schematicSize.Y; y++) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + //Liquids are fine, the structure is sealed. + if (ShouldAvoidLocation(new Point(x, y), false)) + canGenerateInLocation = false; + + if (tile.TileType == TileID.Dirt || tile.TileType == TileID.Stone || tile.TileType == TileID.ClayBlock || tile.TileType == TileID.Sand) + normalTilesInArea++; + + if (tile.HasTile) + activeTilesInArea++; + + //Avoid the desert due to sand checks + if (tile.WallType == WallID.HardenedSand || tile.WallType == WallID.Sandstone) + canGenerateInLocation = false; + } + } + if (!canGenerateInLocation || normalTilesInArea < activeTilesInArea * 0.8f || !structures.CanPlace(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y))) + tries++; + else + { + bool _ = true; + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action(FillSurfaceShrineChest)); + structures.AddProtectedStructure(new Rectangle(placementPoint.X, placementPoint.Y, (int)schematicSize.X, (int)schematicSize.Y), 4); + break; + } + + } while (tries <= 50000); + } + #endregion + + //Enums and generation methods for old shrines + //Currently still used for Abyss (Terminus) shrine #region Enumeration public enum UndergroundShrineType { @@ -181,7 +792,7 @@ namespace CalamityMod.World #endregion #region Direct Gen - public static void PlaceShrines() + /*public static void PlaceShrines() { int x = Main.maxTilesX; int y = Main.maxTilesY; @@ -222,7 +833,7 @@ namespace CalamityMod.World } } - for (int k = 0; k < (int)(x * y * shrineChance); k++) //Cavern Shrine + for (int k = 0; k < (int)(x * y * shrineChance); k++) //Cavern { int tilesX = WorldGen.genRand.Next((int)(x * 0.3), generateBack); int tilesX2 = WorldGen.genRand.Next(generateForward, (int)(x * 0.7)); @@ -299,7 +910,7 @@ namespace CalamityMod.World break; } } - } + }*/ #endregion } }