From d01044fa6f2ab39ccfdb3103102386b2de2a7d1f Mon Sep 17 00:00:00 2001 From: Altixal <73398287+Altixal@users.noreply.github.com> Date: Wed, 13 Nov 2024 23:03:26 +0700 Subject: [PATCH] basic attacks will also add sounds and visuals later --- Items/Mounts/ExoTank.cs | 69 +++++++++++++++++- ...ods.CalamityMod.Projectiles.Typeless.hjson | 1 + Projectiles/Typeless/ExoTankMissile.cs | 42 +++++++++++ Projectiles/Typeless/ExoTankMissile.png | Bin 0 -> 1482 bytes 4 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 Projectiles/Typeless/ExoTankMissile.cs create mode 100644 Projectiles/Typeless/ExoTankMissile.png 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 0000000000000000000000000000000000000000..20caaad2d970924382487e157591402cb44b8acb GIT binary patch literal 1482 zcmV;*1vUDKP)j-5)$SQW5?)xRS+ZUDPGeAfX(rz0r z!ovVzBV$Z;1_+s2Rhu4l3zgc}b6>kMAV^t~WlCGWh5^E6Yj0j2tlL>VOAxc6=6^_4 z%uqHod;Nqt zT}Q~2H1}%+*Y`S#9PZ0P_~x&7A&Ci;$v5kWm;=F?L1Dk_HF6j43VCLWuOvCJu20Np z3xte{;img$8y@b9%E}ucY=n%d&Hy1BENau0*(}w*_W0VP288H10G-a$#`mc$5JF=w zVF%D~RJQNL>&{(4%&PDt`=&`q7u1@AbjCjSTbcu5yj+5qA9%(ajKgttp3 zP6%2zlT@%qMEgvnn)^_@;l#UtJ480Xh8Krjc7NJ+-a(BSPOzeeqjIwWPD zXn{QSsncUdrQFP`20Ldk&dy@I4ToEmaak zXsKP$cONBQbnVyB9*AfI zK+LJA*@{Q%QO+p0_ch3`!5Kk*4PwGemDVg(veEKY{tFZo$)yM>V&621X~ z8X9e8c-0Y{G2E~5Ph&f>3^%O`sqg2emxW{k%^uRT*xc0@DQ5Tv2o9_2=`&`A!e^(BV>S(QALoRu-kC2co-mT#EhxV0O57; k#5TV&bAD`JQ(oH>VeLZ+sB?|X00000NkvXXu0mjf0NIJgf&c&j literal 0 HcmV?d00001