From 5d541b7d5a42bc0a337f1e3d0c464f721b2116a7 Mon Sep 17 00:00:00 2001 From: doze-zoze Date: Thu, 20 Nov 2025 20:24:21 -0600 Subject: [PATCH] rework to glaive and blazing star --- Items/Weapons/Rogue/BlazingStar.cs | 48 ++-- Items/Weapons/Rogue/Glaive.cs | 42 ++-- ...Mods.CalamityMod.Items.Weapons.Rogue.hjson | 9 +- .../Mods.CalamityMod.Projectiles.Rogue.hjson | 2 + NPCs/CalamityGlobalNPC.cs | 27 +++ Projectiles/Rogue/BlazingStarOrbital.cs | 73 ++++++ Projectiles/Rogue/BlazingStarProj.cs | 151 ++++++------- Projectiles/Rogue/GlaiveOrbital.cs | 66 ++++++ Projectiles/Rogue/GlaiveProj.cs | 210 ++++-------------- 9 files changed, 335 insertions(+), 293 deletions(-) create mode 100644 Projectiles/Rogue/BlazingStarOrbital.cs create mode 100644 Projectiles/Rogue/GlaiveOrbital.cs diff --git a/Items/Weapons/Rogue/BlazingStar.cs b/Items/Weapons/Rogue/BlazingStar.cs index cd545b0e47..948c72fd19 100644 --- a/Items/Weapons/Rogue/BlazingStar.cs +++ b/Items/Weapons/Rogue/BlazingStar.cs @@ -12,8 +12,8 @@ namespace CalamityMod.Items.Weapons.Rogue { public override void SetDefaults() { - Item.width = 1; - Item.height = 1; + Item.width = 32; + Item.height = 32; Item.damage = 75; Item.DamageType = RogueDamageClass.Instance; Item.autoReuse = true; @@ -22,7 +22,7 @@ namespace CalamityMod.Items.Weapons.Rogue Item.useTime = 15; Item.useAnimation = 15; Item.useStyle = ItemUseStyleID.Swing; - Item.knockBack = 4f; + Item.knockBack = 3; Item.value = CalamityGlobalItem.RarityLightRedBuyPrice; Item.rare = ItemRarityID.LightRed; Item.UseSound = SoundID.Item1; @@ -30,36 +30,40 @@ namespace CalamityMod.Items.Weapons.Rogue Item.shootSpeed = 13f; Item.shoot = ModContent.ProjectileType(); } + public override float StealthVelocityMultiplier => 1.3f; - // Terraria seems to really dislike high crit values in SetDefaults + public override float StealthDamageMultiplier => 0.5f; public override void ModifyWeaponCrit(Player player, ref float crit) => crit += 4; - - public override float StealthDamageMultiplier => 0.6f; - public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { + var p = Projectile.NewProjectileDirect(source, position, velocity, type, damage, knockback, player.whoAmI, 0f, -1f); if (player.Calamity().StealthStrikeAvailable()) { - for (int i = 0; i < 3; i++) - { - Vector2 perturbedSpeed = velocity.RotatedBy(MathHelper.Lerp(-MathHelper.ToRadians(8f), MathHelper.ToRadians(8f), i / 2f)); - Projectile proj = Projectile.NewProjectileDirect(source, position, perturbedSpeed, type, damage, knockback, player.whoAmI); - if (proj.whoAmI.WithinBounds(Main.maxProjectiles)) - proj.Calamity().stealthStrike = true; + p.Calamity().stealthStrike = true; + p.netUpdate = true; - Projectile projectile = Projectile.NewProjectileDirect(source, position, perturbedSpeed, type, damage, knockback, player.whoAmI); - if (projectile.whoAmI.WithinBounds(Main.maxProjectiles)) + var goType = ModContent.ProjectileType(); + if (player.ownedProjectileCounts[goType] <= 0) + { + p = Projectile.NewProjectileDirect(source, position, Vector2.Zero, goType, damage, 10, player.whoAmI, 0f, -1f); + p.Calamity().stealthStrike = true; + } + else + { + foreach (var proj in Main.ActiveProjectiles) { - projectile.penetrate = -1; - projectile.Calamity().stealthStrike = true; + if (proj.active && proj.type == goType && proj.owner == player.whoAmI) + { + proj.timeLeft += 300; + proj.netUpdate = true; + break; + } } } - return false; - } - return true; - } - public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] < 3; + } + return false; + } public override void AddRecipes() { CreateRecipe(). diff --git a/Items/Weapons/Rogue/Glaive.cs b/Items/Weapons/Rogue/Glaive.cs index d303ab8633..3c10931c2e 100644 --- a/Items/Weapons/Rogue/Glaive.cs +++ b/Items/Weapons/Rogue/Glaive.cs @@ -9,16 +9,13 @@ namespace CalamityMod.Items.Weapons.Rogue { public class Glaive : RogueWeapon { - //These 2 are used on the Projectile AI and thus remain here - public static float Speed = 13f; - public static float StealthSpeedMult = 1.3f; - public override void SetDefaults() { Item.width = 34; Item.height = 32; - Item.damage = 45; + Item.damage = 25; Item.DamageType = RogueDamageClass.Instance; + Item.autoReuse = true; Item.noMelee = true; Item.noUseGraphic = true; Item.useTime = 15; @@ -29,21 +26,40 @@ namespace CalamityMod.Items.Weapons.Rogue Item.rare = ItemRarityID.Orange; Item.UseSound = SoundID.Item1; - Item.shootSpeed = Speed; + Item.shootSpeed = 13f; Item.shoot = ModContent.ProjectileType(); } - public override float StealthVelocityMultiplier => StealthSpeedMult; + public override float StealthVelocityMultiplier => 1.3f; - // Terraria seems to really dislike high crit values in SetDefaults + public override float StealthDamageMultiplier => 0.5f; public override void ModifyWeaponCrit(Player player, ref float crit) => crit += 6; - public override bool CanUseItem(Player player) => player.ownedProjectileCounts[Item.shoot] <= 0; public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { - int p = Projectile.NewProjectile(source, position, velocity, type, damage, knockback, player.whoAmI, 0f, -1f); - if (player.Calamity().StealthStrikeAvailable() && p.WithinBounds(Main.maxProjectiles)) + var p = Projectile.NewProjectileDirect(source, position, velocity, type, damage, knockback, player.whoAmI, 0f, -1f); + if (player.Calamity().StealthStrikeAvailable()) { - Main.projectile[p].Calamity().stealthStrike = true; - Main.projectile[p].penetrate = 4; + p.Calamity().stealthStrike = true; + p.netUpdate = true; + + var goType = ModContent.ProjectileType(); + if (player.ownedProjectileCounts[goType] <= 0) + { + p = Projectile.NewProjectileDirect(source, position, Vector2.Zero, ModContent.ProjectileType(), damage, 10, player.whoAmI, 0f, -1f); + p.Calamity().stealthStrike = true; + } + else + { + foreach (var proj in Main.ActiveProjectiles) + { + if (proj.active && proj.type == goType && proj.owner == player.whoAmI) + { + proj.timeLeft += 300; + proj.netUpdate = true; + break; + } + } + } + } return false; } diff --git a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson index a3d4771575..bd602efe6b 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson @@ -65,8 +65,9 @@ BlazingStar: { DisplayName: Blazing Star Tooltip: ''' - Tosses up to 3 red hot returning glaives - Stealth strikes throw three glaives with infinite piercing + Tosses a red-hot ricocheting glaive + After bouncing off of tiles, the glaive can re-hit the same enemy + Stealth strikes shred the first enemy they hit and provide rings of high-knockback orbiting glaives ''' } @@ -503,8 +504,8 @@ Glaive: { DisplayName: Glaive Tooltip: ''' - Tosses a very fast and sharp returning glaive - Stealth strikes are faster and can ricochet between enemies, or stick into a single enemy + Tosses a ricocheting glaive + Stealth strikes shred the first enemy they hit and provide a ring of high-knockback orbiting glaives ''' } diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson index c03a360b6d..d33d20d187 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson @@ -323,3 +323,5 @@ WrathwingCinder.DisplayName: Wrathwing Eruption WrathwingFireball.DisplayName: Wrathwing Fireball WrathwingSpear.DisplayName: Wrathwing WulfrumKnifeProj.DisplayName: Wulfrum Knife +GlaiveOrbital.DisplayName: Glaive Orbital +BlazingStarOrbital.DisplayName: Blazing Star Orbital diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index a058d88d82..d23dda15d6 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -358,6 +358,10 @@ namespace CalamityMod.NPCs public const float hyperiusLifePercentThreshold = 0.07f; public int hyperiusFxTimer = 0; + public int glaiveShredTimer = 0; + + public int blazingStarShredTimer = 0; + /// /// Tracks the strength of Calamity's cursor effect; increments by 2 on every frame.
/// If this value reaches , the enemy is afflicted with True Vulnerability Hex. @@ -1048,6 +1052,29 @@ namespace CalamityMod.NPCs manaBurnPeak = 0; playerManaBurnIntensity = 0; } + //This is at the end to make sure the dmg check for particle creations runs properly + if (glaiveShredTimer > 0 || blazingStarShredTimer > 0) + { + int dmg = 0; + if (glaiveShredTimer > 0) + { + dmg += 120; // 60 DPS + glaiveShredTimer--; + } + if (blazingStarShredTimer > 0) + { + dmg += 480; // 240 DPS + blazingStarShredTimer--; + } + npc.lifeRegenCount -= dmg; + if (damage < dmg/12) // 1/6th of the DPS dealt by Glaive Shred shows up as the indicator, unless another debuff does more per tick + damage = dmg/12; + + if (-120 * damage >= npc.lifeRegenCount) + { + GeneralParticleHandler.SpawnParticle(new CustomSpark(npc.Center, new Vector2(1, 0).RotatedByRandom(7), "CalamityMod/Particles/TrientCircularSmear", false, 15, 0.4f + 0.1f * npc.width / 16f, Color.White, new Vector2(0.5f, 1f))); + } + } } public void ApplyDPSDebuff(int lifeRegenValue, int damageValue, ref int lifeRegen, ref int damage) diff --git a/Projectiles/Rogue/BlazingStarOrbital.cs b/Projectiles/Rogue/BlazingStarOrbital.cs new file mode 100644 index 0000000000..367cbe811b --- /dev/null +++ b/Projectiles/Rogue/BlazingStarOrbital.cs @@ -0,0 +1,73 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Rogue +{ + public class BlazingStarOrbital : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Rogue"; + public override string Texture => "CalamityMod/Items/Weapons/Rogue/BlazingStar"; + + private static int Lifetime = 300; + public override void SetStaticDefaults() + { + ProjectileID.Sets.TrailCacheLength[Type] = 3; + ProjectileID.Sets.TrailingMode[Type] = 0; + } + + public override void SetDefaults() + { + Projectile.width = 272; + Projectile.height = 272; + Projectile.friendly = true; + Projectile.tileCollide = false; + Projectile.penetrate = -1; + Projectile.MaxUpdates = 1; + Projectile.timeLeft = Lifetime; + Projectile.DamageType = RogueDamageClass.Instance; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 10; + } + public override void AI() + { + Projectile.Center = Main.player[Projectile.owner].Center; + Projectile.rotation += 0.2f; Lifetime = 300; + Projectile.ai[0]++; + } + + public override bool PreDraw(ref Color lightColor) + { + float distance = MathHelper.Min(Projectile.ai[0] / 15f, 1f); + if (Projectile.timeLeft < 15) + { + distance = Projectile.timeLeft / 15f; + } + int firstRingGlaives = 3; + int secondRingGlaives = 6; + for (var i2 = 0; i2 < 5; i2++)//Afteriamges + { + for (var i = 0; i < firstRingGlaives; i++) + { + float glaiveRot = MathHelper.TwoPi * ((i / (float)firstRingGlaives)); + float opacity = i2 / 5f; + Main.spriteBatch.Draw(TextureAssets.Projectile[Type].Value, Projectile.Center + new Vector2(distance * 64, 0).RotatedBy(Projectile.rotation + glaiveRot + (1f * i2 / 5f)) - Main.screenPosition, null, lightColor * opacity, Main.GlobalTimeWrappedHourly * -10, TextureAssets.Projectile[Type].Size() * 0.5f, 0.5f * opacity + 0.5f, 0, 1); ; + } + for (var i = 0; i < secondRingGlaives; i++) + { + float glaiveRot = MathHelper.TwoPi * ((i / (float)secondRingGlaives)); + float opacity = 1 - i2 / 5f; + Main.spriteBatch.Draw(TextureAssets.Projectile[Type].Value, Projectile.Center + new Vector2(distance * 128, 0).RotatedBy(-Projectile.rotation * 0.5f + glaiveRot + (0.45f * i2 / 5f)) - Main.screenPosition, null, lightColor * opacity, Main.GlobalTimeWrappedHourly * 10, TextureAssets.Projectile[Type].Size() * 0.5f, 0.5f * opacity + 0.5f, 0, 1); ; + } + } + return false; + } + + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + { + modifiers.HitDirectionOverride = -target.DirectionTo(Main.player[Projectile.owner].Center).X.DirectionalSign(); + } + } +} diff --git a/Projectiles/Rogue/BlazingStarProj.cs b/Projectiles/Rogue/BlazingStarProj.cs index a7270c0862..abee87ca43 100644 --- a/Projectiles/Rogue/BlazingStarProj.cs +++ b/Projectiles/Rogue/BlazingStarProj.cs @@ -1,6 +1,4 @@ -using System; -using CalamityMod.Buffs.DamageOverTime; -using CalamityMod.Items.Weapons.Rogue; +using CalamityMod.Projectiles.Typeless; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; @@ -14,9 +12,9 @@ namespace CalamityMod.Projectiles.Rogue public new string LocalizationCategory => "Projectiles.Rogue"; public override string Texture => "CalamityMod/Items/Weapons/Rogue/BlazingStar"; - public static int Lifetime = 1540; - public static int ReboundTime = 60; - public static float Speed = 13f; + private static int Lifetime = 300; + private int timeAlive => Lifetime - Projectile.timeLeft; + private bool hasHit = false; public override void SetStaticDefaults() { @@ -26,108 +24,82 @@ namespace CalamityMod.Projectiles.Rogue public override void SetDefaults() { - Projectile.width = 34; - Projectile.height = 32; + Lifetime = 300; + Projectile.width = 16; + Projectile.height = 16; Projectile.friendly = true; Projectile.tileCollide = true; - Projectile.ignoreWater = true; - Projectile.penetrate = 5; + Projectile.penetrate = 10; + Projectile.MaxUpdates = 3; Projectile.timeLeft = Lifetime; + DrawOffsetX = -10; Projectile.DamageType = RogueDamageClass.Instance; - Projectile.usesIDStaticNPCImmunity = true; - Projectile.idStaticNPCHitCooldown = 10; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = -1; } public override void AI() { - if (Projectile.Calamity().stealthStrike) - Projectile.penetrate = Projectile.maxPenetrate = -1; + Projectile.rotation += 0.175f * Projectile.direction; - // Boomerang rotation - Projectile.rotation += 0.4f * Projectile.direction; - - // Boomerang sound - if (Projectile.soundDelay == 0) + if (timeAlive == 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) - { - Projectile.tileCollide = false; - float returnSpeed = 32.5f; - float acceleration = 2f; - Player owner = Main.player[Projectile.owner]; - - // Delete the projectile if it's excessively far away. - // Relying on the length instead of a second square root call for Normalize is used here for general performance since both the distance - // and normalized vector are used in this code. - float distanceToPlayer = Projectile.Distance(owner.Center); - Vector2 velocity = (owner.Center - Projectile.Center) / distanceToPlayer * returnSpeed; - - // Kill the projectile is if it's super far from the player. - if (distanceToPlayer > 3000f) - Projectile.Kill(); - - // Home back in on the player. - - // No, projectiles do not have a SimpleFlyMovement extension method like NPCs do. - if (Projectile.velocity.X < velocity.X) + Projectile.localNPCHitCooldown = -1; + if (Projectile.Calamity().stealthStrike) { - Projectile.velocity.X = Projectile.velocity.X + acceleration; - if (Projectile.velocity.X < 0f && velocity.X > 0f) - Projectile.velocity.X += acceleration; - } - else if (Projectile.velocity.X > velocity.X) - { - Projectile.velocity.X = Projectile.velocity.X - acceleration; - if (Projectile.velocity.X > 0f && velocity.X < 0f) - Projectile.velocity.X -= acceleration; - } - if (Projectile.velocity.Y < velocity.Y) - { - Projectile.velocity.Y = Projectile.velocity.Y + acceleration; - if (Projectile.velocity.Y < 0f && velocity.Y > 0f) - Projectile.velocity.Y += acceleration; - } - else if (Projectile.velocity.Y > velocity.Y) - { - Projectile.velocity.Y = Projectile.velocity.Y - acceleration; - if (Projectile.velocity.Y > 0f && velocity.Y < 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(); + Projectile.penetrate = -1; + Projectile.MaxUpdates++; } } } - public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) - { - target.AddBuff(BuffID.OnFire3, 180); - } - - public override void OnHitPlayer(Player target, Player.HurtInfo info) - { - target.AddBuff(BuffID.OnFire3, 180); - } - public override bool PreDraw(ref Color lightColor) { CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Type], lightColor, 1); return false; } - // Make the star bounce on tiles. + void Ricochet() + { + float maxDistance = 1600f; + float npcDistCompare = 1600f; + int index = -1; + foreach (NPC n in Main.ActiveNPCs) // Find an NPC to ricochet to + { + if (!n.CanBeChasedBy(Projectile) || !Projectile.WithinRange(n.Center, maxDistance) || Projectile.localNPCImmunity[n.whoAmI] != 0) + continue; + + float currentNPCDist = Vector2.Distance(n.Center, Projectile.Center); + if ((currentNPCDist < npcDistCompare) && (Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))) + { + npcDistCompare = currentNPCDist; + index = n.whoAmI; + } + } + + // If you find an NPC, ricochet in their direction and reset iframes for them + if (index != -1) + { + Projectile.ai[1] = index; + Projectile.velocity = CalamityUtils.CalculatePredictiveAimToTargetMaxUpdates(Projectile.Center, Main.npc[index], Projectile.velocity.Length(), Projectile.MaxUpdates); + } + } + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) + { + if (Projectile.Calamity().stealthStrike) + { + if (!hasHit) + { + target.Calamity().blazingStarShredTimer += 300; + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), 0, 0, Projectile.owner, 0f, 0.1f); + } + hasHit = true; + } + Ricochet(); + } + + + // Make it bounce on tiles. public override bool OnTileCollide(Vector2 oldVelocity) { // Impacts the terrain even though it bounces off. @@ -142,7 +114,10 @@ namespace CalamityMod.Projectiles.Rogue { Projectile.velocity.Y = -oldVelocity.Y; } - Projectile.ai[0] = 1f; + Projectile.ResetLocalNPCHitImmunity(); + Ricochet(); + if (Projectile.penetrate > 0) + Projectile.penetrate--; return false; } } diff --git a/Projectiles/Rogue/GlaiveOrbital.cs b/Projectiles/Rogue/GlaiveOrbital.cs new file mode 100644 index 0000000000..bbf9278897 --- /dev/null +++ b/Projectiles/Rogue/GlaiveOrbital.cs @@ -0,0 +1,66 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Rogue +{ + public class GlaiveOrbital : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Rogue"; + public override string Texture => "CalamityMod/Items/Weapons/Rogue/Glaive"; + + private static int Lifetime = 300; + + public override void SetStaticDefaults() + { + ProjectileID.Sets.TrailCacheLength[Type] = 3; + ProjectileID.Sets.TrailingMode[Type] = 0; + } + + public override void SetDefaults() + { + Projectile.width = 136; + Projectile.height = 136; + Projectile.friendly = true; + Projectile.tileCollide = false; + Projectile.penetrate = -1; + Projectile.MaxUpdates = 1; + Projectile.timeLeft = Lifetime; + Projectile.DamageType = RogueDamageClass.Instance; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 10; + } + public override void AI() + { + Projectile.Center = Main.player[Projectile.owner].Center; + Projectile.rotation += 0.2f; Projectile.ai[0]++; + } + + public override bool PreDraw(ref Color lightColor) + { + float distance = MathHelper.Min(MathHelper.Lerp(0, 64, Projectile.ai[0] / 15f), 64f); + if (Projectile.timeLeft < 15) + { + distance = MathHelper.Lerp(0, 64, Projectile.timeLeft / 15f); + } + int glaiveCount = 3; + for (var i2 = 0; i2 < 5; i2++)//Afteriamges + { + for (var i = 0; i < glaiveCount; i++) + { + float glaiveRot = MathHelper.TwoPi * ((i / (float)glaiveCount)); + float opacity = i2 / 5f; + Main.spriteBatch.Draw(TextureAssets.Projectile[Type].Value, Projectile.Center + new Vector2(distance, 0).RotatedBy(Projectile.rotation + glaiveRot + (1f * i2 / 5f)) - Main.screenPosition, null, lightColor * opacity, Main.GlobalTimeWrappedHourly * -10, TextureAssets.Projectile[Type].Size() * 0.5f, 0.5f * opacity + 0.5f, 0, 1); ; + } + } + return false; + } + + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + { + modifiers.HitDirectionOverride = -target.DirectionTo(Main.player[Projectile.owner].Center).X.DirectionalSign(); + } + } +} diff --git a/Projectiles/Rogue/GlaiveProj.cs b/Projectiles/Rogue/GlaiveProj.cs index 40c9a6b8d6..b571cc12c5 100644 --- a/Projectiles/Rogue/GlaiveProj.cs +++ b/Projectiles/Rogue/GlaiveProj.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using CalamityMod.Items.Weapons.Rogue; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; using Terraria.ID; @@ -15,9 +12,8 @@ namespace CalamityMod.Projectiles.Rogue public override string Texture => "CalamityMod/Items/Weapons/Rogue/Glaive"; private static int Lifetime = 180; - private static int ReboundTime = 40; - private List HitNPCs = []; - public ref float AIState => ref Projectile.ai[0]; // 0 - Going out. 1 - Returning. 2 - Stealth stuck to enemy. + private int timeAlive => Lifetime - Projectile.timeLeft; + private bool hasHit = false; public override void SetStaticDefaults() { @@ -31,111 +27,26 @@ namespace CalamityMod.Projectiles.Rogue Projectile.height = 16; Projectile.friendly = true; Projectile.tileCollide = true; - Projectile.penetrate = 3; - Projectile.MaxUpdates = 3; + Projectile.penetrate = 4; + Projectile.MaxUpdates = 2; Projectile.timeLeft = Lifetime; DrawOffsetX = -10; Projectile.DamageType = RogueDamageClass.Instance; - Projectile.usesIDStaticNPCImmunity = true; - Projectile.idStaticNPCHitCooldown = 20; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = -1; } public override void AI() { - // Boomerang rotation Projectile.rotation += 0.175f * Projectile.direction; - // Boomerang sound - if (Projectile.soundDelay == 0) + if (timeAlive == 0) { - Projectile.soundDelay = 8; - SoundEngine.PlaySound(SoundID.Item7, Projectile.position); - } - - // Returns after some number of frames in the air - if (Projectile.timeLeft < Lifetime - ReboundTime) - AIState = 1f; - - if (AIState == 0f && Projectile.ai[1] >= 0) - { - if (Projectile.timeLeft % 10 == 0) - Projectile.velocity = Utils.DirectionTo(Projectile.Center, Main.npc[(int)Projectile.ai[1]].Center) * Projectile.velocity.Length(); - } - - if (AIState == 1f) - { - Projectile.tileCollide = false; - - float returnSpeed = Glaive.Speed * 1.6f; - float acceleration = 1.4f; - + Projectile.localNPCHitCooldown = -1; if (Projectile.Calamity().stealthStrike) { - returnSpeed *= Glaive.StealthSpeedMult; - acceleration *= Glaive.StealthSpeedMult; - } - - 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(); - } - - if (AIState == 2f) - { - Projectile.tileCollide = false; - Projectile.velocity = Vector2.Zero; - if (Main.npc[(int)Projectile.ai[1]].active) - { - if (Projectile.FinalExtraUpdate()) - Projectile.Center += Main.npc[(int)Projectile.ai[1]].velocity; - } - else - AIState = 1f; - - if (Projectile.penetrate == -1) - { - AIState = 1f; + Projectile.penetrate = -1; + Projectile.MaxUpdates++; } } } @@ -146,78 +57,43 @@ namespace CalamityMod.Projectiles.Rogue return false; } + void Ricochet() + { + float maxDistance = 1000f; + float npcDistCompare = 1000f; + int index = -1; + foreach (NPC n in Main.ActiveNPCs) // Find an NPC to ricochet to + { + if (!n.CanBeChasedBy(Projectile) || !Projectile.WithinRange(n.Center, maxDistance) || Projectile.localNPCImmunity[n.whoAmI] != 0) + continue; + + float currentNPCDist = Vector2.Distance(n.Center, Projectile.Center); + if ((currentNPCDist < npcDistCompare) && (Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))) + { + npcDistCompare = currentNPCDist; + index = n.whoAmI; + } + } + + // If you find an NPC, ricochet in their direction and reset iframes for them + if (index != -1) + { + Projectile.ai[1] = index; + Projectile.velocity = CalamityUtils.CalculatePredictiveAimToTargetMaxUpdates(Projectile.Center, Main.npc[index], Projectile.velocity.Length(), Projectile.MaxUpdates); + } + } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { if (Projectile.Calamity().stealthStrike) { - if (AIState != 2f) - { - HitNPCs.Add(target.whoAmI); - float maxDistance = 1000f; - float npcDistCompare = 1000f; - int index = -1; - foreach (NPC n in Main.ActiveNPCs) // Find an NPC to ricochet to - { - if (!n.CanBeChasedBy(Projectile) || !Projectile.WithinRange(n.Center, maxDistance) || HitNPCs.Contains(n.whoAmI)) - continue; - - float currentNPCDist = Vector2.Distance(n.Center, Projectile.Center); - if ((currentNPCDist < npcDistCompare) && (Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))) - { - npcDistCompare = currentNPCDist; - index = n.whoAmI; - } - } - - // If you find an NPC, ricochet in their direction and reset iframes for them - if (index != -1) - { - Projectile.ai[1] = index; - Projectile.velocity = Utils.DirectionTo(Projectile.Center, Main.npc[index].Center) * Projectile.velocity.Length(); - Projectile.perIDStaticNPCImmunity[Type][index] = Main.GameUpdateCount; // Resets the iframes - } - else // If there are no new NPCs to ricochet to, try to go back to an already hit NPC - { - maxDistance = 1000f; - npcDistCompare = 1000f; - index = -1; - foreach (NPC n in Main.ActiveNPCs) - { - if (!n.CanBeChasedBy(Projectile) || !Projectile.WithinRange(n.Center, maxDistance) || n.whoAmI == target.whoAmI) - continue; - - float currentNPCDist = Vector2.Distance(n.Center, Projectile.Center); - if ((currentNPCDist < npcDistCompare) && (Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1))) - { - npcDistCompare = currentNPCDist; - index = n.whoAmI; - } - } - - // If this can find an NPC, ricochet back to them - if (index != -1) - { - Projectile.ai[1] = index; - Projectile.velocity = Utils.DirectionTo(Projectile.Center, Main.npc[index].Center) * Projectile.velocity.Length(); - Projectile.perIDStaticNPCImmunity[Type][index] = Main.GameUpdateCount; // Resets the iframes - } - else // If you still find no one new, stick to the hit NPC - { - Projectile.ai[1] = target.whoAmI; - AIState = 2f; - } - } - } - Projectile.timeLeft = Lifetime + ReboundTime * 3; - } - // After its last hit, starts returning instead of vanishing. Can pierce infinitely on the way back. - if (Projectile.penetrate == 1) - { - Projectile.penetrate = -1; - AIState = 1f; + if (!hasHit) + target.Calamity().glaiveShredTimer += 300; + hasHit = true; } + Ricochet(); } + // Make it bounce on tiles. public override bool OnTileCollide(Vector2 oldVelocity) { @@ -233,7 +109,9 @@ namespace CalamityMod.Projectiles.Rogue { Projectile.velocity.Y = -oldVelocity.Y; } - AIState = 1f; + Ricochet(); + if (Projectile.penetrate > 0) + Projectile.penetrate--; return false; } }