Merge pull request #1406 from CalamityTeam/TheElixir

The Elixir
This commit is contained in:
CongratsIsTrash authored and GitHub committed 2026-04-30 19:17:11 -04:00
commit 4098f2deaf
6 files changed
+350 -2

No files matched your search

+208 -2
View File
@@ -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;
}
/// <summary>
/// Returns a random position in the Lihzhard Temple to teleport the player to. <br></br>
/// Used primarily for <see cref="Items.Potions.TheElixir"/>.
/// </summary>
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);
}
/// <summary>
/// Returns a random position in the Void (Abyss Layer 4) to teleport the player to. <br></br>
/// Used primarily for <see cref="Items.Potions.TheElixir"/>.
/// </summary>
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;
}
/// <summary>
/// Returns a random position in the Forsaken Archives to teleport the player to. <br></br>
/// Used primarily for <see cref="Items.Potions.TheElixir"/>.
/// </summary>
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;
+111
View File
@@ -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;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 933 B

@@ -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:
+19
View File
@@ -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<Point>("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.
+3
View File
@@ -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)