Add dungeon tp logic

This commit is contained in:
Nathanael Overton committed 2026-04-29 19:15:09 -04:00
1 parent 53e1f51c56
commit 7fe67be756
4 files changed
+65 -7

No files matched your search

+28
View File
@@ -4325,6 +4325,34 @@ namespace CalamityMod.CalPlayer
return null;
}
public static Vector2? GetDungeonArchivePosition(Player player)
{
if (WorldgenManagementSystem.DungeonArchivePos == Point.Zero)
return null;
bool canSpawn = false;
// Define an area around the center to search for a valid spot to tp
int rangeX = 10;
int rangeY = 30;
int teleportStartX = WorldgenManagementSystem.DungeonArchivePos.X - rangeX;
int teleportStartY = WorldgenManagementSystem.DungeonArchivePos.Y;
Player.RandomTeleportationAttemptSettings settings = new Player.RandomTeleportationAttemptSettings
{
mostlySolidFloor = true,
avoidAnyLiquid = true,
avoidLava = true,
avoidHurtTiles = true,
avoidWalls = false,
attemptsBeforeGivingUp = 1000,
maximumFallDistanceFromOrignalPoint = 30
};
Vector2 vector = player.CheckForGoodTeleportationSpot(ref canSpawn, teleportStartX, rangeX, teleportStartY, rangeY, settings);
return canSpawn ? vector : null;
}
public static void ModTeleport(Player player, Vector2 pos, bool playSound = true, int style = TeleportationStyleID.RecallPotion)
{
+15 -7
View File
@@ -1,4 +1,5 @@
using CalamityMod.CalPlayer;
using CalamityMod.Systems;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
@@ -41,20 +42,27 @@ namespace CalamityMod.Items.Potions
{
if (player.whoAmI == Main.myPlayer)
{
if (Main.rand.NextBool(2))
if (Main.rand.NextBool(1))
{
//If it fails, inflict the player with 5 seconds of Chaos State
player.AddBuff(BuffID.ChaosState, 300, true);
Vector2? abyss = CalamityPlayer.GetAbyssPosition(player);
if (!abyss.HasValue)
Vector2? location;
bool archiveStoredPositionExists = WorldgenManagementSystem.DungeonArchivePos != Point.Zero;
if (archiveStoredPositionExists && Main.rand.NextBool())
location = CalamityPlayer.GetDungeonArchivePosition(player);
else
location = CalamityPlayer.GetAbyssPosition(player);
if (!location.HasValue)
return false;
CalamityPlayer.ModTeleport(player, abyss.Value, false, TeleportationStyleID.RodOfDiscord);
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;
+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)