From 3e4597bbaba3560936f349235349f7edc9bdbdfb Mon Sep 17 00:00:00 2001 From: fryzahh Date: Tue, 9 Jun 2026 20:52:22 -0400 Subject: [PATCH] Another elixir fix attempt --- Items/Potions/TheElixir.cs | 59 ++++++++++--------- .../Players/TheElixirTeleportSyncPacket.cs | 23 ++------ 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/Items/Potions/TheElixir.cs b/Items/Potions/TheElixir.cs index ebd7dd105f..f171f01100 100644 --- a/Items/Potions/TheElixir.cs +++ b/Items/Potions/TheElixir.cs @@ -6,8 +6,8 @@ using Terraria; using Terraria.Audio; using Terraria.Chat; using Terraria.ID; -using Terraria.ModLoader; using Terraria.Localization; +using Terraria.ModLoader; namespace CalamityMod.Items.Potions { @@ -45,45 +45,32 @@ namespace CalamityMod.Items.Potions public override bool? UseItem(Player player) { + // 25% chance to "fail" a teleport and send the player to one of three random dangerous locations. if (Main.rand.NextBool(4)) { + if (Main.netMode == NetmodeID.SinglePlayer) + { + player.GetModPlayer().RunDangerousLocationTeleportation(); + } + else if (player.whoAmI == Main.myPlayer) + { + TheElixirTeleportSyncPacket.Send(player); + } + if (player.whoAmI == Main.myPlayer) { - Vector2? location = null; - int locationIndex = Main.rand.Next(3); - if (locationIndex == 0) - location = CalamityPlayer.GetDungeonArchivesTeleportPosition(player); - if (locationIndex == 1) - location = CalamityPlayer.GetAbyssVoidTeleportPosition(player); - if (locationIndex == 2) - location = CalamityPlayer.GetTempleTeleportPosition(player); - - if (Main.netMode == NetmodeID.SinglePlayer) - { - 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); - } - else - { - TheElixirTeleportSyncPacket.Send(player, locationIndex); - SoundEngine.PlaySound(SoundID.Item6, player.Center); - } + player.AddBuff(BuffID.ChaosState, 300); + player.AddBuff(BuffID.Cursed, 300); } } //If it doesn't fail, just act like a Potion of Return else { if (player.whoAmI == Main.myPlayer) - { player.DoPotionOfReturnTeleportationAndSetTheComebackPoint(); - SoundEngine.PlaySound(SoundID.Item6, player.Center); - } } + //Dust and Teleport sounds happen regardless of if it fails or not Rectangle rect = player.getRect(); int dustAmt = rect.Width * rect.Height / 5; @@ -125,4 +112,22 @@ namespace CalamityMod.Items.Potions return true; } } + + public class TheElixirPlayer : ModPlayer + { + public void RunDangerousLocationTeleportation() + { + int locationIndex = Main.rand.Next(3); + Vector2? location = null; + if (locationIndex == 0) + location = CalamityPlayer.GetDungeonArchivesTeleportPosition(Player); + if (locationIndex == 1) + location = CalamityPlayer.GetAbyssVoidTeleportPosition(Player); + if (locationIndex == 2) + location = CalamityPlayer.GetTempleTeleportPosition(Player); + + if (location.HasValue) + CalamityPlayer.ModTeleport(Player, location.Value, true, TeleportationStyleID.RecallPotion); + } + } } diff --git a/Packets/Players/TheElixirTeleportSyncPacket.cs b/Packets/Players/TheElixirTeleportSyncPacket.cs index aa3adda15c..d07339afa3 100644 --- a/Packets/Players/TheElixirTeleportSyncPacket.cs +++ b/Packets/Players/TheElixirTeleportSyncPacket.cs @@ -1,5 +1,6 @@ using System.IO; using CalamityMod.CalPlayer; +using CalamityMod.Items.Potions; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; @@ -10,39 +11,23 @@ namespace CalamityMod.Packets { public static TheElixirTeleportSyncPacket Instance { get; private set; } - public static void Send(Player player, int locationIndex = -1, int toClient = -1, int ignoreClient = -1) + public static void Send(Player player, int toClient = -1, int ignoreClient = -1) { - if (player is null || locationIndex == -1) + if (player is null) return; var packet = Instance.CreateBasePacket(); packet.WriteWhoAmI(player); - packet.Write(locationIndex); packet.Send(toClient, ignoreClient); } public override void HandlePacket(BinaryReader packet, int sender) { var player = packet.ReadPlayer(); - var locationIndex = packet.ReadInt32(); - if (player is null) return; - Vector2? location = null; - if (locationIndex == 0) - location = CalamityPlayer.GetDungeonArchivesTeleportPosition(player); - if (locationIndex == 1) - location = CalamityPlayer.GetAbyssVoidTeleportPosition(player); - if (locationIndex == 2) - location = CalamityPlayer.GetTempleTeleportPosition(player); - - if (!location.HasValue) - return; - - player.AddBuff(BuffID.ChaosState, 300, false); - player.AddBuff(BuffID.Cursed, 300, false); - CalamityPlayer.ModTeleport(player, location.Value, false, TeleportationStyleID.RecallPotion); + player.GetModPlayer().RunDangerousLocationTeleportation(); } } }