Another elixir fix attempt
This commit is contained in:
1 parent
45d2483374
commit
3e4597bbab
2 files changed
+36
-46
No files matched your search
+32
-27
@@ -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<TheElixirPlayer>().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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<TheElixirPlayer>().RunDangerousLocationTeleportation();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user