diff --git a/Projectiles/Summon/BelladonnaPetal.cs b/Projectiles/Summon/BelladonnaPetal.cs index 8b14bf0a79..ad834aeacb 100644 --- a/Projectiles/Summon/BelladonnaPetal.cs +++ b/Projectiles/Summon/BelladonnaPetal.cs @@ -20,7 +20,7 @@ namespace CalamityMod.Projectiles.Summon // A variable where the potential target will be written on. public NPC targetFound; - + public override void SetStaticDefaults() { ProjectileID.Sets.MinionShot[Projectile.type] = true; @@ -78,7 +78,7 @@ namespace CalamityMod.Projectiles.Summon } // Check for it so it doesn't update the velocity indefinetly, meaning it would be homing. - if (CheckForFiring == 0f) + if (CheckForFiring == 0f) { Projectile.velocity = CalamityUtils.CalculatePredictiveAimToTarget(Projectile.Center, targetFound, BelladonnaSpiritStaff.PetalVelocity); @@ -87,7 +87,7 @@ namespace CalamityMod.Projectiles.Summon SoundEngine.PlaySound(SoundID.Grass, Projectile.Center); CheckForFiring = 1f; - Projectile.netUpdate= true; + Projectile.netUpdate = true; } // In case the shot was about to fade out, un-fade. @@ -97,7 +97,6 @@ namespace CalamityMod.Projectiles.Summon // If there's target, but 1 second hasn't passed, rotate to point at the target, while still having gravity. else if (target != null && AITimer < BelladonnaSpiritStaff.PetalTimeBeforeTargetting) { - // "(AITimer / It's maxuimum value)" so it's a fraction between 0 and 1. Projectile.rotation = MathHelper.Lerp(Projectile.rotation, (target.Center - Projectile.Center).ToRotation() + MathHelper.PiOver2, @@ -108,7 +107,7 @@ namespace CalamityMod.Projectiles.Summon // Puts the potentialTarget on this variable that won't update constantly so the projectile doesn't become incredibly homing. targetFound = target; - + Projectile.netUpdate = true; } diff --git a/Projectiles/Summon/BelladonnaSpirit.cs b/Projectiles/Summon/BelladonnaSpirit.cs index d6f4fd1daa..d4693f2afe 100644 --- a/Projectiles/Summon/BelladonnaSpirit.cs +++ b/Projectiles/Summon/BelladonnaSpirit.cs @@ -1,179 +1,126 @@ -using CalamityMod.Buffs.Summon; -using CalamityMod.CalPlayer; +using System; +using CalamityMod.Buffs.Summon; using CalamityMod.Items.Weapons.Summon; +using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; -using System; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.DataStructures; -using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Summon { - public class BelladonnaSpirit : ModProjectile, ILocalizedModType + public class BelladonnaSpirit : BaseMinionProjectile { - public new string LocalizationCategory => "Projectiles.Summon"; - - public Player Owner => Main.player[Projectile.owner]; - public CalamityPlayer ModdedOwner => Owner.Calamity(); - public NPC Target => Owner.Center.MinionHoming(BelladonnaSpiritStaff.EnemyDistanceDetection, Owner, CalamityPlayer.areThereAnyDamnBosses); - public ref float PetalFireTimer => ref Projectile.ai[0]; - - public override void SetStaticDefaults() - { - Main.projFrames[Projectile.type] = 5; - ProjectileID.Sets.MinionSacrificable[Projectile.type] = true; - ProjectileID.Sets.MinionTargettingFeature[Projectile.type] = true; - } + public override int AssociatedProjectileTypeID => ModContent.ProjectileType(); + public override int AssociatedBuffTypeID => ModContent.BuffType(); + public override ref bool AssociatedMinionBool => ref ModdedOwner.belladonaSpirit; + public override bool PreHardmodeMinionTileVision => true; + public override int AnimationFrames => 5; + public ref float ShootingTimer => ref Projectile.ai[0]; public override void SetDefaults() { - Projectile.minionSlots = 1; - Projectile.penetrate = -1; - + base.SetDefaults(); Projectile.width = 28; Projectile.height = 48; - - Projectile.DamageType = DamageClass.Summon; - Projectile.netImportant = true; - Projectile.friendly = true; - Projectile.minion = true; - Projectile.tileCollide = false; } - public override void AI() - { - // Checks if the minion can still exist. - CanMinionExist(); - - // Does the animation of the minion. - DoAnimation(Target); - - // Points in the right directions. - PointInDirection(Target); - - // Vibes around the player. + public override void MinionAI() + { FollowPlayer(); + if (Target != null) + AttackTarget(); - // The minions push eachother to not clump. Projectile.MinionAntiClump(); - - // If there's a target, it'll shoot at it. - if (Target is not null) - TargetNPC(); + Projectile.spriteDirection = Target == null ? MathF.Sign(Projectile.velocity.X) : MathF.Sign(Target.Center.X - Projectile.Center.X); Projectile.netUpdate = true; + if (Projectile.netSpam >= 10) + Projectile.netSpam = 9; } - #region Methods - - public void CanMinionExist() - { - Owner.AddBuff(ModContent.BuffType(), 1); - if (Projectile.type == ModContent.ProjectileType()) - { - if (Owner.dead) - ModdedOwner.belladonaSpirit = false; - if (ModdedOwner.belladonaSpirit) - Projectile.timeLeft = 2; - } - } - - public override void OnSpawn(IEntitySource source) - { - int dustAmount = 45; - for (int dustIndex = 0; dustIndex < dustAmount; dustIndex++) - { - float angle = MathHelper.TwoPi / 45f * dustIndex; - Vector2 velocity = angle.ToRotationVector2() * Main.rand.NextFloat(3f, 4.5f); - Dust spawnDust = Dust.NewDustPerfect(Projectile.Center, 39, velocity); - spawnDust.noGravity = true; - spawnDust.scale = velocity.Length() * 0.1f; - spawnDust.velocity *= 0.3f; - } - } - - public void DoAnimation(NPC target) - { - int speedModifier = (target is not null) ? 2 : 1; - - Projectile.frameCounter++; - Projectile.frame = Projectile.frameCounter / (Main.projFrames[Projectile.type] * speedModifier) % Main.projFrames[Projectile.type]; - } - - public void PointInDirection(NPC target) - { - // If there's a target look at the target. - if (target is not null) - Projectile.spriteDirection = ((target.Center.X - Projectile.Center.X) < 0).ToDirectionInt(); - - // If there's not a target, the minion just points where it's going. - else - if (Math.Abs(Projectile.velocity.X) > 0.01f) - Projectile.spriteDirection = -Math.Sign(Projectile.velocity.X); - } + #region AI Methods public void FollowPlayer() { // If the minion starts to get far, force the minion to go to you. - if (Projectile.WithinRange(Owner.Center, BelladonnaSpiritStaff.EnemyDistanceDetection) && !Projectile.WithinRange(Owner.Center, 300f)) + if (Projectile.WithinRange(Owner.Center, MaxEnemyDistanceDetection) && !Projectile.WithinRange(Owner.Center, 300f)) Projectile.velocity = (Owner.Center - Projectile.Center) / 30f; // The minion will change directions to you if it's going away from you, meaning it'll just hover around you. - else if (!Projectile.WithinRange(Owner.Center, 160f)) + else if (!Projectile.WithinRange(Owner.Center, 160f)) Projectile.velocity = (Projectile.velocity * 37f + Projectile.SafeDirectionTo(Owner.Center) * 17f) / 40f; // Teleport to the owner if sufficiently far away. - if (!Projectile.WithinRange(Owner.Center, BelladonnaSpiritStaff.EnemyDistanceDetection)) + if (!Projectile.WithinRange(Owner.Center, MaxEnemyDistanceDetection)) { Projectile.position = Owner.Center; Projectile.velocity *= 0.3f; } } - public void TargetNPC() + public void AttackTarget() { // The minion will slowly go up until it throws the petal. // This essentially makes the minion stay above you and trigger the "Turn back to player", it'll do this continuously, giving the effect of bouncing. // Yes, it's very wacky. You can make it better if you wish. - Projectile.velocity.Y -= MathHelper.Lerp(0, 0.005f, PetalFireTimer % BelladonnaSpiritStaff.FireRate); - - if (Main.myPlayer == Projectile.owner) - FirePetals(); + Projectile.velocity.Y -= MathHelper.Lerp(0, 0.005f, ShootingTimer % BelladonnaSpiritStaff.FireRate); - if (PetalFireTimer < BelladonnaSpiritStaff.FireRate) - PetalFireTimer++; - } - - public void FirePetals() - { - if (PetalFireTimer == BelladonnaSpiritStaff.FireRate) // Every 75 frames, throws a petal. + ShootingTimer++; + if (ShootingTimer == BelladonnaSpiritStaff.FireRate && Main.myPlayer == Projectile.owner) // Every 75 frames, throws a petal. { // Throws the petal upwards with a random force and inherits the minion's speed. Vector2 petalShootVelocity = (-Vector2.UnitY * Main.rand.NextFloat(7f, 8.5f)) + Vector2.UnitX * Projectile.velocity.X + Vector2.UnitY * Projectile.velocity.Y * 0.35f; - - int petal = Projectile.NewProjectile(Projectile.GetSource_FromThis(), + + Projectile petal = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), Projectile.Center, petalShootVelocity, - ModContent.ProjectileType(), - Projectile.damage, - Projectile.knockBack, + ModContent.ProjectileType(), + Projectile.damage, + Projectile.knockBack, Projectile.owner); - - if (Main.projectile.IndexInRange(petal)) - { - Main.projectile[petal].rotation = Main.rand.NextFloat(0, MathHelper.TwoPi); - } + petal.rotation = Main.rand.NextFloat(0, MathHelper.TwoPi); // Resets the timer. - PetalFireTimer = 0f; + ShootingTimer = 0f; + } + } + + #endregion + + public override void OnSpawn(IEntitySource source) + { + if (!Main.dedServ) + { + int dustAmount = 45; + for (int dustIndex = 0; dustIndex < dustAmount; dustIndex++) + { + float angle = MathHelper.TwoPi / 45f * dustIndex; + Vector2 velocity = angle.ToRotationVector2() * Main.rand.NextFloat(3f, 4.5f); + Dust spawnDust = Dust.NewDustPerfect(Projectile.Center, 39, velocity); + spawnDust.noGravity = true; + spawnDust.scale = velocity.Length() * 0.1f; + spawnDust.velocity *= 0.3f; + } } } public override bool? CanDamage() => false; - #endregion + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = ModContent.Request(Texture).Value; + Vector2 position = Projectile.Center - Main.screenPosition; + Rectangle sourceRectangle = texture.Frame(verticalFrames: AnimationFrames, frameY: Projectile.frame); + Vector2 origin = sourceRectangle.Size() * 0.5f; + SpriteEffects effects = Projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + + Main.EntitySpriteDraw(texture, position, sourceRectangle, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, effects); + + return false; + } } } diff --git a/Projectiles/Summon/BelladonnaSpirit.png b/Projectiles/Summon/BelladonnaSpirit.png index 3f62956805..5063d8c384 100644 Binary files a/Projectiles/Summon/BelladonnaSpirit.png and b/Projectiles/Summon/BelladonnaSpirit.png differ