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.
This commit is contained in:
Memes authored and Cameron Ewell committed 2023-03-13 11:19:02 -04:00
1 parent 027bb4de70
commit d0d75a4662
5 files changed
+197 -64

No files matched your search

+2 -2
View File
@@ -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<HerringMinion>()] > 0)
if (player.ownedProjectileCounts[ModContent.ProjectileType<HerringAI>()] > 0)
{
modPlayer.herring = true;
}
+13 -13
View File
@@ -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<HerringAI>();
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<HerringMinion>();
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;
}
+104
View File
@@ -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<Herring>(), 1);
if (Projectile.type == ModContent.ProjectileType<HerringAI>())
{
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<HerringMinion>(), 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;
}
}
+78 -49
View File
@@ -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<Herring>(), 1);
if (Projectile.type == ModContent.ProjectileType<HerringMinion>())
{
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<HerringAI>())
{
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
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB