diff --git a/Items/Weapons/Rogue/EclipsesFall.cs b/Items/Weapons/Rogue/EclipsesFall.cs index 50ab8f9f39..38c1d153a7 100644 --- a/Items/Weapons/Rogue/EclipsesFall.cs +++ b/Items/Weapons/Rogue/EclipsesFall.cs @@ -1,5 +1,6 @@ using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Rogue; +using CalamityMod.Tiles.Furniture.CraftingStations; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; @@ -19,46 +20,42 @@ namespace CalamityMod.Items.Weapons.Rogue public override void SafeSetDefaults() { - item.width = 72; item.damage = 1060; + item.knockBack = 3.5f; + item.useAnimation = item.useTime = 21; + item.autoReuse = true; + item.Calamity().rogue = true; + item.shootSpeed = 15f; + item.shoot = ModContent.ProjectileType(); + + item.useStyle = ItemUseStyleID.SwingThrow; + item.width = item.height = 72; item.noMelee = true; item.noUseGraphic = true; - item.useAnimation = 21; - item.useStyle = ItemUseStyleID.SwingThrow; - item.useTime = 21; - item.knockBack = 3.5f; item.UseSound = SoundID.Item1; - item.autoReuse = true; - item.height = 72; item.value = Item.buyPrice(2, 50, 0, 0); item.rare = 10; item.Calamity().customRarity = CalamityRarity.Violet; - item.shoot = ModContent.ProjectileType(); - item.shootSpeed = 15f; - item.Calamity().rogue = true; } - public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) - { - if (player.Calamity().StealthStrikeAvailable()) - { - int p = Projectile.NewProjectile(position.X, position.Y, speedX, speedY, ModContent.ProjectileType(), damage, knockBack, player.whoAmI, 0f, 0f); - Main.projectile[p].Calamity().stealthStrike = true; - } - else - { - Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI, 0f, 0f); - } - return false; - } + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (player.Calamity().StealthStrikeAvailable()) + { + type = ModContent.ProjectileType(); + } + int proj = Projectile.NewProjectile(position, new Vector2(speedX, speedY), type, damage, knockBack, player.whoAmI); + Main.projectile[proj].Calamity().stealthStrike = player.Calamity().StealthStrikeAvailable(); + return false; + } public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); - recipe.AddIngredient(ModContent.ItemType(), 1); + recipe.AddIngredient(ModContent.ItemType()); recipe.AddIngredient(ModContent.ItemType(), 15); recipe.AddIngredient(ModContent.ItemType(), 6); - recipe.AddTile(TileID.LunarCraftingStation); + recipe.AddTile(ModContent.TileType()); recipe.SetResult(this); recipe.AddRecipe(); } diff --git a/Items/Weapons/Summon/BensUmbrella.cs b/Items/Weapons/Summon/BensUmbrella.cs index d53d17fc6e..deb68215dc 100644 --- a/Items/Weapons/Summon/BensUmbrella.cs +++ b/Items/Weapons/Summon/BensUmbrella.cs @@ -22,39 +22,38 @@ namespace CalamityMod.Items.Weapons.Summon public override void SetDefaults() { - item.mana = 99; item.damage = 963; + item.knockBack = 1f; + item.mana = 99; + item.useTime = item.useAnimation = 10; + item.summon = true; + item.shootSpeed = 0f; + item.shoot = ModContent.ProjectileType(); + item.useStyle = ItemUseStyleID.SwingThrow; item.width = 74; item.height = 72; - item.useTime = item.useAnimation = 10; item.noMelee = true; - item.knockBack = 1f; - item.value = Item.buyPrice(5, 0, 0, 0); - item.Calamity().customRarity = CalamityRarity.ItemSpecific; - item.rare = 10; item.UseSound = SoundID.Item68; - item.shoot = ModContent.ProjectileType(); - item.shootSpeed = 10f; - item.summon = true; + item.value = Item.buyPrice(5, 0, 0, 0); + item.rare = 10; + item.Calamity().customRarity = CalamityRarity.ItemSpecific; } public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0 && player.maxMinions >= 5; public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - position = Main.MouseWorld; - speedX = 0; - speedY = 0; - for (int x = 0; x < Main.projectile.Length; x++) + for (int x = 0; x < Main.maxProjectiles; x++) { Projectile projectile = Main.projectile[x]; if (projectile.active && projectile.owner == player.whoAmI && projectile.type == type) { projectile.Kill(); + break; } } - Projectile.NewProjectile(position.X, position.Y, speedX, speedY, type, damage, knockBack, player.whoAmI); + Projectile.NewProjectile(player.Center, Vector2.Zero, type, damage, knockBack, player.whoAmI); return false; } diff --git a/Projectiles/Rogue/EclipsesFallMain.cs b/Projectiles/Rogue/EclipsesFallMain.cs index 5969e11d6e..afa7481f67 100644 --- a/Projectiles/Rogue/EclipsesFallMain.cs +++ b/Projectiles/Rogue/EclipsesFallMain.cs @@ -33,50 +33,40 @@ namespace CalamityMod.Projectiles.Rogue public override void AI() { - if (Main.rand.Next(8) == 0) + if (Main.rand.NextBool(8)) { Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 138, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); } - projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 0.785f; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver4; } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { - for (int n = 0; n < Main.rand.Next(3, 6); n++) //3 to 5 spears - { - float x = target.position.X + (float)Main.rand.Next(-400, 400); - float y = target.position.Y - (float)Main.rand.Next(500, 800); - Vector2 vector = new Vector2(x, y); - float num13 = target.position.X + (float)(target.width / 2) - vector.X; - float num14 = target.position.Y + (float)(target.height / 2) - vector.Y; - num13 += (float)Main.rand.Next(-100, 101); - int num15 = 29; - float num16 = (float)Math.Sqrt((double)(num13 * num13 + num14 * num14)); - num16 = (float)num15 / num16; - num13 *= num16; - num14 *= num16; - Projectile.NewProjectile(x, y, num13, num14, ModContent.ProjectileType(), (int)(projectile.damage * 0.08f * Main.rand.NextFloat(4f, 7f)), (int)(projectile.knockBack * 0.1f * Main.rand.NextFloat(7f, 10f)), projectile.owner, 0f, 0f); - } + SpawnSpears(target.Center); } public override void OnHitPvp(Player target, int damage, bool crit) { + SpawnSpears(target.Center); + } + + private void SpawnSpears(Vector2 targetPos) + { for (int n = 0; n < Main.rand.Next(3, 6); n++) //3 to 5 spears { - float x = target.position.X + (float)Main.rand.Next(-400, 400); - float y = target.position.Y - (float)Main.rand.Next(500, 800); - Vector2 vector = new Vector2(x, y); - float num13 = target.position.X + (float)(target.width / 2) - vector.X; - float num14 = target.position.Y + (float)(target.height / 2) - vector.Y; - num13 += (float)Main.rand.Next(-100, 101); - int num15 = 29; - float num16 = (float)Math.Sqrt((double)(num13 * num13 + num14 * num14)); - num16 = (float)num15 / num16; - num13 *= num16; - num14 *= num16; - Projectile.NewProjectile(x, y, num13, num14, ModContent.ProjectileType(), (int)(projectile.damage * 0.08f * Main.rand.NextFloat(4f, 7f)), (int)(projectile.knockBack * 0.1f * Main.rand.NextFloat(7f, 10f)), projectile.owner, 0f, 0f); + float x = targetPos.X + Main.rand.Next(-400, 401); + float y = targetPos.Y - Main.rand.Next(500, 801); + Vector2 source = new Vector2(x, y); + Vector2 velocity = targetPos - source; + velocity.X += Main.rand.Next(-100, 101); + float speed = 29f; + float targetDist = velocity.Length(); + targetDist = speed / targetDist; + velocity.X *= targetDist; + velocity.Y *= targetDist; + Projectile.NewProjectile(source, velocity, ModContent.ProjectileType(), (int)(projectile.damage * 0.08f * Main.rand.NextFloat(4f, 7f)), (int)(projectile.knockBack * 0.1f * Main.rand.NextFloat(7f, 10f)), projectile.owner, 0f, 0f); } - } + } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { diff --git a/Projectiles/Rogue/EclipsesSmol.cs b/Projectiles/Rogue/EclipsesSmol.cs index fa9ad85291..0da5447707 100644 --- a/Projectiles/Rogue/EclipsesSmol.cs +++ b/Projectiles/Rogue/EclipsesSmol.cs @@ -18,7 +18,6 @@ namespace CalamityMod.Projectiles.Rogue projectile.width = 20; projectile.height = 20; projectile.friendly = true; - projectile.penetrate = 1; projectile.tileCollide = false; projectile.ignoreWater = true; projectile.timeLeft = 150; @@ -28,36 +27,30 @@ namespace CalamityMod.Projectiles.Rogue public override void AI() { - projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 0.785f; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver4; CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 400f, 24f, 20f); } public override void Kill(int timeLeft) { - Main.PlaySound(SoundID.Item14, (int)projectile.position.X, (int)projectile.position.Y); - for (int num621 = 0; num621 < 20; num621++) + Main.PlaySound(SoundID.Item14, projectile.Center); + for (int i = 0; i < 2; i++) { - if (Main.rand.NextBool(10)) - { - int num622 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 138, 0f, 0f, 100, default, 1.2f); - Main.dust[num622].velocity *= 3f; - if (Main.rand.NextBool(2)) - { - Main.dust[num622].scale = 0.5f; - Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; - } - } + int dustInt = Dust.NewDust(projectile.position, projectile.width, projectile.height, 138, 0f, 0f, 100, default, 1.2f); + Main.dust[dustInt].velocity *= 3f; + if (Main.rand.NextBool(2)) + { + Main.dust[dustInt].scale = 0.5f; + Main.dust[dustInt].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; + } } - for (int num623 = 0; num623 < 35; num623++) + for (int j = 0; j < 3; j++) { - if (Main.rand.NextBool(10)) - { - int num624 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 138, 0f, 0f, 100, default, 1.7f); - Main.dust[num624].noGravity = true; - Main.dust[num624].velocity *= 5f; - num624 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 138, 0f, 0f, 100, default, 1f); - Main.dust[num624].velocity *= 2f; - } + int moreDust = Dust.NewDust(projectile.position, projectile.width, projectile.height, 138, 0f, 0f, 100, default, 1.7f); + Main.dust[moreDust].noGravity = true; + Main.dust[moreDust].velocity *= 5f; + moreDust = Dust.NewDust(projectile.position, projectile.width, projectile.height, 138, 0f, 0f, 100, default, 1f); + Main.dust[moreDust].velocity *= 2f; } } diff --git a/Projectiles/Rogue/EclipsesStealth.cs b/Projectiles/Rogue/EclipsesStealth.cs index 748254fc39..f08ba0a765 100644 --- a/Projectiles/Rogue/EclipsesStealth.cs +++ b/Projectiles/Rogue/EclipsesStealth.cs @@ -56,19 +56,24 @@ namespace CalamityMod.Projectiles.Rogue } } } + + //Behavior when not sticking to anything if (projectile.ai[0] == 0f) { - projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 0.785f; + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver4; if (Main.rand.NextBool(8)) //dust { Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 138, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); } } + + //Ensures that a spear will last 15 seconds after it hits something if (projectile.ai[0] == 1f && !changedTimeLeft) { projectile.timeLeft = 900; changedTimeLeft = true; } + //Sticky Behaviour projectile.StickyProjAI(15); } diff --git a/Projectiles/Summon/CloudElementalMinion.cs b/Projectiles/Summon/CloudElementalMinion.cs index 757990b8bf..28ae075ac1 100644 --- a/Projectiles/Summon/CloudElementalMinion.cs +++ b/Projectiles/Summon/CloudElementalMinion.cs @@ -101,7 +101,7 @@ namespace CalamityMod.Projectiles.Summon projectile.frame = 0; } - projectile.ChargingMinionAI(500f, 800f, 1200f, 400f, 0, 30f, 8f, -4f, 40f, 8f, false, true); + projectile.ChargingMinionAI(500f, 800f, 1200f, 400f, 0, 30f, 8f, -4f, 40f, 8f, false, true, 1); } } } diff --git a/Projectiles/Summon/MagicAxe.cs b/Projectiles/Summon/MagicAxe.cs index 61e111e760..1b0a2be506 100644 --- a/Projectiles/Summon/MagicAxe.cs +++ b/Projectiles/Summon/MagicAxe.cs @@ -41,176 +41,22 @@ namespace CalamityMod.Projectiles.Summon public override void AI() { - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - projectile.rotation += 0.075f; projectile.alpha -= 50; - float num634 = 1200f; - float num635 = 2500f; - projectile.MinionAntiClump(); - if (projectile.ai[1] <= 30) + counter++; + if (counter == 30) + { + projectile.netUpdate = true; + } + else if (counter < 30) { - projectile.ai[1]++; return; } - bool flag24 = false; - if (projectile.ai[0] == 2f) - { - counter += 1; - projectile.extraUpdates = 4; - if (counter > 30) - { - counter = 1; - projectile.ai[0] = 0f; - projectile.extraUpdates = 1; - projectile.numUpdates = 0; - projectile.netUpdate = true; - } - else - { - flag24 = true; - } - } - if (flag24) - { - return; - } - Vector2 vector46 = projectile.position; - float homingRange = MagicHat.Range; - bool homeIn = false; - if (player.HasMinionAttackTargetNPC) - { - NPC npc = Main.npc[player.MinionAttackTargetNPC]; - if (npc.CanBeChasedBy(projectile, false)) - { - float num646 = Vector2.Distance(npc.Center, projectile.Center); - if (!homeIn && num646 < homingRange) - { - homingRange = num646; - vector46 = npc.Center; - homeIn = true; - } - } - } - if (!homeIn) - { - for (int num645 = 0; num645 < Main.npc.Length; num645++) - { - NPC nPC2 = Main.npc[num645]; - if (nPC2.CanBeChasedBy(projectile, false)) - { - float num646 = Vector2.Distance(nPC2.Center, projectile.Center); - if (!homeIn && num646 < homingRange) - { - homingRange = num646; - vector46 = nPC2.Center; - homeIn = true; - } - } - } - } - float num647 = num634; - if (homeIn) - { - num647 = num635; - } - if (Vector2.Distance(player.Center, projectile.Center) > num647) - { - projectile.ai[0] = 1f; - projectile.netUpdate = true; - } - if (homeIn && projectile.ai[0] == 0f) - { - Vector2 vector47 = vector46 - projectile.Center; - float num648 = vector47.Length(); - vector47.Normalize(); - if (num648 > 200f) - { - float scaleFactor2 = 24f; //8 - vector47 *= scaleFactor2; - projectile.velocity = (projectile.velocity * 40f + vector47) / 41f; - } - else - { - float num649 = 12f; //4 - vector47 *= -num649; - projectile.velocity = (projectile.velocity * 40f + vector47) / 41f; //41 - } - } - else - { - bool flag26 = false; - float num636 = 400f; - if (!flag26) - { - flag26 = projectile.ai[0] == 1f; - } - float num650 = 6f; - if (flag26) - { - num650 = 15f; - } - Vector2 center2 = projectile.Center; - Vector2 vector48 = player.Center - center2 + new Vector2(0f, -60f); - float playerDist = vector48.Length(); - if (playerDist > 200f && num650 < 8f) - { - num650 = 8f; - } - if (playerDist < num636 && flag26 && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) - { - projectile.ai[0] = 0f; - projectile.netUpdate = true; - } - if (playerDist > 2000f) - { - projectile.position.X = player.Center.X - (float)(projectile.width / 2); - projectile.position.Y = player.Center.Y - (float)(projectile.height / 2); - projectile.netUpdate = true; - } - if (playerDist > 70f) - { - vector48.Normalize(); - vector48 *= num650; - projectile.velocity = (projectile.velocity * 40f + vector48) / 41f; - } - else if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f) - { - projectile.velocity.X = -0.15f; - projectile.velocity.Y = -0.05f; - } - } - if (counter > 0) - { - counter += Main.rand.Next(1, 4); - } - if (counter > 30) - { - counter = 0; - projectile.netUpdate = true; - } - if (projectile.ai[0] == 0f) - { - if (counter == 0 && homeIn && homingRange < 500f) - { - counter += 1; - if (Main.myPlayer == projectile.owner) - { - projectile.ai[0] = 2f; - Vector2 value20 = vector46 - projectile.Center; - value20.Normalize(); - projectile.velocity = value20 * 16f; //8 - projectile.netUpdate = true; - } - } - } + + projectile.ChargingMinionAI(MagicHat.Range, 1200f, 2500f, 400f, 1, 30f, 24f, -12f, 30f, 16f, true, true, 3); } - public override Color? GetAlpha(Color lightColor) - { - return new Color(0, 255, 111, projectile.alpha); - } + public override Color? GetAlpha(Color lightColor) => new Color(0, 255, 111, projectile.alpha); public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { diff --git a/Projectiles/Summon/MagicBird.cs b/Projectiles/Summon/MagicBird.cs index 05bc217a9f..eca8ff4e74 100644 --- a/Projectiles/Summon/MagicBird.cs +++ b/Projectiles/Summon/MagicBird.cs @@ -35,8 +35,8 @@ namespace CalamityMod.Projectiles.Summon { projectile.spriteDirection = projectile.direction = (projectile.velocity.X > 0).ToDirectionInt(); projectile.rotation = projectile.velocity.ToRotation() + (projectile.spriteDirection == 1 ? 0f : MathHelper.Pi); - projectile.frameCounter++; - if (projectile.frameCounter > 6) + + if (projectile.frameCounter++ % 6 == 0) { projectile.frame++; projectile.frameCounter = 0; @@ -45,19 +45,18 @@ namespace CalamityMod.Projectiles.Summon { projectile.frame = 0; } - projectile.ai[0]++; - projectile.ai[1]++; - if (projectile.ai[0] >= 20f) + + if (projectile.ai[0]++ % 20f == 0f) { Vector2 dspeed = projectile.velocity * Main.rand.NextFloat(0.3f,0.6f); int dust = Dust.NewDust(projectile.Center, 1, 1, 67, dspeed.X, dspeed.Y, 50, default, 1.2f); Main.dust[dust].noGravity = true; - projectile.ai[0] = 0f; } //Homing - if (projectile.ai[1] > 30f) + if (projectile.ai[1]++ > 30f) HomingAI(); + //Fade in if (projectile.alpha > 0) { @@ -94,7 +93,7 @@ namespace CalamityMod.Projectiles.Summon for (int i = 0; i < Main.npc.Length; ++i) { NPC npc = Main.npc[i]; - if (npc == null || !npc.active) + if (npc is null || !npc.active) continue; if (npc.CanBeChasedBy(projectile, false)) @@ -130,10 +129,7 @@ namespace CalamityMod.Projectiles.Summon } } - public override Color? GetAlpha(Color lightColor) - { - return new Color(255, 239, 0, projectile.alpha); - } + public override Color? GetAlpha(Color lightColor) => new Color(255, 239, 0, projectile.alpha); public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { diff --git a/Projectiles/Summon/MagicHammer.cs b/Projectiles/Summon/MagicHammer.cs index afddf9d1a4..d1740b14db 100644 --- a/Projectiles/Summon/MagicHammer.cs +++ b/Projectiles/Summon/MagicHammer.cs @@ -44,15 +44,22 @@ namespace CalamityMod.Projectiles.Summon projectile.alpha = 50; } } + projectile.rotation += 0.075f; - if (counter <= 30) + + counter++; + if (counter == 30) + { + projectile.netUpdate = true; + } + else if (counter < 30) { - counter++; return; } - int num716 = -1; - Vector2 vector59 = projectile.Center; - float num717 = MagicHat.Range; + + int targetIndex = -1; + Vector2 targetVec = projectile.Center; + float maxDistance = MagicHat.Range; if (projectile.localAI[0] > 0f) { projectile.localAI[0] -= 1f; @@ -63,39 +70,35 @@ namespace CalamityMod.Projectiles.Summon if (player.HasMinionAttackTargetNPC) { NPC npc = Main.npc[player.MinionAttackTargetNPC]; - if (npc.CanBeChasedBy(projectile, false) && (projectile.ai[0] == 0f || projectile.ai[0] == (float)(player.MinionAttackTargetNPC + 1))) + if (npc.CanBeChasedBy(projectile, false) && (projectile.ai[0] == 0f || projectile.ai[0] == player.MinionAttackTargetNPC + 1f)) { - Vector2 center4 = npc.Center; - float num719 = Vector2.Distance(center4, vector59); - if (num719 < num717) + float targetDist = Vector2.Distance(npc.Center, targetVec); + if (targetDist < maxDistance) { - num717 = num719; - vector59 = center4; - num716 = player.MinionAttackTargetNPC; + targetVec = npc.Center; + targetIndex = player.MinionAttackTargetNPC; } } } else { - for (int num718 = 0; num718 < Main.npc.Length; num718++) + for (int i = 0; i < Main.npc.Length; i++) { - NPC nPC6 = Main.npc[num718]; - if (nPC6.CanBeChasedBy(projectile, false) && (projectile.ai[0] == 0f || projectile.ai[0] == (float)(num718 + 1))) + NPC npc = Main.npc[i]; + if (npc.CanBeChasedBy(projectile, false) && (projectile.ai[0] == 0f || projectile.ai[0] == i + 1f)) { - Vector2 center4 = nPC6.Center; - float num719 = Vector2.Distance(center4, vector59); - if (num719 < num717) + float targetDist = Vector2.Distance(npc.Center, targetVec); + if (targetDist < maxDistance) { - num717 = num719; - vector59 = center4; - num716 = num718; + targetVec = npc.Center; + targetIndex = i; } } } } - if (num716 >= 0) + if (targetIndex >= 0) { - projectile.ai[0] = (float)(num716 + 1); + projectile.ai[0] = targetIndex + 1f; projectile.netUpdate = true; } } @@ -103,40 +106,39 @@ namespace CalamityMod.Projectiles.Summon { projectile.localAI[0] = 30f; } - bool flag32 = false; + bool canHome = false; if (projectile.ai[0] != 0f) { - int num720 = (int)(projectile.ai[0] - 1f); - if (Main.npc[num720].active && !Main.npc[num720].dontTakeDamage && Main.npc[num720].immune[projectile.owner] == 0) + int target = (int)(projectile.ai[0] - 1f); + NPC npc = Main.npc[target]; + if (npc.CanBeChasedBy(projectile, false) && npc.immune[projectile.owner] == 0) { - float num721 = Main.npc[num720].position.X + (float)(Main.npc[num720].width / 2); - float num722 = Main.npc[num720].position.Y + (float)(Main.npc[num720].height / 2); - float num723 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num721) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num722); - if (num723 < MagicHat.Range * 1.25f) + float targetDist = Vector2.Distance(npc.Center, targetVec); + if (targetDist < maxDistance * 1.25f) { - flag32 = true; - vector59 = Main.npc[num720].Center; + canHome = true; + targetVec = npc.Center; } } else { projectile.ai[0] = 0f; - flag32 = false; + canHome = false; projectile.netUpdate = true; } } - if (flag32) + if (canHome) { - Vector2 v = vector59 - projectile.Center; - float num724 = projectile.velocity.ToRotation(); - float num725 = v.ToRotation(); - float num726 = num725 - num724; - num726 = MathHelper.WrapAngle(num726); - projectile.velocity = projectile.velocity.RotatedBy(num726 * 0.25, default); + Vector2 velocity = targetVec - projectile.Center; + float trajectory = projectile.velocity.ToRotation(); + float target = velocity.ToRotation(); + float rotateAmt = target - trajectory; + rotateAmt = MathHelper.WrapAngle(rotateAmt); + projectile.velocity = projectile.velocity.RotatedBy(rotateAmt * 0.25, default); } - float num727 = projectile.velocity.Length(); + float speed = projectile.velocity.Length(); projectile.velocity.Normalize(); - projectile.velocity *= num727 + 0.0025f; + projectile.velocity *= speed + 0.0025f; } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) @@ -145,10 +147,7 @@ namespace CalamityMod.Projectiles.Summon return false; } - public override Color? GetAlpha(Color lightColor) - { - return new Color(255, 56, 0, projectile.alpha); - } + public override Color? GetAlpha(Color lightColor) => new Color(255, 56, 0, projectile.alpha); public override void Kill(int timeLeft) { diff --git a/Projectiles/Summon/MagicRifle.cs b/Projectiles/Summon/MagicRifle.cs index 97b294b3a4..8f20a75ca5 100644 --- a/Projectiles/Summon/MagicRifle.cs +++ b/Projectiles/Summon/MagicRifle.cs @@ -9,7 +9,6 @@ namespace CalamityMod.Projectiles.Summon public class MagicRifle : ModProjectile { private int counter = 0; - private bool canHome = false; public override void SetStaticDefaults() { DisplayName.SetDefault("Rifle"); @@ -39,11 +38,16 @@ namespace CalamityMod.Projectiles.Summon projectile.MinionAntiClump(); //Try not to do anything at first - if (counter <= 30) + counter++; + if (counter == 30) { - counter++; - canHome = true; + projectile.netUpdate = true; } + else if (counter < 30) + { + return; + } + float homingRange = MagicHat.Range; Vector2 targetVec = projectile.position; Vector2 half = new Vector2(0.5f); @@ -52,7 +56,7 @@ namespace CalamityMod.Projectiles.Summon if (player.HasMinionAttackTargetNPC) { NPC npc = Main.npc[player.MinionAttackTargetNPC]; - if (npc.CanBeChasedBy(projectile, false) && canHome) + if (npc.CanBeChasedBy(projectile, false)) { //Adding a check on the NPC's size allows it to target big things like Providence Vector2 sizeCheck = npc.position + npc.Size * half; @@ -71,7 +75,7 @@ namespace CalamityMod.Projectiles.Summon for (int npcIndex = 0; npcIndex < Main.maxNPCs; npcIndex++) { NPC npc = Main.npc[npcIndex]; - if (npc.CanBeChasedBy(projectile, false) && canHome) + if (npc.CanBeChasedBy(projectile, false)) { Vector2 sizeCheck = npc.position + npc.Size * half; float targetDist = Vector2.Distance(npc.Center, projectile.Center); diff --git a/Projectiles/Summon/MagicUmbrella.cs b/Projectiles/Summon/MagicUmbrella.cs index 2367bc2b61..71cbd42f06 100644 --- a/Projectiles/Summon/MagicUmbrella.cs +++ b/Projectiles/Summon/MagicUmbrella.cs @@ -10,7 +10,6 @@ namespace CalamityMod.Projectiles.Summon public class MagicUmbrella : ModProjectile { private int counter = 0; - private bool canHome = false; public override void SetStaticDefaults() { DisplayName.SetDefault("Umbrella"); @@ -38,182 +37,22 @@ namespace CalamityMod.Projectiles.Summon public override void AI() { - Player player = Main.player[projectile.owner]; projectile.rotation += 0.075f; projectile.alpha -= 50; - float num633 = MagicHat.Range; - float num634 = 1600f; - float num635 = 2200f; - float num636 = 150f; - projectile.MinionAntiClump(); - if (counter <= 30) + counter++; + if (counter == 30) { - counter++; - canHome = false; + projectile.netUpdate = true; } - else + else if (counter < 30) { - canHome = true; + return; } - bool flag24 = false; - if (projectile.ai[0] == 2f) - { - projectile.ai[1] += 1f; - projectile.extraUpdates = 1; - if (projectile.ai[1] > 40f) - { - projectile.ai[1] = 1f; - projectile.ai[0] = 0f; - projectile.extraUpdates = 0; - projectile.numUpdates = 0; - projectile.netUpdate = true; - } - else - { - flag24 = true; - } - } - if (flag24) - { - return; - } - if (!canHome) - { - return; - } - Vector2 vector46 = projectile.position; - bool flag25 = false; - if (player.HasMinionAttackTargetNPC) - { - NPC npc = Main.npc[player.MinionAttackTargetNPC]; - if (npc.CanBeChasedBy(projectile, false) && canHome) - { - float num646 = Vector2.Distance(npc.Center, projectile.Center); - if (!flag25 && num646 < num633) - { - num633 = num646; - vector46 = npc.Center; - flag25 = true; - } - } - } - if (!flag25) - { - for (int num645 = 0; num645 < Main.npc.Length; num645++) - { - NPC nPC2 = Main.npc[num645]; - if (nPC2.CanBeChasedBy(projectile, false) && canHome) - { - float num646 = Vector2.Distance(nPC2.Center, projectile.Center); - if (!flag25 && num646 < num633) - { - num633 = num646; - vector46 = nPC2.Center; - flag25 = true; - } - } - } - } - float num647 = num634; - if (flag25) - { - num647 = num635; - } - if (Vector2.Distance(player.Center, projectile.Center) > num647) - { - projectile.ai[0] = 1f; - projectile.netUpdate = true; - } - if (flag25 && projectile.ai[0] == 0f) - { - Vector2 vector47 = vector46 - projectile.Center; - float num648 = vector47.Length(); - vector47.Normalize(); - if (num648 > 200f) - { - float scaleFactor2 = 9f; //8 - vector47 *= scaleFactor2; - projectile.velocity = (projectile.velocity * 40f + vector47) / 41f; - } - else - { - float num649 = 4f; - vector47 *= -num649; - projectile.velocity = (projectile.velocity * 40f + vector47) / 41f; - } - } - else - { - bool flag26 = false; - if (!flag26) - { - flag26 = projectile.ai[0] == 1f; - } - float num650 = 6f; - if (flag26) - { - num650 = 15f; - } - Vector2 center2 = projectile.Center; - Vector2 vector48 = player.Center - center2 + new Vector2(0f, -60f); - float num651 = vector48.Length(); - if (num651 > 200f && num650 < 8f) - { - num650 = 8f; - } - if (num651 < num636 && flag26 && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) - { - projectile.ai[0] = 0f; - projectile.netUpdate = true; - } - if (num651 > 2000f) - { - projectile.position.X = player.Center.X - (float)(projectile.width / 2); - projectile.position.Y = player.Center.Y - (float)(projectile.height / 2); - projectile.netUpdate = true; - } - if (num651 > 70f) - { - vector48.Normalize(); - vector48 *= num650; - projectile.velocity = (projectile.velocity * 40f + vector48) / 41f; - } - else if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f) - { - projectile.velocity.X = -0.15f; - projectile.velocity.Y = -0.05f; - } - } - if (projectile.ai[1] > 0f) - { - projectile.ai[1] += (float)Main.rand.Next(1, 4); - } - if (projectile.ai[1] > 40f) - { - projectile.ai[1] = 0f; - projectile.netUpdate = true; - } - if (projectile.ai[0] == 0f) - { - if (projectile.ai[1] == 0f && flag25 && num633 < 500f) - { - projectile.ai[1] += 1f; - if (Main.myPlayer == projectile.owner) - { - projectile.ai[0] = 2f; - Vector2 value20 = vector46 - projectile.Center; - value20.Normalize(); - projectile.velocity = value20 * 9f; //8 - projectile.netUpdate = true; - } - } - } + + projectile.ChargingMinionAI(MagicHat.Range, 1600f, 2200f, 150f, 0, 40f, 9f, -4f, 40f, 9f, true, true); } - public override Color? GetAlpha(Color lightColor) - { - return new Color(75, 255, 255, projectile.alpha); - } + public override Color? GetAlpha(Color lightColor) => new Color(75, 255, 255, projectile.alpha); public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { @@ -235,21 +74,7 @@ namespace CalamityMod.Projectiles.Summon { if (Main.rand.NextBool(4)) { - for (int n = 0; n < Main.rand.Next(1, 3); n++) //1 to 2 baseball bats - { - float x = target.position.X + (float)Main.rand.Next(-400, 400); - float y = target.position.Y - (float)Main.rand.Next(500, 800); - Vector2 vector = new Vector2(x, y); - float num13 = target.position.X + (float)(target.width / 2) - vector.X; - float num14 = target.position.Y + (float)(target.height / 2) - vector.Y; - num13 += (float)Main.rand.Next(-100, 101); - int num15 = 29; - float num16 = (float)Math.Sqrt((double)(num13 * num13 + num14 * num14)); - num16 = (float)num15 / num16; - num13 *= num16; - num14 *= num16; - Projectile.NewProjectile(x, y, num13, num14, ModContent.ProjectileType(), (int)(projectile.damage * Main.rand.NextFloat(0.3f, 0.6f)), projectile.knockBack * Main.rand.NextFloat(0.7f, 1f), projectile.owner, 0f, 0f); - } + SpawnBaseballBats(target.Center); } } @@ -257,22 +82,26 @@ namespace CalamityMod.Projectiles.Summon { if (Main.rand.NextBool(4)) { - for (int n = 0; n < Main.rand.Next(1, 3); n++) //1 to 2 baseball bats - { - float x = target.position.X + (float)Main.rand.Next(-400, 400); - float y = target.position.Y - (float)Main.rand.Next(500, 800); - Vector2 vector = new Vector2(x, y); - float num13 = target.position.X + (float)(target.width / 2) - vector.X; - float num14 = target.position.Y + (float)(target.height / 2) - vector.Y; - num13 += (float)Main.rand.Next(-100, 101); - int num15 = 29; - float num16 = (float)Math.Sqrt((double)(num13 * num13 + num14 * num14)); - num16 = (float)num15 / num16; - num13 *= num16; - num14 *= num16; - Projectile.NewProjectile(x, y, num13, num14, ModContent.ProjectileType(), (int)(projectile.damage * Main.rand.NextFloat(0.3f, 0.6f)), projectile.knockBack * Main.rand.NextFloat(0.7f, 1f), projectile.owner, 0f, 0f); - } + SpawnBaseballBats(target.Center); } } + + private void SpawnBaseballBats(Vector2 targetPos) + { + for (int n = 0; n < Main.rand.Next(1, 3); n++) //1 to 2 baseball bats + { + float x = targetPos.X + Main.rand.Next(-400, 401); + float y = targetPos.Y - Main.rand.Next(500, 801); + Vector2 source = new Vector2(x, y); + Vector2 velocity = targetPos - source; + velocity.X += Main.rand.Next(-100, 101); + float speed = 29f; + float targetDist = velocity.Length(); + targetDist = speed / targetDist; + velocity.X *= targetDist; + velocity.Y *= targetDist; + Projectile.NewProjectile(source, velocity, ModContent.ProjectileType(), (int)(projectile.damage * Main.rand.NextFloat(0.3f, 0.6f)), projectile.knockBack * Main.rand.NextFloat(0.7f, 1f), projectile.owner, 0f, 0f); + } + } } } diff --git a/Utilities/CalamityUtils.cs b/Utilities/CalamityUtils.cs index eaa6a24b8d..224134ff26 100644 --- a/Utilities/CalamityUtils.cs +++ b/Utilities/CalamityUtils.cs @@ -1008,7 +1008,7 @@ namespace CalamityMod } } - public static void ChargingMinionAI(this Projectile projectile, float range, float maxPlayerDist, float extraMaxPlayerDist, float safeDist, int initialUpdates, float chargeDelayTime, float goToSpeed, float goBackSpeed, float chargeCounterMax, float chargeSpeed, bool tileVision, bool ignoreTilesWhenCharging) + public static void ChargingMinionAI(this Projectile projectile, float range, float maxPlayerDist, float extraMaxPlayerDist, float safeDist, int initialUpdates, float chargeDelayTime, float goToSpeed, float goBackSpeed, float chargeCounterMax, float chargeSpeed, bool tileVision, bool ignoreTilesWhenCharging, int updateDifference = 1) { Player player = Main.player[projectile.owner]; CalamityPlayer modPlayer = player.Calamity(); @@ -1021,7 +1021,7 @@ namespace CalamityMod if (projectile.ai[0] == 2f) { projectile.ai[1] += 1f; - projectile.extraUpdates = initialUpdates + (projectile.type == ModContent.ProjectileType() ? 2 : 1); + projectile.extraUpdates = initialUpdates + updateDifference; if (projectile.ai[1] > chargeDelayTime) { projectile.ai[1] = 1f;