From b24863d23df6943afa134638ec3ffd6beef31f7a Mon Sep 17 00:00:00 2001 From: IbanPlay <56191483+IbanPlay@users.noreply.github.com> Date: Mon, 21 Feb 2022 23:12:26 +0100 Subject: [PATCH] Every normalization is now safe Minus some particle ones but those don't matter that much --- DataStructures/Attunement.cs | 2 +- Items/Weapons/Melee/ArkoftheCosmos.cs | 2 +- Items/Weapons/Melee/ArkoftheElements.cs | 4 ++-- Items/Weapons/Melee/TrueArkoftheAncients.cs | 8 ++++---- .../Melee/ArkOfTheAncients_ParryHoldout.cs | 4 ++-- .../Melee/ArkOfTheCosmos_BlastAttack.cs | 2 +- .../Melee/ArkOfTheCosmos_ParryHoldout.cs | 4 ++-- .../Melee/ArkOfTheCosmos_SwungBlade.cs | 6 +++--- .../Melee/ArkOfTheElements_ParryHoldout.cs | 4 ++-- .../Melee/ArkoftheCosmos_Constellation.cs | 4 ++-- .../Melee/BrokenBiomeBlade_AridGrandeur.cs | 2 +- .../Melee/BrokenBiomeBlade_BitingEmbrace.cs | 2 +- .../Melee/BrokenBiomeBlade_DecaysRetort.cs | 2 +- .../BrokenBiomeBlade_GrovetendersTouch.cs | 4 ++-- Projectiles/Melee/Galaxia_AndromedasStride.cs | 2 +- Projectiles/Melee/Galaxia_AriesWrath.cs | 14 ++++++------- .../Melee/Galaxia_AriesWrathConstellation.cs | 4 ++-- Projectiles/Melee/Galaxia_PhoenixsPride.cs | 12 +++++------ Projectiles/Melee/Galaxia_PolarisGaze.cs | 2 +- Projectiles/Melee/Galaxia_PolarisGazeDash.cs | 2 +- Projectiles/Melee/Galaxia_PolarisGazeStar.cs | 2 +- .../MendedBiomeBlade_DecaysRetortDash.cs | 2 -- .../MendedBiomeBlade_ExtantAbhorrence.cs | 2 +- ...endedBiomeBlade_GestureForTheDrownedOrb.cs | 2 +- ...dBiomeBlade_GrovetendersEntanglingVines.cs | 2 +- .../Melee/MendedBiomeBlade_HeavensMight.cs | 4 ++-- .../MendedBiomeBlade_TrueAridGrandeur.cs | 2 +- .../MendedBiomeBlade_TrueAridGrandeurShot.cs | 2 +- .../MendedBiomeBlade_TrueBitingEmbrace.cs | 2 +- .../MendedBiomeBlade_TrueDecaysRetort.cs | 2 +- .../MendedBiomeBlade_TrueGrovetendersTouch.cs | 4 ++-- Projectiles/Melee/TrueAncientBlast.cs | 2 +- .../TrueArkOfTheAncients_ParryHoldout.cs | 4 ++-- .../Melee/TrueBiomeBlade_ChainedMeatHook.cs | 2 +- ...TrueBiomeBlade_LamentationsOfTheChained.cs | 4 ++-- .../Melee/TrueBiomeBlade_MercurialTides.cs | 2 +- .../Melee/TrueBiomeBlade_SanguineFury.cs | 4 ++-- .../Melee/TrueBiomeBlade_SanguineFuryWheel.cs | 2 +- .../Melee/TrueBiomeBlade_SwordsmithsPride.cs | 20 +++++++++---------- 39 files changed, 75 insertions(+), 77 deletions(-) diff --git a/DataStructures/Attunement.cs b/DataStructures/Attunement.cs index efa0e8d0bc..ddf7c43e3c 100644 --- a/DataStructures/Attunement.cs +++ b/DataStructures/Attunement.cs @@ -541,7 +541,7 @@ namespace CalamityMod.DataStructures if (UseTimer % 30 == 29 && Main.rand.Next(2) == 0) { Main.PlaySound(SoundID.Item78); - Projectile beamSword = Projectile.NewProjectileDirect(player.Center, player.DirectionTo(Main.MouseWorld) * 15f, ProjectileType(), (int)(OmegaBiomeBlade.WhirlwindAttunement_PassiveBaseDamage * player.MeleeDamage()), 10f, player.whoAmI, 1f); + Projectile beamSword = Projectile.NewProjectileDirect(player.Center, player.SafeDirectionTo(Main.MouseWorld, Vector2.One) * 15f, ProjectileType(), (int)(OmegaBiomeBlade.WhirlwindAttunement_PassiveBaseDamage * player.MeleeDamage()), 10f, player.whoAmI, 1f); beamSword.timeLeft = 50; UseTimer++; } diff --git a/Items/Weapons/Melee/ArkoftheCosmos.cs b/Items/Weapons/Melee/ArkoftheCosmos.cs index cfa0b467fa..e10e244f67 100644 --- a/Items/Weapons/Melee/ArkoftheCosmos.cs +++ b/Items/Weapons/Melee/ArkoftheCosmos.cs @@ -150,7 +150,7 @@ namespace CalamityMod.Items.Weapons.Melee if (scissorState != 2) { Vector2 throwVector = new Vector2(speedX, speedY); - Projectile.NewProjectile(player.Center + Vector2.Normalize(throwVector) * 20, new Vector2(speedX, speedY) * 1.4f, ProjectileType(), (int)(damage * NeedleDamageMultiplier), knockBack, player.whoAmI); + Projectile.NewProjectile(player.Center + Utils.SafeNormalize(throwVector, Vector2.Zero) * 20, new Vector2(speedX, speedY) * 1.4f, ProjectileType(), (int)(damage * NeedleDamageMultiplier), knockBack, player.whoAmI); } Combo += 1; diff --git a/Items/Weapons/Melee/ArkoftheElements.cs b/Items/Weapons/Melee/ArkoftheElements.cs index b430bb294e..bd657ec4ea 100644 --- a/Items/Weapons/Melee/ArkoftheElements.cs +++ b/Items/Weapons/Melee/ArkoftheElements.cs @@ -144,10 +144,10 @@ namespace CalamityMod.Items.Weapons.Melee { Vector2 throwVector = new Vector2(speedX, speedY); float empoweredNeedles = Charge > 0 ? 1f : 0f; - Projectile.NewProjectile(player.Center + Vector2.Normalize(throwVector) * 20, new Vector2(speedX, speedY) * 2.8f, ProjectileType(), (int)(damage * 0.5f), knockBack, player.whoAmI, empoweredNeedles); + Projectile.NewProjectile(player.Center + Utils.SafeNormalize(throwVector, Vector2.Zero) * 20, new Vector2(speedX, speedY) * 2.8f, ProjectileType(), (int)(damage * 0.5f), knockBack, player.whoAmI, empoweredNeedles); - Vector2 Shift = Vector2.Normalize(new Vector2(speedX, speedY).RotatedBy(MathHelper.PiOver2)) * 20; + Vector2 Shift = Utils.SafeNormalize(new Vector2(speedX, speedY).RotatedBy(MathHelper.PiOver2), Vector2.Zero) * 20; Projectile.NewProjectile(player.Center + Shift, throwVector.RotatedBy(MathHelper.PiOver4 * 0.3f), ProjectileType(), (int)(damage * 0.2f), knockBack, player.whoAmI); Projectile.NewProjectile(player.Center + Shift * 1.2f, throwVector.RotatedBy(MathHelper.PiOver4 * 0.4f) * 0.8f, ProjectileType(), (int)(damage * 0.2f), knockBack, player.whoAmI); diff --git a/Items/Weapons/Melee/TrueArkoftheAncients.cs b/Items/Weapons/Melee/TrueArkoftheAncients.cs index d27a9760de..425a48d2c7 100644 --- a/Items/Weapons/Melee/TrueArkoftheAncients.cs +++ b/Items/Weapons/Melee/TrueArkoftheAncients.cs @@ -85,8 +85,8 @@ namespace CalamityMod.Items.Weapons.Melee { if (Charge > 0 && player.controlUp) { - float angle = player.DirectionTo(Main.MouseWorld).ToRotation(); - Vector2 laserVector = player.DirectionTo(Main.MouseWorld) * 600; + float angle = player.SafeDirectionTo(Main.MouseWorld, Vector2.UnitY).ToRotation(); + Vector2 laserVector = player.SafeDirectionTo(Main.MouseWorld, Vector2.UnitY) * 600; Projectile.NewProjectile(player.Center + angle.ToRotationVector2() * 90f, laserVector, ProjectileType(), (int)(damage * Charge * chargeDamageMultiplier * blastDamageMultiplier), 0, player.whoAmI); if (Main.LocalPlayer.Calamity().GeneralScreenShakePower < 3) @@ -115,9 +115,9 @@ namespace CalamityMod.Items.Weapons.Melee { //Only shoot the center star if theres no charge if (Charge == 0) - Projectile.NewProjectile(player.Center + Vector2.Normalize(new Vector2(speedX, speedY)) * 20, new Vector2(speedX, speedY), ProjectileType(), (int)(damage * glassStarDamageMultiplier), knockBack, player.whoAmI); + Projectile.NewProjectile(player.Center + Utils.SafeNormalize(new Vector2(speedX, speedY), Vector2.Zero) * 20, new Vector2(speedX, speedY), ProjectileType(), (int)(damage * glassStarDamageMultiplier), knockBack, player.whoAmI); - Vector2 Shift = Vector2.Normalize(new Vector2(speedX, speedY).RotatedBy(MathHelper.PiOver2)) * 30; + Vector2 Shift = Utils.SafeNormalize(new Vector2(speedX, speedY).RotatedBy(MathHelper.PiOver2), Vector2.Zero) * 30; Projectile.NewProjectile(player.Center + Shift, new Vector2(speedX, speedY).RotatedBy(MathHelper.PiOver4 * 0.3f) , ProjectileType(), (int)(damage * glassStarDamageMultiplier), knockBack, player.whoAmI, Charge > 0 ? 1 : 0); Projectile.NewProjectile(player.Center - Shift, new Vector2(speedX, speedY).RotatedBy(-MathHelper.PiOver4 * 0.3f), ProjectileType(), (int)(damage * glassStarDamageMultiplier), knockBack, player.whoAmI, Charge > 0 ? 1 : 0); diff --git a/Projectiles/Melee/ArkOfTheAncients_ParryHoldout.cs b/Projectiles/Melee/ArkOfTheAncients_ParryHoldout.cs index d4019af866..11e6f4c878 100644 --- a/Projectiles/Melee/ArkOfTheAncients_ParryHoldout.cs +++ b/Projectiles/Melee/ArkOfTheAncients_ParryHoldout.cs @@ -96,7 +96,7 @@ namespace CalamityMod.Projectiles.Melee projectile.timeLeft = (int)MaxTime; Main.PlaySound(SoundID.DD2_SkyDragonsFuryShot, projectile.Center); - projectile.velocity = Owner.DirectionTo(Owner.Calamity().mouseWorld); + projectile.velocity = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); projectile.velocity.Normalize(); projectile.rotation = projectile.velocity.ToRotation(); @@ -136,7 +136,7 @@ namespace CalamityMod.Projectiles.Melee //Bounce off the player if they are in the air if (Owner.velocity.Y != 0) - Owner.velocity += Vector2.Normalize(Owner.Center - proj.Center) * 2; + Owner.velocity += Utils.SafeNormalize(Owner.Center - proj.Center, Vector2.Zero) * 2; break; } } diff --git a/Projectiles/Melee/ArkOfTheCosmos_BlastAttack.cs b/Projectiles/Melee/ArkOfTheCosmos_BlastAttack.cs index 2f43b783ca..eb3f8e965c 100644 --- a/Projectiles/Melee/ArkOfTheCosmos_BlastAttack.cs +++ b/Projectiles/Melee/ArkOfTheCosmos_BlastAttack.cs @@ -169,7 +169,7 @@ namespace CalamityMod.Projectiles.Melee { Owner.Calamity().LungingDown = true; Owner.fallStart = (int)(Owner.position.Y / 16f); - Owner.velocity = Owner.DirectionTo(scissorPosition) * 60f; + Owner.velocity = Owner.SafeDirectionTo(scissorPosition, Vector2.Zero) * 60f; if (Owner.Distance(scissorPosition) < 60f) { diff --git a/Projectiles/Melee/ArkOfTheCosmos_ParryHoldout.cs b/Projectiles/Melee/ArkOfTheCosmos_ParryHoldout.cs index 5420714fca..ffbf00b35f 100644 --- a/Projectiles/Melee/ArkOfTheCosmos_ParryHoldout.cs +++ b/Projectiles/Melee/ArkOfTheCosmos_ParryHoldout.cs @@ -113,7 +113,7 @@ namespace CalamityMod.Projectiles.Melee var sound = Main.PlaySound(SoundID.Item84, projectile.Center); CalamityUtils.SafeVolumeChange(ref sound, 0.3f); - projectile.velocity = Owner.DirectionTo(Main.MouseWorld); + projectile.velocity = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); projectile.velocity.Normalize(); projectile.rotation = projectile.velocity.ToRotation(); @@ -145,7 +145,7 @@ namespace CalamityMod.Projectiles.Melee { GeneralParryEffects(); if (Owner.velocity.Y != 0) - Owner.velocity += Vector2.Normalize(Owner.Center - proj.Center) * 2; + Owner.velocity += Utils.SafeNormalize(Owner.Center - proj.Center, Vector2.Zero) * 2; } //Reduce the projectile's damage by 300 for a second. diff --git a/Projectiles/Melee/ArkOfTheCosmos_SwungBlade.cs b/Projectiles/Melee/ArkOfTheCosmos_SwungBlade.cs index 70c1ae489f..39b21ac742 100644 --- a/Projectiles/Melee/ArkOfTheCosmos_SwungBlade.cs +++ b/Projectiles/Melee/ArkOfTheCosmos_SwungBlade.cs @@ -327,7 +327,7 @@ namespace CalamityMod.Projectiles.Melee { float maxDistance = projectile.scale * 78f; Vector2 distance = Main.rand.NextVector2Circular(maxDistance, maxDistance); - Vector2 angularVelocity = Vector2.Normalize(distance.RotatedBy(MathHelper.PiOver2 * Owner.direction)) * 2 * (1f + distance.Length() / 15f); + Vector2 angularVelocity = Utils.SafeNormalize(distance.RotatedBy(MathHelper.PiOver2 * Owner.direction), Vector2.Zero) * 2 * (1f + distance.Length() / 15f); Particle glitter = new CritSpark(Owner.Center + distance, Owner.velocity + angularVelocity, Main.rand.Next(3) == 0 ? Color.Turquoise : Color.Coral, currentColor, 1f + 1 * (distance.Length() / maxDistance), 10, 0.05f, 3f); GeneralParticleHandler.SpawnParticle(glitter); } @@ -386,7 +386,7 @@ namespace CalamityMod.Projectiles.Melee { float maxDistance = projectile.scale * 78f; Vector2 distance = Main.rand.NextVector2Circular(maxDistance, maxDistance); - Vector2 angularVelocity = Vector2.Normalize(distance.RotatedBy(-MathHelper.PiOver2)) * 2 * (1f + distance.Length() / 15f); + Vector2 angularVelocity = Utils.SafeNormalize(distance.RotatedBy(-MathHelper.PiOver2), Vector2.Zero) * 2 * (1f + distance.Length() / 15f); Color glitterColor = Main.hslToRgb(Main.rand.NextFloat(), 1, 0.5f); Particle glitter = new CritSpark(projectile.Center + distance, Owner.velocity + angularVelocity, Color.White , glitterColor, 1f + 1 * (distance.Length() / maxDistance), 10, 0.05f, 3f); GeneralParticleHandler.SpawnParticle(glitter); @@ -455,7 +455,7 @@ namespace CalamityMod.Projectiles.Melee Main.PlaySound(SoundID.Item84, projectile.Center); - Vector2 sliceDirection = Vector2.Normalize(direction) * 40; + Vector2 sliceDirection = Utils.SafeNormalize(direction, Vector2.One) * 40; Particle SliceLine = new LineVFX(projectile.Center - sliceDirection, sliceDirection * 2f, 0.2f, Color.Orange * 0.7f, expansion : 250f) { Lifetime = 10 diff --git a/Projectiles/Melee/ArkOfTheElements_ParryHoldout.cs b/Projectiles/Melee/ArkOfTheElements_ParryHoldout.cs index da475b14ca..774bfe31c6 100644 --- a/Projectiles/Melee/ArkOfTheElements_ParryHoldout.cs +++ b/Projectiles/Melee/ArkOfTheElements_ParryHoldout.cs @@ -113,7 +113,7 @@ namespace CalamityMod.Projectiles.Melee var sound = Main.PlaySound(SoundID.Item84, projectile.Center); CalamityUtils.SafeVolumeChange(ref sound, 0.3f); - projectile.velocity = Owner.DirectionTo(Main.MouseWorld); + projectile.velocity = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); projectile.velocity.Normalize(); projectile.rotation = projectile.velocity.ToRotation(); @@ -145,7 +145,7 @@ namespace CalamityMod.Projectiles.Melee { GeneralParryEffects(); if (Owner.velocity.Y != 0) - Owner.velocity += Vector2.Normalize(Owner.Center - proj.Center) * 2; + Owner.velocity += Utils.SafeNormalize(Owner.Center - proj.Center, Vector2.Zero) * 2; } //Reduce the projectile's damage by 200 for a second. diff --git a/Projectiles/Melee/ArkoftheCosmos_Constellation.cs b/Projectiles/Melee/ArkoftheCosmos_Constellation.cs index 70f4b0d723..cd975416f0 100644 --- a/Projectiles/Melee/ArkoftheCosmos_Constellation.cs +++ b/Projectiles/Melee/ArkoftheCosmos_Constellation.cs @@ -89,7 +89,7 @@ namespace CalamityMod.Projectiles.Melee constellationColorHue = (constellationColorHue + 0.16f) % 1; constellationColor = Main.hslToRgb(constellationColorHue, 1, 0.8f); - offset = Main.rand.NextFloat(-50f, 50f) * Vector2.Normalize(SizeVector.RotatedBy(MathHelper.PiOver2)); + offset = Main.rand.NextFloat(-50f, 50f) * Utils.SafeNormalize(SizeVector.RotatedBy(MathHelper.PiOver2), Vector2.Zero); Star = new GenericSparkle(AnchorStart + SizeVector * i + offset, Vector2.Zero, Color.White, constellationColor, Main.rand.NextFloat(1f, 1.5f), 20, 0f, 3f); BootlegSpawnParticle(Star); @@ -101,7 +101,7 @@ namespace CalamityMod.Projectiles.Melee constellationColorHue = (constellationColorHue + 0.16f) % 1; constellationColor = Main.hslToRgb(constellationColorHue, 1, 0.8f); - offset = Main.rand.NextFloat(-50f, 50f) * Vector2.Normalize(SizeVector.RotatedBy(MathHelper.PiOver2)); + offset = Main.rand.NextFloat(-50f, 50f) * Utils.SafeNormalize(SizeVector.RotatedBy(MathHelper.PiOver2), Vector2.Zero); Star = new GenericSparkle(AnchorStart + SizeVector * i + offset, Vector2.Zero, Color.White, constellationColor, Main.rand.NextFloat(1f, 1.5f), 20, 0f, 3f); BootlegSpawnParticle(Star); diff --git a/Projectiles/Melee/BrokenBiomeBlade_AridGrandeur.cs b/Projectiles/Melee/BrokenBiomeBlade_AridGrandeur.cs index bebaf99992..203b2aaf60 100644 --- a/Projectiles/Melee/BrokenBiomeBlade_AridGrandeur.cs +++ b/Projectiles/Melee/BrokenBiomeBlade_AridGrandeur.cs @@ -122,7 +122,7 @@ namespace CalamityMod.Projectiles.Melee Lighting.AddLight(projectile.Center, new Vector3(1f, 0.56f, 0.56f) * ShredRatio); //Manage position and rotation - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.rotation = direction.ToRotation(); projectile.Center = Owner.Center + (direction * 60); diff --git a/Projectiles/Melee/BrokenBiomeBlade_BitingEmbrace.cs b/Projectiles/Melee/BrokenBiomeBlade_BitingEmbrace.cs index 7cd9462c7e..983d976b44 100644 --- a/Projectiles/Melee/BrokenBiomeBlade_BitingEmbrace.cs +++ b/Projectiles/Melee/BrokenBiomeBlade_BitingEmbrace.cs @@ -133,7 +133,7 @@ namespace CalamityMod.Projectiles.Melee } //Take the direction the sword is swung. FUCK not controlling the swing direction more than just left/right :| - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.rotation = direction.ToRotation(); diff --git a/Projectiles/Melee/BrokenBiomeBlade_DecaysRetort.cs b/Projectiles/Melee/BrokenBiomeBlade_DecaysRetort.cs index a19e2edfe2..db33bf30e4 100644 --- a/Projectiles/Melee/BrokenBiomeBlade_DecaysRetort.cs +++ b/Projectiles/Melee/BrokenBiomeBlade_DecaysRetort.cs @@ -60,7 +60,7 @@ namespace CalamityMod.Projectiles.Melee { CanBounce = 1f; projectile.timeLeft = (int)MaxTime; - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.rotation = direction.ToRotation(); if (CanLunge == 1f) diff --git a/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouch.cs b/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouch.cs index 743e5b75c7..34e83fd530 100644 --- a/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouch.cs +++ b/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouch.cs @@ -104,7 +104,7 @@ namespace CalamityMod.Projectiles.Melee { if (!initialized) //Initialization. create control points & shit) { - projectile.velocity = Owner.DirectionTo(Owner.Calamity().mouseWorld); + projectile.velocity = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); Reach = MathHelper.Clamp((Owner.Center - Owner.Calamity().mouseWorld).Length(), MinReach, MaxReach); Main.PlaySound(SoundID.DD2_OgreSpit, projectile.Center); controlPoint1 = projectile.Center; @@ -145,7 +145,7 @@ namespace CalamityMod.Projectiles.Melee //Shmoove the player if a tile is hit. This movement always happens if the owner isnt on the ground, but will only happen if the projectile is above the player if they are standing on the ground) if (Collision.SolidCollision(projectile.position, 32, 32) && (Owner.velocity.Y != 0 || projectile.position.Y < Owner.position.Y)) { - Owner.velocity = Owner.DirectionTo(projectile.Center) * ReelBackStrenght; + Owner.velocity = Owner.SafeDirectionTo(projectile.Center, Vector2.Zero) * ReelBackStrenght; SnapCoyoteTime = 0f; } Main.PlaySound(SoundID.Item65, projectile.position); diff --git a/Projectiles/Melee/Galaxia_AndromedasStride.cs b/Projectiles/Melee/Galaxia_AndromedasStride.cs index 08bc19d94b..e77e013927 100644 --- a/Projectiles/Melee/Galaxia_AndromedasStride.cs +++ b/Projectiles/Melee/Galaxia_AndromedasStride.cs @@ -107,7 +107,7 @@ namespace CalamityMod.Projectiles.Melee if (State == 0f) { - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.Center = Owner.Center + (direction * 70f * ChargeDisplacement()); diff --git a/Projectiles/Melee/Galaxia_AriesWrath.cs b/Projectiles/Melee/Galaxia_AriesWrath.cs index 1d74281023..c454692c06 100644 --- a/Projectiles/Melee/Galaxia_AriesWrath.cs +++ b/Projectiles/Melee/Galaxia_AriesWrath.cs @@ -78,7 +78,7 @@ namespace CalamityMod.Projectiles.Melee NPC potentialTarget = TargetNext(target.Center, i); if (potentialTarget == null) break; - Projectile proj = Projectile.NewProjectileDirect(target.Center, target.DirectionTo(potentialTarget.Center) * 25f, ProjectileType(), (int)(damage * FourSeasonsGalaxia.AriesAttunement_OnHitBoltDamageReduction), 0, Owner.whoAmI, 0.9f, MathHelper.PiOver4 * 0.4f); + Projectile proj = Projectile.NewProjectileDirect(target.Center, target.SafeDirectionTo(potentialTarget.Center, Vector2.Zero) * 25f, ProjectileType(), (int)(damage * FourSeasonsGalaxia.AriesAttunement_OnHitBoltDamageReduction), 0, Owner.whoAmI, 0.9f, MathHelper.PiOver4 * 0.4f); proj.scale = 2f; } Array.Clear(excludedTargets, 0, 3); @@ -135,9 +135,9 @@ namespace CalamityMod.Projectiles.Melee projectile.velocity *= 10f; } if (projectile.velocity.AngleBetween(Owner.Center - projectile.Center) > MathHelper.PiOver4) - projectile.velocity = (projectile.velocity.ToRotation().AngleTowards(projectile.DirectionTo(Owner.Center).ToRotation(), MathHelper.Pi / 20f)).ToRotationVector2() * projectile.velocity.Length() * 0.98f; + projectile.velocity = (projectile.velocity.ToRotation().AngleTowards(projectile.SafeDirectionTo(Owner.Center, Vector2.Zero).ToRotation(), MathHelper.Pi / 20f)).ToRotationVector2() * projectile.velocity.Length() * 0.98f; else - projectile.velocity = (projectile.velocity.ToRotation().AngleTowards(projectile.DirectionTo(Owner.Center).ToRotation(), MathHelper.Pi)).ToRotationVector2() * projectile.velocity.Length() * 1.05f; + projectile.velocity = (projectile.velocity.ToRotation().AngleTowards(projectile.SafeDirectionTo(Owner.Center, Vector2.Zero).ToRotation(), MathHelper.Pi)).ToRotationVector2() * projectile.velocity.Length() * 1.05f; projectile.rotation = Main.GlobalTime * 25f; projectile.scale = MathHelper.Clamp((Owner.Center - projectile.Center).Length() / (FourSeasonsGalaxia.AriesAttunement_Reach * 0.5f), 0.3f, 2f); projectile.timeLeft = 4; @@ -163,12 +163,12 @@ namespace CalamityMod.Projectiles.Melee projectile.Center = projectile.Center.MoveTowards(Owner.Calamity().mouseWorld, 40f * ThrowDisplace()); if ((projectile.Center - Owner.Center).Length() > FourSeasonsGalaxia.AriesAttunement_Reach) - projectile.Center = Owner.Center + Owner.DirectionTo(projectile.Center) * FourSeasonsGalaxia.AriesAttunement_Reach; + projectile.Center = Owner.Center + Owner.SafeDirectionTo(projectile.Center, Vector2.Zero) * FourSeasonsGalaxia.AriesAttunement_Reach; projectile.rotation = Main.GlobalTime * 25f; //Make the owner look like theyre "holding" the sword bla bla Owner.heldProj = projectile.whoAmI; - projectile.velocity = Owner.DirectionTo(projectile.Center); + projectile.velocity = Owner.SafeDirectionTo(projectile.Center, Vector2.Zero); Owner.direction = Math.Sign(projectile.velocity.X); Owner.itemRotation = projectile.velocity.ToRotation(); if (Owner.direction != 1) @@ -197,14 +197,14 @@ namespace CalamityMod.Projectiles.Melee { float maxDistance = projectile.scale * 82f; Vector2 distance = Main.rand.NextVector2Circular(maxDistance, maxDistance); - Vector2 angularVelocity = Vector2.Normalize(distance.RotatedBy(MathHelper.PiOver2)) * 2f * (1f + distance.Length() / 15f); + Vector2 angularVelocity = Utils.SafeNormalize(distance.RotatedBy(MathHelper.PiOver2), Vector2.Zero) * 2f * (1f + distance.Length() / 15f); Particle glitter = new CritSpark(projectile.Center + distance, angularVelocity, Main.rand.Next(3) == 0 ? Color.HotPink : Color.Plum, Color.DarkOrchid, 1f + 1 * (distance.Length() / maxDistance), 10, 0.05f, 3f); GeneralParticleHandler.SpawnParticle(glitter); } float smokeDistance = projectile.scale * 62f; Vector2 smokePos = Main.rand.NextVector2Circular(smokeDistance, smokeDistance); - Vector2 smokeSpeed = Vector2.Normalize(smokePos.RotatedBy(MathHelper.PiOver2)) * 0.1f * (1f + smokePos.Length() / 15f); + Vector2 smokeSpeed = Utils.SafeNormalize(smokePos.RotatedBy(MathHelper.PiOver2), Vector2.Zero) * 0.1f * (1f + smokePos.Length() / 15f); Particle smoke = new HeavySmokeParticle(projectile.Center + smokePos, smokeSpeed, Color.Lerp(Color.Navy, Color.Indigo, (float)Math.Sin(Main.GlobalTime * 6f)), 30, Main.rand.NextFloat(0.4f, 1f) * projectile.scale, 0.8f, 0, false, 0, true); GeneralParticleHandler.SpawnParticle(smoke); diff --git a/Projectiles/Melee/Galaxia_AriesWrathConstellation.cs b/Projectiles/Melee/Galaxia_AriesWrathConstellation.cs index 85b2838aeb..36e4d598f5 100644 --- a/Projectiles/Melee/Galaxia_AriesWrathConstellation.cs +++ b/Projectiles/Melee/Galaxia_AriesWrathConstellation.cs @@ -60,7 +60,7 @@ namespace CalamityMod.Projectiles.Melee for (float i = 0 + Main.rand.NextFloat(0.2f, 0.5f); i < 1; i += Main.rand.NextFloat(0.2f, 0.5f)) { - offset = Main.rand.NextFloat(-50f, 50f) * Vector2.Normalize(SizeVector.RotatedBy(MathHelper.PiOver2)); + offset = Main.rand.NextFloat(-50f, 50f) * Utils.SafeNormalize(SizeVector.RotatedBy(MathHelper.PiOver2), Vector2.Zero); Star = new GenericSparkle(projectile.Center + SizeVector * i + offset, Vector2.Zero, Color.White, Color.Plum, Main.rand.NextFloat(1f, 1.5f), 20, 0f, 3f); GeneralParticleHandler.SpawnParticle(Star); @@ -69,7 +69,7 @@ namespace CalamityMod.Projectiles.Melee if (Main.rand.Next(3) == 0) { - offset = Main.rand.NextFloat(-50f, 50f) * Vector2.Normalize(SizeVector.RotatedBy(MathHelper.PiOver2)); + offset = Main.rand.NextFloat(-50f, 50f) * Utils.SafeNormalize(SizeVector.RotatedBy(MathHelper.PiOver2), Vector2.Zero); Star = new GenericSparkle(projectile.Center + SizeVector * i + offset, Vector2.Zero, Color.White, Color.Plum, Main.rand.NextFloat(1f, 1.5f), 20, 0f, 3f); GeneralParticleHandler.SpawnParticle(Star); diff --git a/Projectiles/Melee/Galaxia_PhoenixsPride.cs b/Projectiles/Melee/Galaxia_PhoenixsPride.cs index 01c93d026b..4f7b1bc07f 100644 --- a/Projectiles/Melee/Galaxia_PhoenixsPride.cs +++ b/Projectiles/Melee/Galaxia_PhoenixsPride.cs @@ -81,7 +81,7 @@ namespace CalamityMod.Projectiles.Melee { Main.PlaySound(SoundID.Item90, projectile.Center); projectile.velocity = Vector2.Zero; - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); initialized = true; } @@ -104,7 +104,7 @@ namespace CalamityMod.Projectiles.Melee Main.LocalPlayer.Calamity().GeneralScreenShakePower = 3; Main.PlaySound(SoundID.Item80, projectile.Center); - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); //PARTICLES LOTS OF PARTICLES LOTS OF SPARKLES YES YES MH YES YES for (int i = 0; i <= 8; i++) { @@ -207,17 +207,17 @@ namespace CalamityMod.Projectiles.Melee } float rotationAdjusted = MathHelper.WrapAngle(projectile.rotation) + MathHelper.Pi; - float mouseAngleAdjusted = MathHelper.WrapAngle(Owner.DirectionTo(Main.MouseWorld).ToRotation()) + MathHelper.Pi; + float mouseAngleAdjusted = MathHelper.WrapAngle(Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.One).ToRotation()) + MathHelper.Pi; float deltaAngleShoot = Math.Abs(MathHelper.WrapAngle(rotationAdjusted - mouseAngleAdjusted)); if (CanDirectFire && deltaAngleShoot < 0.1f) { if (Owner.whoAmI == Main.myPlayer) { - Projectile.NewProjectile(Owner.Center, Owner.DirectionTo(Main.MouseWorld) * 15f, ProjectileType(), (int)(projectile.damage * FourSeasonsGalaxia.PhoenixAttunement_BoltDamageReduction), 0f, Owner.whoAmI, 0.1f, MathHelper.Pi * 0.02f); + Projectile.NewProjectile(Owner.Center, Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.One) * 15f, ProjectileType(), (int)(projectile.damage * FourSeasonsGalaxia.PhoenixAttunement_BoltDamageReduction), 0f, Owner.whoAmI, 0.1f, MathHelper.Pi * 0.02f); } CanDirectFire = false; - AngleReset = Owner.DirectionTo(Main.MouseWorld).ToRotation(); + AngleReset = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.One).ToRotation(); } @@ -225,7 +225,7 @@ namespace CalamityMod.Projectiles.Melee { float maxDistance = projectile.scale * 1.9f * 78f; Vector2 distance = Main.rand.NextVector2Circular(maxDistance, maxDistance); - Vector2 angularVelocity = Vector2.Normalize(distance.RotatedBy(MathHelper.PiOver2)) * 2f * (1f + distance.Length() / 15f); + Vector2 angularVelocity = Utils.SafeNormalize(distance.RotatedBy(MathHelper.PiOver2), Vector2.Zero) * 2f * (1f + distance.Length() / 15f); Particle glitter = new CritSpark(Owner.Center + distance, Owner.velocity + angularVelocity, Main.rand.Next(3) == 0 ? Color.Turquoise : Color.Coral, currentColor, 1f + 1 * (distance.Length() / maxDistance), 10, 0.05f, 3f); GeneralParticleHandler.SpawnParticle(glitter); } diff --git a/Projectiles/Melee/Galaxia_PolarisGaze.cs b/Projectiles/Melee/Galaxia_PolarisGaze.cs index 25bbdc9e7f..b4ae8b1a55 100644 --- a/Projectiles/Melee/Galaxia_PolarisGaze.cs +++ b/Projectiles/Melee/Galaxia_PolarisGaze.cs @@ -156,7 +156,7 @@ namespace CalamityMod.Projectiles.Melee Shred = 0; //Manage position and rotation - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.rotation = direction.ToRotation(); projectile.Center = Owner.Center + (direction * 60); diff --git a/Projectiles/Melee/Galaxia_PolarisGazeDash.cs b/Projectiles/Melee/Galaxia_PolarisGazeDash.cs index 987484119e..5241445e8a 100644 --- a/Projectiles/Melee/Galaxia_PolarisGazeDash.cs +++ b/Projectiles/Melee/Galaxia_PolarisGazeDash.cs @@ -62,7 +62,7 @@ namespace CalamityMod.Projectiles.Melee //Explode into cosmic bolts for (int i = 0; i < 3; i++) { - Projectile blast = Projectile.NewProjectileDirect(Owner.Center, Owner.DirectionTo(target.Center).RotatedByRandom(MathHelper.PiOver4) * 30f, ProjectileType(), (int)(FourSeasonsGalaxia.PolarisAttunement_SlashBoltsDamage * Owner.meleeDamage), 0f, Owner.whoAmI, 0.55f, MathHelper.Pi * 0.01f); + Projectile blast = Projectile.NewProjectileDirect(Owner.Center, Owner.SafeDirectionTo(target.Center, Vector2.Zero).RotatedByRandom(MathHelper.PiOver4) * 30f, ProjectileType(), (int)(FourSeasonsGalaxia.PolarisAttunement_SlashBoltsDamage * Owner.meleeDamage), 0f, Owner.whoAmI, 0.55f, MathHelper.Pi * 0.01f); { blast.timeLeft = 100; } diff --git a/Projectiles/Melee/Galaxia_PolarisGazeStar.cs b/Projectiles/Melee/Galaxia_PolarisGazeStar.cs index a3ee2e6786..1d57f9f4c5 100644 --- a/Projectiles/Melee/Galaxia_PolarisGazeStar.cs +++ b/Projectiles/Melee/Galaxia_PolarisGazeStar.cs @@ -67,7 +67,7 @@ namespace CalamityMod.Projectiles.Melee Main.PlaySound(SoundID.Item90, projectile.Center); initialized = true; - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.rotation = direction.ToRotation(); diff --git a/Projectiles/Melee/MendedBiomeBlade_DecaysRetortDash.cs b/Projectiles/Melee/MendedBiomeBlade_DecaysRetortDash.cs index 0b05a945d7..2ea73c22ad 100644 --- a/Projectiles/Melee/MendedBiomeBlade_DecaysRetortDash.cs +++ b/Projectiles/Melee/MendedBiomeBlade_DecaysRetortDash.cs @@ -67,13 +67,11 @@ namespace CalamityMod.Projectiles.Melee Vector2 Shake = projectile.timeLeft < 15 ? Vector2.Zero : Vector2.One.RotatedByRandom(MathHelper.TwoPi) * (15 - projectile.timeLeft / 5f) * 0.5f; - Vector2 lineDirection = Vector2.Normalize(DashEnd - DashStart); int dist = (int)Vector2.Distance(DashEnd, DashStart) / 16; Vector2[] Nodes = new Vector2[dist + 1]; Nodes[0] = DashStart; Nodes[dist] = DashEnd; - for (int i = 1; i < dist + 1; i++) { Vector2 positionAlongLine = Vector2.Lerp(DashStart, DashEnd, i / (float)dist); //Get the position of the segment along the line diff --git a/Projectiles/Melee/MendedBiomeBlade_ExtantAbhorrence.cs b/Projectiles/Melee/MendedBiomeBlade_ExtantAbhorrence.cs index 68f4dd8bad..86ee6241a4 100644 --- a/Projectiles/Melee/MendedBiomeBlade_ExtantAbhorrence.cs +++ b/Projectiles/Melee/MendedBiomeBlade_ExtantAbhorrence.cs @@ -108,7 +108,7 @@ namespace CalamityMod.Projectiles.Melee if (State == 0f) { - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.Center = Owner.Center + (direction * 70f * ChargeDisplacement()); diff --git a/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedOrb.cs b/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedOrb.cs index 89c4b074c6..40a4ae7a46 100644 --- a/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedOrb.cs +++ b/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedOrb.cs @@ -75,7 +75,7 @@ namespace CalamityMod.Projectiles.Melee return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Bottom, projectile.Bottom - (Vector2.UnitY * scaleY * 110), scaleX * 40, ref collisionPoint); float halfLenght = 66f * projectile.scale; - return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center + Vector2.Normalize(projectile.velocity.RotatedBy(MathHelper.PiOver2)) * halfLenght, projectile.Center - Vector2.Normalize(projectile.velocity.RotatedBy(MathHelper.PiOver2)) * halfLenght, 40f, ref collisionPoint); + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center + Utils.SafeNormalize(projectile.velocity.RotatedBy(MathHelper.PiOver2), Vector2.Zero) * halfLenght, projectile.Center - Utils.SafeNormalize(projectile.velocity.RotatedBy(MathHelper.PiOver2), Vector2.Zero) * halfLenght, 40f, ref collisionPoint); } public override void DrawBehind(int index, List drawCacheProjsBehindNPCsAndTiles, List drawCacheProjsBehindNPCs, List drawCacheProjsBehindProjectiles, List drawCacheProjsOverWiresUI) diff --git a/Projectiles/Melee/MendedBiomeBlade_GrovetendersEntanglingVines.cs b/Projectiles/Melee/MendedBiomeBlade_GrovetendersEntanglingVines.cs index 37ff452df6..291c7a08f5 100644 --- a/Projectiles/Melee/MendedBiomeBlade_GrovetendersEntanglingVines.cs +++ b/Projectiles/Melee/MendedBiomeBlade_GrovetendersEntanglingVines.cs @@ -66,7 +66,7 @@ namespace CalamityMod.Projectiles.Melee float opacity = projectile.timeLeft > 10 ? 1 : projectile.timeLeft / 10f; Vector2 Shake = projectile.timeLeft < 15 ? Vector2.Zero : Vector2.One.RotatedByRandom(MathHelper.TwoPi) * (15 - projectile.timeLeft / 5f) * 0.5f; - Vector2 lineDirection = Vector2.Normalize(Target.Center - NPCfrom.Center); + Vector2 lineDirection = Utils.SafeNormalize(Target.Center - NPCfrom.Center, Vector2.Zero); int dist = (int)Vector2.Distance(Target.Center, NPCfrom.Center) / 16; Vector2[] Nodes = new Vector2[dist + 1]; Nodes[0] = NPCfrom.Center; diff --git a/Projectiles/Melee/MendedBiomeBlade_HeavensMight.cs b/Projectiles/Melee/MendedBiomeBlade_HeavensMight.cs index 0ae5022b6c..0c379b589d 100644 --- a/Projectiles/Melee/MendedBiomeBlade_HeavensMight.cs +++ b/Projectiles/Melee/MendedBiomeBlade_HeavensMight.cs @@ -81,7 +81,7 @@ namespace CalamityMod.Projectiles.Melee { Main.PlaySound(SoundID.Item90, projectile.Center); projectile.velocity = Vector2.Zero; - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); oldDirection = direction; initialized = true; @@ -102,7 +102,7 @@ namespace CalamityMod.Projectiles.Melee { CurrentState = 1f; Main.PlaySound(SoundID.Item80, projectile.Center); - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); //PARTICLES LOTS OF PARTICLES LOTS OF SPARKLES YES YES MH YES YES for (int i = 0; i <= 8; i++) { diff --git a/Projectiles/Melee/MendedBiomeBlade_TrueAridGrandeur.cs b/Projectiles/Melee/MendedBiomeBlade_TrueAridGrandeur.cs index 79baa9e483..c2d5efb1a0 100644 --- a/Projectiles/Melee/MendedBiomeBlade_TrueAridGrandeur.cs +++ b/Projectiles/Melee/MendedBiomeBlade_TrueAridGrandeur.cs @@ -124,7 +124,7 @@ namespace CalamityMod.Projectiles.Melee Lighting.AddLight(projectile.Center, new Vector3(1f, 0.56f, 0.56f) * ShredRatio); //Manage position and rotation - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.rotation = direction.ToRotation(); projectile.Center = Owner.Center + (direction * 60); diff --git a/Projectiles/Melee/MendedBiomeBlade_TrueAridGrandeurShot.cs b/Projectiles/Melee/MendedBiomeBlade_TrueAridGrandeurShot.cs index ffc2a1187f..b1ca5d626c 100644 --- a/Projectiles/Melee/MendedBiomeBlade_TrueAridGrandeurShot.cs +++ b/Projectiles/Melee/MendedBiomeBlade_TrueAridGrandeurShot.cs @@ -60,7 +60,7 @@ namespace CalamityMod.Projectiles.Melee projectile.timeLeft = (int)(30f + ShredRatio * 30f); initialized = true; - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.rotation = direction.ToRotation(); diff --git a/Projectiles/Melee/MendedBiomeBlade_TrueBitingEmbrace.cs b/Projectiles/Melee/MendedBiomeBlade_TrueBitingEmbrace.cs index 987eec2b16..0da458e866 100644 --- a/Projectiles/Melee/MendedBiomeBlade_TrueBitingEmbrace.cs +++ b/Projectiles/Melee/MendedBiomeBlade_TrueBitingEmbrace.cs @@ -129,7 +129,7 @@ namespace CalamityMod.Projectiles.Melee break; } - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.rotation = direction.ToRotation(); diff --git a/Projectiles/Melee/MendedBiomeBlade_TrueDecaysRetort.cs b/Projectiles/Melee/MendedBiomeBlade_TrueDecaysRetort.cs index 1426434789..46e010cd88 100644 --- a/Projectiles/Melee/MendedBiomeBlade_TrueDecaysRetort.cs +++ b/Projectiles/Melee/MendedBiomeBlade_TrueDecaysRetort.cs @@ -65,7 +65,7 @@ namespace CalamityMod.Projectiles.Melee { CanBounce = 1f; projectile.timeLeft = (int)MaxTime; - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.rotation = direction.ToRotation(); if (CanLunge == 1f && !ChargedUp) diff --git a/Projectiles/Melee/MendedBiomeBlade_TrueGrovetendersTouch.cs b/Projectiles/Melee/MendedBiomeBlade_TrueGrovetendersTouch.cs index 14461e6d76..ff1c46dbec 100644 --- a/Projectiles/Melee/MendedBiomeBlade_TrueGrovetendersTouch.cs +++ b/Projectiles/Melee/MendedBiomeBlade_TrueGrovetendersTouch.cs @@ -158,7 +158,7 @@ namespace CalamityMod.Projectiles.Melee { if (!initialized) //Initialization. create control points & shit) { - projectile.velocity = Owner.DirectionTo(Owner.Calamity().mouseWorld); + projectile.velocity = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); Reach = MathHelper.Clamp((Owner.Center - Owner.Calamity().mouseWorld).Length(), MinReach, MaxReach); Main.PlaySound(SoundID.DD2_OgreSpit, projectile.Center); controlPoint1 = projectile.Center; @@ -201,7 +201,7 @@ namespace CalamityMod.Projectiles.Melee //Shmoove the player if a tile is hit. This movement always happens if the owner isnt on the ground, but will only happen if the projectile is above the player if they are standing on the ground) if (Collision.SolidCollision(projectile.position, 32, 32) && (Owner.velocity.Y != 0 || projectile.position.Y < Owner.position.Y)) { - Owner.velocity = Owner.DirectionTo(projectile.Center) * ReelBackStrenght; + Owner.velocity = Owner.SafeDirectionTo(projectile.Center, Vector2.Zero) * ReelBackStrenght; SnapCoyoteTime = 0f; } Main.PlaySound(SoundID.Item65, projectile.position); diff --git a/Projectiles/Melee/TrueAncientBlast.cs b/Projectiles/Melee/TrueAncientBlast.cs index 8af6799405..3cc36c5c6f 100644 --- a/Projectiles/Melee/TrueAncientBlast.cs +++ b/Projectiles/Melee/TrueAncientBlast.cs @@ -79,7 +79,7 @@ namespace CalamityMod.Projectiles.Melee for (int i = 0; i < 10; i++) { - Vector2 particleSpeed = Vector2.Normalize(projectile.velocity).RotatedByRandom(MathHelper.PiOver4 * 0.8f) * Main.rand.NextFloat(2.6f, 4f); + Vector2 particleSpeed = Utils.SafeNormalize(projectile.velocity, Vector2.Zero).RotatedByRandom(MathHelper.PiOver4 * 0.8f) * Main.rand.NextFloat(2.6f, 4f); Particle energyLeak = new SquishyLightParticle(target.Center, particleSpeed, Main.rand.NextFloat(0.3f, 0.6f), Color.Cyan, 60, 1, 1.5f, hueShift: 0.02f); GeneralParticleHandler.SpawnParticle(energyLeak); } diff --git a/Projectiles/Melee/TrueArkOfTheAncients_ParryHoldout.cs b/Projectiles/Melee/TrueArkOfTheAncients_ParryHoldout.cs index 9b91f1a6da..80ac0f3cf6 100644 --- a/Projectiles/Melee/TrueArkOfTheAncients_ParryHoldout.cs +++ b/Projectiles/Melee/TrueArkOfTheAncients_ParryHoldout.cs @@ -96,7 +96,7 @@ namespace CalamityMod.Projectiles.Melee projectile.timeLeft = (int)MaxTime; Main.PlaySound(SoundID.DD2_SkyDragonsFuryShot, projectile.Center); - projectile.velocity = Owner.DirectionTo(Owner.Calamity().mouseWorld); + projectile.velocity = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); projectile.velocity.Normalize(); projectile.rotation = projectile.velocity.ToRotation(); @@ -136,7 +136,7 @@ namespace CalamityMod.Projectiles.Melee //Bounce off the player if they are in the air if (Owner.velocity.Y != 0) - Owner.velocity += Vector2.Normalize(Owner.Center - proj.Center) * 2; + Owner.velocity += Utils.SafeNormalize(Owner.Center - proj.Center, Vector2.Zero) * 2; break; diff --git a/Projectiles/Melee/TrueBiomeBlade_ChainedMeatHook.cs b/Projectiles/Melee/TrueBiomeBlade_ChainedMeatHook.cs index f6d97f1081..b42962727c 100644 --- a/Projectiles/Melee/TrueBiomeBlade_ChainedMeatHook.cs +++ b/Projectiles/Melee/TrueBiomeBlade_ChainedMeatHook.cs @@ -75,7 +75,7 @@ namespace CalamityMod.Projectiles.Melee { if (projectile.timeLeft == MaxTwirlTime) { - projectile.velocity = Owner.DirectionTo(Owner.Calamity().mouseWorld); + projectile.velocity = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); Main.PlaySound(SoundID.Item71, projectile.Center); for (int i = 0; i < 4; i++) { diff --git a/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained.cs b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained.cs index 1b2ced5d6c..f0f9c8539a 100644 --- a/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained.cs +++ b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained.cs @@ -170,7 +170,7 @@ namespace CalamityMod.Projectiles.Melee return; } - projectile.velocity = Owner.DirectionTo(Owner.Calamity().mouseWorld); + projectile.velocity = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); projectile.velocity.Normalize(); projectile.rotation = projectile.velocity.ToRotation(); projectile.Center = Owner.Center + (projectile.velocity * 60); @@ -326,7 +326,7 @@ namespace CalamityMod.Projectiles.Melee Vector2 directionFromHead = direction.RotatedBy(MathHelper.ToRadians(MathHelper.Lerp(0, 160f * flip, (float)Math.Sin(randomNumber * MathHelper.Pi)))) * MathHelper.Lerp(130f, 200f, MathHelper.Clamp((float)Math.Sin(randomNumber * MathHelper.Pi) - 0.5f, 0f, 1f) * 2f); control2 = control3 + directionFromHead; - Vector2 directionFromSecondToLastPoint = Vector2.Normalize(directionFromHead.RotatedBy(MathHelper.Pi - MathHelper.ToRadians(MathHelper.Lerp(80f * flip, 110f * flip, (float)Math.Sin(randomNumber * MathHelper.Pi))))) * MathHelper.Lerp(120f, 280f, (float)Math.Sin(randomNumber * MathHelper.Pi)); + Vector2 directionFromSecondToLastPoint = Utils.SafeNormalize(directionFromHead.RotatedBy(MathHelper.Pi - MathHelper.ToRadians(MathHelper.Lerp(80f * flip, 110f * flip, (float)Math.Sin(randomNumber * MathHelper.Pi)))), Vector2.Zero) * MathHelper.Lerp(120f, 280f, (float)Math.Sin(randomNumber * MathHelper.Pi)); control1 = control2 + directionFromSecondToLastPoint; control3 += Vector2.UnitX.RotatedBy(MathHelper.TwoPi * seed1) * seed3 * 30f; diff --git a/Projectiles/Melee/TrueBiomeBlade_MercurialTides.cs b/Projectiles/Melee/TrueBiomeBlade_MercurialTides.cs index 6d639b49bd..2ce54768e8 100644 --- a/Projectiles/Melee/TrueBiomeBlade_MercurialTides.cs +++ b/Projectiles/Melee/TrueBiomeBlade_MercurialTides.cs @@ -107,7 +107,7 @@ namespace CalamityMod.Projectiles.Melee if (State == 0f) { - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.Center = Owner.Center + (direction * 70f * ChargeDisplacement()); diff --git a/Projectiles/Melee/TrueBiomeBlade_SanguineFury.cs b/Projectiles/Melee/TrueBiomeBlade_SanguineFury.cs index 5321a2e6d2..9d310bf8a2 100644 --- a/Projectiles/Melee/TrueBiomeBlade_SanguineFury.cs +++ b/Projectiles/Melee/TrueBiomeBlade_SanguineFury.cs @@ -143,7 +143,7 @@ namespace CalamityMod.Projectiles.Melee Lighting.AddLight(projectile.Center, new Vector3(1f, 0.56f, 0.56f) * ShredRatio); //Manage position and rotation - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.rotation = direction.ToRotation(); projectile.Center = Owner.Center + (direction * 60); @@ -176,7 +176,7 @@ namespace CalamityMod.Projectiles.Melee { Owner.Calamity().LungingDown = true; Owner.fallStart = (int)(Owner.position.Y / 16f); - Owner.velocity = Owner.DirectionTo(Wheel.Center) * 60f; + Owner.velocity = Owner.SafeDirectionTo(Wheel.Center, Vector2.Zero) * 60f; if (Owner.Distance(Wheel.Center) < 60f) Wheel.active = false; diff --git a/Projectiles/Melee/TrueBiomeBlade_SanguineFuryWheel.cs b/Projectiles/Melee/TrueBiomeBlade_SanguineFuryWheel.cs index ef90d89c5e..3915cde832 100644 --- a/Projectiles/Melee/TrueBiomeBlade_SanguineFuryWheel.cs +++ b/Projectiles/Melee/TrueBiomeBlade_SanguineFuryWheel.cs @@ -67,7 +67,7 @@ namespace CalamityMod.Projectiles.Melee Main.PlaySound(SoundID.Item90, projectile.Center); initialized = true; - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); projectile.rotation = direction.ToRotation(); diff --git a/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPride.cs b/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPride.cs index a0f8867dad..0bbca6f07c 100644 --- a/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPride.cs +++ b/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPride.cs @@ -87,7 +87,7 @@ namespace CalamityMod.Projectiles.Melee { Main.PlaySound(SoundID.Item90, projectile.Center); projectile.velocity = Vector2.Zero; - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); direction.Normalize(); initialized = true; } @@ -107,7 +107,7 @@ namespace CalamityMod.Projectiles.Melee { CurrentState = 1f; Main.PlaySound(SoundID.Item80, projectile.Center); - direction = Owner.DirectionTo(Owner.Calamity().mouseWorld); + direction = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero); //PARTICLES LOTS OF PARTICLES LOTS OF SPARKLES YES YES MH YES YES for (int i = 0; i <= 8; i++) { @@ -179,33 +179,33 @@ namespace CalamityMod.Projectiles.Melee if (sightLine == null) { - sightLine = new LineVFX(Owner.Center, Owner.DirectionTo(Owner.Calamity().mouseWorld), 0.2f, Color.HotPink, false); + sightLine = new LineVFX(Owner.Center, Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.One), 0.2f, Color.HotPink, false); GeneralParticleHandler.SpawnParticle(sightLine); } else { - sightLine.Position = Owner.Center + Owner.DirectionTo(Owner.Calamity().mouseWorld) * projectile.scale * 1.88f * 40; - (sightLine as LineVFX).LineVector = Owner.DirectionTo(Owner.Calamity().mouseWorld) * projectile.scale * 1.88f * 38f; + sightLine.Position = Owner.Center + Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.One) * projectile.scale * 1.88f * 40; + (sightLine as LineVFX).LineVector = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.One) * projectile.scale * 1.88f * 38f; sightLine.Scale = 0.2f; sightLine.Time = 0; sightLine.Color = currentColor * 0.7f; } float rotationAdjusted = MathHelper.WrapAngle(projectile.rotation) + MathHelper.Pi; - float mouseAngleAdjusted = MathHelper.WrapAngle(Owner.DirectionTo(Main.MouseWorld).ToRotation()) + MathHelper.Pi; + float mouseAngleAdjusted = MathHelper.WrapAngle(Owner.SafeDirectionTo(Main.MouseWorld, Vector2.One).ToRotation()) + MathHelper.Pi; float deltaAngleShoot = Math.Abs(MathHelper.WrapAngle(rotationAdjusted - mouseAngleAdjusted)); if (CanDirectFire && deltaAngleShoot < 0.1f) { - Particle Blink = new GenericSparkle(Owner.Center + Owner.DirectionTo(Main.MouseWorld) * projectile.scale * 1.88f * 78f, Owner.velocity, Color.White, currentColor, 1.5f, 10, 0.1f, 3f); + Particle Blink = new GenericSparkle(Owner.Center + Owner.SafeDirectionTo(Main.MouseWorld, Vector2.One) * projectile.scale * 1.88f * 78f, Owner.velocity, Color.White, currentColor, 1.5f, 10, 0.1f, 3f); GeneralParticleHandler.SpawnParticle(Blink); if (Owner.whoAmI == Main.myPlayer) { - Projectile.NewProjectile(Owner.Center, Owner.DirectionTo(Main.MouseWorld) * 15f, ProjectileType(), (int)(projectile.damage * OmegaBiomeBlade.WhirlwindAttunement_BeamDamageReduction), 0f, Owner.whoAmI); + Projectile.NewProjectile(Owner.Center, Owner.SafeDirectionTo(Main.MouseWorld, Vector2.One) * 15f, ProjectileType(), (int)(projectile.damage * OmegaBiomeBlade.WhirlwindAttunement_BeamDamageReduction), 0f, Owner.whoAmI); } CanDirectFire = false; - AngleReset = Owner.DirectionTo(Main.MouseWorld).ToRotation(); + AngleReset = Owner.SafeDirectionTo(Main.MouseWorld, Vector2.One).ToRotation(); } @@ -213,7 +213,7 @@ namespace CalamityMod.Projectiles.Melee { float maxDistance = projectile.scale * 1.9f * 78f; Vector2 distance = Main.rand.NextVector2Circular(maxDistance, maxDistance); - Vector2 angularVelocity = Vector2.Normalize(distance.RotatedBy(MathHelper.PiOver2)) * 2f * (1f + distance.Length() / 15f); + Vector2 angularVelocity = Utils.SafeNormalize(distance.RotatedBy(MathHelper.PiOver2), Vector2.Zero) * 2f * (1f + distance.Length() / 15f); Particle glitter = new CritSpark(Owner.Center + distance, Owner.velocity + angularVelocity, Color.White, currentColor, 1f + 1 * (distance.Length() / maxDistance), 10, 0.05f, 3f); GeneralParticleHandler.SpawnParticle(glitter); }