Sulphuric water poison meter

This commit is contained in:
Dominic committed 2022-10-14 11:24:42 -05:00
1 parent 3a4fe3b586
commit 93aeb92d84
8 files changed
+196 -27

No files matched your search

+8 -1
View File
@@ -80,6 +80,7 @@ namespace CalamityMod.CalPlayer
public static bool areThereAnyDamnEvents = false;
public bool drawBossHPBar = true;
public float stealthUIAlpha = 1f;
public float SulphWaterUIOpacity = 1f;
public bool shouldDrawSmallText = true;
public int projTypeJustHitBy;
public int sCalDeathCount = 0;
@@ -195,7 +196,6 @@ namespace CalamityMod.CalPlayer
public int modStealthTimer;
public int dashTimeMod;
public int hInfernoBoost = 0;
public int pissWaterBoost = 0;
public int packetTimer = 0;
public int navyRodAuraTimer = 0;
public int brimLoreInfernoTimer = 0;
@@ -225,6 +225,7 @@ namespace CalamityMod.CalPlayer
public int aBulwarkRareTimer = 0;
public int spiritOriginBullseyeShootCountdown = 0;
public int spiritOriginConvertedCrit = 0;
public float SulphWaterPoisoningLevel;
private const int DashDisableCooldown = 12;
@@ -776,6 +777,9 @@ namespace CalamityMod.CalPlayer
public bool banishingFire = false;
public bool wither = false;
public bool ManaBurn = false;
public const int SulphSeaWaterSafetyTime = 720;
public const int SulphSeaWaterRecoveryTime = 150;
#endregion
#region Buff
@@ -2120,6 +2124,7 @@ namespace CalamityMod.CalPlayer
auralisAurora = 0;
fungalSymbioteTimer = 0;
aBulwarkRareTimer = 0;
SulphWaterPoisoningLevel = 0f;
spiritOriginConvertedCrit = 0;
rage = 0f;
adrenaline = 0f;
@@ -2213,6 +2218,8 @@ namespace CalamityMod.CalPlayer
stealthUIAlpha -= 0.035f;
stealthUIAlpha = MathHelper.Clamp(stealthUIAlpha, 0f, 1f);
}
if (SulphWaterUIOpacity > 0f)
SulphWaterUIOpacity = MathHelper.Clamp(SulphWaterUIOpacity - 0.035f, 0f, 1f);
#endregion
#region Buffs
+12 -26
View File
@@ -9,6 +9,7 @@ using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ModLoader;
using Terraria.DataStructures;
namespace CalamityMod.CalPlayer
{
@@ -156,39 +157,24 @@ namespace CalamityMod.CalPlayer
lifeRegenLost += 4;
}
// Slowly increase the sulphuric water poisoning effect. Once it's high enough, the player starts taking damage over time.
if (ZoneSulphur && Player.IsUnderwater() && !decayEffigy && !abyssalDivingSuit && !Player.lavaWet && !Player.honeyWet)
{
Player.AddBuff(ModContent.BuffType<SulphuricPoisoning>(), 2, true);
pissWaterBoost++;
float increment = 1f / SulphSeaWaterSafetyTime;
if (sulphurskin)
increment *= 0.5f;
if (sulfurSet)
increment *= 0.5f;
if (Player.lifeRegen > 0)
Player.lifeRegen = 0;
Player.lifeRegenTime = 0;
int waterDivisor = 250;
int minimumRegenLost = 8;
if (sulfurSet && sulphurskin)
SulphWaterPoisoningLevel = MathHelper.Clamp(SulphWaterPoisoningLevel + increment, 0f, 1f);
if (SulphWaterPoisoningLevel >= 1f)
{
waterDivisor = 500;
minimumRegenLost = 1;
SulphWaterPoisoningLevel = 0f;
Player.Hurt(PlayerDeathReason.ByCustomReason($"{Player.name}'s flesh was dissolved by sulphuric water."), Math.Min(Player.statLifeMax2 / 2, 200), 0);
}
else if (sulfurSet)
{
waterDivisor = 400;
minimumRegenLost = 3;
}
else if (sulphurskin)
{
waterDivisor = 350;
minimumRegenLost = 2;
}
int sulphurWater = pissWaterBoost / waterDivisor;
if (sulphurWater < minimumRegenLost)
sulphurWater = minimumRegenLost;
lifeRegenLost += sulphurWater;
}
else
pissWaterBoost = 0;
SulphWaterPoisoningLevel = MathHelper.Clamp(SulphWaterPoisoningLevel - 1f / SulphSeaWaterRecoveryTime, 0f, 1f);
if (sulphurPoison)
{
+20
View File
@@ -17,6 +17,7 @@ using Terraria.ModLoader.Config;
using CalamityMod.Items.PermanentBoosters;
using CalamityMod.UI.Rippers;
using CalamityMod.UI.DraedonsArsenal;
using CalamityMod.UI.SulphurousWaterMeter;
namespace CalamityMod
{
@@ -140,6 +141,22 @@ namespace CalamityMod
[Tooltip("$Mods.CalamityMod.Config.EntryTooltip.StealthMeterPosY")]
public float StealthMeterPosY { get; set; }
[Label("$Mods.CalamityMod.Config.EntryTitle.SulphuricWaterMeterPosX")]
[BackgroundColor(192, 54, 64, 192)]
[SliderColor(224, 165, 56, 128)]
[Range(0f, 100f)]
[DefaultValue(SulphurousWaterMeterUI.DefaultPosX)]
[Tooltip("$Mods.CalamityMod.Config.EntryTooltip.SulphuricWaterMeterPosX")]
public float SulphuricWaterMeterPosX { get; set; }
[Label("$Mods.CalamityMod.Config.EntryTitle.SulphuricWaterMeterPosY")]
[BackgroundColor(192, 54, 64, 192)]
[SliderColor(224, 165, 56, 128)]
[Range(0f, 100f)]
[DefaultValue(SulphurousWaterMeterUI.DefaultPosY)]
[Tooltip("$Mods.CalamityMod.Config.EntryTooltip.SulphuricWaterMeterPosY")]
public float SulphuricWaterMeterPosY { get; set; }
[Label("$Mods.CalamityMod.Config.EntryTitle.ChargeMeter")]
[BackgroundColor(192, 54, 64, 192)]
[DefaultValue(true)]
@@ -394,6 +411,9 @@ namespace CalamityMod
new("StealthMeterPosX", ItemID.LaserRuler),
new("StealthMeterPosY", ItemID.LaserRuler),
new("SulphuricWaterMeterPosX", ItemID.LaserRuler),
new("SulphuricWaterMeterPosY", ItemID.LaserRuler),
new("ChargeMeter", ModContent.ItemType<DraedonPowerCell>()),
new("ChargeMeterPosX", ItemID.LaserRuler),
new("ChargeMeterPosY", ItemID.LaserRuler),
+4
View File
@@ -56,6 +56,8 @@ Config:
"StealthMeter": "Display Stealth Meter",
"StealthMeterPosX": "Stealth Meter X Position",
"StealthMeterPosY": "Stealth Meter Y Position",
"SulphuricWaterMeterPosX": "Sulphuric Water Poison Meter X Position",
"SulphuricWaterMeterPosY": "Sulphuric Water Poison Meter Y Position",
"TownNPCSpawnRateMultiplier": "Town NPC Spawn Rate Multiplier",
"TownNPCsSpawnAtNight": "Town NPCs Spawn at Night",
"VanillaCooldownDisplay": "Display Vanilla Cooldowns",
@@ -102,6 +104,8 @@ Config:
"StealthMeter": "Enables the Stealth Meter UI, which shows the player's current stealth level.\nThe Stealth Meter is always hidden if not wearing Rogue armor.",
"StealthMeterPosX": "The X position of the Stealth Meter, measured as a % of your screen width.\nThe meter can be dragged with the mouse if Lock Meter Positions is disabled.",
"StealthMeterPosY": "The Y position of the Stealth Meter, measured as a % of your screen height.\nThe meter can be dragged with the mouse if Lock Meter Positions is disabled.",
"SulphuricWaterMeterPosX": "The X position of the Sulphuric Water Poison Meter, measured as a % of your screen width.\nThe meter can be dragged with the mouse if Lock Meter Positions is disabled.",
"SulphuricWaterMeterPosY": "The Y position of the Sulphuric Water Poison Meter, measured as a % of your screen height.\nThe meter can be dragged with the mouse if Lock Meter Positions is disabled.",
"TownNPCSpawnRateMultiplier": "Directly multiply the rate at which town NPCs spawn and respawn.\nThis reduces waiting times if a boss or event wipes your whole town.",
"TownNPCsSpawnAtNight": "When enabled, town NPCs can spawn and respawn at night.\nThis includes the Old Man.",
"VanillaCooldownDisplay": "Adds the vanilla debuffs Potion Sickness and Chaos State to the Cooldown Rack.\nThis doesn't remove them from your buff list, but can help with visibility nontheless",
+8
View File
@@ -5,6 +5,7 @@ using CalamityMod.UI.DraedonsArsenal;
using CalamityMod.UI.DraedonSummoning;
using CalamityMod.UI.ModeIndicator;
using CalamityMod.UI.Rippers;
using CalamityMod.UI.SulphurousWaterMeter;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
@@ -89,6 +90,13 @@ namespace CalamityMod.Systems
return true;
}, InterfaceScaleType.None));
// Sulphuric water poison bar
layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Sulphuric Water Poisoning UI", () =>
{
SulphurousWaterMeterUI.Draw(Main.spriteBatch, Main.LocalPlayer);
return true;
}, InterfaceScaleType.None));
// Charge meter
layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Charge UI", () =>
{
Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

@@ -0,0 +1,144 @@
using System;
using CalamityMod.CalPlayer;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using ReLogic.Content;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.UI.SulphurousWaterMeter
{
public class SulphurousWaterMeterUI : ModSystem
{
// These values were decided relative to the stealth meter positions, and are by default slightly below them.
internal const float DefaultPosX = StealthUI.DefaultStealthPosX;
internal const float DefaultPosY = StealthUI.DefaultStealthPosY + 0.0377f;
private const float MouseDragEpsilon = 0.05f; // 0.05%
private static Vector2? dragOffset = null;
private static Texture2D edgeTexture, barTexture;
public override void OnModLoad()
{
edgeTexture = ModContent.Request<Texture2D>("CalamityMod/UI/SulphurousWaterMeter/SulphWaterMeter", AssetRequestMode.ImmediateLoad).Value;
barTexture = ModContent.Request<Texture2D>("CalamityMod/UI/SulphurousWaterMeter/SulphWaterBar", AssetRequestMode.ImmediateLoad).Value;
Reset();
}
public override void Unload()
{
Reset();
edgeTexture = barTexture = null;
}
private static void Reset() => dragOffset = null;
public static void Draw(SpriteBatch spriteBatch, Player player)
{
// Sanity check the planned position before drawing. This is done relative.
Vector2 screenRatioPosition = new Vector2(CalamityConfig.Instance.SulphuricWaterMeterPosX, CalamityConfig.Instance.SulphuricWaterMeterPosY);
if (screenRatioPosition.X < 0f || screenRatioPosition.X > 100f)
screenRatioPosition.X = DefaultPosX;
if (screenRatioPosition.Y < 0f || screenRatioPosition.Y > 100f)
screenRatioPosition.Y = DefaultPosY;
// Convert the screen ratio position to an absolute position in pixels
// Cast to integer to prevent blurriness which results from decimal pixel positions
float uiScale = Main.UIScale;
Vector2 screenPos = screenRatioPosition;
screenPos.X = (int)(screenPos.X * 0.01f * Main.screenWidth);
screenPos.Y = (int)(screenPos.Y * 0.01f * Main.screenHeight);
CalamityPlayer modPlayer = player.Calamity();
// If not drawing the water meter, save its latest position to config and leave.
if (modPlayer.SulphWaterUIOpacity > 0f)
DrawWaterBar(spriteBatch, modPlayer, screenPos);
else
{
bool changed = false;
if (CalamityConfig.Instance.SulphuricWaterMeterPosX != screenRatioPosition.X)
{
CalamityConfig.Instance.SulphuricWaterMeterPosX = screenRatioPosition.X;
changed = true;
}
if (CalamityConfig.Instance.SulphuricWaterMeterPosY != screenRatioPosition.Y)
{
CalamityConfig.Instance.SulphuricWaterMeterPosY = screenRatioPosition.Y;
changed = true;
}
if (changed)
CalamityMod.SaveConfig(CalamityConfig.Instance);
}
Rectangle mouseHitbox = new Rectangle((int)Main.MouseScreen.X, (int)Main.MouseScreen.Y, 8, 8);
Rectangle waterBarArea = Utils.CenteredRectangle(screenPos, edgeTexture.Size() * uiScale);
MouseState ms = Mouse.GetState();
Vector2 mousePos = Main.MouseScreen;
// Handle mouse dragging
if (waterBarArea.Intersects(mouseHitbox))
{
if (!CalamityConfig.Instance.MeterPosLock)
Main.LocalPlayer.mouseInterface = true;
// If the mouse is on top of the meter, show the player's accumulated sulphuric poisoning.
if (modPlayer.SulphWaterPoisoningLevel > 0f && modPlayer.SulphWaterUIOpacity >= 0f)
{
string poisonText = (modPlayer.SulphWaterPoisoningLevel * 100f).ToString("n2");
string textToDisplay = $"Sulphuric Poisoning: {poisonText}/100";
Main.instance.MouseText(textToDisplay, 0, 0, -1, -1, -1, -1);
modPlayer.SulphWaterUIOpacity = MathHelper.Lerp(modPlayer.SulphWaterUIOpacity, 0.25f, 0.035f);
}
Vector2 newScreenRatioPosition = screenRatioPosition;
// As long as the mouse button is held down, drag the meter along with an offset.
if (!CalamityConfig.Instance.MeterPosLock && ms.LeftButton == ButtonState.Pressed)
{
// If the drag offset doesn't exist yet, create it.
if (!dragOffset.HasValue)
dragOffset = mousePos - screenPos;
// Given the mouse's absolute current position, compute where the corner of the water bar should be based on the original drag offset.
Vector2 newCorner = mousePos - dragOffset.GetValueOrDefault(Vector2.Zero);
// Convert the new corner position into a screen ratio position.
newScreenRatioPosition.X = (100f * newCorner.X) / Main.screenWidth;
newScreenRatioPosition.Y = (100f * newCorner.Y) / Main.screenHeight;
}
// Compute the change in position. If it is large enough, actually move the meter
Vector2 delta = newScreenRatioPosition - screenRatioPosition;
if (Math.Abs(delta.X) >= MouseDragEpsilon || Math.Abs(delta.Y) >= MouseDragEpsilon)
{
CalamityConfig.Instance.SulphuricWaterMeterPosX = newScreenRatioPosition.X;
CalamityConfig.Instance.SulphuricWaterMeterPosY = newScreenRatioPosition.Y;
}
// When the mouse is released, save the config and destroy the drag offset.
if (ms.LeftButton == ButtonState.Released)
{
dragOffset = null;
CalamityMod.SaveConfig(CalamityConfig.Instance);
}
}
else
modPlayer.SulphWaterUIOpacity = MathHelper.Clamp(modPlayer.SulphWaterUIOpacity + (modPlayer.SulphWaterPoisoningLevel > 0f).ToDirectionInt() * 0.06f, 0f, 1f);
}
private static void DrawWaterBar(SpriteBatch spriteBatch, CalamityPlayer modPlayer, Vector2 screenPos)
{
float uiScale = Main.UIScale;
float offset = (edgeTexture.Width - barTexture.Width) * 0.5f;
spriteBatch.Draw(edgeTexture, screenPos, null, Color.White * modPlayer.SulphWaterUIOpacity, 0f, edgeTexture.Size() * 0.5f, uiScale, SpriteEffects.None, 0);
float completionRatio = MathHelper.Clamp(modPlayer.SulphWaterPoisoningLevel, 0f, 1f);
Rectangle barRectangle = new Rectangle(0, 0, (int)(barTexture.Width * completionRatio), barTexture.Width);
spriteBatch.Draw(barTexture, screenPos + new Vector2(offset * uiScale, 0), barRectangle, Color.White * modPlayer.SulphWaterUIOpacity, 0f, edgeTexture.Size() * 0.5f, uiScale, SpriteEffects.None, 0);
}
}
}