diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index ba0becc54f..4b5b825f67 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -5257,13 +5257,7 @@ namespace CalamityMod.CalPlayer { for (int s = 0; s < 3; s++) { - Vector2 velocity = new Vector2((float)Main.rand.Next(-50, 51), (float)Main.rand.Next(-50, 51)); - while (velocity.X == 0f && velocity.Y == 0f) - { - velocity = new Vector2((float)Main.rand.Next(-50, 51), (float)Main.rand.Next(-50, 51)); - } - velocity.Normalize(); - velocity *= (float)Main.rand.Next(30, 61) * 0.1f; + Vector2 velocity = CalamityUtils.RandomVelocity(50f, 30f, 60f); Projectile.NewProjectile(target.Center, velocity, ModContent.ProjectileType(), (int)(damage * 0.15), 0f, player.whoAmI); } } @@ -5666,13 +5660,7 @@ namespace CalamityMod.CalPlayer { for (int s = 0; s < 3; s++) { - Vector2 velocity = new Vector2((float)Main.rand.Next(-50, 51), (float)Main.rand.Next(-50, 51)); - while (velocity.X == 0f && velocity.Y == 0f) - { - velocity = new Vector2((float)Main.rand.Next(-50, 51), (float)Main.rand.Next(-50, 51)); - } - velocity.Normalize(); - velocity *= (float)Main.rand.Next(30, 61) * 0.1f; + Vector2 velocity = CalamityUtils.RandomVelocity(50f, 30f, 60f); Projectile.NewProjectile(target.Center, velocity, ModContent.ProjectileType(), (int)(damage * 0.15), 0f, player.whoAmI); } } @@ -5680,13 +5668,7 @@ namespace CalamityMod.CalPlayer { for (int s = 0; s < 3; s++) { - Vector2 velocity = new Vector2((float)Main.rand.Next(-50, 51), (float)Main.rand.Next(-50, 51)); - while (velocity.X == 0f && velocity.Y == 0f) - { - velocity = new Vector2((float)Main.rand.Next(-50, 51), (float)Main.rand.Next(-50, 51)); - } - velocity.Normalize(); - velocity *= (float)Main.rand.Next(30, 61) * 0.1f; + Vector2 velocity = CalamityUtils.RandomVelocity(50f, 30f, 60f); int spark = Projectile.NewProjectile(target.Center, velocity, ModContent.ProjectileType(), (int)(damage * 0.1), 0f, player.whoAmI); Main.projectile[spark].Calamity().forceRogue = true; Main.projectile[spark].localNPCHitCooldown = -1; @@ -5711,13 +5693,7 @@ namespace CalamityMod.CalPlayer int leafAmt = Main.rand.Next(2, 4); for (int l = 0; l < leafAmt; l++) { - Vector2 velocity = new Vector2((float)Main.rand.Next(-100, 101), (float)Main.rand.Next(-100, 101)); - while (velocity.X == 0f && velocity.Y == 0f) - { - velocity = new Vector2((float)Main.rand.Next(-100, 101), (float)Main.rand.Next(-100, 101)); - } - velocity.Normalize(); - velocity *= (float)Main.rand.Next(70, 101) * 0.1f; + Vector2 velocity = CalamityUtils.RandomVelocity(100f, 70f, 100f); int FUCKYOU = Projectile.NewProjectile(target.Center, velocity, ProjectileID.Leaf, (int)(damage * 0.25), 0f, player.whoAmI); Main.projectile[FUCKYOU].Calamity().forceTypeless = true; Main.projectile[FUCKYOU].netUpdate = true; @@ -5751,13 +5727,7 @@ namespace CalamityMod.CalPlayer bloodflareMageCooldown = 120; for (int i = 0; i < 3; i++) { - Vector2 velocity = new Vector2((float)Main.rand.Next(-100, 101), (float)Main.rand.Next(-100, 101)); - while (velocity.X == 0f && velocity.Y == 0f) - { - velocity = new Vector2((float)Main.rand.Next(-100, 101), (float)Main.rand.Next(-100, 101)); - } - velocity.Normalize(); - velocity *= (float)Main.rand.Next(70, 101) * 0.1f; + Vector2 velocity = CalamityUtils.RandomVelocity(100f, 70f, 100f); int fire = Projectile.NewProjectile(target.Center, velocity, ProjectileID.BallofFire, (int)(damage * 0.5), 0f, player.whoAmI); Main.projectile[fire].Calamity().forceTypeless = true; Main.projectile[fire].netUpdate = true; diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index 23a97c74f1..8c5d9b2fda 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -843,15 +843,9 @@ namespace CalamityMod.Projectiles { if (projectile.owner == Main.myPlayer && Main.player[projectile.owner].ownedProjectileCounts[90] < 30) { - for (int num252 = 0; num252 < 2; num252++) + for (int i = 0; i < 2; i++) { - Vector2 value15 = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101)); - while (value15.X == 0f && value15.Y == 0f) - { - value15 = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101)); - } - value15.Normalize(); - value15 *= Main.rand.Next(70, 101) * 0.1f; + Vector2 velocity = CalamityUtils.RandomVelocity(100f, 70f, 100f); int shard = Projectile.NewProjectile(projectile.oldPosition + projectile.Size * 0.5f, value15, ProjectileID.CrystalShard, (int)(projectile.damage * 0.25), 0f, projectile.owner, 0f, 0f); Main.projectile[shard].ranged = false; } @@ -1143,7 +1137,7 @@ namespace CalamityMod.Projectiles //flask of party affects all types of weapons, !projectile.melee is to prevent double flask effects if (!projectile.melee && player.meleeEnchant == 7) - Projectile.NewProjectile(target.Center.X, target.Center.Y, target.velocity.X, target.velocity.Y, ProjectileID.ConfettiMelee, 0, 0f, projectile.owner, 0f, 0f); + Projectile.NewProjectile(target.Center, target.velocity, ProjectileID.ConfettiMelee, 0, 0f, projectile.owner, 0f, 0f); if (rogue && stealthStrike && modPlayer.dragonScales && CalamityUtils.CountProjectiles(ProjectileType()) < 2) { @@ -1186,7 +1180,7 @@ namespace CalamityMod.Projectiles { if (player.ghostHurt) { - projectile.ghostHurt(damage, new Vector2(target.Center.X, target.Center.Y)); + projectile.ghostHurt(damage, target.Center); } if (player.setNebula && player.nebulaCD == 0 && Main.rand.Next(3) == 0) @@ -1198,7 +1192,7 @@ namespace CalamityMod.Projectiles ItemID.NebulaPickup2, ItemID.NebulaPickup3 }); - int nebulaBooster = Item.NewItem((int)target.position.X, (int)target.position.Y, target.width, target.height, boosterType, 1, false, 0, false, false); + int nebulaBooster = Item.NewItem(target.Center, target.Size, boosterType, 1, false, 0, false, false); Main.item[nebulaBooster].velocity.Y = Main.rand.Next(-20, 1) * 0.2f; Main.item[nebulaBooster].velocity.X = Main.rand.Next(10, 31) * 0.2f * projectile.direction; if (Main.netMode == NetmodeID.MultiplayerClient) @@ -1213,23 +1207,23 @@ namespace CalamityMod.Projectiles // Increases the degree to which Spectre Healing set contributes to the lifesteal cap if (player.ghostHeal) { - float num = 0.1f; - num -= projectile.numHits * 0.025f; - if (num < 0f) - num = 0f; + float cooldownMult = 0.1f; + cooldownMult -= projectile.numHits * 0.025f; + if (cooldownMult < 0f) + cooldownMult = 0f; - float num2 = damage * num; - Main.player[Main.myPlayer].lifeSteal -= num2; + float cooldown = damage * cooldownMult; + Main.player[Main.myPlayer].lifeSteal -= cooldown; } // Increases the degree to which Vampire Knives contribute to the lifesteal cap if (projectile.type == ProjectileID.VampireKnife) { - float num = damage * 0.075f; - if (num < 0f) - num = 0f; + float cooldown = damage * 0.075f; + if (cooldown < 0f) + cooldown = 0f; - Main.player[Main.myPlayer].lifeSteal -= num; + Main.player[Main.myPlayer].lifeSteal -= cooldown; } if (modPlayer.vampiricTalisman && rogue && crit) @@ -1391,13 +1385,13 @@ namespace CalamityMod.Projectiles (projectile.magic || rogue || projectile.melee || projectile.IsSummon() || projectile.ranged) && player.ownedProjectileCounts[ProjectileType()] < 6) { - int plague = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ProjectileType(), CalamityUtils.DamageSoftCap(projectile.damage * 0.25, 30), 0f, projectile.owner, 0f, 0f); + int plague = Projectile.NewProjectile(projectile.Center, Vector2.Zero, ProjectileType(), CalamityUtils.DamageSoftCap(projectile.damage * 0.25, 30), 0f, projectile.owner, 0f, 0f); Main.projectile[plague].Calamity().forceTypeless = true; } if (modPlayer.reaverBlast && projectile.melee) { - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ProjectileType(), CalamityUtils.DamageSoftCap(projectile.damage * 0.2, 30), 0f, projectile.owner, 0f, 0f); + Projectile.NewProjectile(projectile.Center, Vector2.Zero, ProjectileType(), CalamityUtils.DamageSoftCap(projectile.damage * 0.2, 30), 0f, projectile.owner, 0f, 0f); } if (projectile.magic) @@ -1408,18 +1402,18 @@ namespace CalamityMod.Projectiles projectile.position = projectile.Center; projectile.width = projectile.height = 96; projectile.Center = projectile.position; - for (int num193 = 0; num193 < 3; num193++) + for (int d = 0; d < 3; d++) { - Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 157, 0f, 0f, 100, new Color(Main.DiscoR, 203, 103), 1.5f); + Dust.NewDust(projectile.position, projectile.width, projectile.height, 157, 0f, 0f, 100, new Color(Main.DiscoR, 203, 103), 1.5f); } - for (int num194 = 0; num194 < 30; num194++) + for (int d = 0; d < 30; d++) { - int num195 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 157, 0f, 0f, 0, new Color(Main.DiscoR, 203, 103), 2.5f); - Main.dust[num195].noGravity = true; - Main.dust[num195].velocity *= 3f; - num195 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 157, 0f, 0f, 100, new Color(Main.DiscoR, 203, 103), 1.5f); - Main.dust[num195].velocity *= 2f; - Main.dust[num195].noGravity = true; + int explode = Dust.NewDust(projectile.position, projectile.width, projectile.height, 157, 0f, 0f, 0, new Color(Main.DiscoR, 203, 103), 2.5f); + Main.dust[explode].noGravity = true; + Main.dust[explode].velocity *= 3f; + explode = Dust.NewDust(projectile.position, projectile.width, projectile.height, 157, 0f, 0f, 100, new Color(Main.DiscoR, 203, 103), 1.5f); + Main.dust[explode].velocity *= 2f; + Main.dust[explode].noGravity = true; } projectile.damage *= modPlayer.auricSet ? 7 : 4; projectile.localNPCHitCooldown = 10; @@ -1429,17 +1423,11 @@ namespace CalamityMod.Projectiles if (modPlayer.reaverBurst) { - int num251 = Main.rand.Next(2, 5); - for (int num252 = 0; num252 < num251; num252++) + int projAmt = Main.rand.Next(2, 5); + for (int i = 0; i < projAmt; i++) { - Vector2 value15 = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101)); - while (value15.X == 0f && value15.Y == 0f) - { - value15 = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101)); - } - value15.Normalize(); - value15 *= Main.rand.Next(70, 101) * 0.1f; - int proj = Projectile.NewProjectile(projectile.oldPosition.X + (projectile.width / 2), projectile.oldPosition.Y + (projectile.height / 2), value15.X, value15.Y, 569 + Main.rand.Next(3), CalamityUtils.DamageSoftCap(projectile.damage * 0.15, 15), 0f, projectile.owner, 0f, 0f); + Vector2 velocity = CalamityUtils.RandomVelocity(100f, 70f, 100f); + int proj = Projectile.NewProjectile(projectile.Center, velocity, ProjectileID.SporeGas + Main.rand.Next(3), CalamityUtils.DamageSoftCap(projectile.damage * 0.15, 15), 0f, projectile.owner, 0f, 0f); Main.projectile[proj].usesLocalNPCImmunity = true; Main.projectile[proj].localNPCHitCooldown = 30; } @@ -1447,14 +1435,14 @@ namespace CalamityMod.Projectiles else if (modPlayer.ataxiaMage && modPlayer.ataxiaDmg <= 0) { SpawnOrb(projectile, 1.25f, ProjectileType(), 800f, 20f); - int num = (int)(projectile.damage * 0.5f); - modPlayer.ataxiaDmg += num; + int cooldown = (int)(projectile.damage * 0.5f); + modPlayer.ataxiaDmg += cooldown; } else if (modPlayer.godSlayerMage && modPlayer.godSlayerDmg <= 0) { SpawnOrb(projectile, modPlayer.auricSet ? 2f : 1.5f, ProjectileType(), 800f, 20f); - int num = (int)(projectile.damage * 0.5f); - modPlayer.godSlayerDmg += num; + int cooldown = (int)(projectile.damage * 0.5f); + modPlayer.godSlayerDmg += cooldown; } } if (projectile.melee) @@ -1473,16 +1461,16 @@ namespace CalamityMod.Projectiles case 0: SpawnOrb(projectile, 1.6f, ProjectileType(), 800f, Main.rand.Next(15, 30)); - int num = (int)(projectile.damage * 0.5f); - modPlayer.xerocDmg += num; + int cooldown = (int)(projectile.damage * 0.5f); + modPlayer.xerocDmg += cooldown; break; case 1: SpawnOrb(projectile, 1.25f, ProjectileType(), 800f, 30f); - int num2 = (int)(projectile.damage * 0.5f); - modPlayer.xerocDmg += num2; + int cooldown = (int)(projectile.damage * 0.5f); + modPlayer.xerocDmg += cooldown; if (target.canGhostHeal && Main.player[Main.myPlayer].lifeSteal > 0f) { @@ -1513,8 +1501,8 @@ namespace CalamityMod.Projectiles case 4: SpawnOrb(projectile, 1.2f, ProjectileType(), 800f, 15f); - int num3 = (int)(projectile.damage * 0.5f); - modPlayer.xerocDmg += num3; + int cooldown = (int)(projectile.damage * 0.5f); + modPlayer.xerocDmg += cooldown; break; @@ -1529,11 +1517,12 @@ namespace CalamityMod.Projectiles { for (int i = 0; i < 6; i++) { - Vector2 pos = new Vector2(target.Center.X + target.width * 0.5f + Main.rand.Next(-201, 201), Main.screenPosition.Y - 600f - Main.rand.Next(50)); - float speedX = (target.Center.X - pos.X) / 30f; - float speedY = (target.Center.Y - pos.Y) * 8; + Vector2 source = new Vector2(target.Center.X + Main.rand.Next(-201, 201), Main.screenPosition.Y - 600f - Main.rand.Next(50)); + float speedX = (target.Center.X - source.X) / 30f; + float speedY = (target.Center.Y - source.Y) * 8; + Vector2 velocity = new Vector2(speedX, speedY); int dmg = (int)(15 + (projectile.damage * 0.05f)); - int feather = Projectile.NewProjectile(pos.X, pos.Y, speedX, speedY, ProjectileType(), dmg, 3, projectile.owner, 0f, Main.rand.Next(15)); + int feather = Projectile.NewProjectile(source, velocity, ProjectileType(), dmg, 3f, projectile.owner); Main.projectile[feather].Calamity().forceRogue = true; modPlayer.featherCrownCooldown = 15; } @@ -1543,11 +1532,10 @@ namespace CalamityMod.Projectiles { for (int i = 0; i < 6; i++) { - Vector2 pos = new Vector2(target.Center.X + target.width * 0.5f + Main.rand.Next(-201, 201), Main.screenPosition.Y - 600f - Main.rand.Next(50)); - Vector2 velocity = (target.Center - pos) / 10f; - float AI1 = Main.rand.Next(3); + Vector2 source = new Vector2(target.Center.X + Main.rand.Next(-201, 201), Main.screenPosition.Y - 600f - Main.rand.Next(50)); + Vector2 velocity = (target.Center - source) / 10f; int dmg = (int)(150 + (projectile.damage * 0.05f)); - int flare = Projectile.NewProjectile(pos, velocity, ProjectileID.LunarFlare, dmg, 3, projectile.owner, 0f, AI1); + int flare = Projectile.NewProjectile(source, velocity, ProjectileID.LunarFlare, dmg, 3, projectile.owner); Main.projectile[flare].Calamity().forceRogue = true; modPlayer.moonCrownCooldown = 15; } @@ -1557,10 +1545,10 @@ namespace CalamityMod.Projectiles { for (int i = 0; i < 6; i++) { - Vector2 pos = new Vector2(target.Center.X + target.width * 0.5f + Main.rand.Next(-201, 201), Main.screenPosition.Y - 600f - Main.rand.Next(50)); - Vector2 velocity = (target.Center - pos) / 40f; + Vector2 source = new Vector2(target.Center.X + Main.rand.Next(-201, 201), Main.screenPosition.Y - 600f - Main.rand.Next(50)); + Vector2 velocity = (target.Center - source) / 40f; int dmg = (int)(1000 + (projectile.damage * 0.05f)); - int flare = Projectile.NewProjectile(pos, velocity, ProjectileType(),dmg, 3f, projectile.owner, 0f, 0f); + int flare = Projectile.NewProjectile(source, velocity, ProjectileType(),dmg, 3f, projectile.owner); Main.projectile[flare].Calamity().rogue = true; modPlayer.nanoFlareCooldown = 15; } @@ -1656,40 +1644,35 @@ namespace CalamityMod.Projectiles if (CalamityMod.boomerangProjList.Contains(projectile.type)) { int spiritDamage = CalamityUtils.DamageSoftCap(projectile.damage * 0.2, 60); - int[] numArray1 = new int[Main.maxNPCs]; - int maxValue1 = 0; - int maxValue2 = 0; + int[] array = new int[Main.maxNPCs]; + int targetArrayA = 0; + int targetArrayB = 0; for (int index = 0; index < Main.maxNPCs; ++index) { - if (Main.npc[index].CanBeChasedBy((object)projectile, false)) + NPC npc = Main.npc[index]; + if (npc.CanBeChasedBy(projectile, false)) { - float num2 = Math.Abs(Main.npc[index].Center.X - projectile.Center.X) + Math.Abs(Main.npc[index].Center.Y - projectile.Center.Y); - if (num2 < 800f) + float npcDist = Vector2.Distance(projectile.Center, npc.Center); + if (npcDist < 800f) { - if (Collision.CanHit(projectile.position, 1, 1, Main.npc[index].position, Main.npc[index].width, Main.npc[index].height) && num2 > 50f) + if (Collision.CanHit(projectile.position, 1, 1, npc.position, npc.width, npc.height) && npcDist > 50f) { - numArray1[maxValue2] = index; - ++maxValue2; + array[targetArrayB] = index; + ++targetArrayB; } - else if (maxValue2 == 0) + else if (targetArrayB == 0) { - numArray1[maxValue1] = index; - ++maxValue1; + array[targetArrayA] = index; + ++targetArrayA; } } } } - if (maxValue1 == 0 && maxValue2 == 0) + if (targetArrayA == 0 && targetArrayB == 0) return; - int num3 = maxValue2 <= 0 ? numArray1[Main.rand.Next(maxValue1)] : numArray1[Main.rand.Next(maxValue2)]; - double num4 = 4.0; - float num5 = (float)Main.rand.Next(-100, 101); - float num6 = (float)Main.rand.Next(-100, 101); - double num7 = Math.Sqrt((double)num5 * (double)num5 + (double)num6 * (double)num6); - float num8 = (float)(num4 / num7); - float SpeedX = num5 * num8; - float SpeedY = num6 * num8; - int ghost = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, SpeedX, SpeedY, ProjectileID.SpectreWrath, spiritDamage, 0f, projectile.owner, (float)num3, 0f); + int target = targetArrayB <= 0 ? array[Main.rand.Next(targetArrayA)] : array[Main.rand.Next(targetArrayB)]; + Vector2 velocity = CalamityUtils.RandomVelocity(100f, 4f, 4f, 1f); + int ghost = Projectile.NewProjectile(projectile.Center, velocity, ProjectileID.SpectreWrath, spiritDamage, 0f, projectile.owner, target, 0f); Main.projectile[ghost].Calamity().forceRogue = true; Main.projectile[ghost].penetrate = 1; modPlayer.shadowPotCooldown = 30; @@ -1746,8 +1729,8 @@ namespace CalamityMod.Projectiles if (modPlayer.godSlayerSummon && modPlayer.godSlayerDmg <= 0) { SpawnOrb(projectile, 2f, ProjectileType(), 800f, 15f, true); - int num = (int)(projectile.damage * 0.5f); - modPlayer.godSlayerDmg += num; + int cooldown = (int)(projectile.damage * 0.5f); + modPlayer.godSlayerDmg += cooldown; } //Priorities: Nucleogenesis => Starbuster Core => Nuclear Rod => Jelly-Charged Battery @@ -1794,8 +1777,8 @@ namespace CalamityMod.Projectiles else if (modPlayer.jellyChargedBattery) { SpawnOrb(projectile, 1.05f, ProjectileType(), 800f, 15f); - int num = (int)(projectile.damage * 0.5f); - modPlayer.jellyDmg += num; + int cooldown = (int)(projectile.damage * 0.5f); + modPlayer.jellyDmg += cooldown; } } @@ -1817,17 +1800,11 @@ namespace CalamityMod.Projectiles { if (modPlayer.tarraRanged && Main.rand.Next(0, 100) >= 88 && player.ownedProjectileCounts[ProjectileType()] <= 20 && (projectile.timeLeft <= 2 || projectile.penetrate <= 1)) { - int num251 = Main.rand.Next(2, 4); - for (int num252 = 0; num252 < num251; num252++) + int projAmt = Main.rand.Next(2, 4); + for (int projCount = 0; projCount < projAmt; projCount++) { - Vector2 value15 = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101)); - while (value15.X == 0f && value15.Y == 0f) - { - value15 = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101)); - } - value15.Normalize(); - value15 *= Main.rand.Next(70, 101) * 0.1f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, value15.X, value15.Y, ProjectileType(), CalamityUtils.DamageSoftCap(projectile.damage * 0.33, 65), 0f, projectile.owner, 0f, 0f); + Vector2 velocity = CalamityUtils.RandomVelocity(100f, 70f, 100f); + Projectile.NewProjectile(projectile.Center, velocity, ProjectileType(), CalamityUtils.DamageSoftCap(projectile.damage * 0.33, 65), 0f, projectile.owner, 0f, 0f); } } } @@ -1988,11 +1965,11 @@ namespace CalamityMod.Projectiles { if (modPlayer.providenceLore && projectile.friendly && projectile.damage > 0 && (projectile.melee || projectile.ranged || projectile.magic || rogue)) { - Main.PlaySound(SoundID.Item20, (int)projectile.position.X, (int)projectile.position.Y); + Main.PlaySound(SoundID.Item20, projectile.Center); for (int dustIndex = 0; dustIndex < 3; dustIndex++) { - int dust = Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, (int)CalamityDusts.ProfanedFire, projectile.oldVelocity.X * 0.5f, projectile.oldVelocity.Y * 0.5f, 0, default, 1f); - Main.dust[dust].noGravity = true; + int fire = Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, (int)CalamityDusts.ProfanedFire, projectile.oldVelocity.X * 0.5f, projectile.oldVelocity.Y * 0.5f, 0, default, 1f); + Main.dust[fire].noGravity = true; } } @@ -2000,16 +1977,10 @@ namespace CalamityMod.Projectiles { if (modPlayer.etherealExtorter && Main.rand.Next(0, 100) >= 95) { - for (int num252 = 0; num252 < 3; num252++) + for (int i = 0; i < 3; i++) { - Vector2 value15 = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101)); - while (value15.X == 0f && value15.Y == 0f) - { - value15 = new Vector2(Main.rand.Next(-100, 101), Main.rand.Next(-100, 101)); - } - value15.Normalize(); - value15 *= Main.rand.Next(70, 101) * 0.1f; - int soul = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, value15.X, value15.Y, ModContent.ProjectileType(), (int)(projectile.damage * 0.33), 0f, projectile.owner, 0f, 0f); + Vector2 velocity = CalamityUtils.RandomVelocity(100f, 70f, 100f); + int soul = Projectile.NewProjectile(projectile.Center, velocity, ModContent.ProjectileType(), (int)(projectile.damage * 0.33), 0f, projectile.owner, 0f, 0f); Main.projectile[soul].tileCollide = false; } } @@ -2065,76 +2036,72 @@ namespace CalamityMod.Projectiles if (Main.player[Main.myPlayer].moonLeech) return; Main.player[Main.myPlayer].lifeSteal -= healAmount * cooldownMultiplier; - float num13 = 0f; - int num14 = projectile.owner; + float lowestHealthCheck = 0f; + int healTarget = projectile.owner; for (int i = 0; i < Main.maxPlayers; i++) { - if (Main.player[i].active && !Main.player[i].dead && ((!player.hostile && !Main.player[i].hostile) || player.team == Main.player[i].team)) + Player otherPlayer = Main.player[i]; + if (otherPlayer.active && !otherPlayer.dead && ((!player.hostile && !otherPlayer.hostile) || player.team == otherPlayer.team)) { - float num15 = Math.Abs(Main.player[i].position.X + (Main.player[i].width / 2) - projectile.position.X + (projectile.width / 2)) + Math.Abs(Main.player[i].position.Y + (Main.player[i].height / 2) - projectile.position.Y + (projectile.height / 2)); - if (num15 < distanceRequired && (Main.player[i].statLifeMax2 - Main.player[i].statLife) > num13) + float playerDist = Vector2.Distance(projectile.Center, otherPlayer.Center); + if (playerDist < distanceRequired && (otherPlayer.statLifeMax2 - otherPlayer.statLife) > lowestHealthCheck) { - num13 = Main.player[i].statLifeMax2 - Main.player[i].statLife; - num14 = i; + lowestHealthCheck = otherPlayer.statLifeMax2 - otherPlayer.statLife; + healTarget = i; } } } - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, healProjectileType, 0, 0f, projectile.owner, num14, healAmount); + Projectile.NewProjectile(projectile.Center, Vector2.Zero, healProjectileType, 0, 0f, projectile.owner, healTarget, healAmount); } #endregion #region AI Shortcuts - public void SpawnOrb(Projectile projectile, float dmgMult, int projType, float distanceRequired, float N, bool gsPhantom = false) + public void SpawnOrb(Projectile projectile, float dmgMult, int projType, float distanceRequired, float speedMult, bool gsPhantom = false) { Player player = Main.player[projectile.owner]; CalamityPlayer modPlayer = player.Calamity(); - int num = (int)(projectile.damage * 0.5f); + int damage = (int)(projectile.damage * 0.5f); float ai1 = Main.rand.NextFloat() + 0.5f; int[] array = new int[Main.maxNPCs]; - int num3 = 0; - int num4 = 0; + int targetArrayIndexA = 0; + int targetArrayIndexB = 0; for (int i = 0; i < Main.maxNPCs; i++) { - if (Main.npc[i].CanBeChasedBy(projectile, false)) + NPC npc = Main.npc[i]; + if (npc.CanBeChasedBy(projectile, false)) { - float num5 = Math.Abs(Main.npc[i].position.X + (Main.npc[i].width / 2) - projectile.position.X + (projectile.width / 2)) + Math.Abs(Main.npc[i].position.Y + (Main.npc[i].height / 2) - projectile.position.Y + (projectile.height / 2)); - if (num5 < distanceRequired) + float enemyDist = Vector2.Distance(projectile.Center, npc.Center); + if (enemyDist < distanceRequired) { - if (Collision.CanHit(projectile.position, 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height) && num5 > 50f) + if (Collision.CanHit(projectile.position, 1, 1, npc.position, npc.width, npc.height) && enemyDist > 50f) { - array[num4] = i; - num4++; + array[targetArrayIndexB] = i; + targetArrayIndexB++; } - else if (num4 == 0) + else if (targetArrayIndexB == 0) { - array[num3] = i; - num3++; + array[targetArrayIndexA] = i; + targetArrayIndexA++; } } } } - if (num3 == 0 && num4 == 0) + if (targetArrayIndexA == 0 && targetArrayIndexB == 0) { return; } - int num6; - if (num4 > 0) + int ai0; + if (targetArrayIndexB > 0) { - num6 = array[Main.rand.Next(num4)]; + ai0 = array[Main.rand.Next(targetArrayIndexB)]; } else { - num6 = array[Main.rand.Next(num3)]; + ai0 = array[Main.rand.Next(targetArrayIndexA)]; } - float num7 = N; - float num8 = Main.rand.Next(-100, 101); - float num9 = Main.rand.Next(-100, 101); - float num10 = (float)Math.Sqrt(num8 * num8 + num9 * num9); - num10 = num7 / num10; - num8 *= num10; - num9 *= num10; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, num8, num9, projType, (int)(num * dmgMult), 0f, projectile.owner, gsPhantom ? 0f : num6, gsPhantom ? ai1 : 0f); + Vector2 velocity = CalamityUtils.RandomVelocity(100f, speedMult, speedMult, 1f); + Projectile.NewProjectile(projectile.Center, velocity, projType, (int)(damage * dmgMult), 0f, projectile.owner, gsPhantom ? 0f : ai0, gsPhantom ? ai1 : 0f); } public static void HomeInOnNPC(Projectile projectile, bool ignoreTiles, float distanceRequired, float homingVelocity, float N) diff --git a/Projectiles/Rogue/FantasyTalismanProj.cs b/Projectiles/Rogue/FantasyTalismanProj.cs index 568106cfd1..bd95a40f0f 100644 --- a/Projectiles/Rogue/FantasyTalismanProj.cs +++ b/Projectiles/Rogue/FantasyTalismanProj.cs @@ -35,11 +35,11 @@ namespace CalamityMod.Projectiles.Rogue { projectile.spriteDirection = projectile.direction = (projectile.velocity.X > 0).ToDirectionInt(); projectile.rotation = projectile.velocity.ToRotation() + (projectile.spriteDirection == 1 ? 0f : MathHelper.Pi); - if (Main.rand.Next(3) == 0) + if (Main.rand.NextBool(3)) { Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 175, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); } - projectile.StickyProjAI(15); + projectile.StickyProjAI(4); if (projectile.ai[0] == 1f) { if (projectile.timeLeft % 10 == 0) @@ -47,40 +47,35 @@ namespace CalamityMod.Projectiles.Rogue if (Main.rand.NextBool(2)) { int spiritDamage = projectile.damage / 2; - int[] numArray1 = new int[Main.maxNPCs]; - int maxValue1 = 0; - int maxValue2 = 0; + int[] array = new int[Main.maxNPCs]; + int targetArrayA = 0; + int targetArrayB = 0; for (int index = 0; index < Main.maxNPCs; ++index) { - if (Main.npc[index].CanBeChasedBy((object) projectile, false)) + NPC npc = Main.npc[index]; + if (npc.CanBeChasedBy(projectile, false)) { - float num2 = Math.Abs(Main.npc[index].Center.X - projectile.Center.X) + Math.Abs(Main.npc[index].Center.Y - projectile.Center.Y); - if (num2 < 800f) + float npcDist = Vector2.Distance(projectile.Center, npc.Center); + if (npcDist < 800f) { - if (Collision.CanHit(projectile.position, 1, 1, Main.npc[index].position, Main.npc[index].width, Main.npc[index].height) && num2 > 50f) + if (Collision.CanHit(projectile.position, 1, 1, npc.position, npc.width, npc.height) && npcDist > 50f) { - numArray1[maxValue2] = index; - ++maxValue2; + array[targetArrayB] = index; + ++targetArrayB; } - else if (maxValue2 == 0) + else if (targetArrayB == 0) { - numArray1[maxValue1] = index; - ++maxValue1; + array[targetArrayA] = index; + ++targetArrayA; } } } } - if (maxValue1 == 0 && maxValue2 == 0) + if (targetArrayA == 0 && targetArrayB == 0) return; - int num3 = maxValue2 <= 0 ? numArray1[Main.rand.Next(maxValue1)] : numArray1[Main.rand.Next(maxValue2)]; - double num4 = 4.0; - float num5 = (float) Main.rand.Next(-100, 101); - float num6 = (float) Main.rand.Next(-100, 101); - double num7 = Math.Sqrt((double) num5 * (double) num5 + (double) num6 * (double) num6); - float num8 = (float) (num4 / num7); - float SpeedX = num5 * num8; - float SpeedY = num6 * num8; - int ghost = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, SpeedX, SpeedY, ProjectileID.SpectreWrath, spiritDamage, 0.0f, projectile.owner, (float)num3, 0f); + int target = targetArrayB <= 0 ? array[Main.rand.Next(targetArrayA)] : array[Main.rand.Next(targetArrayB)]; + Vector2 velocity = CalamityUtils.RandomVelocity(100f, 4f, 4f, 1f); + int ghost = Projectile.NewProjectile(projectile.Center, velocity, ProjectileID.SpectreWrath, spiritDamage, 0f, projectile.owner, target, 0f); Main.projectile[ghost].Calamity().forceRogue = true; Main.projectile[ghost].penetrate = 1; } @@ -107,13 +102,5 @@ namespace CalamityMod.Projectiles.Rogue } return null; } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - if (projectile.timeLeft > 240) - { - projectile.timeLeft = 240; - } - } } } diff --git a/Projectiles/Rogue/FantasyTalismanStealth.cs b/Projectiles/Rogue/FantasyTalismanStealth.cs index fb1ddd368f..bdf4928009 100644 --- a/Projectiles/Rogue/FantasyTalismanStealth.cs +++ b/Projectiles/Rogue/FantasyTalismanStealth.cs @@ -35,7 +35,7 @@ namespace CalamityMod.Projectiles.Rogue { projectile.spriteDirection = projectile.direction = (projectile.velocity.X > 0).ToDirectionInt(); projectile.rotation = projectile.velocity.ToRotation() + (projectile.spriteDirection == 1 ? 0f : MathHelper.Pi); - if (Main.rand.Next(3) == 0) + if (Main.rand.NextBool(3)) { Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 175, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); } @@ -45,11 +45,11 @@ namespace CalamityMod.Projectiles.Rogue { if (projectile.owner == Main.myPlayer) { - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); + Projectile.NewProjectile(projectile.Center, Vector2.Zero, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); } } } - projectile.StickyProjAI(15); + projectile.StickyProjAI(4); if (projectile.ai[0] == 1f) { if (projectile.timeLeft % 4 == 0) @@ -57,40 +57,35 @@ namespace CalamityMod.Projectiles.Rogue if (Main.rand.NextBool(2)) { int spiritDamage = projectile.damage / 2; - int[] numArray1 = new int[Main.maxNPCs]; - int maxValue1 = 0; - int maxValue2 = 0; + int[] array = new int[Main.maxNPCs]; + int targetArrayA = 0; + int targetArrayB = 0; for (int index = 0; index < Main.maxNPCs; ++index) { - if (Main.npc[index].CanBeChasedBy((object) projectile, false)) + NPC npc = Main.npc[index]; + if (npc.CanBeChasedBy(projectile, false)) { - float num2 = Math.Abs(Main.npc[index].Center.X - projectile.Center.X) + Math.Abs(Main.npc[index].Center.Y - projectile.Center.Y); - if (num2 < 800f) + float npcDist = Vector2.Distance(projectile.Center, npc.Center); + if (npcDist < 800f) { - if (Collision.CanHit(projectile.position, 1, 1, Main.npc[index].position, Main.npc[index].width, Main.npc[index].height) && num2 > 50f) + if (Collision.CanHit(projectile.position, 1, 1, npc.position, npc.width, npc.height) && npcDist > 50f) { - numArray1[maxValue2] = index; - ++maxValue2; + array[targetArrayB] = index; + ++targetArrayB; } - else if (maxValue2 == 0) + else if (targetArrayB == 0) { - numArray1[maxValue1] = index; - ++maxValue1; + array[targetArrayA] = index; + ++targetArrayA; } } } } - if (maxValue1 == 0 && maxValue2 == 0) + if (targetArrayA == 0 && targetArrayB == 0) return; - int num3 = maxValue2 <= 0 ? numArray1[Main.rand.Next(maxValue1)] : numArray1[Main.rand.Next(maxValue2)]; - double num4 = 4.0; - float num5 = (float) Main.rand.Next(-100, 101); - float num6 = (float) Main.rand.Next(-100, 101); - double num7 = Math.Sqrt((double) num5 * (double) num5 + (double) num6 * (double) num6); - float num8 = (float) (num4 / num7); - float SpeedX = num5 * num8; - float SpeedY = num6 * num8; - int ghost = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, SpeedX, SpeedY, ProjectileID.SpectreWrath, spiritDamage, 0.0f, projectile.owner, (float)num3, 0f); + int target = targetArrayB <= 0 ? array[Main.rand.Next(targetArrayA)] : array[Main.rand.Next(targetArrayB)]; + Vector2 velocity = CalamityUtils.RandomVelocity(100f, 4f, 4f, 1f); + int ghost = Projectile.NewProjectile(projectile.Center, velocity, ProjectileID.SpectreWrath, spiritDamage, 0f, projectile.owner, target, 0f); Main.projectile[ghost].Calamity().forceRogue = true; Main.projectile[ghost].penetrate = 1; } @@ -117,13 +112,5 @@ namespace CalamityMod.Projectiles.Rogue } return null; } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - if (projectile.timeLeft > 240) - { - projectile.timeLeft = 240; - } - } } } diff --git a/Projectiles/Summon/LuxorsGiftSummon.cs b/Projectiles/Summon/LuxorsGiftSummon.cs index 29066770e9..4345c84869 100644 --- a/Projectiles/Summon/LuxorsGiftSummon.cs +++ b/Projectiles/Summon/LuxorsGiftSummon.cs @@ -96,7 +96,7 @@ namespace CalamityMod.Projectiles.Summon projectile.ChargingMinionAI(700f, 1000f, 2200f, 150f, 0, 40f, 9f, -4f, 40f, 9f, true, true); - projectile.rotation = projectile.velocity.ToRotation() + 1.57f; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; } public override Color? GetAlpha(Color lightColor) diff --git a/Utilities/CalamityUtils.cs b/Utilities/CalamityUtils.cs index 83159a845c..904aa22370 100644 --- a/Utilities/CalamityUtils.cs +++ b/Utilities/CalamityUtils.cs @@ -1001,6 +1001,19 @@ namespace CalamityMod return newDamage; } + public static Vector2 RandomVelocity(float directionMult, float speedLowerLimit, float speedCap, float speedMult = 0.1f) + { + Vector2 velocity = new Vector2(Main.rand.NextFloat(-directionMult, directionMult), Main.rand.NextFloat(-directionMult, directionMult)); + //Rerolling to avoid dividing by zero + while (velocity.X == 0f && velocity.Y == 0f) + { + velocity = new Vector2(Main.rand.NextFloat(-directionMult, directionMult), Main.rand.NextFloat(-directionMult, directionMult)); + } + velocity.Normalize(); + velocity *= Main.rand.NextFloat(speedLowerLimit, speedCap) * speedMult; + return velocity; + } + public static void MinionAntiClump(this Projectile projectile, float pushForce = 0.05f) { for (int k = 0; k < Main.maxProjectiles; k++)