From 24e78d29b9ec6ce9ee62a81d182a40f4635ff64d Mon Sep 17 00:00:00 2001 From: Memes Date: Sun, 19 May 2024 14:01:43 +0200 Subject: [PATCH] Condemnation as a base holdout. --- Items/Weapons/Ranged/Condemnation.cs | 11 +- Projectiles/Ranged/CondemnationHoldout.cs | 163 +++++++++------------- 2 files changed, 71 insertions(+), 103 deletions(-) diff --git a/Items/Weapons/Ranged/Condemnation.cs b/Items/Weapons/Ranged/Condemnation.cs index 9f80655ae3..8adb29a61a 100644 --- a/Items/Weapons/Ranged/Condemnation.cs +++ b/Items/Weapons/Ranged/Condemnation.cs @@ -44,10 +44,15 @@ namespace CalamityMod.Items.Weapons.Ranged public override void HoldItem(Player player) { - if (Main.myPlayer == player.whoAmI) - player.Calamity().rightClickListener = true; + var calPlayer = player.Calamity(); - if (player.Calamity().mouseRight && player.ownedProjectileCounts[ModContent.ProjectileType()] <= 0) + if (Main.myPlayer == player.whoAmI) + { + calPlayer.rightClickListener = true; + calPlayer.mouseRotationListener = true; + } + + if (calPlayer.mouseRight && player.ownedProjectileCounts[ModContent.ProjectileType()] <= 0) { Item.noUseGraphic = false; } diff --git a/Projectiles/Ranged/CondemnationHoldout.cs b/Projectiles/Ranged/CondemnationHoldout.cs index 04693f2c48..adb6c6d397 100644 --- a/Projectiles/Ranged/CondemnationHoldout.cs +++ b/Projectiles/Ranged/CondemnationHoldout.cs @@ -1,18 +1,20 @@ -using CalamityMod.Items.Weapons.Ranged; -using CalamityMod.Sounds; +using System.IO; +using CalamityMod.Items.Weapons.Ranged; +using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; using Terraria.ID; -using Terraria.Localization; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Ranged { - public class CondemnationHoldout : ModProjectile + public class CondemnationHoldout : BaseGunHoldoutProjectile { - public override LocalizedText DisplayName => CalamityUtils.GetItemName(); - private Player Owner => Main.player[Projectile.owner]; + public override int AssociatedItemID => ModContent.ItemType(); + public override float MaxOffsetLengthFromArm => 25f; + public override float OffsetXUpwards => -5f; + public override float BaseOffsetY => -5f; private ref float CurrentChargingFrames => ref Projectile.ai[0]; private ref float ArrowsLoaded => ref Projectile.ai[1]; @@ -22,24 +24,8 @@ namespace CalamityMod.Projectiles.Ranged public const float velocityMultiplier = 1.2f; public bool homing = false; - public override string Texture => "CalamityMod/Items/Weapons/Ranged/Condemnation"; - - public override void SetDefaults() + public override void KillHoldoutLogic() { - Projectile.width = 130; - Projectile.height = 42; - Projectile.friendly = true; - Projectile.penetrate = -1; - Projectile.tileCollide = false; - Projectile.DamageType = DamageClass.Ranged; - Projectile.ignoreWater = true; - } - - public override void AI() - { - Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true); - Vector2 tipPosition = armPosition + Projectile.velocity * Projectile.width * 0.5f; - // Fire arrows if the owner stops channeling or otherwise cannot use the weapon. if (Owner.CantUseHoldout()) { @@ -51,65 +37,61 @@ namespace CalamityMod.Projectiles.Ranged } // Fire one charged arrow every frame until you're out of arrows. - ShootProjectiles(tipPosition, homing); + ShootProjectiles(homing); --ArrowsLoaded; if (ArrowsLoaded == 0 && homing == true) homing = false; } - else + } + + public override void HoldoutAI() + { + // Frame 1 effects: Record how fast the Condemnation item being used is, to determine how fast to load arrows. + if (FramesToLoadNextArrow == 0f) { + SoundEngine.PlaySound(SoundID.Item20, Projectile.Center); + FramesToLoadNextArrow = HeldItem.useAnimation; + } - // Frame 1 effects: Record how fast the Condemnation item being used is, to determine how fast to load arrows. - if (FramesToLoadNextArrow == 0f) + // If no arrows are loaded, spawn a bit of dust to indicate it's not ready yet. + // Spawn the same dust if the max number of arrows have been loaded or the player ran out of ammos to load. + if (ArrowsLoaded <= 0f || ArrowsLoaded >= Condemnation.MaxLoadedArrows || !Owner.HasAmmo(Owner.ActiveItem())) + SpawnCannotLoadArrowsDust(GunTipPosition); + + if (Owner.HasAmmo(HeldItem)) + { + // Actually make progress towards loading more arrows. + ++CurrentChargingFrames; + + // If it is time to load an arrow, produce a pulse of dust and add an arrow. + // Also accelerate charging, because it's fucking awesome. + // Take the ammo here as well + if (CurrentChargingFrames >= FramesToLoadNextArrow && ArrowsLoaded < Condemnation.MaxLoadedArrows) { - SoundEngine.PlaySound(SoundID.Item20, Projectile.Center); - FramesToLoadNextArrow = Owner.ActiveItem().useAnimation; - } + // Save the stats here for later + Owner.PickAmmo(HeldItem, out _, out float shootSpeed, out int damage, out float knockback, out _); + Projectile.damage = damage; + Projectile.knockBack = knockback; + storedVelocity = shootSpeed * velocityMultiplier; - // If no arrows are loaded, spawn a bit of dust to indicate it's not ready yet. - // Spawn the same dust if the max number of arrows have been loaded or the player ran out of ammos to load. - if (ArrowsLoaded <= 0f || ArrowsLoaded >= Condemnation.MaxLoadedArrows || !Owner.HasAmmo(Owner.ActiveItem())) - SpawnCannotLoadArrowsDust(tipPosition); + SpawnArrowLoadedDust(); + CurrentChargingFrames = 0f; + ++ArrowsLoaded; + --FramesToLoadNextArrow; - if (Owner.HasAmmo(Owner.ActiveItem())) - { - // Actually make progress towards loading more arrows. - ++CurrentChargingFrames; + // Play a sound for additional notification that an arrow has been loaded. + var loadSound = SoundEngine.PlaySound(SoundID.Item108 with { Volume = SoundID.Item108.Volume * 0.3f }); - // If it is time to load an arrow, produce a pulse of dust and add an arrow. - // Also accelerate charging, because it's fucking awesome. - // Take the ammo here as well - if (CurrentChargingFrames >= FramesToLoadNextArrow && ArrowsLoaded < Condemnation.MaxLoadedArrows) + if (ArrowsLoaded >= Condemnation.MaxLoadedArrows) { - // Save the stats here for later - Item heldItem = Owner.ActiveItem(); - Owner.PickAmmo(heldItem, out _, out float shootSpeed, out int damage, out float knockback, out _); - Projectile.damage = damage; - Projectile.knockBack = knockback; - storedVelocity = shootSpeed * velocityMultiplier; - - SpawnArrowLoadedDust(tipPosition); - CurrentChargingFrames = 0f; - ++ArrowsLoaded; - --FramesToLoadNextArrow; - - // Play a sound for additional notification that an arrow has been loaded. - var loadSound = SoundEngine.PlaySound(SoundID.Item108 with { Volume = SoundID.Item108.Volume * 0.3f }); - - if (ArrowsLoaded >= Condemnation.MaxLoadedArrows) - { - SoundEngine.PlaySound(new("CalamityMod/Sounds/Custom/AbilitySounds/BrimflameRecharge")); - homing = true; - } + SoundEngine.PlaySound(new("CalamityMod/Sounds/Custom/AbilitySounds/BrimflameRecharge")); + homing = true; } } } - - UpdateProjectileHeldVariables(armPosition); - ManipulatePlayerVariables(); } - public void SpawnArrowLoadedDust(Vector2 tipPosition) + public void SpawnArrowLoadedDust() { if (Main.dedServ) return; @@ -126,7 +108,7 @@ namespace CalamityMod.Projectiles.Ranged Vector2 end = nextAngle.ToRotationVector2(); for (int j = 0; j < 40; j++) { - Dust starDust = Dust.NewDustPerfect(tipPosition, 267); + Dust starDust = Dust.NewDustPerfect(GunTipPosition, 267); starDust.scale = 2.5f; starDust.velocity = Vector2.Lerp(start, end, j / 40f) * 16f; starDust.color = Color.Crimson; @@ -138,7 +120,7 @@ namespace CalamityMod.Projectiles.Ranged for (int i = 0; i < 36; i++) { - Dust chargeMagic = Dust.NewDustPerfect(tipPosition, 267); + Dust chargeMagic = Dust.NewDustPerfect(GunTipPosition, 267); chargeMagic.velocity = (MathHelper.TwoPi * i / 36f).ToRotationVector2() * 5f + Owner.velocity; chargeMagic.scale = Main.rand.NextFloat(1f, 1.5f); chargeMagic.color = Color.Violet; @@ -146,62 +128,43 @@ namespace CalamityMod.Projectiles.Ranged } } - public void SpawnCannotLoadArrowsDust(Vector2 tipPosition) + public void SpawnCannotLoadArrowsDust(Vector2 GunTipPosition) { if (Main.dedServ) return; for (int i = 0; i < 2; i++) { - Dust chargeMagic = Dust.NewDustPerfect(tipPosition + Main.rand.NextVector2Circular(20f, 20f), 267); - chargeMagic.velocity = (tipPosition - chargeMagic.position) * 0.1f + Owner.velocity; + Dust chargeMagic = Dust.NewDustPerfect(GunTipPosition + Main.rand.NextVector2Circular(20f, 20f), 267); + chargeMagic.velocity = (GunTipPosition - chargeMagic.position) * 0.1f + Owner.velocity; chargeMagic.scale = Main.rand.NextFloat(1f, 1.5f); chargeMagic.color = Projectile.GetAlpha(Color.White); chargeMagic.noGravity = true; } } - public void ShootProjectiles(Vector2 tipPosition, bool homing) + public void ShootProjectiles(bool homing) { if (Main.myPlayer != Projectile.owner) return; Vector2 shootVelocity = Projectile.velocity.SafeNormalize(Vector2.UnitY) * storedVelocity; int ArrowType = homing ? ModContent.ProjectileType() : ModContent.ProjectileType(); - Projectile.NewProjectile(Projectile.GetSource_FromThis(), tipPosition, shootVelocity, ArrowType, Projectile.damage, Projectile.knockBack, Projectile.owner); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), GunTipPosition, shootVelocity, ArrowType, Projectile.damage, Projectile.knockBack, Projectile.owner); } - private void UpdateProjectileHeldVariables(Vector2 armPosition) + public override void SendExtraAIHoldout(BinaryWriter writer) { - if (Main.myPlayer == Projectile.owner) - { - float interpolant = Utils.GetLerpValue(5f, 25f, Projectile.Distance(Main.MouseWorld), true); - Vector2 oldVelocity = Projectile.velocity; - Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.SafeDirectionTo(Main.MouseWorld), interpolant); - if (Projectile.velocity != oldVelocity) - { - Projectile.netSpam = 0; - Projectile.netUpdate = true; - } - } - - Projectile.position = armPosition - Projectile.Size * 0.5f; - Projectile.rotation = Projectile.velocity.ToRotation(); - if (Projectile.spriteDirection == -1) - Projectile.rotation += MathHelper.Pi; - Projectile.spriteDirection = Projectile.direction; - Projectile.timeLeft = 2; + writer.Write(FramesToLoadNextArrow); + writer.Write(storedVelocity); + writer.Write(homing); } - private void ManipulatePlayerVariables() + public override void ReceiveExtraAIHoldout(BinaryReader reader) { - Owner.ChangeDir(Projectile.direction); - Owner.heldProj = Projectile.whoAmI; - Owner.itemTime = 2; - Owner.itemAnimation = 2; - Owner.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation(); + FramesToLoadNextArrow = reader.ReadSingle(); + storedVelocity = reader.ReadSingle(); + homing = reader.ReadBoolean(); } - - public override bool? CanDamage() => false; } }