From 41ac8ec337994abdaecdc0d471d0dd475d39a9b3 Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Fri, 8 May 2020 20:12:31 -0400 Subject: [PATCH] Rewrote Valkyrie Ray as a holdout. Now benefits from speed reforges. --- Items/Weapons/Magic/ValkyrieRay.cs | 89 ++------------- Projectiles/Magic/ValkyrieRayBeam.cs | 4 +- Projectiles/Magic/ValkyrieRayStaff.cs | 144 +++++++++++++++++++++++++ Projectiles/Magic/ValkyrieRayStaff.png | Bin 0 -> 1095 bytes 4 files changed, 156 insertions(+), 81 deletions(-) create mode 100644 Projectiles/Magic/ValkyrieRayStaff.cs create mode 100644 Projectiles/Magic/ValkyrieRayStaff.png diff --git a/Items/Weapons/Magic/ValkyrieRay.cs b/Items/Weapons/Magic/ValkyrieRay.cs index 1c75922f5e..095e5705b7 100644 --- a/Items/Weapons/Magic/ValkyrieRay.cs +++ b/Items/Weapons/Magic/ValkyrieRay.cs @@ -9,10 +9,13 @@ namespace CalamityMod.Items.Weapons.Magic { public class ValkyrieRay : ModItem { + // The base use time of the weapon is 47: 28 charge frames + 19 cooldown frames. + // The rate at which it progresses through its charge and discharge cycle is dynamically sped up by reforges. + // This math is handled in its holdout projectile, ValkyrieRayStaff. + public const int ChargeFrames = 28; + public const int CooldownFrames = 19; + public const float GemDistance = 18f; public static readonly Color LightColor = new Color(235, 40, 121); - private const float GemDistance = 18f; - private const int ReuseCount = 14; - private int useCounter = 0; public override void SetStaticDefaults() { @@ -29,91 +32,19 @@ namespace CalamityMod.Items.Weapons.Magic item.knockBack = 8.5f; item.magic = true; item.mana = 26; - item.useTime = 2; - item.useAnimation = item.useTime * ReuseCount; + item.useTime = ChargeFrames + CooldownFrames; + item.useAnimation = ChargeFrames + CooldownFrames; item.useStyle = 5; item.UseSound = SoundID.NPCDeath7; item.useTurn = false; item.noMelee = true; + item.noUseGraphic = true; item.value = Item.buyPrice(gold: 36); item.rare = 5; - item.shoot = ModContent.ProjectileType(); + item.shoot = ModContent.ProjectileType(); item.shootSpeed = 25f; } - public override Vector2? HoldoutOrigin() => new Vector2(10, 10); - - // The weapon functions as a fake Clockwork Assault Rifle where only one the many shots actually fires something. - public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) - { - useCounter++; - - // Compute the gem position, which is needed for both charging and firing - float angle = new Vector2(speedX, speedY).ToRotation(); - Vector2 gemOffset = Vector2.One * GemDistance * 1.4142f; // distance to gem on staff - Vector2 gemPos = position + gemOffset.RotatedBy(angle - MathHelper.PiOver4); - - // Actually fire the weapon if it's the final reuse - if (useCounter == ReuseCount) - { - // Produce firing dust and play sound - if (Main.netMode != NetmodeID.Server) - { - SpawnFiringDust(gemPos); - Main.PlaySound(SoundID.Item28, gemPos); - Main.PlaySound(SoundID.Item60, gemPos); - } - useCounter = 0; - - // Change the projectile's spawning position to the gem position - position = gemPos; - - // Manually set the player's item times to longer when the weapon is fired so the staff sticks around a little longer - player.itemTime = 19; - player.itemAnimation = 19; - player.itemAnimationMax = 19; - return true; - } - - // Otherwise, produce small amounts of charging dust and light which scales with the charge. - else if (Main.netMode != NetmodeID.Server) - { - SpawnChargeDust(gemPos); - float brightness = (float)useCounter / ReuseCount; - Lighting.AddLight(gemPos, LightColor.ToVector3() * brightness); - } - return false; - } - - private void SpawnFiringDust(Vector2 center) - { - int numDust = 36; - int dustID = 73; - for(int i = 0; i < numDust; ++i) - { - Dust d = Dust.NewDustDirect(center, 0, 0, dustID, 0f, 0f); - d.velocity = (i * MathHelper.TwoPi / numDust).ToRotationVector2() * 2.2f; - d.scale = 1.4f; - d.noGravity = true; - } - } - - private void SpawnChargeDust(Vector2 center) - { - int numDust = 2; - int dustID = 73; - float incomingRadius = 9f; - for(int i = 0; i < numDust; ++i) - { - Vector2 offsetUnit = Main.rand.NextVector2Unit(); - Vector2 dustPos = center + offsetUnit * incomingRadius; - Dust d = Dust.NewDustDirect(dustPos, 0, 0, dustID, 0f, 0f); - d.velocity = offsetUnit * -Main.rand.NextFloat(2f, 3.5f); - d.scale = Main.rand.NextFloat(0.4f, 1f); - d.noGravity = true; - } - } - public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); diff --git a/Projectiles/Magic/ValkyrieRayBeam.cs b/Projectiles/Magic/ValkyrieRayBeam.cs index cf9afc1ca1..57be18cc03 100644 --- a/Projectiles/Magic/ValkyrieRayBeam.cs +++ b/Projectiles/Magic/ValkyrieRayBeam.cs @@ -135,8 +135,8 @@ namespace CalamityMod.Projectiles.Magic public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { - // If the beam doesn't have a defined projection vector, don't draw anything. - if (beamVector == Vector2.Zero) + // If the beam doesn't have a defined projection vector or hasn't yet had its velocity set to zero, don't draw anything. + if (beamVector == Vector2.Zero || projectile.velocity != Vector2.Zero) return false; Texture2D tex = Main.projectileTexture[projectile.type]; diff --git a/Projectiles/Magic/ValkyrieRayStaff.cs b/Projectiles/Magic/ValkyrieRayStaff.cs new file mode 100644 index 0000000000..5e52313fe0 --- /dev/null +++ b/Projectiles/Magic/ValkyrieRayStaff.cs @@ -0,0 +1,144 @@ +using CalamityMod.Items.Weapons.Magic; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class ValkyrieRayStaff : ModProjectile + { + private const float AimResponsiveness = 0.66f; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Valkyrie Ray"); + } + + public override void SetDefaults() + { + projectile.width = 54; + projectile.height = 52; + // This projectile has no hitboxes and no damage type. + projectile.friendly = false; + projectile.melee = false; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.timeLeft = 900; + } + + // ai[0] is a time-dilated frame counter. ai[1] is whether the beam has already fired. + // localAI[0] is the rate at which the "frame" counter increases. + public override void AI() + { + Player player = Main.player[projectile.owner]; + Vector2 rrp = player.RotatedRelativePoint(player.MountedCenter, true); + + // Calculate how quickly the staff should charge. Charge increases by some number close to 1 every frame. + // Speed increasing reforges make this number greater than 1. Slowing reforges make it smaller than 1. + if (projectile.localAI[0] == 0f) + projectile.localAI[0] = 47f / Main.player[projectile.owner].HeldItem.useTime; + + // Increment the timer for the staff. If the timer has passed 47, destroy it. + projectile.ai[0] += projectile.localAI[0]; + int maxTime = ValkyrieRay.ChargeFrames + ValkyrieRay.CooldownFrames; + if (projectile.ai[0] > maxTime) + { + projectile.Kill(); + return; + } + + // Compute the weapon's charge. + float chargeLevel = MathHelper.Clamp(projectile.ai[0] / ValkyrieRay.ChargeFrames, 0f, 1f); + + // Common code among holdouts to keep the holdout projectile directly in the player's hand + UpdatePlayerVisuals(player, rrp); + + // Compute the gem position, which is needed for visual effects + float angle = projectile.rotation - MathHelper.PiOver2; + Vector2 gemOffset = Vector2.One * ValkyrieRay.GemDistance * 1.4142f; // distance to gem on staff + Vector2 gemPos = projectile.Center + gemOffset.RotatedBy(angle); + + // Firing or charging? + if (chargeLevel >= 1f && projectile.ai[1] == 0f) + { + projectile.ai[1] = 1f; // so it never fires again + FiringEffects(gemPos); + if (projectile.owner == Main.myPlayer) + { + Projectile laser = Projectile.NewProjectileDirect(gemPos, projectile.velocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + laser.Center = gemPos; + } + } + else if (projectile.ai[1] == 0f) + { + // The player can constantly re-aim the staff while it's charging, but once it fires it is locked in place. + UpdateAim(rrp, projectile.velocity.Length()); + ChargingEffects(gemPos, chargeLevel); + } + } + + private void UpdatePlayerVisuals(Player player, Vector2 rrp) + { + // Place the projectile directly into the player's hand at all times + projectile.Center = rrp; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver4; + + // The staff is a holdout projectile, so change the player's variables to reflect that + player.ChangeDir(projectile.direction); + player.heldProj = projectile.whoAmI; + player.itemTime = 2; + player.itemAnimation = 2; + + // Multiplying by projectile.direction is required due to vanilla spaghetti. + player.itemRotation = (projectile.velocity * projectile.direction).ToRotation(); + } + + // Adjusts the aim vector of the staff to point towards the mouse. This is Last Prism code. + private void UpdateAim(Vector2 source, float speed) + { + Vector2 aimVector = Vector2.Normalize(Main.MouseWorld - source); + if (aimVector.HasNaNs()) + aimVector = -Vector2.UnitY; + aimVector = Vector2.Normalize(Vector2.Lerp(aimVector, Vector2.Normalize(projectile.velocity), AimResponsiveness)); + aimVector *= 30f; + + if (aimVector != projectile.velocity) + projectile.netUpdate = true; + projectile.velocity = aimVector; + } + + private void ChargingEffects(Vector2 center, float chargeLevel) + { + Lighting.AddLight(center, ValkyrieRay.LightColor.ToVector3() * chargeLevel); + + int numDust = 2; + int dustID = 73; + float incomingRadius = 9f; + for (int i = 0; i < numDust; ++i) + { + Vector2 offsetUnit = Main.rand.NextVector2Unit(); + Vector2 dustPos = center + offsetUnit * incomingRadius; + Dust d = Dust.NewDustDirect(dustPos, 0, 0, dustID, 0f, 0f); + d.velocity = offsetUnit * -Main.rand.NextFloat(2f, 3.5f); + d.scale = Main.rand.NextFloat(0.4f, 1f); + d.noGravity = true; + } + } + + private void FiringEffects(Vector2 center) + { + Main.PlaySound(SoundID.Item28, center); + Main.PlaySound(SoundID.Item60, center); + int numDust = 36; + int dustID = 73; + for (int i = 0; i < numDust; ++i) + { + Dust d = Dust.NewDustDirect(center, 0, 0, dustID, 0f, 0f); + d.velocity = (i * MathHelper.TwoPi / numDust).ToRotationVector2() * 2.2f; + d.scale = 1.4f; + d.noGravity = true; + } + } + } +} diff --git a/Projectiles/Magic/ValkyrieRayStaff.png b/Projectiles/Magic/ValkyrieRayStaff.png new file mode 100644 index 0000000000000000000000000000000000000000..18ec195aa0f50f4959122b73dc463d40b2cb50bb GIT binary patch literal 1095 zcmV-N1i1T&P)Px(0ZBwbRA_h2#maR1lY5yC427ph{0dd;1CV<0{TiYHL+w2__d=e z3)j|62kYM1hCDVla;O(DV^Y~ajvxG`4cuLO3n-r)n>u{a2i$(ojbKMzT^829eHW;&JAzznl~;_9C>ZNMX+!hoPXRydOrAUIUt0*4 ztf~V=Ba0)r_r7J|i%nazklFtQ*zo3ypl0D@u=3GQ!=nnuE{NWCx87pt%Woe`%)4R1 zTVUR-DG`jFFcmcI?Mj$Rvv|R+pz^BH2%7e_Bae*@#5tBQ)42Z_axoNGxokUVXxag; zu9_Ob>C>ginOgtx{otA94}%q}YryomD-zEOrasARM!{I$NgI0kjgyJ%S+grZLsNWx zusJq6Zq$SKhP%w6}c=n~k;Ju|Y!3*!VpBahIxln&?{pt{M=UHFLTVof!9t&Ci z<>TYt#LvISIo~S}R)fzsC+9z29-CUzb_!HPqaygLyc`@p)S0fV0}+K7>p#I%ZFQWT zXByhG@MKL@V&2Vhvq|O7WbPPf&Hf3x4t0iG{ra!UTVn%JLC1B}ne4uzHs0l0GrN)7 z70eMbOeRunn@jHP-Jx zTRNr!=hRn;`IRMcpRlPT&gOf|DK8cUV}W3*th5BQwRa?T!B9_)E*cZjJ>~}5RN((( z?0oO5(xyUBW5dQxJwAJ|45i6iV`tB?V5+ht?j|*LbbDU~+S)tN-Bjptgz=#!Z;hRe zvGlnVvhqbsCnmlSI=bPUx?;-Y2oATzZx)9trqblCv0ihTzF%(~IC=uZ-&7!PjYTsimG#zXMeYq{rXlXJ7mN)te*