Merge of new shrines and other schematic changes

This commit is contained in:
Cameron Ewell authored and GitHub committed 2023-01-16 18:46:41 -05:00
commit 36a56819e0
24 files changed
+893 -15

No files matched your search

+46
View File
@@ -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<OnyxLabSeeker>();
Item.Calamity().MaxCharge = 100;
Item.Calamity().ChargePerUse = 10;
Item.Calamity().UsesCharge = true;
Item.rare = ModContent.RarityType<DarkOrange>();
}
public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0 && CalamityWorld.CavernLabCenter != Vector2.Zero;
public override void AddRecipes()
{
//Temporary recipe probably
CreateRecipe().
AddIngredient<LabSeekingMechanism>().
AddIngredient(ItemID.Obsidian, 25).
AddTile(TileID.Anvils).
Register();
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

+63
View File
@@ -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<Texture2D>(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;
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
+39
View File
@@ -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),
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+17 -7
View File
@@ -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) =>
{
@@ -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<OnyxExcavatorKey>());
}
}
}
File renamed without changes.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

+1
View File
@@ -83,6 +83,7 @@ namespace CalamityMod.World
public static Vector2 JungleLabCenter;
public static Vector2 HellLabCenter;
public static Vector2 IceLabCenter;
public static Vector2 CavernLabCenter;
#endregion
}
+78 -3
View File
@@ -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<ChestItem> contents = new List<ChestItem>()
{
new ChestItem(ModContent.ItemType<DubiousPlating>(), WorldGen.genRand.Next(10, 17 + 1)),
new ChestItem(ModContent.ItemType<MysteriousCircuitry>(), 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<LabSeekingMechanism>(), 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<Point> 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<Chest>(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
}
}
+1 -1
View File
@@ -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<SunkenStalactites>(), true, false, -1, 0);
}
+615 -4
View File
@@ -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<Navystone>() ||
tile.TileType == ModContent.TileType<EutrophicSand>() ||
tile.WallType == ModContent.WallType<NavystoneWall>() ||
tile.WallType == ModContent.WallType<EutrophicSandWall>())
{
return true;
}
if (tile.TileType == ModContent.TileType<HazardChevronPanels>() ||
tile.TileType == ModContent.TileType<LaboratoryPanels>() ||
tile.TileType == ModContent.TileType<LaboratoryPipePlating>() ||
tile.TileType == ModContent.TileType<LaboratoryPlating>() ||
tile.TileType == ModContent.TileType<RustedPipes>() ||
tile.TileType == ModContent.TileType<RustedPlating>())
{
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<ChestItem> contents = new List<ChestItem>()
{
new ChestItem(ModContent.ItemType<CorruptionEffigy>(), 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<Chest>(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<ChestItem> contents = new List<ChestItem>()
{
new ChestItem(ModContent.ItemType<CrimsonEffigy>(), 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<Chest>(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<ChestItem> contents = new List<ChestItem>()
{
new ChestItem(ModContent.ItemType<LuxorsGift>(), 1),
new ChestItem(ModContent.ItemType<Items.Placeables.PrismShard>(), 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<Chest>(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<ChestItem> contents = new List<ChestItem>()
{
new ChestItem(ModContent.ItemType<UnstableGraniteCore>(), 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<Chest>(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<ChestItem> contents = new List<ChestItem>()
{
new ChestItem(ModContent.ItemType<TundraLeash>(), 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<Chest>(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<ChestItem> contents = new List<ChestItem>()
{
new ChestItem(ModContent.ItemType<GladiatorsLocket>(), 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<Chest>(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<ChestItem> contents = new List<ChestItem>()
{
new ChestItem(ModContent.ItemType<FungalSymbiote>(), 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<Chest>(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<ChestItem> contents = new List<ChestItem>()
{
new ChestItem(ModContent.ItemType<TrinketofChi>(), 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<Chest>(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
}
}