diff --git a/Items/Mounts/ExoTank.cs b/Items/Mounts/ExoTank.cs index 4fa1fb0d4a..3582dc165d 100644 --- a/Items/Mounts/ExoTank.cs +++ b/Items/Mounts/ExoTank.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using CalamityMod.Buffs.Mounts; +using CalamityMod.Projectiles.Summon; +using CalamityMod.Projectiles.Typeless; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -18,9 +20,6 @@ namespace CalamityMod.Items.Mounts MountData.spawnDustNoGravity = true; MountData.buff = ModContent.BuffType(); - // Attack (lasers; rockets are determined by extra frames) - MountData.abilityCooldown = 6; - // Horizontal movement MountData.runSpeed = 9f; MountData.dashSpeed = 22.5f; @@ -73,6 +72,70 @@ namespace CalamityMod.Items.Mounts } } + public override void UpdateEffects(Player player) + { + if (Main.myPlayer == player.whoAmI) + { + Mount tank = player.mount; + + // Find the closest NPC targetable by the tank + float range = 960f; // 60 tiles + int targetNPC = -1; + foreach (NPC target in Main.ActiveNPCs) + { + if (!target.CanBeChasedBy(tank)) + continue; + + Vector2 targetDif = target.Center - player.Center; + + // The tank has a sight line of 120 degrees, similar to Toy Tank + if (player.direction == 1 && MathF.Abs(targetDif.ToRotation()) > MathHelper.ToRadians(60f)) + continue; + + if (player.direction == -1 && MathF.Abs(targetDif.ToRotation()) < MathHelper.ToRadians(120f)) + continue; + + float distance = targetDif.Length(); + if (distance < range && Collision.CanHitLine(player.Center, 0, 0, target.position, target.width, target.height)) + { + range = distance; + targetNPC = target.whoAmI; + } + } + if (targetNPC != -1) + { + tank._aiming = true; + + if (tank._frameExtraCounter == 0f) + { + // Release 3 missiles matching the animation frames + if (tank._frameExtra > 0 && tank._frameExtra < 4) + { + for (int i = 0; i < 3; i++) + { + Vector2 rocketPos = player.Center - Vector2.UnitX * (60f - 4f * i - 6f * tank._frameExtra) * player.direction - Vector2.UnitY * (72f - 8f * i); + Vector2 rocketVel = (Vector2.UnitX * player.direction).RotatedBy(-MathHelper.PiOver4 * player.direction) * 10f; + int rocketDamage = (int)player.GetBestClassDamage().ApplyTo(800); + float rocketKB = 1f; + Projectile.NewProjectile(new EntitySource_Parent(player), rocketPos, rocketVel, ModContent.ProjectileType(), rocketDamage, rocketKB, player.whoAmI); + } + } + + // Fires a bullet on every frame switch + Vector2 bulletPos = player.Center + Main.rand.NextVector2Circular(3f, 3f) + Vector2.UnitX * 80f * player.direction - Vector2.UnitY * 8f; + Vector2 bulletVel = (Main.npc[targetNPC].Center - bulletPos).SafeNormalize(Vector2.UnitX * player.direction) * Main.rand.NextFloat(10f, 12f); + int bulletDamage = (int)player.GetBestClassDamage().ApplyTo(400); + float bulletKB = 1f; + Projectile laser = Projectile.NewProjectileDirect(new EntitySource_Parent(player), bulletPos, bulletVel, ModContent.ProjectileType(), bulletDamage, bulletKB, player.whoAmI); + if (laser.whoAmI.WithinBounds(Main.maxProjectiles)) + laser.DamageType = DamageClass.Generic; + } + } + else + tank._aiming = false; + } + } + public override bool UpdateFrame(Player mountedPlayer, int state, Vector2 velocity) { // Locked to 2 states: moving and not moving diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Typeless.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Typeless.hjson index 5aec3443cb..909f7ac945 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Typeless.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Typeless.hjson @@ -49,6 +49,7 @@ EmpyreanMarble.DisplayName: Empyrean Marble EmpyreanStellarDetritus.DisplayName: Empyrean Stellar Detritus EnergyShell.DisplayName: Energy Shell EutrophicSandBallGun.DisplayName: Eutrophic Sand +ExoTankMissile.DisplayName: Miracle Missile FeralDoubleBobber.DisplayName: Feral Bobber FlameLickedBarrage.DisplayName: Flame Licked Barrage FlameLickedHellblast.DisplayName: Flame Licked Hellblast diff --git a/Projectiles/Typeless/ExoTankMissile.cs b/Projectiles/Typeless/ExoTankMissile.cs new file mode 100644 index 0000000000..dd2bf26e66 --- /dev/null +++ b/Projectiles/Typeless/ExoTankMissile.cs @@ -0,0 +1,42 @@ +using CalamityMod.Buffs.DamageOverTime; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Typeless +{ + public class ExoTankMissile : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Typeless"; + + public override void SetStaticDefaults() + { + Main.projFrames[Type] = 4; + ProjectileID.Sets.CultistIsResistantTo[Type] = true; + } + + public override void SetDefaults() + { + Projectile.width = 66; + Projectile.height = 22; + Projectile.friendly = true; + Projectile.penetrate = 1; + Projectile.MaxUpdates = 3; + Projectile.timeLeft = 90 * Projectile.MaxUpdates; + } + + public override void AI() + { + Projectile.frameCounter++; + Projectile.frame = Projectile.frameCounter / 5 % Main.projFrames[Type]; + + CalamityUtils.HomeInOnNPC(Projectile, false, 1200f, 15f, 20f); + Projectile.rotation = Projectile.velocity.ToRotation(); + } + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(ModContent.BuffType(), 300); + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => Projectile.RotatingHitboxCollision(targetHitbox); + } +} diff --git a/Projectiles/Typeless/ExoTankMissile.png b/Projectiles/Typeless/ExoTankMissile.png new file mode 100644 index 0000000000..20caaad2d9 Binary files /dev/null and b/Projectiles/Typeless/ExoTankMissile.png differ