diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs
index 2aca24c0fd..387525521a 100644
--- a/CalPlayer/CalamityPlayer.cs
+++ b/CalPlayer/CalamityPlayer.cs
@@ -70,6 +70,7 @@ using CalamityMod.Systems;
using CalamityMod.Systems.Collections;
using CalamityMod.Systems.Mechanic;
using CalamityMod.Utilities;
+using CalamityMod.Waters;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -4296,12 +4297,217 @@ namespace CalamityMod.CalPlayer
vector = player.CheckForGoodTeleportationSpot(ref canSpawn, halfWorldXTiles + smallerCheckRadius, smallerCheckRadius, teleportStartY, teleportRangeY, settings);
if (canSpawn)
- {
return (Vector2?)vector;
- }
+
return null;
}
+ ///
+ /// Returns a random position in the Lihzhard Temple to teleport the player to.
+ /// Used primarily for .
+ ///
+ public static Vector2? GetTempleTeleportPosition(Player player)
+ {
+ int foundX = -1;
+ int foundY = -1;
+ bool dungeonOnRightSide = Main.dungeonX > Main.spawnTileX;
+ int xSearchEnd = dungeonOnRightSide ? 20 : Main.maxTilesX - 20;
+
+ if (dungeonOnRightSide)
+ {
+ for (int i = Main.spawnTileX; i >= xSearchEnd; i -= 2)
+ {
+ for (int j = (int)Main.worldSurface; j < Main.maxTilesY - 210; j++)
+ {
+ Tile tile = Framing.GetTileSafely(i, j);
+ if (tile.WallType == WallID.LihzahrdBrickUnsafe)
+ {
+ foundX = i;
+ foundY = j;
+ break;
+ }
+ }
+ if (foundX != -1)
+ break;
+ }
+ }
+ else
+ {
+ for (int i = Main.spawnTileX; i <= xSearchEnd; i += 2)
+ {
+ for (int j = (int)Main.worldSurface; j < Main.maxTilesY - 210; j++)
+ {
+ Tile tile = Framing.GetTileSafely(i, j);
+ if (tile.WallType == WallID.LihzahrdBrickUnsafe)
+ {
+ foundX = i;
+ foundY = j;
+ break;
+ }
+ }
+
+ if (foundX != -1)
+ break;
+ }
+ }
+
+ if (foundX == -1)
+ return null;
+
+ int attempts = 25;
+ int rangeX = 300;
+ int rangeY = 300;
+ int randomFluff = 500;
+ Point finalTeleportPoint = Point.Zero;
+ for (int i = 0; i < attempts; i++)
+ {
+ for (int x = 0; x <= rangeX; x++)
+ {
+ for (int y = 0; y <= rangeY; y++)
+ {
+ int teleportPosX = foundX + x + Main.rand.Next(-randomFluff, randomFluff);
+ int teleportPosY = foundY + y + Main.rand.Next(-randomFluff, randomFluff);
+ Tile tile = Framing.GetTileSafely(teleportPosX, teleportPosY);
+ Tile tileAbove = Framing.GetTileSafely(teleportPosX, teleportPosY - 1);
+ Tile tileBelow = Framing.GetTileSafely(teleportPosX, teleportPosY + 1);
+
+ if (!tileAbove.HasTile && tileBelow.HasTile && tile.WallType == WallID.LihzahrdBrickUnsafe)
+ {
+ finalTeleportPoint = new(tile.X(), tile.Y());
+ if (!Collision.SolidCollision(finalTeleportPoint.ToWorldCoordinates(), player.width, player.height))
+ break;
+ }
+ }
+ }
+ }
+
+ return finalTeleportPoint.ToWorldCoordinates() - new Vector2(player.width, player.height);
+ }
+
+ ///
+ /// Returns a random position in the Void (Abyss Layer 4) to teleport the player to.
+ /// Used primarily for .
+ ///
+ public static Vector2? GetAbyssVoidTeleportPosition(Player player)
+ {
+ bool canSpawn = false;
+ int halfWorldWidth = Main.maxTilesX / 2;
+
+ int abyssStartX = Abyss.AtLeftSideOfWorld ? halfWorldWidth - (halfWorldWidth - 135) + 35 : halfWorldWidth + (halfWorldWidth - 135) - 35;
+ int abyssXRange = 50;
+
+ int teleportStartY = Main.remixWorld ? SulphurousSea.YStart - (int)(Main.UnderworldLayer * 0.6f) : Main.maxTilesY - 300;
+ int teleportRangeY = 80;
+
+ Player.RandomTeleportationAttemptSettings settings = new Player.RandomTeleportationAttemptSettings
+ {
+ mostlySolidFloor = false,
+ avoidAnyLiquid = false,
+ avoidLava = true,
+ avoidHurtTiles = true,
+ avoidWalls = false,
+ attemptsBeforeGivingUp = 1000,
+ maximumFallDistanceFromOrignalPoint = 10
+ };
+
+ Vector2 teleportPosition = player.CheckForGoodTeleportationSpot(ref canSpawn, abyssStartX, abyssXRange, teleportStartY, teleportRangeY, settings);
+ return canSpawn ? teleportPosition : null;
+ }
+
+ ///
+ /// Returns a random position in the Forsaken Archives to teleport the player to.
+ /// Used primarily for .
+ ///
+ public static Vector2? GetDungeonArchivesTeleportPosition(Player player)
+ {
+ // Define an area around the center to search for a valid spot to tp
+ int teleportStartX = WorldgenManagementSystem.DungeonArchivePos.X;
+ int teleportStartY = WorldgenManagementSystem.DungeonArchivePos.Y;
+
+ // Manually search for the Archives from the bottom of the world if the Archive position isn't saved.
+ if (WorldgenManagementSystem.DungeonArchivePos == Point.Zero)
+ {
+ int foundX = -1;
+ int foundY = -1;
+ bool dungeonOnRightSide = Main.dungeonX > Main.spawnTileX;
+ int xSearchStart = dungeonOnRightSide ? Main.maxTilesX - 20 : 20;
+
+ if (dungeonOnRightSide)
+ {
+ for (int y = Main.UnderworldLayer; y > (int)Main.rockLayer; y--)
+ {
+ for (int x = xSearchStart; x >= Main.maxTilesX / 2; x -= 2)
+ {
+ Tile tile = Framing.GetTileSafely(x, y);
+ if (Main.wallDungeon[tile.WallType] && Main.tileDungeon[tile.TileType])
+ {
+ foundX = x;
+ foundY = y;
+ break;
+ }
+ }
+
+ if (foundY != -1)
+ break;
+ }
+ }
+ else
+ {
+ for (int y = Main.UnderworldLayer; y > (int)Main.rockLayer; y--)
+ {
+ for (int x = xSearchStart; x <= Main.maxTilesX / 2; x += 2)
+ {
+ Tile tile = Framing.GetTileSafely(x, y);
+ if (Main.wallDungeon[tile.WallType] && Main.tileDungeon[tile.TileType])
+ {
+ foundX = x;
+ foundY = y;
+ break;
+ }
+ }
+
+ if (foundY != -1)
+ break;
+ }
+ }
+
+ if (foundY == -1)
+ return null;
+
+ teleportStartX = foundX;
+ teleportStartY = foundY;
+ }
+
+ int attempts = 25;
+ int rangeX = 100;
+ int rangeY = 200;
+ int randomFluff = 60;
+ Point finalTeleportPoint = Point.Zero;
+ for (int i = 0; i < attempts; i++)
+ {
+ for (int x = -rangeX; x <= rangeX; x++)
+ {
+ for (int y = 0; y <= rangeY; y++)
+ {
+ int teleportPosX = teleportStartX + x + Main.rand.Next(-randomFluff, randomFluff);
+ int teleportPosY = teleportStartY + y + Main.rand.Next(-randomFluff, randomFluff);
+ Tile tile = Framing.GetTileSafely(teleportPosX, teleportPosY);
+ Tile tileAbove = Framing.GetTileSafely(teleportPosX, teleportPosY - 1);
+ Tile tileBelow = Framing.GetTileSafely(teleportPosX, teleportPosY + 1);
+
+ if (!tileAbove.HasTile && tileBelow.HasUnactuatedTile && Main.wallDungeon[tile.WallType])
+ {
+ finalTeleportPoint = new(tile.X(), tile.Y());
+ if (!Collision.SolidCollision(finalTeleportPoint.ToWorldCoordinates(), player.width, player.height))
+ break;
+ }
+ }
+ }
+ }
+
+ return finalTeleportPoint.ToWorldCoordinates() - new Vector2(player.width, player.height);
+ }
+
public static void ModTeleport(Player player, Vector2 pos, bool playSound = true, int style = TeleportationStyleID.RecallPotion)
{
bool postImmune = player.immune;
diff --git a/Items/Potions/TheElixir.cs b/Items/Potions/TheElixir.cs
new file mode 100644
index 0000000000..9a18138074
--- /dev/null
+++ b/Items/Potions/TheElixir.cs
@@ -0,0 +1,111 @@
+using CalamityMod.CalPlayer;
+using CalamityMod.Systems;
+using Microsoft.Xna.Framework;
+using Terraria;
+using Terraria.Audio;
+using Terraria.ID;
+using Terraria.ModLoader;
+
+namespace CalamityMod.Items.Potions
+{
+ public class TheElixir : ModItem, ILocalizedModType
+ {
+ public new string LocalizationCategory => "Items.Potions";
+
+ public override void SetStaticDefaults()
+ {
+ Item.ResearchUnlockCount = 20;
+ ItemID.Sets.DrinkParticleColors[Type] = new Color[3] {
+ new Color(159, 67, 199),
+ new Color(176, 147, 243),
+ new Color(84, 50, 185)
+ };
+ }
+
+ public override void SetDefaults()
+ {
+ Item.value = Item.sellPrice(silver: 2);
+ Item.rare = ItemRarityID.Blue;
+ Item.DefaultToFood(28, 51, 0, 0, true);
+ }
+
+ // Player is unable to use the item when Chaos State is enabled to prevent spamming the item.
+ // Even though the item also inflicts Cursed, this is kept as a failsafe in the event the player has something equipped that
+ // provides immunity to Cursed. (i.e Countercurse Mantra or Nazar)
+ public override bool CanUseItem(Player player)
+ {
+ if (player.HasBuff(BuffID.ChaosState))
+ return false;
+
+ return base.CanUseItem(player);
+ }
+
+ public override bool? UseItem(Player player)
+ {
+ if (player.whoAmI == Main.myPlayer)
+ {
+ if (Main.rand.NextBool(4))
+ {
+ int roll = Main.rand.Next(3);
+ Vector2? location = roll switch
+ {
+ 1 => CalamityPlayer.GetAbyssVoidTeleportPosition(player),
+ 2 => CalamityPlayer.GetTempleTeleportPosition(player),
+ _ => CalamityPlayer.GetDungeonArchivesTeleportPosition(player)
+ };
+
+ if (!location.HasValue)
+ return false;
+
+ player.AddBuff(BuffID.ChaosState, 300, false);
+ player.AddBuff(BuffID.Cursed, 300, false);
+ CalamityPlayer.ModTeleport(player, location.Value, false, TeleportationStyleID.RecallPotion);
+ }
+ //If it doesn't fail, just act like a Potion of Return
+ else
+ player.DoPotionOfReturnTeleportationAndSetTheComebackPoint();
+
+ //Dust and Teleport sounds happen regardless of if it fails or not
+ Rectangle rect = player.getRect();
+ int dustAmt = rect.Width * rect.Height / 5;
+ for (int k = 0; k < dustAmt; k++)
+ {
+ Dust dust = Dust.NewDustDirect(new Vector2(rect.X, rect.Y), rect.Width, rect.Height, DustID.TeleportationPotion);
+ dust.scale = Main.rand.NextFloat(0.2f, 0.7f);
+ if (k < 10)
+ dust.scale += 0.25f;
+ if (k < 5)
+ dust.scale += 0.25f;
+ }
+ for (int k = 0; k < 70; k++)
+ {
+ Dust dust = Dust.NewDustDirect(new Vector2(rect.X, rect.Y), rect.Width, rect.Height, DustID.DungeonSpirit);
+ dust.noGravity = true;
+ for (int i = 0; i < 5; i++)
+ {
+ if (Main.rand.NextBool(3))
+ dust.velocity *= 0.75f;
+ }
+ if (Main.rand.NextBool(3))
+ {
+ dust.velocity *= 2f;
+ dust.scale *= 1.2f;
+ }
+ if (Main.rand.NextBool(3))
+ {
+ dust.velocity *= 2f;
+ dust.scale *= 1.2f;
+ }
+ if (Main.rand.NextBool())
+ {
+ dust.fadeIn = Main.rand.NextFloat(0.75f, 1f);
+ dust.scale = Main.rand.NextFloat(0.25f, 0.75f);
+ }
+ dust.scale *= 0.8f;
+ }
+ SoundEngine.PlaySound(SoundID.Item6, player.Center);
+ }
+ return true;
+ }
+ }
+}
diff --git a/Items/Potions/TheElixir.png b/Items/Potions/TheElixir.png
new file mode 100644
index 0000000000..1d25a72177
Binary files /dev/null and b/Items/Potions/TheElixir.png differ
diff --git a/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson b/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson
index d31e4bf699..6064fba5d9 100644
--- a/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson
+++ b/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson
@@ -487,6 +487,15 @@ TequilaSunrise: {
'''
}
+TheElixir: {
+ DisplayName: The Elixir
+ Tooltip:
+ '''
+ Functions as a Potion of Return
+ Occasionally sends you... [c/AA23C4:somewhere else]
+ '''
+}
+
Vodka: {
DisplayName: Vodka
Tooltip:
diff --git a/Systems/World/WorldgenManagementSystem.cs b/Systems/World/WorldgenManagementSystem.cs
index 5399d037a4..0ccd7c76dc 100644
--- a/Systems/World/WorldgenManagementSystem.cs
+++ b/Systems/World/WorldgenManagementSystem.cs
@@ -12,6 +12,7 @@ using Terraria.GameContent.Generation;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
+using Terraria.ModLoader.IO;
using Terraria.WorldBuilding;
using static CalamityMod.World.CalamityWorld;
@@ -19,10 +20,28 @@ namespace CalamityMod.Systems
{
public class WorldgenManagementSystem : ModSystem
{
+ #region StructurePosStoring
+ public static Point DungeonArchivePos = Point.Zero;
+
+ public override void SaveWorldData(TagCompound tag)
+ {
+ tag["DungeonArchivePos"] = DungeonArchivePos;
+ }
+
+ public override void LoadWorldData(TagCompound tag)
+ {
+ if (tag.ContainsKey("DungeonArchivePos"))
+ DungeonArchivePos = tag.Get("DungeonArchivePos");
+ else
+ DungeonArchivePos = Point.Zero;
+ }
+ #endregion
+
#region PreWorldGen
public override void PreWorldGen()
{
Abyss.TotalPlacedIslandsSoFar = 0;
+ DungeonArchivePos = Point.Zero;
//roxShrinePlaced = false;
// This will only be applied at world-gen time to new worlds.
diff --git a/World/DungeonArchive.cs b/World/DungeonArchive.cs
index a1958e2331..59fd429795 100644
--- a/World/DungeonArchive.cs
+++ b/World/DungeonArchive.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using CalamityMod.Schematics;
+using CalamityMod.Systems;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
@@ -72,6 +73,8 @@ namespace CalamityMod.World
if (placedArchive)
{
+ WorldgenManagementSystem.DungeonArchivePos = new Point(i, j);
+
bool firstItem = false;
if (dungeonArchiveColor == 0)