From 93aeb92d849cb3f9ccfbdac389bb5b3f3372b78c Mon Sep 17 00:00:00 2001 From: Dominic Date: Fri, 14 Oct 2022 11:24:42 -0500 Subject: [PATCH] Sulphuric water poison meter --- CalPlayer/CalamityPlayer.cs | 9 +- CalPlayer/CalamityPlayerLifeRegen.cs | 38 ++--- CalamityConfig.cs | 20 +++ Localization/enUS.hjson | 4 + Systems/UIManagementSystem.cs | 8 + UI/SulphurousWaterMeter/SulphWaterBar.png | Bin 0 -> 166 bytes UI/SulphurousWaterMeter/SulphWaterMeter.png | Bin 0 -> 298 bytes .../SulphurousWaterMeterUI.cs | 144 ++++++++++++++++++ 8 files changed, 196 insertions(+), 27 deletions(-) create mode 100644 UI/SulphurousWaterMeter/SulphWaterBar.png create mode 100644 UI/SulphurousWaterMeter/SulphWaterMeter.png create mode 100644 UI/SulphurousWaterMeter/SulphurousWaterMeterUI.cs diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index a08c46c1d0..5343c75a2f 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -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 diff --git a/CalPlayer/CalamityPlayerLifeRegen.cs b/CalPlayer/CalamityPlayerLifeRegen.cs index 7ce319a4a4..690cc1a53f 100644 --- a/CalPlayer/CalamityPlayerLifeRegen.cs +++ b/CalPlayer/CalamityPlayerLifeRegen.cs @@ -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(), 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) { diff --git a/CalamityConfig.cs b/CalamityConfig.cs index f5553c1b85..a5dfabdaa3 100644 --- a/CalamityConfig.cs +++ b/CalamityConfig.cs @@ -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()), new("ChargeMeterPosX", ItemID.LaserRuler), new("ChargeMeterPosY", ItemID.LaserRuler), diff --git a/Localization/enUS.hjson b/Localization/enUS.hjson index 7dfc0377d0..753cd9e2d4 100644 --- a/Localization/enUS.hjson +++ b/Localization/enUS.hjson @@ -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", diff --git a/Systems/UIManagementSystem.cs b/Systems/UIManagementSystem.cs index 4d93a3799e..bb9155904d 100644 --- a/Systems/UIManagementSystem.cs +++ b/Systems/UIManagementSystem.cs @@ -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", () => { diff --git a/UI/SulphurousWaterMeter/SulphWaterBar.png b/UI/SulphurousWaterMeter/SulphWaterBar.png new file mode 100644 index 0000000000000000000000000000000000000000..0ef0e181d8cfc6b7acd39a437aac5ea8f9c671bb GIT binary patch literal 166 zcmeAS@N?(olHy`uVBq!ia0vp^3P3Ex!3HF)PTTVM%xNb!1@J z*w6hZkrl}2EbxddW?8eR=RL2FMJ#}E(iWC_;A2_iie2P_t5+^pA-*8ZVU z%zNq(U&NJdPLVelch8iX(kg4<_>z%%F&{|j5@t3whHdVwSLPp)ng%q6!PC{xWt~$( F69C1aEqwq0 literal 0 HcmV?d00001 diff --git a/UI/SulphurousWaterMeter/SulphWaterMeter.png b/UI/SulphurousWaterMeter/SulphWaterMeter.png new file mode 100644 index 0000000000000000000000000000000000000000..72b6858ebf13b053c5f716c0ece4de72a4a7bf00 GIT binary patch literal 298 zcmeAS@N?(olHy`uVBq!ia0vp^CO|C2!3-pogLyvzDaPU;cPEB*=VV?2IV|apzK#qG z8~eHcB(ehe5&=FTu8eH_g;DO72Eppers<9jK33K?o{2!olaC@E11XM@Aiv=M5WsM+ zd2b|8jI+QavY3H^?+^$xifVW@00rAUT^vI!{FhD)6lzf5aB;q~=YMZ8^KzeDwW|69 z`%Lbc(NO*6D~yyMr8+!17<5wdL}h$J@H0PU71P$-xQ6R*HtH>1 z=BlcF{KMoaGngMu(o$ghk>ly@s;U=ob=tvcf6Mq;qnSkOmrrQnl3r%;Aiv6PRpuXq h;{QwXTb2az)t~3Qxh8hXKA@8rJYD@<);T3K0RZg{XfXf) literal 0 HcmV?d00001 diff --git a/UI/SulphurousWaterMeter/SulphurousWaterMeterUI.cs b/UI/SulphurousWaterMeter/SulphurousWaterMeterUI.cs new file mode 100644 index 0000000000..4244b70d54 --- /dev/null +++ b/UI/SulphurousWaterMeter/SulphurousWaterMeterUI.cs @@ -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("CalamityMod/UI/SulphurousWaterMeter/SulphWaterMeter", AssetRequestMode.ImmediateLoad).Value; + barTexture = ModContent.Request("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); + } + } +}