diff --git a/Items/Weapons/Magic/AetherfluxCannon.cs b/Items/Weapons/Magic/AetherfluxCannon.cs index 11d3ad3d29..782fffeba9 100644 --- a/Items/Weapons/Magic/AetherfluxCannon.cs +++ b/Items/Weapons/Magic/AetherfluxCannon.cs @@ -39,11 +39,12 @@ namespace CalamityMod.Items.Weapons.Magic public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; + public override void HoldItem(Player player) => player.Calamity().mouseRotationListener = true; + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { - Vector2 shootVelocity = velocity; - Vector2 shootDirection = shootVelocity.SafeNormalize(Vector2.UnitX * player.direction); - Projectile.NewProjectile(source, position, shootDirection, type, damage, knockback, player.whoAmI); + Vector2 spawnPosition = player.RotatedRelativePoint(player.MountedCenter, true); + Projectile.NewProjectileDirect(source, spawnPosition, player.Calamity().mouseWorld - spawnPosition, ModContent.ProjectileType(), damage, knockback, player.whoAmI); return false; } diff --git a/Projectiles/Magic/AetherfluxCannonHoldout.cs b/Projectiles/Magic/AetherfluxCannonHoldout.cs index 94e57a3010..f516b8a025 100644 --- a/Projectiles/Magic/AetherfluxCannonHoldout.cs +++ b/Projectiles/Magic/AetherfluxCannonHoldout.cs @@ -1,65 +1,54 @@ using CalamityMod.Items.Weapons.Magic; +using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Audio; +using Terraria.GameContent; using Terraria.ID; -using Terraria.Localization; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic { - public class AetherfluxCannonHoldout : ModProjectile + public class AetherfluxCannonHoldout : BaseGunHoldoutProjectile { - public override LocalizedText DisplayName => CalamityUtils.GetItemName(); - private const int FramesPerFireRateIncrease = 36; - - private Player Owner => Main.player[Projectile.owner]; + public override int AssociatedItemID => ModContent.ItemType(); + public override float MaxOffsetLengthFromArm => 10f; + public override float OffsetXUpwards => -15f; + public override float OffsetXDownwards => 10f; + public override float BaseOffsetY => -15f; + public override float OffsetYUpwards => 8f; + public override float OffsetYDownwards => 15f; + public override string Texture => "CalamityMod/Projectiles/Magic/AetherfluxCannonHoldout"; private ref float DeployedFrames => ref Projectile.ai[0]; private ref float AnimationRate => ref Projectile.ai[1]; private ref float LastShootAttemptTime => ref Projectile.localAI[0]; private ref float LastAnimationTime => ref Projectile.localAI[1]; - public override void SetStaticDefaults() - { - Main.projFrames[Projectile.type] = 8; - } + public override void SetStaticDefaults() => Main.projFrames[Type] = 8; - public override void SetDefaults() + public override void KillHoldoutLogic() { - Projectile.width = 58; - Projectile.height = 94; - Projectile.friendly = true; - Projectile.penetrate = -1; - Projectile.tileCollide = false; - Projectile.ignoreWater = true; - Projectile.DamageType = DamageClass.Magic; - } + base.KillHoldoutLogic(); - public override void AI() - { - Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true); - Vector2 gunBarrelPos = armPosition + Projectile.velocity * Projectile.height * 0.4f; - - // If the player is unable to continue using the holdout, delete it. - if (Owner.CantUseHoldout() || !Owner.HasAmmo(Owner.ActiveItem())) - { + bool actuallyShoot = DeployedFrames >= (HeldItem?.useAnimation ?? AetherfluxCannon.UseTime); + bool manaOK = !actuallyShoot || Owner.CheckMana(Owner.ActiveItem(), -1, true, false); + if (!manaOK) Projectile.Kill(); - return; - } + } + public override void HoldoutAI() + { // Play a sound frame 1. if (DeployedFrames <= 0f) - { SoundEngine.PlaySound(SoundID.DD2_DarkMageCastHeal with { Volume = SoundID.DD2_DarkMageCastHeal.Volume * 1.5f }, Projectile.Center); - } // Update damage based on curent magic damage stat (so Mana Sickness affects it) - Item weaponItem = Owner.ActiveItem(); - Projectile.damage = weaponItem is null ? 0 : Owner.GetWeaponDamage(weaponItem); + Projectile.damage = HeldItem is null ? 0 : Owner.GetWeaponDamage(HeldItem); // Get the original weapon's use time. - int itemUseTime = weaponItem?.useAnimation ?? AetherfluxCannon.UseTime; + int itemUseTime = HeldItem?.useAnimation ?? AetherfluxCannon.UseTime; // 36, base use time, will result in 5. Speed increasing reforges push it to 4. int framesPerShot = itemUseTime / 7; @@ -73,7 +62,7 @@ namespace CalamityMod.Projectiles.Magic if (DeployedFrames - LastAnimationTime >= AnimationRate) { LastAnimationTime = DeployedFrames; - Projectile.frame = (Projectile.frame + 1) % Main.projFrames[Projectile.type]; + Projectile.frame = (Projectile.frame + 1) % Main.projFrames[Type]; } // Once past the initial spin-up time, fire constantly as long as mana is available. @@ -89,7 +78,7 @@ namespace CalamityMod.Projectiles.Magic SoundEngine.PlaySound(SoundID.Item91, Projectile.Center); int projID = ModContent.ProjectileType(); - float shootSpeed = weaponItem.shootSpeed; + float shootSpeed = HeldItem.shootSpeed; Vector2 shootDirection = Projectile.velocity.SafeNormalize(Vector2.UnitY); Vector2 shootVelocity = shootDirection * shootSpeed; @@ -102,67 +91,24 @@ namespace CalamityMod.Projectiles.Magic for (int i = -1; i <= 1; i += 2) { - Vector2 laserStartPos = gunBarrelPos + i * perp + Main.rand.NextVector2CircularEdge(6f, 6f); + Vector2 laserStartPos = GunTipPosition + i * perp + Main.rand.NextVector2CircularEdge(6f, 6f); Vector2 dustOnlySpread = Main.rand.NextVector2Circular(shootSpeed, shootSpeed); Vector2 dustVelocity = shootVelocity + dustInaccuracy * dustOnlySpread; - if (actuallyShoot) - { - Projectile godRay = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), laserStartPos, shootVelocity, projID, Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 0f); - // Tell this Phased God Ray exactly which way it should be waving. - godRay.localAI[1] = i * 0.5f; - } - SpawnFiringDust(gunBarrelPos, dustVelocity); + if (actuallyShoot && Main.myPlayer == Projectile.owner) + Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), laserStartPos, shootVelocity, projID, Projectile.damage, Projectile.knockBack, Projectile.owner, i * 0.5f); + SpawnFiringDust(GunTipPosition, dustVelocity); } } - - // Delete the laser gun if a mana cost cannot be paid. - else - { - Projectile.Kill(); - return; - } } - - UpdateProjectileHeldVariables(armPosition); - ManipulatePlayerVariables(); } - private void UpdateProjectileHeldVariables(Vector2 armPosition) - { - 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.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; - Projectile.Center = armPosition + Projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction) * 8f; - Projectile.spriteDirection = Projectile.direction; - Projectile.timeLeft = 2; - } - - private void ManipulatePlayerVariables() - { - Owner.ChangeDir(Projectile.direction); - Owner.heldProj = Projectile.whoAmI; - Owner.itemTime = 2; - Owner.itemAnimation = 2; - Owner.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation(); - } - - private void SpawnFiringDust(Vector2 gunBarrelPos, Vector2 laserVelocity) + private void SpawnFiringDust(Vector2 GunTipPosition, Vector2 laserVelocity) { int dustID = 133; int dustRadius = 12; float dustRandomness = 11f; int dustDiameter = 2 * dustRadius; - Vector2 dustCorner = gunBarrelPos - Vector2.One * dustRadius; + Vector2 dustCorner = GunTipPosition - Vector2.One * dustRadius; for (int i = 0; i < 2; i++) { Vector2 dustVel = laserVelocity + Main.rand.NextVector2Circular(dustRandomness, dustRandomness); @@ -173,9 +119,18 @@ namespace CalamityMod.Projectiles.Magic } } - public override bool? CanDamage() => false; + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + Rectangle frame = texture.Frame(verticalFrames: Main.projFrames[Type], frameY: Projectile.frame); + float drawRotation = Projectile.rotation + (Projectile.spriteDirection == -1 ? MathHelper.Pi : 0f) + MathHelper.PiOver2; + Vector2 rotationPoint = frame.Size() * 0.5f; + SpriteEffects flipSprite = (Projectile.spriteDirection * Owner.gravDir == -1) ? SpriteEffects.FlipVertically : SpriteEffects.None; - // prevents the item from appearing backwards frame 1 - public override bool PreDraw(ref Color lightColor) => FramesPerFireRateIncrease > 0f; + Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), drawRotation, rotationPoint, Projectile.scale * Owner.gravDir, flipSprite); + + return false; + } } } diff --git a/Projectiles/Magic/PhasedGodRay.cs b/Projectiles/Magic/PhasedGodRay.cs index 97b300715c..633e74c335 100644 --- a/Projectiles/Magic/PhasedGodRay.cs +++ b/Projectiles/Magic/PhasedGodRay.cs @@ -17,7 +17,7 @@ namespace CalamityMod.Projectiles.Magic // They are extremely carefully chosen and barely work as is! private const float WaveTheta = 0.09f; private const int WaveTwistFrames = 9; - private ref float WaveFrameState => ref Projectile.localAI[1]; + private ref float WaveFrameState => ref Projectile.ai[0]; public override string Texture => "CalamityMod/Projectiles/LaserProj"; @@ -53,7 +53,7 @@ namespace CalamityMod.Projectiles.Magic float waveSign = WaveFrameState < 0f ? -1f : 1f; - // Initialize waving. Setting localAI[1] to a number between -1 and 1 tells it which way to wave. + // Initialize waving. Setting ai[0] to a number between -1 and 1 tells it which way to wave. // Exactly 0 is a coinflip. if (Math.Abs(WaveFrameState) < 1f) {