diff --git a/Items/LabFinders/OnyxSeekingMechanism.cs b/Items/LabFinders/OnyxSeekingMechanism.cs new file mode 100644 index 0000000000..493289cc0f --- /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, 1000). + 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/SchematicManager.cs b/Schematics/SchematicManager.cs index fb4db262ff..aad9a78b97 100644 --- a/Schematics/SchematicManager.cs +++ b/Schematics/SchematicManager.cs @@ -34,6 +34,9 @@ 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_CavernWorkshop.csch"; + internal const string AstralBeaconKey = "Astral Beacon"; internal const string AstralBeaconFilename = "Schematics/AstralBeacon.csch"; @@ -55,6 +58,7 @@ namespace CalamityMod.Schematics [PlagueLabKey] = CalamitySchematicIO.LoadSchematic(PlagueLabFilename), [HellLabKey] = CalamitySchematicIO.LoadSchematic(HellLabFilename), [IceLabKey] = CalamitySchematicIO.LoadSchematic(IceLabFilename), + [CavernLabKey] = CalamitySchematicIO.LoadSchematic(CavernLabFilename), // Astral world gen structures [AstralBeaconKey] = CalamitySchematicIO.LoadSchematic(AstralBeaconFilename), diff --git a/Systems/WorldgenManagementSystem.cs b/Systems/WorldgenManagementSystem.cs index dcf531afdd..9748c3899d 100644 --- a/Systems/WorldgenManagementSystem.cs +++ b/Systems/WorldgenManagementSystem.cs @@ -173,6 +173,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); 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 bda1944730..f97d21f445 100644 --- a/World/DraedonStructures.cs +++ b/World/DraedonStructures.cs @@ -605,5 +605,88 @@ 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), + }; + + //Special, non-main line lab: Adds the base Lab Seeking Mechanism + contents.Insert(0, 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 underworldTop = Main.maxTilesY - 200; + int placementPositionX = WorldGen.genRand.Next((int)(Main.maxTilesX * 0.15f), (int)(Main.maxTilesX * 0.85f)); + int placementPositionY = WorldGen.genRand.Next(underworldTop - 400, underworldTop - 50); + + placementPoint = new Point(placementPositionX, placementPositionY); + Vector2 schematicSize = new Vector2(TileMaps[mapKey].GetLength(0), TileMaps[mapKey].GetLength(1)); + int activeTilesInArea = 0; + 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; + + activeTilesInArea++; + } + } + } + if (!canGenerateInLocation || nearbyOtherWorkshop || plainTilesInArea < totalTiles * 0.4f || !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 } }