using Microsoft.Xna.Framework; using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Summon { public class DreadmineTurret : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Summon"; public float count = 0; public override void SetStaticDefaults() { Main.projFrames[Projectile.type] = 4; ProjectileID.Sets.MinionTargettingFeature[Projectile.type] = true; } public override void SetDefaults() { Projectile.width = 26; Projectile.height = 26; Projectile.ignoreWater = true; Projectile.tileCollide = false; Projectile.sentry = true; Projectile.timeLeft = Projectile.SentryLifeTime; Projectile.penetrate = -1; Projectile.DamageType = DamageClass.Summon; } public override void AI() { Projectile.frameCounter++; if (Projectile.frameCounter > 6) { Projectile.frame++; Projectile.frameCounter = 0; } if (Projectile.frame >= Main.projFrames[Projectile.type]) { Projectile.frame = 0; } Projectile.velocity = new Vector2(0f, (float)Math.Sin((double)(6.28318548f * Projectile.ai[0] / 300f)) * 0.5f); Projectile.ai[0] += 1f; if (Projectile.ai[0] >= 300f) { Projectile.ai[0] = 0f; Projectile.netUpdate = true; } if (Main.rand.NextBool(15)) { int num = 0; for (int i = 0; i < Main.maxProjectiles; i++) { if (Main.projectile[i].active && Main.projectile[i].owner == Main.myPlayer && Main.projectile[i].type == ModContent.ProjectileType()) { num++; } } if (Main.rand.Next(15) >= num && num < 10) { int num2 = 50; int num3 = 24; int num4 = 90; for (int j = 0; j < num2; j++) { int num5 = Main.rand.Next(200 - j * 2, 400 + j * 2); Vector2 center = Projectile.Center; center.X += (float)Main.rand.Next(-num5, num5 + 1); center.Y += (float)Main.rand.Next(-num5, num5 + 1); if (!Collision.SolidCollision(center, num3, num3)) { center.X += (float)(num3 / 2); center.Y += (float)(num3 / 2); if (Collision.CanHit(new Vector2(Projectile.Center.X, Projectile.position.Y), 1, 1, center, 1, 1) || Collision.CanHit(new Vector2(Projectile.Center.X, Projectile.position.Y - 50f), 1, 1, center, 1, 1)) { int num6 = (int)center.X / 16; int num7 = (int)center.Y / 16; bool flag = false; if (Main.rand.NextBool(3) && Main.tile[num6, num7] != null && Main.tile[num6, num7].WallType > 0) { flag = true; } else { center.X -= (float)(num4 / 2); center.Y -= (float)(num4 / 2); if (Collision.SolidCollision(center, num4, num4)) { center.X += (float)(num4 / 2); center.Y += (float)(num4 / 2); flag = true; } } if (flag) { for (int k = 0; k < Main.maxProjectiles; k++) { if (Main.projectile[k].active && Main.projectile[k].owner == Main.myPlayer && Main.projectile[k].type == ModContent.ProjectileType() && (center - Main.projectile[k].Center).Length() < 48f) { flag = false; break; } } if (flag && Main.myPlayer == Projectile.owner) { int p = Projectile.NewProjectile(Projectile.GetSource_FromThis(), center, Vector2.Zero, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 0f); if (Main.projectile.IndexInRange(p)) Main.projectile[p].originalDamage = Projectile.originalDamage; } } } } } } } } public override bool? CanDamage() => false; } }