diff --git a/Items/Weapons/Rogue/WulfrumKnife.cs b/Items/Weapons/Rogue/WulfrumKnife.cs index 8c015cb8b3..d7ba09836e 100644 --- a/Items/Weapons/Rogue/WulfrumKnife.cs +++ b/Items/Weapons/Rogue/WulfrumKnife.cs @@ -59,7 +59,7 @@ namespace CalamityMod.Items.Weapons.Rogue { player.Calamity().rightClickListener = true; - if (player.Calamity().mouseRight && Main.rand.NextBool(7)) + if (player.Calamity().mouseRight && Main.rand.NextBool(7) && !Main.playerInventory) { Particle streak = new ManaDrainStreak(player, Main.rand.NextFloat(0.2f, 0.5f), Main.rand.NextVector2CircularEdge(1f, 1f) * Main.rand.NextFloat(170f, 670f), Main.rand.NextFloat(30f, 44f), Color.GreenYellow, Color.DeepSkyBlue, Main.rand.Next(15, 30)); GeneralParticleHandler.SpawnParticle(streak); @@ -69,7 +69,7 @@ namespace CalamityMod.Items.Weapons.Rogue public override void GrabRange(Player player, ref int grabRange) { float rangeMult = 2f; - if (player.Distance(Item.Center) < 670 && player.HeldItem.type == ModContent.ItemType() && player.Calamity().mouseRight) + if (player.Distance(Item.Center) < 670 && player.HeldItem.type == ModContent.ItemType() && player.Calamity().mouseRight && !Main.playerInventory) rangeMult = 20f; grabRange = (int)(grabRange * rangeMult); diff --git a/Items/Weapons/Summon/WulfrumController.cs b/Items/Weapons/Summon/WulfrumController.cs index 07672937a7..97e4b2dc77 100644 --- a/Items/Weapons/Summon/WulfrumController.cs +++ b/Items/Weapons/Summon/WulfrumController.cs @@ -13,7 +13,10 @@ namespace CalamityMod.Items.Weapons.Summon public override void SetStaticDefaults() { DisplayName.SetDefault("Wulfrum Controller"); - Tooltip.SetDefault("Summons a wulfrum droid to fight for you"); + Tooltip.SetDefault("Summons a wulfrum droid to fight for you\n" + + "Hold right click while holding the remote to switch all of your drones into supercharge mode\n" + + "Supercharged droids will stop attacking and focus you with a beam of wulfrum energy\n" + + "The beam provides extra regeneration and defense"); SacrificeTotal = 1; } @@ -36,6 +39,11 @@ namespace CalamityMod.Items.Weapons.Summon Item.DamageType = DamageClass.Summon; } + public override void HoldItem(Player player) + { + player.Calamity().rightClickListener = 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) diff --git a/Particles/WulfrumDroidEmote.cs b/Particles/WulfrumDroidEmote.cs new file mode 100644 index 0000000000..e4548ed528 --- /dev/null +++ b/Particles/WulfrumDroidEmote.cs @@ -0,0 +1,50 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class WulfrumDroidEmote : Particle + { + public override string Texture => "CalamityMod/Particles/WulfrumDroidEmotes"; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + + public Rectangle Frame; + + public WulfrumDroidEmote(Vector2 position, Vector2 velocity, int lifeTime, float scale = 1f, int variant = -1) + { + Position = position; + Velocity = velocity; + Color = Color.White; + Scale = scale; + Lifetime = lifeTime; + Rotation = velocity.ToRotation() + MathHelper.PiOver2; + + if (variant == -1) + variant = Main.rand.Next(15); + + Frame = new Rectangle(16 * (variant % 8), 16 * (variant / 8), 16, 16); + } + + public override void Update() + { + Velocity *= 0.96f; + Scale *= 0.97f; + + Color lightColor = Frame.Y > 0 ? new Color(112, 244, 244) : new Color(194, 255, 62); + Lighting.AddLight(Position, lightColor.ToVector3()); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D emoteTexture = ModContent.Request(Texture).Value; + Vector2 origin = new Vector2(Frame.Width / 2f, Frame.Height); + float opacity = 1 - (float)Math.Pow(LifetimeCompletion, 4f); + + spriteBatch.Draw(emoteTexture, Position - Main.screenPosition, Frame, Color * opacity, Rotation, origin, Scale, SpriteEffects.None, 0); + } + } +} diff --git a/Particles/WulfrumDroidEmotes.png b/Particles/WulfrumDroidEmotes.png new file mode 100644 index 0000000000..8528061bbb Binary files /dev/null and b/Particles/WulfrumDroidEmotes.png differ diff --git a/Particles/WulfrumDroidSweatEmote.cs b/Particles/WulfrumDroidSweatEmote.cs new file mode 100644 index 0000000000..1b6ecbc941 --- /dev/null +++ b/Particles/WulfrumDroidSweatEmote.cs @@ -0,0 +1,46 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class WulfrumDroidSweatEmote : Particle + { + public override string Texture => "CalamityMod/Particles/WulfrumDroidSweatEmote"; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + + public WulfrumDroidSweatEmote(Vector2 position, Vector2 velocity, int lifeTime, float scale = 1f) + { + Position = position; + Velocity = velocity; + Color = Color.White; + Scale = scale; + Lifetime = lifeTime; + Rotation = velocity.ToRotation() + MathHelper.PiOver2; + + } + + public override void Update() + { + Velocity *= 0.96f; + Scale *= 0.97f; + Velocity.Y += 0.06f; + + Lighting.AddLight(Position, new Color(194, 255, 62).ToVector3()); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D emoteTexture = ModContent.Request(Texture).Value; + Vector2 origin = new Vector2(emoteTexture.Width / 2f, emoteTexture.Height / 2f); + float opacity = 1 - (float)Math.Pow(LifetimeCompletion, 4f); + + SpriteEffects effect = Velocity.X > 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + + spriteBatch.Draw(emoteTexture, Position - Main.screenPosition, null, Color * opacity, Rotation, origin, Scale, effect, 0); + } + } +} diff --git a/Particles/WulfrumDroidSweatEmote.png b/Particles/WulfrumDroidSweatEmote.png new file mode 100644 index 0000000000..8cb5164da2 Binary files /dev/null and b/Particles/WulfrumDroidSweatEmote.png differ diff --git a/Projectiles/Summon/WulfrumDroid.cs b/Projectiles/Summon/WulfrumDroid.cs index 83bedff251..6a8da848bc 100644 --- a/Projectiles/Summon/WulfrumDroid.cs +++ b/Projectiles/Summon/WulfrumDroid.cs @@ -4,12 +4,76 @@ using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; +using System; +using Terraria.Audio; +using CalamityMod.Particles; namespace CalamityMod.Projectiles.Summon { public class WulfrumDroid : ModProjectile { - public float dust = 0f; + public static readonly SoundStyle HelloSound = new("CalamityMod/Sounds/Custom/WulfrumDroidSpawnBeep") { PitchVariance = 0.4f }; + public static readonly SoundStyle PewSound = new("CalamityMod/Sounds/Custom/WulfrumDroidFire") { PitchVariance = 0.4f, Volume = 0.6f, MaxInstances = 0 }; + public static readonly SoundStyle RandomChirpSound = new("CalamityMod/Sounds/Custom/WulfrumDroidChirp", 4) { PitchVariance = 0.3f }; + public static readonly SoundStyle HurrySound = new("CalamityMod/Sounds/Custom/WulfrumDroidHurry", 2) { PitchVariance = 0.3f }; + public int NewSoundDelay + { + get + { + int minionCount = 1; + for (int i = 0; i < Main.maxProjectiles; i++) + { + Projectile proj = Main.projectile[i]; + if (proj.active && proj.owner == Owner.whoAmI && proj.type == Type && proj.whoAmI != Projectile.whoAmI) + { + minionCount++; + } + } + + return (int)(Main.rand.Next(340, 1660) * minionCount); + } + } + + public float Initialized = 0f; + public static float AggroRange = 450f; + public static float ShootDelay = 110f; //This is the max delay, but it can b e shorter + public enum BehaviorState { Aggressive, Idle, BuffOwner }; + public BehaviorState State + { + get => (BehaviorState)(int)Projectile.ai[0]; + + set => Projectile.ai[0] = (float)value; + } + + public ref float ShootTimer => ref Projectile.ai[1]; + public NPC Target + { + get + { + NPC target = null; + + if (Owner.HasMinionAttackTargetNPC) + target = CheckNPCTargetValidity(Main.npc[Owner.MinionAttackTargetNPC]); + + if (target != null) + return target; + + else + { + for (int npcIndex = 0; npcIndex < Main.npc.Length; npcIndex++) + { + target = CheckNPCTargetValidity(Main.npc[npcIndex]); + if (target != null) + return target; + } + } + + return null; + } + } + + public Player Owner => Main.player[Projectile.owner]; + public override void SetStaticDefaults() { @@ -33,27 +97,52 @@ namespace CalamityMod.Projectiles.Summon Projectile.timeLeft *= 5; Projectile.minion = true; Projectile.DamageType = DamageClass.Summon; + Initialized = 0f; + } + + //Returns the npc if targetable, returns null if not + public NPC CheckNPCTargetValidity(NPC potentialTarget) + { + if (potentialTarget.CanBeChasedBy(this, false)) + { + float targetDist = Vector2.Distance(potentialTarget.Center, Projectile.Center); + + if ((targetDist < AggroRange) && Collision.CanHitLine(Projectile.position, Projectile.width, Projectile.height, potentialTarget.position, potentialTarget.width, potentialTarget.height)) + { + return potentialTarget; + } + } + + return null; } public override void AI() { Player player = Main.player[Projectile.owner]; CalamityPlayer modPlayer = player.Calamity(); - if (dust == 0f) + + //Spawn dust + if (Initialized == 0f) { - int dustAmt = 36; + int dustAmt = Main.rand.Next(10, 16); for (int dustIndex = 0; dustIndex < dustAmt; dustIndex++) { - Vector2 source = Vector2.Normalize(Projectile.velocity) * new Vector2((float)Projectile.width / 2f, (float)Projectile.height) * 0.75f; - source = source.RotatedBy((double)((float)(dustIndex - (dustAmt / 2 - 1)) * MathHelper.TwoPi / (float)dustAmt), default) + Projectile.Center; - Vector2 dustVel = source - Projectile.Center; - int green = Dust.NewDust(source + dustVel, 0, 0, 61, dustVel.X * 1.1f, dustVel.Y * 1.1f, 100, default, 1.4f); - Main.dust[green].noGravity = true; - Main.dust[green].noLight = true; - Main.dust[green].velocity = dustVel; + Vector2 direction = Main.rand.NextVector2CircularEdge(1f, 1f); + + Dust wishyDust = Dust.NewDustPerfect(Projectile.Center + direction * Main.rand.NextFloat(1f, 8f), 229, Alpha : 100, Scale: Main.rand.NextFloat(1f, 1.4f)); + wishyDust.noGravity = true; + wishyDust.noLight = true; + wishyDust.velocity = direction * Main.rand.NextFloat(2f, 4); } - dust += 1f; + + SoundEngine.PlaySound(HelloSound, Projectile.Center); + Projectile.soundDelay = NewSoundDelay; + + Initialized ++; } + + + //Do frame stuff i guess Projectile.frameCounter++; if (Projectile.frameCounter > 8) { @@ -64,145 +153,161 @@ namespace CalamityMod.Projectiles.Summon { Projectile.frame = 0; } - bool correctMinion = Projectile.type == ModContent.ProjectileType(); + + + //Buff stuff player.AddBuff(ModContent.BuffType(), 3600); - if (correctMinion) - { - if (player.dead) - { - modPlayer.wDroid = false; - } - if (modPlayer.wDroid) - { - Projectile.timeLeft = 2; - } - } + if (player.dead) + modPlayer.wDroid = false; + if (modPlayer.wDroid) + Projectile.timeLeft = 2; Projectile.MinionAntiClump(); - Vector2 targetVector = Projectile.position; - float range = 450f; - bool foundTarget = false; - int targetIndex = -1; - if (player.HasMinionAttackTargetNPC) - { - NPC npc = Main.npc[player.MinionAttackTargetNPC]; - if (npc.CanBeChasedBy((object) this, false)) - { - float targetDist = Vector2.Distance(npc.Center, Projectile.Center); - if ((!foundTarget && targetDist < range) && Collision.CanHitLine(Projectile.position, Projectile.width, Projectile.height, npc.position, npc.width, npc.height)) - { - range = targetDist; - targetVector = npc.Center; - foundTarget = true; - targetIndex = npc.whoAmI; - } - } - } - if (!foundTarget) - { - for (int npcIndex = 0; npcIndex < Main.npc.Length; ++npcIndex) - { - NPC npc = Main.npc[npcIndex]; - if (npc.CanBeChasedBy((object) this, false)) - { - float targetDist = Vector2.Distance(npc.Center, Projectile.Center); - if ((!foundTarget && targetDist < range) && Collision.CanHitLine(Projectile.position, Projectile.width, Projectile.height, npc.position, npc.width, npc.height)) - { - range = targetDist; - targetVector = npc.Center; - foundTarget = true; - targetIndex = npcIndex; - } - } - } - } - float separationAnxietyDist = 500f; - if (foundTarget) - separationAnxietyDist = 1000f; - if (Vector2.Distance(player.Center, Projectile.Center) > separationAnxietyDist) - { - Projectile.ai[0] = 1f; - Projectile.netUpdate = true; - } - if (Projectile.ai[0] == 1f) - Projectile.tileCollide = false; - if (foundTarget && Projectile.ai[0] == 0f) - { - Vector2 targetPos = targetVector - Projectile.Center; - float targetDist = targetPos.Length(); - targetPos.Normalize(); - if (targetDist > 200f) - { - float speed = 6f; - Vector2 goToTarget = targetPos * speed; - Projectile.velocity.X = (Projectile.velocity.X * 40f + goToTarget.X) / 41f; - Projectile.velocity.Y = (Projectile.velocity.Y * 40f + goToTarget.Y) / 41f; - } - else if (Projectile.velocity.Y > -1f) - Projectile.velocity.Y -= 0.1f; - } + + + //Lets only recalculate our target once per frame aight + NPC targetCache = Target; + float separationAnxietyDist = targetCache != null ? 1000f : 500f; //Have more lenience on how far away from the player should the drone return if theyre attacking an enemy + + if (Projectile.soundDelay > 0) + Projectile.soundDelay--; else { + SoundEngine.PlaySound(RandomChirpSound with { Volume = RandomChirpSound.Volume * Main.rand.NextFloat(0.5f, 1f) }, Projectile.Center); + Projectile.soundDelay = NewSoundDelay; + + if (targetCache == null) + { + Vector2 emoteDirection = -Vector2.UnitY.RotatedByRandom(MathHelper.PiOver2 * 0.7f); + + Particle emote = new WulfrumDroidEmote(Projectile.Center + emoteDirection * 10f, emoteDirection * Main.rand.NextFloat(3f, 5f), Main.rand.Next(30, 65), Main.rand.NextFloat(1.4f, 2f)); + GeneralParticleHandler.SpawnParticle(emote); + } + } + + //Return to the player if too far away from them. Hurry up droids! + if (Vector2.Distance(Owner.Center, Projectile.Center) > separationAnxietyDist) + { + State = BehaviorState.Idle; + Projectile.netUpdate = true; + + //play the hurry sound once and never again until it is reset + if (Projectile.soundDelay < 10000) + SoundEngine.PlaySound(HurrySound, Projectile.Center); + + Projectile.soundDelay = 10010; + + if (Main.rand.NextBool(7)) + { + Vector2 emoteDirection = -Vector2.UnitY.RotatedByRandom(MathHelper.PiOver2 * 0.7f); + emoteDirection.X -= Math.Sign(Projectile.velocity.X) * 1f; + + Particle emote = new WulfrumDroidSweatEmote(Projectile.Center + emoteDirection * 10f, emoteDirection * Main.rand.NextFloat(3f, 5f), Main.rand.Next(20, 35), Main.rand.NextFloat(1.4f, 2f)); + GeneralParticleHandler.SpawnParticle(emote); + } + } + + else if (Projectile.soundDelay >= 10000) + Projectile.soundDelay = NewSoundDelay; + + if (targetCache != null && State == BehaviorState.Aggressive) + { + Vector2 vectorToTarget = targetCache.Center - Projectile.Center; + float distanceToTarget = vectorToTarget.Length(); + vectorToTarget = vectorToTarget.SafeNormalize(Vector2.Zero); + + //Accelerate towards target if far away + if (distanceToTarget > 200f) + Projectile.velocity = Vector2.Lerp(Projectile.velocity, vectorToTarget * 6f, 1 / 41f); + + //"Float" the minion + else if (Projectile.velocity.Y > -1f) + Projectile.velocity.Y -= 0.1f; + + //Small tweak that makes the minion hop away from the targets center if its too aligned with it vertically + if (Math.Abs(Projectile.Center.X - targetCache.Center.X) < 10f) + Projectile.velocity.X += 4f * Math.Sign(Projectile.Center.X - targetCache.Center.X); + } + + + else + { + //Become passive if theres obstruction between it and the player if (!Collision.CanHitLine(Projectile.Center, 1, 1, player.Center, 1, 1)) - Projectile.ai[0] = 1f; - float returnSpeed = 6f; - if (Projectile.ai[0] == 1f) - returnSpeed = 15f; + State = BehaviorState.Idle; + + float returnSpeed = State == BehaviorState.Idle ? 15f : 6f; + + //Accelerate towards the player if too far & not fast enough Vector2 playerVec = player.Center - Projectile.Center + new Vector2(0f, -60f); float playerDist = playerVec.Length(); if (playerDist > 200f && returnSpeed < 9f) returnSpeed = 9f; - if (playerDist < 100f && Projectile.ai[0] == 1f && !Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height)) + + + if (playerDist < 100f && State == BehaviorState.Idle && !Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height)) { - Projectile.ai[0] = 0f; + State = BehaviorState.Aggressive; Projectile.netUpdate = true; } + + //Teleport to player if too far away. if (playerDist > 2000f) { - Projectile.position.X = player.Center.X - (float) (Projectile.width / 2); - Projectile.position.Y = player.Center.Y - (float) (Projectile.width / 2); + Projectile.Center = player.Center; Projectile.netUpdate = true; } + + //Aim towards the top of the player else if (playerDist > 70f) - { - playerVec.Normalize(); - Projectile.velocity = (Projectile.velocity * 20f + playerVec * returnSpeed) / 21f; - } + Projectile.velocity = Vector2.Lerp(Projectile.velocity, playerVec.SafeNormalize(Vector2.Zero) * returnSpeed, 1 / 21f); + else { + //Get unstuck if your movespeed is zero if (Projectile.velocity.X == 0f && Projectile.velocity.Y == 0f) - { - Projectile.velocity.X = -0.15f; - Projectile.velocity.Y = -0.05f; - } + Projectile.velocity = Main.rand.NextVector2CircularEdge(1f, 1f) * -0.15f; + + //Accelerate more Projectile.velocity *= 1.01f; } } + Projectile.rotation = Projectile.velocity.X * 0.05f; - if (Projectile.velocity.X > 0f) - Projectile.spriteDirection = Projectile.direction = 1; - else if (Projectile.velocity.X < 0f) - Projectile.spriteDirection = Projectile.direction = -1; - if (Projectile.ai[1] > 0f) - Projectile.ai[1] += (float) Main.rand.Next(1, 4); - if (Projectile.ai[1] > 90f) + Projectile.spriteDirection = Projectile.direction = Math.Sign(Projectile.velocity.X); + + //Increase the timer by a random number + if (ShootTimer > 0f) + ShootTimer += (float) Main.rand.Next(1, 4); + + if (ShootTimer > ShootDelay) { - Projectile.ai[1] = 0.0f; + ShootTimer = 0f; Projectile.netUpdate = true; } - if (Projectile.ai[1] != 0f) + + if (ShootTimer > 0) return; - ++Projectile.ai[1]; - if (Main.myPlayer != Projectile.owner) + + ShootTimer++; + + if (targetCache == null) return; - if (!foundTarget) - return; - Vector2 velocity = targetVector - Projectile.Center; + + SoundEngine.PlaySound(PewSound, Projectile.Center); + //Recoil + Vector2 velocity = targetCache.Center - Projectile.Center; velocity.Normalize(); velocity *= 10f; - int bolt = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); - Main.projectile[bolt].originalDamage = Projectile.originalDamage; - Main.projectile[bolt].netUpdate = true; - Projectile.netUpdate = true; + Projectile.velocity += velocity * -0.3f; + + + if (Main.myPlayer == Projectile.owner) + { + int bolt = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); + Main.projectile[bolt].originalDamage = Projectile.originalDamage; + Main.projectile[bolt].netUpdate = true; + Projectile.netUpdate = true; + } } public override bool? CanDamage() => false; diff --git a/Sounds/Custom/WulfrumDroidChirp1.ogg b/Sounds/Custom/WulfrumDroidChirp1.ogg new file mode 100644 index 0000000000..874e122f60 Binary files /dev/null and b/Sounds/Custom/WulfrumDroidChirp1.ogg differ diff --git a/Sounds/Custom/WulfrumDroidChirp2.ogg b/Sounds/Custom/WulfrumDroidChirp2.ogg new file mode 100644 index 0000000000..2a7dde01fc Binary files /dev/null and b/Sounds/Custom/WulfrumDroidChirp2.ogg differ diff --git a/Sounds/Custom/WulfrumDroidChirp3.ogg b/Sounds/Custom/WulfrumDroidChirp3.ogg new file mode 100644 index 0000000000..847313cd6d Binary files /dev/null and b/Sounds/Custom/WulfrumDroidChirp3.ogg differ diff --git a/Sounds/Custom/WulfrumDroidChirp4.ogg b/Sounds/Custom/WulfrumDroidChirp4.ogg new file mode 100644 index 0000000000..e033b0f0b3 Binary files /dev/null and b/Sounds/Custom/WulfrumDroidChirp4.ogg differ diff --git a/Sounds/Custom/WulfrumDroidFire.ogg b/Sounds/Custom/WulfrumDroidFire.ogg new file mode 100644 index 0000000000..d9f5eaa407 Binary files /dev/null and b/Sounds/Custom/WulfrumDroidFire.ogg differ diff --git a/Sounds/Custom/WulfrumDroidHurry1.ogg b/Sounds/Custom/WulfrumDroidHurry1.ogg new file mode 100644 index 0000000000..c5fa53dc3d Binary files /dev/null and b/Sounds/Custom/WulfrumDroidHurry1.ogg differ diff --git a/Sounds/Custom/WulfrumDroidHurry2.ogg b/Sounds/Custom/WulfrumDroidHurry2.ogg new file mode 100644 index 0000000000..a7a108538f Binary files /dev/null and b/Sounds/Custom/WulfrumDroidHurry2.ogg differ diff --git a/Sounds/Custom/WulfrumDroidSpawnBeep.ogg b/Sounds/Custom/WulfrumDroidSpawnBeep.ogg new file mode 100644 index 0000000000..bc1ba987b1 Binary files /dev/null and b/Sounds/Custom/WulfrumDroidSpawnBeep.ogg differ