diff --git a/ExtraTextures/ExtraTextureRefs.cs b/ExtraTextures/ExtraTextureRefs.cs index 724db66b6e..c512f067bd 100644 --- a/ExtraTextures/ExtraTextureRefs.cs +++ b/ExtraTextures/ExtraTextureRefs.cs @@ -32,6 +32,12 @@ namespace CalamityMod.ExtraTextures public static Asset FlyingCarpetVanilla; public static Asset FlyingCarpetAuric; + // Particles + public static Asset CircularSmear; + public static Asset CircularSmearFire1; + public static Asset CircularSmearFire2; + public static Asset CircularSmearFire3; + // Boss Heads // I know it's not exactly a Texture2D but it belongs to ExtraTextures. public static int BossHeadIndex_ChadPrime; @@ -60,6 +66,11 @@ namespace CalamityMod.ExtraTextures FlyingCarpetVanilla = TextureAssets.FlyingCarpet; FlyingCarpetAuric = ModContent.Request("CalamityMod/ExtraTextures/AuricCarpet", AssetRequestMode.AsyncLoad); + + CircularSmear = ModContent.Request("CalamityMod/Particles/CircularSmear", AssetRequestMode.AsyncLoad); + CircularSmearFire1 = ModContent.Request("CalamityMod/Particles/CircularSmearFire1", AssetRequestMode.AsyncLoad); + CircularSmearFire2 = ModContent.Request("CalamityMod/Particles/CircularSmearFire2", AssetRequestMode.AsyncLoad); + CircularSmearFire3 = ModContent.Request("CalamityMod/Particles/CircularSmearFire3", AssetRequestMode.AsyncLoad); } public override void Unload() diff --git a/Items/Weapons/Ranged/AngelicShotgun.cs b/Items/Weapons/Ranged/AngelicShotgun.cs index 94509f3045..92fed342f9 100644 --- a/Items/Weapons/Ranged/AngelicShotgun.cs +++ b/Items/Weapons/Ranged/AngelicShotgun.cs @@ -61,10 +61,11 @@ namespace CalamityMod.Items.Weapons.Ranged for (int i = 0; i < NumBullets; ++i) { Vector2 randomVelocity = baseVelocity.RotatedByRandom(MathHelper.ToRadians(12.5f)) * Main.rand.NextFloat(0.88f, 1.12f); - Projectile.NewProjectile(source, position, randomVelocity, type, damage, knockback, player.whoAmI); + Projectile.NewProjectile(source, position + velocity.SafeNormalize(Vector2.Zero) * 16f, randomVelocity, type, damage, knockback, player.whoAmI); } // Spawn a beam from the sky ala Deathhail Staff or Lunar Flare + // This is more powerful if Hallow-Point Rounds (either naturally used or converted) are fired bool empowered = type == ModContent.ProjectileType(); float laserSpeed = 8f; int laserDamage = (int)(damage * (empowered ? 3f : 2f)); diff --git a/Particles/CircularSmearVFX.cs b/Particles/CircularSmearVFX.cs index 35c866c06f..ef20086549 100644 --- a/Particles/CircularSmearVFX.cs +++ b/Particles/CircularSmearVFX.cs @@ -1,4 +1,8 @@ -using Microsoft.Xna.Framework; +using CalamityMod.ExtraTextures; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using ReLogic.Content; namespace CalamityMod.Particles { @@ -8,9 +12,11 @@ namespace CalamityMod.Particles public override bool UseAdditiveBlend => true; public override bool SetLifetime => true; - public float opacity; + public override bool UseCustomDraw => true; - public CircularSmearVFX(Vector2 position, Color color, float rotation, float scale) + public Asset LoadedAsset; + + public CircularSmearVFX(Vector2 position, Color color, float rotation, float scale, Asset? texture = null) { Position = position; Velocity = Vector2.Zero; @@ -18,6 +24,15 @@ namespace CalamityMod.Particles Scale = scale; Rotation = rotation; Lifetime = 2; + + LoadedAsset = texture; + if (LoadedAsset is null) + LoadedAsset = ExtraTextureRefs.CircularSmear; + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + spriteBatch.Draw(LoadedAsset.Value, Position - Main.screenPosition, null, Color, Rotation, LoadedAsset.Value.Size() * 0.5f, Scale, SpriteEffects.None, 0); } } } diff --git a/Projectiles/Melee/DivineHatchetBoomerang.cs b/Projectiles/Melee/DivineHatchetBoomerang.cs index 561fb30b9c..3c110a15a9 100644 --- a/Projectiles/Melee/DivineHatchetBoomerang.cs +++ b/Projectiles/Melee/DivineHatchetBoomerang.cs @@ -1,6 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.ExtraTextures; +using CalamityMod.Particles; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; @@ -14,11 +15,16 @@ namespace CalamityMod.Projectiles.Melee public new string LocalizationCategory => "Projectiles.Melee"; public override string Texture => "CalamityMod/Items/Weapons/Melee/SeekingScorcher"; - private bool hasHitEnemy = false; - private static int Lifetime = 300; - private static int ReboundTime = 100; - private int targetNPC = -1; - private List previousNPCs = new List() { -1 }; + // Stats + public const int ReboundTime = 100; + public const int MaxBounces = 3; + public const float MaxHomingRange = 1000f; // 62.5 blocks + + private List PreviousNPCs = new List() { -1 }; + public Player Owner => Main.player[Projectile.owner]; + public ref float AirTime => ref Projectile.ai[0]; + + public Particle Smear; public override void SetStaticDefaults() { @@ -29,122 +35,51 @@ namespace CalamityMod.Projectiles.Melee public override void SetDefaults() { - Projectile.width = 60; - Projectile.height = 60; + Projectile.width = Projectile.height = 94; Projectile.friendly = true; Projectile.tileCollide = false; - Projectile.penetrate = 3; - Projectile.timeLeft = Lifetime; Projectile.DamageType = DamageClass.MeleeNoSpeed; - Projectile.extraUpdates = 1; + Projectile.MaxUpdates = 2; + Projectile.penetrate = -1; + Projectile.timeLeft = 150 * Projectile.MaxUpdates; Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = 10; + Projectile.localNPCHitCooldown = -1; } public override void AI() { + if (AirTime % 8f == 0f) + SoundEngine.PlaySound(SoundID.Item7, Projectile.Center); + + // Boomerang rotation + Projectile.rotation += Projectile.direction * 0.4f; + + if (Smear == null) + { + Smear = new CircularSmearVFX(Projectile.Center, Color.Black, Projectile.rotation, 0.63f, ExtraTextureRefs.CircularSmearFire3); + GeneralParticleHandler.SpawnParticle(Smear); + } + else + { + Smear.Rotation = Projectile.rotation + MathHelper.ToRadians(75f); + Smear.Time = 0; + Smear.Position = Projectile.Center; + Smear.Scale = 0.63f; + Smear.Color = Color.Gold; + } + //holy dust if (Main.rand.NextBool(8)) { Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, DustID.CopperCoin, Projectile.velocity.X * 0.5f, Projectile.velocity.Y * 0.5f); } - // Boomerang rotation - Projectile.rotation += 0.4f * (float)Projectile.direction; - - // Boomerang sound - if (Projectile.soundDelay == 0) - { - Projectile.soundDelay = 8; - SoundEngine.PlaySound(SoundID.Item7, Projectile.position); - } - // Returns after some number of frames in the air - if (Projectile.timeLeft < Lifetime - ReboundTime) - Projectile.ai[0] = 1f; - - if (Projectile.ai[0] != 0f) - { - float returnSpeed = 26f; - float acceleration = 1.4f; - - Player owner = Main.player[Projectile.owner]; - - // Delete the projectile if it's excessively far away. - Vector2 playerCenter = owner.Center; - float xDist = playerCenter.X - Projectile.Center.X; - float yDist = playerCenter.Y - Projectile.Center.Y; - float dist = (float)Math.Sqrt((double)(xDist * xDist + yDist * yDist)); - if (dist > 3000f) - Projectile.Kill(); - - dist = returnSpeed / dist; - xDist *= dist; - yDist *= dist; - - // Home back in on the player. - if (Projectile.velocity.X < xDist) - { - Projectile.velocity.X += acceleration; - if (Projectile.velocity.X < 0f && xDist > 0f) - Projectile.velocity.X += acceleration; - } - else if (Projectile.velocity.X > xDist) - { - Projectile.velocity.X -= acceleration; - if (Projectile.velocity.X > 0f && xDist < 0f) - Projectile.velocity.X -= acceleration; - } - if (Projectile.velocity.Y < yDist) - { - Projectile.velocity.Y += acceleration; - if (Projectile.velocity.Y < 0f && yDist > 0f) - Projectile.velocity.Y += acceleration; - } - else if (Projectile.velocity.Y > yDist) - { - Projectile.velocity.Y -= acceleration; - if (Projectile.velocity.Y > 0f && yDist < 0f) - Projectile.velocity.Y -= acceleration; - } - - // Delete the projectile if it touches its owner. - if (Main.myPlayer == Projectile.owner) - if (Projectile.Hitbox.Intersects(owner.Hitbox)) - Projectile.Kill(); - - //home in on nearby NPCs if not returning to player - if (Projectile.penetrate != -1) - { - if (!hasHitEnemy) - { - float range = 999f; - for (int a = 0; a < Main.npc.Length; a++) - { - if (Main.npc[a].CanBeChasedBy(Projectile, false)) - { - if (Vector2.Distance(Main.npc[a].Center, Projectile.Center) < range) - { - Vector2 newVelocity = Main.npc[a].Center - Projectile.Center; - newVelocity.Normalize(); - newVelocity *= 15f; - Projectile.velocity = newVelocity; - } - } - } - } - else - { - if (targetNPC >= 0) - { - Vector2 newVelocity = Main.npc[targetNPC].Center - Projectile.Center; - newVelocity.Normalize(); - newVelocity *= 15f; - Projectile.velocity = newVelocity; - } - } - } - } + AirTime++; + if (AirTime > ReboundTime) + ReturnToOwner(); + else if (AirTime == ReboundTime) + SeekNPC(); } public override bool PreDraw(ref Color lightColor) @@ -153,70 +88,61 @@ namespace CalamityMod.Projectiles.Melee return false; } - //glowmask effect + // Glowmask public override Color? GetAlpha(Color lightColor) => new Color(200, 200, 200, 200); public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { - //inflict Holy Flames for 6 seconds target.AddBuff(ModContent.BuffType(), 180); - if (Projectile.penetrate != -1) + // Disallow the NPC to be targeted again + PreviousNPCs.Add(target.whoAmI); + if (AirTime <= ReboundTime) + SeekNPC(); + } + + public void SeekNPC() + { + // Return if exceeding max number of bounces + if (Projectile.numHits >= MaxBounces) { - //find a nearby NPC to track - float minDist = 999f; - int index = 0; - foreach (NPC npc in Main.ActiveNPCs) - { - bool hasHitNPC = false; - for (int j = 0; j < previousNPCs.Count; j++) - { - if (previousNPCs[j] == npc.whoAmI) - { - hasHitNPC = true; - } - } + AirTime = ReboundTime + 1f; + ReturnToOwner(); + return; + } - if (npc == target) - { - previousNPCs.Add(npc.whoAmI); - } - if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC) - { - float dist = (Projectile.Center - npc.Center).Length(); - if (dist < minDist) - { - minDist = dist; - index = npc.whoAmI; - } - } - } + // Find the closest NPC targetable + float range = MaxHomingRange; + int targetNPC = -1; + foreach (NPC target in Main.ActiveNPCs) + { + if (!target.CanBeChasedBy(Projectile) || PreviousNPCs.Contains(target.whoAmI)) + continue; - Vector2 velocityNew; - if (minDist < 999f) + float distance = Vector2.Distance(target.Center, Projectile.Center); + if (distance < range && Collision.CanHit(Projectile, target)) { - hasHitEnemy = true; - targetNPC = index; - velocityNew = Main.npc[index].Center - Projectile.Center; - velocityNew.Normalize(); - velocityNew *= 15f; - Projectile.velocity = velocityNew; - } - else - { - Projectile.penetrate = -1; - Projectile.ai[0] = 1f; - targetNPC = -1; + range = distance; + targetNPC = target.whoAmI; } } - // After its last hit, starts returning instead of vanishing. Can pierce infinitely on the way back. - if (Projectile.penetrate == 1) + // Move towards the target if found and slightly restore airtime + if (targetNPC != -1f) { - Projectile.penetrate = -1; - Projectile.ai[0] = 1f; - targetNPC = -1; + AirTime -= 6f; + Projectile.velocity = Projectile.SafeDirectionTo(Main.npc[targetNPC].Center) * 15f; } } + + public void ReturnToOwner() + { + // Swiftly move back towards the player + Projectile.velocity = Projectile.SafeDirectionTo(Owner.Center) * 20f; + + // Delete the projectile if it touches its owner or too far away. + if (Projectile.Hitbox.Intersects(Owner.Hitbox) || Vector2.Distance(Projectile.Center, Owner.Center) >= 3000f) + Projectile.Kill(); + } } } diff --git a/Projectiles/Ranged/AngelicBeam.cs b/Projectiles/Ranged/AngelicBeam.cs index c4727f2462..6748cc971a 100644 --- a/Projectiles/Ranged/AngelicBeam.cs +++ b/Projectiles/Ranged/AngelicBeam.cs @@ -82,12 +82,13 @@ namespace CalamityMod.Projectiles.Ranged if (Main.rand.NextBool(4)) { Color fireColor = Main.hslToRgb(Main.rand.NextFloat(0.08f, 0.13f) + 0.05f * MathF.Sin(Main.GlobalTimeWrappedHourly * 5f), 1f, 0.7f); - Particle fire = new GlowOrbParticle(Projectile.Center, (Vector2.UnitX).RotatedByRandom(MathHelper.Pi) * (Main.rand.NextFloat(1f, 3f) + 3f * Projectile.scale), false, 9, Main.rand.NextFloat(1f, 1.2f), fireColor); + Particle fire = new GlowOrbParticle(Projectile.Center, (Vector2.UnitX).RotatedByRandom(MathHelper.Pi) * (Main.rand.NextFloat(1f, 3f) + 3f * Projectile.scale), false, 9, Main.rand.NextFloat(1f, 1.2f) * Projectile.scale, fireColor); GeneralParticleHandler.SpawnParticle(fire); } } - public override void ModifyDamageHitbox(ref Rectangle hitbox) => hitbox.Inflate((int)(Projectile.width * (Projectile.scale - 1f)), (int)(Projectile.width * (Projectile.scale - 1f))); + // Hitbox size does not normally scale with Projectile.scale for some reason so this is done manually + public override void ModifyDamageHitbox(ref Rectangle hitbox) => hitbox.Inflate((int)(Projectile.width * (Projectile.scale - 1f)), (int)(Projectile.height * (Projectile.scale - 1f))); public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { @@ -97,8 +98,8 @@ namespace CalamityMod.Projectiles.Ranged { Dust dust = Dust.NewDustPerfect(target.Center, ModContent.DustType(), (Vector2.UnitX).RotatedByRandom(MathHelper.Pi) * Main.rand.NextFloat(2f, 12f)); dust.noGravity = true; - dust.scale = Main.rand.NextFloat(1.2f, 2.5f) * Projectile.scale; - dust.color = Main.hslToRgb(Main.rand.NextFloat(0.033f, 0.167f), 1f, 0.66f); + dust.scale = Main.rand.NextFloat(1f, 2.4f) * Projectile.scale; + dust.color = Main.hslToRgb(Main.rand.NextFloat(0.033f, 0.167f), 1f, 0.7f); dust.noLightEmittence = true; } }