diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 123ceb6319..4e5bd4612c 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -5862,7 +5862,13 @@ namespace CalamityMod.CalPlayer #region Custom Hurt Sounds if (hurtSoundTimer == 0) { - if ((profanedCrystal || profanedCrystalForce) && !profanedCrystalHide) + if (Player.GetModPlayer().ProtectionMatrixDurability > 0) + { + playSound = false; + SoundEngine.PlaySound(RoverDrive.ShieldHurtSound, Player.position); + hurtSoundTimer = 20; + } + else if ((profanedCrystal || profanedCrystalForce) && !profanedCrystalHide) { playSound = false; SoundEngine.PlaySound(Providence.DeathSound, Player.position); diff --git a/Cooldowns/WulfrumBastion.cs b/Cooldowns/WulfrumBastion.cs index b5418deda6..7961b3cf8a 100644 --- a/Cooldowns/WulfrumBastion.cs +++ b/Cooldowns/WulfrumBastion.cs @@ -25,6 +25,7 @@ namespace CalamityMod.Cooldowns public override Color CooldownStartColor => PowerActive ? Color.Lerp(new Color(112, 244, 244), new Color(54, 177, 221), DurabilityPercent) : new Color(92, 187, 99); public override Color CooldownEndColor => PowerActive ? Color.Lerp(new Color(112, 244, 244), new Color(54, 177, 221), DurabilityPercent) : new Color(160, 232, 77); public override SoundStyle? EndSound => new("CalamityMod/Sounds/Custom/AbilitySounds/WulfrumBastionRecharge"); + //public override bool SavedWithPlayer => false; public override void OnCompleted() { diff --git a/Cooldowns/WulfrumRoverDrive.cs b/Cooldowns/WulfrumRoverDrive.cs new file mode 100644 index 0000000000..c76057cca2 --- /dev/null +++ b/Cooldowns/WulfrumRoverDrive.cs @@ -0,0 +1,82 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.GameContent; +using static CalamityMod.CalamityUtils; +using static Terraria.ModLoader.ModContent; +using CalamityMod.Items.Accessories; +using Terraria.Audio; +using Terraria.Graphics.Shaders; +using System; + +namespace CalamityMod.Cooldowns +{ + public class WulfrumRoverDriveDurability : CooldownHandler + { + private static Color ringColorLerpStart = new Color(49, 220, 221); + private static Color ringColorLerpEnd = new Color(99, 226, 142); + + private float AdjustedCompletion => (instance.timeLeft) / (float)RoverDrive.ProtectionMatrixDurabilityMax; + + public static new string ID => "WulfrumRoverDriveDurability"; + public override bool CanTickDown => !instance.player.GetModPlayer().RoverDriveOn || instance.timeLeft <= 0; + public override bool ShouldDisplay => instance.player.GetModPlayer().RoverDriveOn; + public override string DisplayName => "Protective Matrix Durability"; + public override string Texture => "CalamityMod/Cooldowns/WulfrumRoverDriveActive"; + public override string OutlineTexture => "CalamityMod/Cooldowns/WulfrumRoverDriveOutline"; + public override string OverlayTexture => "CalamityMod/Cooldowns/WulfrumRoverDriveOverlay"; + public override Color OutlineColor => new Color(112, 244, 244); + 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; + public override bool PersistsThroughDeath => false; + + + public override void ApplyBarShaders(float opacity) + { + //Use the adjusted completion + GameShaders.Misc["CalamityMod:CircularBarShader"].UseOpacity(opacity); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseSaturation(AdjustedCompletion); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseColor(CooldownStartColor); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseSecondaryColor(CooldownEndColor); + GameShaders.Misc["CalamityMod:CircularBarShader"].Apply(); + } + + public override void DrawCompact(SpriteBatch spriteBatch, Vector2 position, float opacity, float scale) + { + Texture2D sprite = Request(Texture).Value; + Texture2D outline = Request(OutlineTexture).Value; + Texture2D overlay = Request(OverlayTexture).Value; + + //Draw the outline + spriteBatch.Draw(outline, position, null, OutlineColor * opacity, 0, outline.Size() * 0.5f, scale, SpriteEffects.None, 0f); + + //Draw the icon + spriteBatch.Draw(sprite, position, null, Color.White * opacity, 0, sprite.Size() * 0.5f, scale, SpriteEffects.None, 0f); + + //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); + } + } + + public class WulfrumRoverDriveRecharge : CooldownHandler + { + private static Color ringColorLerpStart = new Color(194, 255, 57); + private static Color ringColorLerpEnd = new Color(92, 187, 99); + + public static new string ID => "WulfrumRoverDriveRecharge"; + public override bool ShouldDisplay => true; + public override string DisplayName => "Protective Matrix Recharge"; + public override string Texture => "CalamityMod/Cooldowns/WulfrumRoverDrive"; + public override bool SavedWithPlayer => false; + public override bool PersistsThroughDeath => false; + public override Color OutlineColor => new Color(194, 255, 67); + 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().ProtectionMatrixDurability = RoverDrive.ProtectionMatrixDurabilityMax; + public override SoundStyle? EndSound => null; + } +} diff --git a/Items/Accessories/RoverDrive.cs b/Items/Accessories/RoverDrive.cs index 4a57154eef..234fa50a45 100644 --- a/Items/Accessories/RoverDrive.cs +++ b/Items/Accessories/RoverDrive.cs @@ -2,12 +2,21 @@ using Terraria; using Terraria.ModLoader; using Terraria.ID; +using CalamityMod.Cooldowns; using CalamityMod.Items.Materials; +using Terraria.Audio; namespace CalamityMod.Items.Accessories { public class RoverDrive : ModItem { + public static readonly SoundStyle ShieldHurtSound = new("CalamityMod/Sounds/Custom/RoverDriveHit") { PitchVariance = 0.6f, Volume = 0.6f, MaxInstances = 0 }; + public static readonly SoundStyle ActivationSound = new("CalamityMod/Sounds/Custom/RoverDriveActivate") { Volume = 0.85f }; + + + public static int ProtectionMatrixDurabilityMax = 50; + public static int ProtectionMatrixRechargeTime = 60 * 10; + public override void SetStaticDefaults() { SacrificeTotal = 1; @@ -39,6 +48,8 @@ namespace CalamityMod.Items.Accessories { CalamityPlayer modPlayer = player.Calamity(); modPlayer.roverDrive = true; + + player.GetModPlayer().RoverDriveOn = true; } //Scrappable for 3-6 wulfrum scrap or a 20% chance to get an energy core @@ -54,4 +65,99 @@ namespace CalamityMod.Items.Accessories } } } + + public class RoverDrivePlayer : ModPlayer + { + public bool RoverDriveOn; + public int ProtectionMatrixDurability = 0; + public int ProtectionMatrixCharge = 0; + + public override void ResetEffects() + { + //Turn this into armor health when we can + if (RoverDriveOn) + Player.statLifeMax2 += ProtectionMatrixDurability; + + else + ProtectionMatrixDurability = 0; + + RoverDriveOn = false; + } + + public override void PostHurt(bool pvp, bool quiet, double damage, int hitDirection, bool crit) + { + if (RoverDriveOn) + { + if (ProtectionMatrixDurability > 0) + { + ProtectionMatrixDurability -= (int)damage; + if (ProtectionMatrixDurability <= 0) + { + ProtectionMatrixDurability = 0; + + //Switch CD + //Sound effect of engine shutting down + } + } + + if (Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveDurability.ID, out var cdDurability)) + { + cdDurability.timeLeft = ProtectionMatrixDurability; + } + + + //Reset recharge time. + if (Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveRecharge.ID, out var cd)) + { + cd.timeLeft = RoverDrive.ProtectionMatrixRechargeTime; + } + } + } + + public override void UpdateDead() + { + ProtectionMatrixDurability = 0; + } + + public override void PostUpdateMiscEffects() + { + if (!RoverDriveOn) + { + if (Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveDurability.ID, out var cdDurability) && !RoverDriveOn) + cdDurability.timeLeft = 0; + + if (Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveRecharge.ID, out var cdRecharge) && !RoverDriveOn) + cdRecharge.timeLeft = 0; + } + + else + { + if (ProtectionMatrixDurability == 0 && !Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveRecharge.ID, out var cd)) + { + Player.AddCooldown(WulfrumRoverDriveRecharge.ID, RoverDrive.ProtectionMatrixRechargeTime); + } + + if (ProtectionMatrixDurability > 0 && !Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveDurability.ID, out cd)) + { + CooldownInstance durabilityCooldown = Player.AddCooldown(WulfrumRoverDriveDurability.ID, RoverDrive.ProtectionMatrixDurabilityMax); + durabilityCooldown.timeLeft = ProtectionMatrixDurability; + + SoundEngine.PlaySound(RoverDrive.ActivationSound, Player.Center); + } + + if (ProtectionMatrixDurability > 0) + { + + Player.Calamity().roverDrive = true; + Player.Calamity().roverDriveTimer = 2; + } + + else + { + Player.Calamity().roverDriveTimer = 618; + Player.Calamity().roverDrive = false; + } + } + } + } } diff --git a/Items/Armor/Wulfrum/WulfrumFusionCannon.cs b/Items/Armor/Wulfrum/WulfrumFusionCannon.cs index 278b0043cc..e791ca4dab 100644 --- a/Items/Armor/Wulfrum/WulfrumFusionCannon.cs +++ b/Items/Armor/Wulfrum/WulfrumFusionCannon.cs @@ -48,6 +48,8 @@ namespace CalamityMod.Items.Armor.Wulfrum Item.useAnimation = 10; Item.useTime = 4; Item.reuseDelay = 17; + + Item.noUseGraphic = false; } public override void ModifyTooltips(List tooltips) @@ -73,9 +75,8 @@ namespace CalamityMod.Items.Armor.Wulfrum } Item.noUseGraphic = false; - if (!player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) || cd.timeLeft > WulfrumHat.BastionCooldown + WulfrumHat.BastionTime - WulfrumHat.BastionBuildTime) - Item.noUseGraphic = true; + Item.noUseGraphic = true; } @@ -105,15 +106,15 @@ namespace CalamityMod.Items.Armor.Wulfrum if (!player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) || cd.timeLeft > WulfrumHat.BastionCooldown + WulfrumHat.BastionTime - WulfrumHat.BastionBuildTime) return; - - if (player.ItemTimeIsZero) noAnimation = false; if (player.itemAnimation > Item.useAnimation) noAnimation = true; float animProgress = 1 - player.itemAnimation / (float)player.itemAnimationMax; - if (noAnimation) + //It beecomes nan if the player loads into a world with the set bonus already active / without shooting any weapons before using it. + //this is because itemAnimationMax isnt set before the item gets used once. + if (noAnimation || animProgress is float.NaN) animProgress = 1; //Default diff --git a/Items/Armor/Wulfrum/WulfrumSet.cs b/Items/Armor/Wulfrum/WulfrumSet.cs index 8ff69224d6..664886d7e9 100644 --- a/Items/Armor/Wulfrum/WulfrumSet.cs +++ b/Items/Armor/Wulfrum/WulfrumSet.cs @@ -455,7 +455,6 @@ namespace CalamityMod.Items.Armor.Wulfrum Main.mouseItem.TurnToAir(); } - //This shouldn't ever be possible since the power mode prevents you from using or moving items around if (!wulfrumSet && WulfrumHat.PowerModeEngaged(Player, out var cd)) { diff --git a/Sounds/Custom/RoverDriveActivate.ogg b/Sounds/Custom/RoverDriveActivate.ogg new file mode 100644 index 0000000000..127d7e65a3 Binary files /dev/null and b/Sounds/Custom/RoverDriveActivate.ogg differ diff --git a/Sounds/Custom/RoverDriveHit.ogg b/Sounds/Custom/RoverDriveHit.ogg new file mode 100644 index 0000000000..726ef852e6 Binary files /dev/null and b/Sounds/Custom/RoverDriveHit.ogg differ