From d0d75a466234f8cc998f7b6ea07af744dba16e33 Mon Sep 17 00:00:00 2001 From: Memes <114233643+Mr-Memes@users.noreply.github.com> Date: Sun, 5 Mar 2023 01:59:00 +0100 Subject: [PATCH] Herring Staff remastered. 1 - Made Herring Staff spawn 1 herring per minion slot. 2 - On use, it spawns an invisible minion and 3 decoration herrings. 3 - Uses Local I-Frames now. --- Buffs/Summon/Herring.cs | 4 +- Items/Weapons/Summon/HerringStaff.cs | 26 +++--- Projectiles/Summon/HerringAI.cs | 104 ++++++++++++++++++++++ Projectiles/Summon/HerringMinion.cs | 127 ++++++++++++++++----------- Projectiles/Summon/HerringMinion.png | Bin 2009 -> 1190 bytes 5 files changed, 197 insertions(+), 64 deletions(-) create mode 100644 Projectiles/Summon/HerringAI.cs diff --git a/Buffs/Summon/Herring.cs b/Buffs/Summon/Herring.cs index 43a5e6fcfa..8ba470808e 100644 --- a/Buffs/Summon/Herring.cs +++ b/Buffs/Summon/Herring.cs @@ -1,4 +1,4 @@ -using CalamityMod.CalPlayer; +using CalamityMod.CalPlayer; using CalamityMod.Projectiles.Summon; using Terraria; using Terraria.ModLoader; @@ -19,7 +19,7 @@ namespace CalamityMod.Buffs.Summon public override void Update(Player player, ref int buffIndex) { CalamityPlayer modPlayer = player.Calamity(); - if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) + if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) { modPlayer.herring = true; } diff --git a/Items/Weapons/Summon/HerringStaff.cs b/Items/Weapons/Summon/HerringStaff.cs index 869db11aeb..8219bc29e8 100644 --- a/Items/Weapons/Summon/HerringStaff.cs +++ b/Items/Weapons/Summon/HerringStaff.cs @@ -12,35 +12,35 @@ namespace CalamityMod.Items.Weapons.Summon public override void SetStaticDefaults() { DisplayName.SetDefault("Herring Staff"); - Tooltip.SetDefault("Summons a herring to fight for you\n" + - "Each herring takes only half of a minion slot"); + Tooltip.SetDefault("Summons a group of herrings to fight for you"); SacrificeTotal = 1; } public override void SetDefaults() { Item.damage = 17; + Item.knockBack = 1.25f; Item.mana = 10; + + Item.shoot = ModContent.ProjectileType(); + Item.width = Item.height = 48; Item.useTime = Item.useAnimation = 30; - Item.useStyle = ItemUseStyleID.Swing; - Item.noMelee = true; - Item.knockBack = 1.25f; - Item.value = CalamityGlobalItem.Rarity3BuyPrice; - Item.rare = ItemRarityID.Orange; - Item.UseSound = SoundID.Item21; - Item.autoReuse = true; - Item.shoot = ModContent.ProjectileType(); + Item.DamageType = DamageClass.Summon; + Item.useStyle = ItemUseStyleID.Swing; + Item.UseSound = SoundID.Item21; + Item.rare = ItemRarityID.Orange; + Item.value = CalamityGlobalItem.Rarity3BuyPrice; + Item.autoReuse = true; + Item.noMelee = true; } public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { if (player.altFunctionUse != 2) { - position = Main.MouseWorld; - velocity = Vector2.Zero; - int p = Projectile.NewProjectile(source, position, velocity, type, damage, knockback, player.whoAmI); + int p = Projectile.NewProjectile(source, Main.MouseWorld, Vector2.Zero, type, damage, knockback, player.whoAmI); if (Main.projectile.IndexInRange(p)) Main.projectile[p].originalDamage = Item.damage; } diff --git a/Projectiles/Summon/HerringAI.cs b/Projectiles/Summon/HerringAI.cs new file mode 100644 index 0000000000..071bdda1b9 --- /dev/null +++ b/Projectiles/Summon/HerringAI.cs @@ -0,0 +1,104 @@ +using CalamityMod.Buffs.Summon; +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Summon +{ + public class HerringAI : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public Player Owner => Main.player[Projectile.owner]; + + public CalamityPlayer moddedOwner => Owner.Calamity(); + + public bool CheckForSpawning = false; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Herring AI"); + ProjectileID.Sets.MinionSacrificable[Projectile.type] = true; + ProjectileID.Sets.MinionTargettingFeature[Projectile.type] = true; + } + + public override void SetDefaults() + { + Projectile.minionSlots = 1f; + Projectile.localNPCHitCooldown = 35; + Projectile.penetrate = -1; + + Projectile.width = Projectile.height = 24; + + Projectile.DamageType = DamageClass.Summon; + Projectile.netImportant = true; + Projectile.usesLocalNPCImmunity = true; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + Projectile.minion = true; + } + + public override void AI() + { + CheckMinionExistance(); // Checks if the minion can still exist. + OnSpawn(); // Makes a dust spawn effect and spawns decorative herrings. + + Projectile.rotation = (Projectile.spriteDirection == -1) ? Projectile.velocity.ToRotation() + MathHelper.Pi : Projectile.velocity.ToRotation(); + Projectile.spriteDirection = (Projectile.velocity.X > 0).ToDirectionInt(); + // Although the sprite is invisible, we'll keep track of it's direction and rotation so we can later apply it to the decorative herrings. + + Projectile.ChargingMinionAI(1200f, 1500f, 2200f, 150f, 0, 24f, 15f, 4f, new Vector2(0f, -60f), 12f, 12f, true, true, 1); // The AI of the minion. + + Projectile.netUpdate = true; + } + + public void CheckMinionExistance() + { + Owner.AddBuff(ModContent.BuffType(), 1); + if (Projectile.type == ModContent.ProjectileType()) + { + if (Owner.dead) + moddedOwner.herring = false; + if (moddedOwner.herring) + Projectile.timeLeft = 2; + } + } + + public void OnSpawn() + { + if (CheckForSpawning == false) + { + int herringAmount = 3; + for (int herringIndex = 0; herringIndex < herringAmount; herringIndex++) + { + float angle = MathHelper.TwoPi / herringAmount * herringIndex; + Vector2 velocity = angle.ToRotationVector2(); + int herring = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), 0, 0f, Projectile.owner, Projectile.whoAmI, angle); + // We'll keep track of the index of the invisible minion and the offset in which each herring spawns so we can later apply it to the decorative herrings. + if (Main.projectile.IndexInRange(herring)) + Main.projectile[herring].originalDamage = 0; + } + // Spawns the decorative fish. + + int dustAmount = 100; + for (int dustIndex = 0; dustIndex < dustAmount; dustIndex++) + { + float angle = MathHelper.TwoPi / dustAmount * dustIndex; + Vector2 velocity = angle.ToRotationVector2() * 20f; + Dust spawnDust = Dust.NewDustPerfect(Projectile.Center, DustID.Water, velocity); + spawnDust.customData = false; + spawnDust.velocity *= 0.3f; + spawnDust.scale = velocity.Length() * 0.1f; + } + // Makes the dust spawn effect. + + CheckForSpawning = true; + } + } + + public override bool OnTileCollide(Vector2 oldVelocity) => false; + } +} diff --git a/Projectiles/Summon/HerringMinion.cs b/Projectiles/Summon/HerringMinion.cs index 1e34673fcd..f6b9cae114 100644 --- a/Projectiles/Summon/HerringMinion.cs +++ b/Projectiles/Summon/HerringMinion.cs @@ -1,7 +1,4 @@ -using CalamityMod.Buffs.Summon; -using CalamityMod.CalPlayer; -using Microsoft.Xna.Framework; -using System; +using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -12,74 +9,69 @@ namespace CalamityMod.Projectiles.Summon { public Player Owner => Main.player[Projectile.owner]; - public CalamityPlayer moddedOwner => Owner.Calamity(); - - public int dustEffect = 3; + public ref float MinionOrigin => ref Projectile.ai[0]; + + public ref float HerringPosition => ref Projectile.ai[1]; public override void SetStaticDefaults() { DisplayName.SetDefault("Herring"); Main.projFrames[Projectile.type] = 8; - ProjectileID.Sets.MinionSacrificable[Projectile.type] = true; - ProjectileID.Sets.MinionTargettingFeature[Projectile.type] = true; + ProjectileID.Sets.MinionShot[Projectile.type] = true; } public override void SetDefaults() { - Projectile.width = 60; - Projectile.height = 24; + Projectile.penetrate = -1; + + Projectile.width = 42; + Projectile.height = 14; + + Projectile.DamageType = DamageClass.Summon; Projectile.netImportant = true; Projectile.friendly = true; Projectile.ignoreWater = true; - Projectile.minionSlots = 0.5f; - Projectile.penetrate = -1; Projectile.tileCollide = false; Projectile.minion = true; - Projectile.DamageType = DamageClass.Summon; - Projectile.usesIDStaticNPCImmunity= true; - Projectile.idStaticNPCHitCooldown = 8; } public override void AI() { - CheckMinionExistance(); // Checks if the minion can still exist. - SpawnEffect(); // Does a dust effectw where it spawns. + NPC target = Projectile.Center.MinionHoming(1200f, Owner); // Detects a target. + Projectile minionAI = Main.projectile[(int)MinionOrigin]; // Gets the invisible minion. + + if (target is not null) + TargetPosition(minionAI); // The minions position themselves near the invisible minion to seem like they're ramming all together. + else + FollowOrigin(minionAI); // Vibes around their respective invisible minion. + + CheckMinionExistance(); // Checks if the decorative herring can still exist, if the invisible minion despawns, so do these ones. DoAnimation(); // Does the animation of the minion. - PointInRightDirection(); // Points at where it's going. + PointInRightDirection(minionAI, target); // Points in the correct direction. + Projectile.MinionAntiClump(); // Prevents the minion from cluttering on one spot. - Projectile.rotation = Projectile.velocity.X * 0.05f; // Does a little movement effect with it's rotation when it's moving. - - Projectile.ChargingMinionAI(1200f, 1500f, 2200f, 150f, 0, 24f, 15f, 4f, new Vector2(0f, -60f), 12f, 12f, true, true, 1); + Projectile.netUpdate = true; } + #region Methods + public void CheckMinionExistance() { - Owner.AddBuff(ModContent.BuffType(), 1); - if (Projectile.type == ModContent.ProjectileType()) - { - if (Owner.dead) - moddedOwner.herring = false; - if (moddedOwner.herring) - Projectile.timeLeft = 2; - } - } + Projectile minionAI = Main.projectile[(int)MinionOrigin]; - public void SpawnEffect() - { - if (dustEffect > 0) + if (MinionOrigin < 0 || MinionOrigin >= Main.projectile.Length) { - int num226 = 36; - for (int num227 = 0; num227 < num226; num227++) - { - Vector2 vector6 = Vector2.Normalize(Projectile.velocity) * new Vector2(Projectile.width / 2f, Projectile.height) * 0.75f; - vector6 = vector6.RotatedBy((double)((num227 - (num226 / 2 - 1)) * 6.28318548f / num226), default) + Projectile.Center; - Vector2 vector7 = vector6 - Projectile.Center; - int num228 = Dust.NewDust(vector6 + vector7, 0, 0, DustID.Water, vector7.X * 1.75f, vector7.Y * 1.75f, 100, default, 1.1f); - Main.dust[num228].noGravity = true; - Main.dust[num228].velocity = vector7; - } - dustEffect--; + Projectile.Kill(); + return; } + + if (!minionAI.active || minionAI.type != ModContent.ProjectileType()) + { + Projectile.Kill(); + return; + } + + Projectile.timeLeft = 2; } public void DoAnimation() @@ -88,12 +80,49 @@ namespace CalamityMod.Projectiles.Summon Projectile.frame = Projectile.frameCounter / 8 % Main.projFrames[Projectile.type]; } - public void PointInRightDirection() + public void PointInRightDirection(Projectile origin, NPC target) { - if (Math.Abs(Projectile.velocity.X) > 0.1f) - Projectile.spriteDirection = Math.Sign(Projectile.velocity.X); + if (target is not null) + { + Projectile.rotation = origin.rotation; + Projectile.spriteDirection = origin.spriteDirection; + // Because when there's a target, the herrings act like the invisible minion, we call it's direction and rotation so that it has a proper look. + } + else + { + Projectile.rotation = (Projectile.spriteDirection == -1) ? Projectile.velocity.ToRotation() + MathHelper.Pi : Projectile.velocity.ToRotation(); + Projectile.spriteDirection = (Projectile.velocity.X > 0).ToDirectionInt(); + // If there isn't a target, just look at where it's going. + } } - public override bool OnTileCollide(Vector2 oldVelocity) => false; + public void FollowOrigin(Projectile origin) + { + if (Projectile.WithinRange(origin.Center, 1200f) && !Projectile.WithinRange(origin.Center, 300f)) // If the minion starts to get far, force the minion to go to you. + Projectile.velocity = (origin.Center - Projectile.Center) / 30f; + else if (!Projectile.WithinRange(origin.Center, 160f)) // The minion will change directions to you if it's going away from you, meaning it'll just hover around you. + Projectile.velocity = (Projectile.velocity * 37f + Projectile.SafeDirectionTo(origin.Center) * 17f) / 40f; + + // Teleport to the owner if sufficiently far away. + if (!Projectile.WithinRange(origin.Center, 1200f)) + { + Projectile.position = origin.Center; + Projectile.velocity *= 0.3f; + } + } + + public void TargetPosition(Projectile origin) + { + Projectile.Center = Vector2.Lerp(Projectile.Center, origin.Center + HerringPosition.ToRotationVector2() * 20f, 0.2f); + Projectile.velocity = Vector2.Zero; + // We set the herrings to their respective offset from the invisible minion's position, and because it's following it's position, we don't give the herring velocity. + + int trailDust = Dust.NewDust(Projectile.Center, Projectile.width, Projectile.height, DustID.Water, -Projectile.velocity.X, -Projectile.velocity.Y); + Main.dust[trailDust].noGravity = true; + Main.dust[trailDust].customData = false; + // When ramming, tries to give the herrings a trail of water, as if they were going fast. + } + + #endregion } } diff --git a/Projectiles/Summon/HerringMinion.png b/Projectiles/Summon/HerringMinion.png index 5e8bef7fba0ca913f83c571a16b4f05a28765428..e4e82c253da16ea70fce9f8a7c6adc132def6959 100644 GIT binary patch literal 1190 zcmV;X1X=ruP)Px(MoC0LRCr$Pojq?8K@f&*egFgtiZ}+ENC>Bk5N;4ik%(v_P$;0K&99+Ii$sU` z5Qr*4LQtB5GAI%a5GMr%AIc91(#B)4L)JIG+1ZeZqMzO(Bocz z?dac4zZkq}b9TjAdD4#6f?}|R?n2a$;odO3uB&V|Ma4mL4H0YylsvWE3ktq}y%m-} z_YWq9=(oL36GdyA13kU86ncC(+>d(xeCx@HJ-ygnj*e0D<%JUzd7VWNURzI=~9 zPbm&cj}=u93f+PbI9%+8x1h(Vo`P~%Hmqc?cO^90+4&rnyB`K&`DlGEEN`#uhUMC` zJJF`_{>Q^=1{7lM^36U;(TM@rYPGQ9shGvF`r!KUv2yVBPguhD?^sdwpa8hCx*B@$ zZhJct3xB`iqaBpH(LIiBc+6iq6P|89eH)hR8xNz;Uv54QuQ%@Bir&Xc!kMgX4ivhT zIz!;lfc9_{U+r`vW#A0;YVh&IaK78W7R4ZLgmZ$iqUu4bj$ZgYbtX!U06sOR_Cw94 z$k~$_P^$7$?Z}Es0Z_N=pj4%(?Zgz#m5@V6W)D={+)-nss$DTqZcK^0P*BPoC^mU& zTqsu545+)%Ty|N#xx%p2dRtv>PJ%E@2#couM3$1da>OfP; ziJ20k8BlH-$X#D7!{>q(vmy?fTYClpq3GN^^%c2Q?lbiZ3cO$J(qU>6V#eH=0i`N0)lMwK z&kgLLW)$Tn;>CV|Pzzej+;L+{95mMuiMvp9pz5bvf}-j{r!6hI3#CqA%~bG?K4%(ZR|ohyuR3Nl<i&+saSTQT&pt%)r7s^$%xVftfTnv;OQ(g-l4e@_}*P*_|n7T4o z-OYT>l^Ch>LmRitUJFh94N~pDlrb~i(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