From fb1df16d7977b2e9cd7b20889ee052bb3e6d7951 Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Wed, 16 Aug 2023 19:10:51 -0400 Subject: [PATCH] Finished mechanical work on Lunic Corps armor to match Halo Needs testing and a few TODOs --- CalPlayer/CalamityPlayer.cs | 16 +++++- CalPlayer/CalamityPlayerMiscEffects.cs | 32 +++++++++-- ...eldDurability.png => LunicCorpsShield.png} | Bin ...yActive.png => LunicCorpsShieldActive.png} | Bin ...bility.cs => LunicCorpsShieldCooldowns.cs} | 54 ++++++++++-------- ...utline.png => LunicCorpsShieldOutline.png} | Bin ...verlay.png => LunicCorpsShieldOverlay.png} | Bin ...Drive.cs => WulfrumRoverDriveCooldowns.cs} | 16 ++++-- 8 files changed, 81 insertions(+), 37 deletions(-) rename Cooldowns/{MasterChefShieldDurability.png => LunicCorpsShield.png} (100%) rename Cooldowns/{MasterChefShieldDurabilityActive.png => LunicCorpsShieldActive.png} (100%) rename Cooldowns/{MasterChefShieldDurability.cs => LunicCorpsShieldCooldowns.cs} (73%) rename Cooldowns/{MasterChefShieldDurabilityOutline.png => LunicCorpsShieldOutline.png} (100%) rename Cooldowns/{MasterChefShieldDurabilityOverlay.png => LunicCorpsShieldOverlay.png} (100%) rename Cooldowns/{WulfrumRoverDrive.cs => WulfrumRoverDriveCooldowns.cs} (91%) diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 7d1ac374e3..4fe2867e49 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -396,7 +396,11 @@ namespace CalamityMod.CalPlayer public bool roverDrive = false; public bool roverDriveShieldVisible = false; + // Lunic Corps shield is controlled by its armor set bool + // Lunic Corps shield comes from an armor set and its visibility is non optional + internal float lunicCorpsShieldPartialRechargeProgress = 0f; + public bool sponge = false; public bool spongeShieldVisible = false; #endregion @@ -5814,20 +5818,26 @@ namespace CalamityMod.CalPlayer roverDriveDurabilityCD.timeLeft = RoverDriveShieldDurability; // Update Lunic Corps Armor durability on the cooldown rack. - if (lunicCorpsSet && cooldowns.TryGetValue(MasterChefShieldDurability.ID, out var masterChefDurabilityCD)) + if (lunicCorpsSet && cooldowns.TryGetValue(Cooldowns.LunicCorpsShieldDurability.ID, out var masterChefDurabilityCD)) masterChefDurabilityCD.timeLeft = LunicCorpsShieldDurability; // TODO -- Sponge cooldown... } - // Regardless of whether shields took damage, stop all shield regen on ANY hit. + // Regardless of whether shields took damage, iterate over all shield regen on ANY hit. // This applies even if you are hit while shields are fully down, or if you unequip any of the relevant items. { + // Rover Drive does not recharge while partially full, only when broken. + // If you are hit when recharging, though, that timer gets reset. if (cooldowns.TryGetValue(WulfrumRoverDriveRecharge.ID, out var roverDriveRechargeCD)) roverDriveRechargeCD.timeLeft = RoverDrive.ShieldRechargeTime; - if (cooldowns.TryGetValue(MasterChefShieldRecharge.ID, out var cd)) + // If the Lunic Corps Armor is still recharging, reset its recharge delay to full. + if (cooldowns.TryGetValue(LunicCorpsShieldRecharge.ID, out var cd)) cd.timeLeft = LunicCorpsHelmet.ShieldRechargeDelay; + // If the Lunic Corps Armor is not yet recharging, start its recharge timer. + else + Player.AddCooldown(Cooldowns.LunicCorpsShieldRecharge.ID, LunicCorpsHelmet.ShieldRechargeDelay, true); // TODO -- Stop Sponge cooldown } diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 2aa0e4d159..a68c336af6 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -3527,26 +3527,47 @@ namespace CalamityMod.CalPlayer // The recharge cooldown is intentionally left in place to prevent hot swapping to recharge the shield if (!lunicCorpsSet) { - if (cooldowns.TryGetValue(MasterChefShieldDurability.ID, out var cdDurability)) + if (cooldowns.TryGetValue(Cooldowns.LunicCorpsShieldDurability.ID, out var cdDurability)) cdDurability.timeLeft = 0; // if (cooldowns.TryGetValue(MasterChefShieldRecharge.ID, out var cdRecharge)) cdRecharge.timeLeft = 0; + + // As Lunic Corps shields can be left in partially recharged states, this is for safety. + // If the player does not have the armor equipped for even one frame, discharge all shields. + LunicCorpsShieldDurability = 0; } // Stuff to do if the Lunic Corps armor is equipped else { - if (LunicCorpsShieldDurability == 0 && !cooldowns.ContainsKey(MasterChefShieldRecharge.ID)) - Player.AddCooldown(MasterChefShieldRecharge.ID, LunicCorpsHelmet.ShieldRechargeDelay); + // If the Lunic Corps shield is discharged and hasn't started its recharge delay, start that. + if (LunicCorpsShieldDurability == 0 && !cooldowns.ContainsKey(LunicCorpsShieldRecharge.ID)) + Player.AddCooldown(LunicCorpsShieldRecharge.ID, LunicCorpsHelmet.ShieldRechargeDelay); // If the shield has greater than zero durability but that durability is not on the cooldown rack, // add it to the cooldown rack and play a sound of the shield turning on. - if (LunicCorpsShieldDurability > 0 && !cooldowns.ContainsKey(MasterChefShieldDurability.ID)) + if (LunicCorpsShieldDurability > 0 && !cooldowns.ContainsKey(Cooldowns.LunicCorpsShieldDurability.ID)) { - CooldownInstance durabilityCooldown = Player.AddCooldown(MasterChefShieldDurability.ID, LunicCorpsHelmet.ShieldDurabilityMax); + var durabilityCooldown = Player.AddCooldown(Cooldowns.LunicCorpsShieldDurability.ID, LunicCorpsHelmet.ShieldDurabilityMax); durabilityCooldown.timeLeft = LunicCorpsShieldDurability; SoundEngine.PlaySound(LunicCorpsHelmet.ActivationSound, Player.Center); } + // If the shield has greater than zero durability and isn't in its recharge delay, actively replenish shield points. + if (LunicCorpsShieldDurability > 0 && !cooldowns.ContainsKey(LunicCorpsShieldRecharge.ID)) + { + // TODO -- sound should be played when recharging starts. This requires extra state tracking + + // This number is not an integer, and stores exact per-frame recharge progress. + lunicCorpsShieldPartialRechargeProgress += LunicCorpsHelmet.ShieldDurabilityMax / (float)LunicCorpsHelmet.TotalShieldRechargeTime; + + // Cast to int to get whole number of shield points recharged this frame. + int pointsActuallyRecharged = (int)lunicCorpsShieldPartialRechargeProgress; + + // Give those points to the real shield durability. Then remove them from recharge progress. + LunicCorpsShieldDurability += pointsActuallyRecharged; + lunicCorpsShieldPartialRechargeProgress -= pointsActuallyRecharged; + } + // Add light if this shield is currently active if (LunicCorpsShieldDurability > 0 && !shieldAddedLight) { @@ -3567,6 +3588,7 @@ namespace CalamityMod.CalPlayer // Stuff to do if the Rover Drive is equipped else { + // If the Rover Drive shield is discharged and hasn't started its recharge delay, start that. if (RoverDriveShieldDurability == 0 && !cooldowns.ContainsKey(WulfrumRoverDriveRecharge.ID)) Player.AddCooldown(WulfrumRoverDriveRecharge.ID, RoverDrive.ShieldRechargeTime); diff --git a/Cooldowns/MasterChefShieldDurability.png b/Cooldowns/LunicCorpsShield.png similarity index 100% rename from Cooldowns/MasterChefShieldDurability.png rename to Cooldowns/LunicCorpsShield.png diff --git a/Cooldowns/MasterChefShieldDurabilityActive.png b/Cooldowns/LunicCorpsShieldActive.png similarity index 100% rename from Cooldowns/MasterChefShieldDurabilityActive.png rename to Cooldowns/LunicCorpsShieldActive.png diff --git a/Cooldowns/MasterChefShieldDurability.cs b/Cooldowns/LunicCorpsShieldCooldowns.cs similarity index 73% rename from Cooldowns/MasterChefShieldDurability.cs rename to Cooldowns/LunicCorpsShieldCooldowns.cs index 162b3b2a1d..1fbea57a38 100644 --- a/Cooldowns/MasterChefShieldDurability.cs +++ b/Cooldowns/LunicCorpsShieldCooldowns.cs @@ -1,34 +1,34 @@ -using Microsoft.Xna.Framework; +using System; +using CalamityMod.CalPlayer; +using CalamityMod.Items.Accessories; +using CalamityMod.Items.Armor.LunicCorps; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.Audio; using Terraria.GameContent; +using Terraria.Graphics.Shaders; using Terraria.Localization; using static CalamityMod.CalamityUtils; using static Terraria.ModLoader.ModContent; -using CalamityMod.Items.Accessories; -using Terraria.Audio; -using Terraria.Graphics.Shaders; -using System; -using CalamityMod.Items.Armor.LunicCorps; -using CalamityMod.CalPlayer; namespace CalamityMod.Cooldowns { - public class MasterChefShieldDurability : CooldownHandler + public class LunicCorpsShieldDurability : CooldownHandler { - private static Color ringColorLerpStart = new Color(49, 220, 221); - private static Color ringColorLerpEnd = new Color(99, 226, 142); + private static Color ringColorLerpStart = new Color(82, 203, 222); + private static Color ringColorLerpEnd = new Color(113, 178, 222); - private float AdjustedCompletion => (instance.timeLeft) / (float)LunicCorpsHelmet.ShieldDurabilityMax; + private float AdjustedCompletion => instance.timeLeft / (float)LunicCorpsHelmet.ShieldDurabilityMax; public static new string ID => "MasterChefShieldDurability"; - public override bool CanTickDown => !instance.player.GetModPlayer().lunicCorpsSet || instance.timeLeft <= 0; - public override bool ShouldDisplay => instance.player.GetModPlayer().lunicCorpsSet; - public override LocalizedText DisplayName => CalamityUtils.GetText($"UI.Cooldowns.{ID}"); - public override string Texture => "CalamityMod/Cooldowns/MasterChefShieldDurabilityActive"; - public override string OutlineTexture => "CalamityMod/Cooldowns/MasterChefShieldDurabilityOutline"; - public override string OverlayTexture => "CalamityMod/Cooldowns/MasterChefShieldDurabilityOverlay"; - public override Color OutlineColor => new Color(112, 244, 244); + public override bool CanTickDown => !instance.player.Calamity().lunicCorpsSet || instance.timeLeft <= 0; + public override bool ShouldDisplay => instance.player.Calamity().lunicCorpsSet; + public override LocalizedText DisplayName => GetText($"UI.Cooldowns.{ID}"); + public override string Texture => "CalamityMod/Cooldowns/LunicCorpsShieldActive"; + public override string OutlineTexture => "CalamityMod/Cooldowns/LunicCorpsShieldOutline"; + public override string OverlayTexture => "CalamityMod/Cooldowns/LunicCorpsShieldOverlay"; + public override Color OutlineColor => new Color(133, 204, 237); public override Color CooldownStartColor => Color.Lerp(ringColorLerpStart, ringColorLerpEnd, instance.Completion); public override Color CooldownEndColor => Color.Lerp(ringColorLerpStart, ringColorLerpEnd, instance.Completion); public override bool SavedWithPlayer => false; @@ -74,22 +74,28 @@ namespace CalamityMod.Cooldowns } } - public class MasterChefShieldRecharge : CooldownHandler + public class LunicCorpsShieldRecharge : CooldownHandler { - private static Color ringColorLerpStart = new Color(194, 255, 57); - private static Color ringColorLerpEnd = new Color(92, 187, 99); + private static Color ringColorLerpStart = new Color(179, 212, 242); + private static Color ringColorLerpEnd = new Color(113, 178, 222); public static new string ID => "MasterChefShieldRecharge"; public override bool ShouldDisplay => true; - public override LocalizedText DisplayName => CalamityUtils.GetText($"UI.Cooldowns.{ID}"); + public override LocalizedText DisplayName => GetText($"UI.Cooldowns.{ID}"); public override string Texture => "CalamityMod/Cooldowns/MasterChefShieldDurability"; public override bool SavedWithPlayer => false; public override bool PersistsThroughDeath => false; - public override Color OutlineColor => new Color(194, 255, 67); + public override Color OutlineColor => new Color(133, 204, 237); public override Color CooldownStartColor => Color.Lerp(ringColorLerpStart, ringColorLerpEnd, instance.Completion); public override Color CooldownEndColor => Color.Lerp(ringColorLerpStart, ringColorLerpEnd, instance.Completion); - public override void OnCompleted() => instance.player.GetModPlayer().LunicCorpsShieldDurability = LunicCorpsHelmet.ShieldDurabilityMax; + // Lunic Corps shields gain their first point of durability when this cooldown completes. + public override void OnCompleted() + { + CalamityPlayer modPlayer = instance.player.Calamity(); + if (modPlayer.lunicCorpsSet) + modPlayer.LunicCorpsShieldDurability = 1; + } public override SoundStyle? EndSound => null; } } diff --git a/Cooldowns/MasterChefShieldDurabilityOutline.png b/Cooldowns/LunicCorpsShieldOutline.png similarity index 100% rename from Cooldowns/MasterChefShieldDurabilityOutline.png rename to Cooldowns/LunicCorpsShieldOutline.png diff --git a/Cooldowns/MasterChefShieldDurabilityOverlay.png b/Cooldowns/LunicCorpsShieldOverlay.png similarity index 100% rename from Cooldowns/MasterChefShieldDurabilityOverlay.png rename to Cooldowns/LunicCorpsShieldOverlay.png diff --git a/Cooldowns/WulfrumRoverDrive.cs b/Cooldowns/WulfrumRoverDriveCooldowns.cs similarity index 91% rename from Cooldowns/WulfrumRoverDrive.cs rename to Cooldowns/WulfrumRoverDriveCooldowns.cs index 78177426dd..b554e51148 100644 --- a/Cooldowns/WulfrumRoverDrive.cs +++ b/Cooldowns/WulfrumRoverDriveCooldowns.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.CalPlayer; using CalamityMod.Items.Accessories; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -22,7 +23,7 @@ namespace CalamityMod.Cooldowns public static new string ID => "WulfrumRoverDriveDurability"; public override bool CanTickDown => !instance.player.Calamity().roverDrive || instance.timeLeft <= 0; public override bool ShouldDisplay => instance.player.Calamity().roverDrive; - public override LocalizedText DisplayName => CalamityUtils.GetText($"UI.Cooldowns.{ID}"); + public override LocalizedText DisplayName => GetText($"UI.Cooldowns.{ID}"); public override string Texture => "CalamityMod/Cooldowns/WulfrumRoverDriveActive"; public override string OutlineTexture => "CalamityMod/Cooldowns/WulfrumRoverDriveOutline"; public override string OverlayTexture => "CalamityMod/Cooldowns/WulfrumRoverDriveOverlay"; @@ -57,13 +58,13 @@ namespace CalamityMod.Cooldowns Texture2D outline = Request(OutlineTexture).Value; Texture2D overlay = Request(OverlayTexture).Value; - //Draw the outline + // Draw the outline spriteBatch.Draw(outline, position, null, OutlineColor * opacity, 0, outline.Size() * 0.5f, scale, SpriteEffects.None, 0f); - //Draw the icon + // Draw the icon spriteBatch.Draw(sprite, position, null, Color.White * opacity, 0, sprite.Size() * 0.5f, scale, SpriteEffects.None, 0f); - //Draw the small overlay + // Draw the small overlay int lostHeight = (int)Math.Ceiling(overlay.Height * AdjustedCompletion); Rectangle crop = new Rectangle(0, lostHeight, overlay.Width, overlay.Height - lostHeight); spriteBatch.Draw(overlay, position + Vector2.UnitY * lostHeight * scale, crop, OutlineColor * opacity * 0.9f, 0, sprite.Size() * 0.5f, scale, SpriteEffects.None, 0f); @@ -89,7 +90,12 @@ namespace CalamityMod.Cooldowns public override Color CooldownEndColor => Color.Lerp(ringColorLerpStart, ringColorLerpEnd, instance.Completion); // Rover Drive shields are recharged as a side effect of the cooldown completing client side - public override void OnCompleted() => instance.player.Calamity().RoverDriveShieldDurability = RoverDrive.ShieldDurabilityMax; + public override void OnCompleted() + { + CalamityPlayer modPlayer = instance.player.Calamity(); + if (modPlayer.roverDrive) + modPlayer.RoverDriveShieldDurability = RoverDrive.ShieldDurabilityMax; + } public override SoundStyle? EndSound => null; } }