diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index f651d43653..841eb32666 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -260,6 +260,9 @@ namespace CalamityMod.Effects // Distorts a texture using a sine wave of specified amplitude and frequency either vertically or horizontally. internal static Asset SineWaveDistortionShader; + + // The swirling aura effect seen around Horrible Hog while its idling. + internal static Asset HorribleHogAuraShader; #endregion #region Big E's Shaders @@ -525,6 +528,9 @@ namespace CalamityMod.Effects SineWaveDistortionShader = LoadShader("SineWaveDistortionShader"); RegisterMiscShader(SineWaveDistortionShader, "SinePass", "SineWaveDistortion"); + + HorribleHogAuraShader = LoadShader("HorribleHogAuraShader"); + RegisterMiscShader(HorribleHogAuraShader, "ScaryAuraPass", "HorribleHogAura"); #endregion #region Loading Big E's Shaders diff --git a/Effects/HorribleHogAuraShader.fx b/Effects/HorribleHogAuraShader.fx new file mode 100644 index 0000000000..7faee3d468 --- /dev/null +++ b/Effects/HorribleHogAuraShader.fx @@ -0,0 +1,68 @@ +sampler vortexNoiseTexture : register(s0); +sampler vortexNoiseTexture2 : register(s1); +sampler distortionTexture : register(s2); + +float time; +float colorPaletteLimit; +float spiralArms; +float spiralAdditionalAngle; +float minPixelFadeDistance; +float maxPixelFadeDistance; + +float2 pixelatonFactor; +float2 spiralTimeOffset; +float2 pixelationFactor; +float3 vortexDarkColor; +float3 vortexBrightColor; + +float inverseLerp(float from, float to, float x) +{ + return saturate((x - from) / (to - from)); +} + +float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0 +{ + // Pixelate. + coords = round(coords * pixelationFactor) / pixelationFactor; + + float2 centeredCoords = coords - 0.5; + float polarAngle = atan2(centeredCoords.y, centeredCoords.x) / 6.283; + float distanceToCenter = length(centeredCoords); + float2 polarCoords = float2(polarAngle, distanceToCenter); + + // Define coordinates for creating the vortex effect. + float vortexRadius = pow(distanceToCenter, 0.6); + float vortexAngle = spiralArms * atan2(centeredCoords.y, centeredCoords.x) / 3.141 + spiralAdditionalAngle * vortexRadius; + float2 vortexPolarCoords = float2(vortexAngle, vortexRadius) * 0.5 + float2(time * spiralTimeOffset.x, time * spiralTimeOffset.y); + + // Add some distortion over it. + float distortion1 = tex2D(distortionTexture, coords * 0.46 + float2(time * -0.02, time * 0.022)).r; + float distortion2 = tex2D(distortionTexture, coords * 0.32 + float2(time * 0.018, time * -0.03)).r; + float totalDistortion = (distortion1 * 0.5) + (distortion2 * 0.5); + + float4 vortexNoiseColor1 = tex2D(vortexNoiseTexture, vortexPolarCoords + totalDistortion); + float4 vortexNoiseColor2 = tex2D(vortexNoiseTexture2, polarCoords + float2(time * -0.02, time * -0.092) + totalDistortion * 0.64); + float4 vortexNoiseColor = lerp(vortexNoiseColor1, vortexNoiseColor2, inverseLerp(0, maxPixelFadeDistance - 0.075, distanceToCenter)); + + // Apply coloration based on pixel brightness. + float brightness = (vortexNoiseColor.r + vortexNoiseColor.g + vortexNoiseColor.b) / 3.0; + vortexNoiseColor.rgb *= lerp(vortexDarkColor, vortexBrightColor, brightness); + + // Quantization. + vortexNoiseColor = round(vortexNoiseColor * colorPaletteLimit) / colorPaletteLimit; + + // Fade out at the edge of the texture. + float edgeFade = inverseLerp(0, minPixelFadeDistance - 0.016, distanceToCenter) * inverseLerp(maxPixelFadeDistance, minPixelFadeDistance, distanceToCenter); + // float edgeOffset = tex2D(edgeFadeTexture, vortexPolarCoords + float2(time * spiralTimeOffset.x, time * spiralTimeOffset.y)).r * 0.13; + // float edgeFade = smoothstep(0.5, opacityCutoffValue, polarCoords.y + edgeOffset); + + return (vortexNoiseColor * edgeFade) * sampleColor.a; +} + +technique Technique1 +{ + pass ScaryAuraPass + { + PixelShader = compile ps_3_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/HorribleHogAuraShader.xnb b/Effects/HorribleHogAuraShader.xnb new file mode 100644 index 0000000000..b9d08f97ca Binary files /dev/null and b/Effects/HorribleHogAuraShader.xnb differ diff --git a/NPCs/NormalNPCs/HorribleHog.cs b/NPCs/NormalNPCs/HorribleHog.cs deleted file mode 100644 index acaeff6720..0000000000 --- a/NPCs/NormalNPCs/HorribleHog.cs +++ /dev/null @@ -1,1866 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using CalamityMod.Buffs.StatDebuffs; -using CalamityMod.DataStructures; -using CalamityMod.Effects; -using CalamityMod.Items.Materials; -using CalamityMod.Items.Tools; -using CalamityMod.Particles; -using CalamityMod.Projectiles.Enemy; -using CalamityMod.Utilities.Daybreak; -using CalamityMod.World; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using ReLogic.Content; -using ReLogic.Utilities; -using Terraria; -using Terraria.Audio; -using Terraria.Chat; -using Terraria.GameContent; -using Terraria.GameContent.Bestiary; -using Terraria.ID; -using Terraria.ModLoader; -using Terraria.ModLoader.IO; -using Terraria.ModLoader.Utilities; -using Terraria.UI.Chat; -using Terraria.Utilities; -using Terraria.WorldBuilding; - -namespace CalamityMod.NPCs.NormalNPCs -{ - public class HorribleHog : ModNPC - { - public enum BehaviorState - { - // Non-attacks. - EngageAnimation = -4, - LaughAtDeadPlayer = -3, - DespawnAnimation = -2, - DeathAnimation = -1, - Idle, - DigTowardsTarget, - - // Attacks. - ChasePlayer, - HogCharge, - JumpAndDash, - HorribleHoller, - VomitBarrage, - } - - private static Asset BloomCircle; - private static Asset ShineFlare; - - private static SoundStyle IdleSound = new("CalamityMod/Sounds/Custom/Piggy/PiggyIdle", 3) - { - Pitch = -0.6f, - PitchVariance = 0.2f, - }; - private static SoundStyle DiggingSlowSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogDiggingSlow") - { - IsLooped = true, - PauseBehavior = PauseBehavior.PauseWithGame, - MaxInstances = 0 - }; - private static SoundStyle DiggingFastSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogDiggingFast") - { - IsLooped = true, - PauseBehavior = PauseBehavior.PauseWithGame, - MaxInstances = 0 - }; - private static SoundStyle DeathSound = new("CalamityMod/Sounds/NPCKilled/HorribleHogDeath"); - private static SoundStyle DeathLaughSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogDeathLaugh", 2); - - public Dictionary PreviousAttackCounters = []; - - public Dictionary AttackWeights = []; - - public bool SearchForTargetEveryFrame; - - public bool HasPlayedEngageAnimation; - - public bool HasPlayedDeathAnimation; - - public bool HasPlayedDespawnAnimation; - - public bool ReadyToPlayLaughingAnimation; - - public float EyeGlintScale; - - public float AfterimageTrailOpacity; - - public float PriitiveTrailOpacity; - - public float HorizontalShakeStrength; - - /// - /// Used as a shader parameter to rotate the already-drawn sprite of Horrible Hog directly regardless of the rotation value of .

- /// Used in cases where Horrible Hog needs to spin while also squashing and stretching. is used for the spritebatch-drawn texture

- /// and needs to rotate towards the NPC's velocity in order for the squashed sprite to face the correct direction. This parameter is then used and a shader is

- /// then applied to the spritebatch to rotate the sprite differently from the value passed in spritebatch's Draw call. - ///
- public float SpriteRotation; - - public Vector2 LastPlayerPosition; - - public Vector2 DiggingEmergeSpot; - - public Vector2 SquashVector; - - public Vector2 SquashVectorTarget; - - public SlotId DeathLaughSoundSlot; - - public SlotId DiggingSoundSlot; - - #region Static Properties - public static int MaxAttacks_ChasePlayer => 2; - public static int MaxAttacks_HogCharge => Main.expertMode ? 2 : 1; - public static int MaxAttacks_HorribleHoller => 1; - public static int MaxAttacks_JumpAndDash => Main.expertMode ? 3 : 2; - public static int MaxAttacks_VomitBarrage => Main.expertMode ? 2 : 1; - public static int MaxAttacksPerCycle => CalamityWorld.revenge ? 5 : Main.expertMode ? 4 : 3; - - public static int Damage_HogCharge => 10; - public static int Damage_ShockwaveProjectile => 10; - public static int Damage_ShockwaveRubbleProjectile => 12; - public static int Damage_VomitChunkProjectile => 12; - public static int Damage_VomitBombProjectile => 18; - public static int Damage_VomitEyeProjectile => 14; - - public static float EngageDistance => 300f; - public static float Idle_MaxSpeed => 2f; - public static float Idle_MaxAcceleration => 0.125f; - - public static int MaxTimeToStartDigging => 300; - - public static int DigTowardsTarget_PreJumpTime => 30; - public static int DigTowardsTarget_FindSuitablePositionTime => 120; - public static int DigTowardsTraget_MaxDiggingTime => 180; - - public static int ChaseTime => 180; - public static float ChasePlayer_MaxSpeed => 5f; - public static float ChasePlayer_MaxAcceleration => 0.3f; - - public static int HogCharge_PreChargeTime => 75; - public static int HogCharge_ChargingTime => 240; - public static int HogCharge_ChargeCooldownTime => CalamityWorld.revenge ? -20 : Main.expertMode ? -30 : -45; - public static int HogCharge_PreDashTime => 45; - public static int HogCharge_DashTime => 20; - public static int HogCharge_MaxCharges => CalamityWorld.revenge ? 4 : Main.expertMode ? 3 : 2; - public static float HogCharge_MaxSpeed => CalamityWorld.revenge ? 18f : Main.expertMode ? 15f : 12f; - public static float HogCharge_MaxAcceleration => CalamityWorld.revenge ? 0.425f : Main.expertMode ? 0.4f : 0.375f; - public static float HogCharge_MaxSlowdownDistance => CalamityWorld.revenge ? 64f : Main.expertMode ? 96f : 128f; - - public static int JumpAndDash_PreJumpTime => 75; - public static int JumpAndDash_JumpPreDashTime => 45; - public static int JumpAndDash_DashTime => 20; - public static int JumpAndDash_CooldownTime => 60; - public static int JumpAndDash_PreVomitTime => 60; - public static int JumpAndDash_PreGroundPoundTime => 45; - public static int JumpAndDash_MaxVomitChunks => CalamityWorld.revenge ? 5 : Main.expertMode ? 4 : 3; - public static int JumpAndDash_VomitTimeInterval => CalamityWorld.revenge ? 10 : 15; - public static int JumpAndDash_MaxBounces => Main.expertMode ? 3 : 2; - public static float JumpAndDash_MaxJumpHeight => 14f; - public static float JumpAndDash_MaxDashSpeed => 20f; - public static float JumpAndDash_MaxBounceSpeed => CalamityWorld.revenge ? 16f : Main.expertMode ? 14f : 12f; - - public static int HorribleHoller_RoarTime => 75; - public static int HorribleHoller_PostRoarCooldownTime => 30; - public static int HorribleHoller_MaxZombies => 3; - - public static int VomitBarrage_PreJumpTime => 75; - public static int VomitBarrage_VomitTime => 25; - public static int VomitBarrage_PostVomitCooldown => 100; - public static int VomitBarrage_MaxVomitChunks => CalamityWorld.revenge ? 10 : Main.expertMode ? 8 : 6; - public static int VomitBarrage_MinVomitBombs => CalamityWorld.death ? 3 : CalamityWorld.revenge ? 2 : 0; - public static int VomitBarrage_MaxVomitBombs => CalamityWorld.death ? 6 : CalamityWorld.revenge ? 5 : Main.expertMode ? 3 : 4; - public static float VomitBarrage_MaxSpeed => 8f; - public static float VomitBarrage_MaxAcceleration => 0.45f; - #endregion - - public ref float Timer => ref NPC.ai[0]; - - public ref float AIState => ref NPC.ai[1]; - - public ref float LocalAIState => ref NPC.ai[2]; - - public ref float MainAttackCounter => ref NPC.ai[3]; - - public ref float MiscAttackCounter => ref NPC.localAI[0]; - - public ref float AltAttackVariant => ref NPC.localAI[1]; - - public ref float DigTimer => ref NPC.localAI[2]; - - public Vector2 VelocityBasedSquashNStretch - { - get - { - float stretch = MathHelper.Clamp(NPC.velocity.Length() / 20f * 0.1f, 1f, 1.05f); - Vector2 stretchedVector = new(1f * stretch, 1f - 1f * stretch * 0.3f); - return stretchedVector; - } - } - - public bool PhaseTwo - { - get - { - if (CalamityWorld.death || Main.getGoodWorld) - return NPC.life <= NPC.lifeMax * 0.7f; - - if (CalamityWorld.revenge) - return NPC.life <= NPC.lifeMax * 0.6f; - - return Main.expertMode && NPC.life <= NPC.lifeMax * 0.5f; - } - } - - public override void Load() - { - if (!Main.dedServ) - { - BloomCircle = ModContent.Request("CalamityMod/Particles/BloomCircle"); - ShineFlare = ModContent.Request("CalamityMod/ExtraTextures/ShineFlare"); - } - } - - public override void SetStaticDefaults() - { - NPCID.Sets.TrailCacheLength[Type] = 5; - NPCID.Sets.TrailingMode[Type] = 0; - NPCID.Sets.CantTakeLunchMoney[Type] = true; - } - - public override void SetDefaults() - { - NPC.width = 40; - NPC.height = 28; - NPC.damage = 20; - NPC.defense = 14; - NPC.lifeMax = 600; - NPC.knockBackResist = 0f; - NPC.npcSlots = 5f; - NPC.rarity = 4; - NPC.value = Item.buyPrice(0, 3, 0, 0); - NPC.HitSound = SoundID.NPCHit1; - NPC.DeathSound = SoundID.NPCDeath1; - NPC.noGravity = false; - NPC.noTileCollide = false; - NPC.dontTakeDamage = false; - - SquashVector = Vector2.One; - SquashVectorTarget = Vector2.One; - ResetAttackWeights(); - } - - public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) - { - bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] - { - BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Events.BloodMoon, - new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.HorribleHog") - }); - } - - public override void SendExtraAI(BinaryWriter writer) - { - writer.Write((byte)PreviousAttackCounters.Count); - foreach (var pair in PreviousAttackCounters) - { - writer.Write((byte)pair.Key); - writer.Write((byte)pair.Value); - } - - writer.Write((byte)AttackWeights.Count); - foreach (var pair in AttackWeights) - { - writer.Write((byte)pair.Key); - writer.Write((byte)pair.Value); - } - - writer.WriteFlags(SearchForTargetEveryFrame, HasPlayedEngageAnimation, HasPlayedDeathAnimation, HasPlayedDespawnAnimation, ReadyToPlayLaughingAnimation); - writer.WritePackedWorldPosition(LastPlayerPosition); - writer.WritePackedWorldPosition(DiggingEmergeSpot); - } - - public override void ReceiveExtraAI(BinaryReader reader) - { - int attackCountersLength = reader.ReadByte(); - for (int i = 0; i < attackCountersLength; i++) - PreviousAttackCounters.Add((BehaviorState)reader.ReadByte(), (int)reader.ReadByte()); - - int attackWeightsLength = reader.ReadByte(); - for (int i = 0; i < attackWeightsLength; i++) - AttackWeights.Add((BehaviorState)reader.ReadByte(), (float)reader.ReadByte()); - - reader.ReadFlags(out SearchForTargetEveryFrame, out HasPlayedEngageAnimation, out HasPlayedDeathAnimation, out HasPlayedDespawnAnimation, out ReadyToPlayLaughingAnimation); - LastPlayerPosition = reader.ReadPackedWorldPosition(); - DiggingEmergeSpot = reader.ReadPackedWorldPosition(); - } - - public override bool CheckDead() - { - if (!HasPlayedDeathAnimation) - { - NPC.life = NPC.lifeMax; - HasPlayedDeathAnimation = true; - SwitchBehavior(specificAttack: BehaviorState.DeathAnimation); - return false; - } - - return true; - } - - public override bool? CanFallThroughPlatforms() - { - // If Hog is not in any of the transitional behavior states, don't fall through platforms. - bool inTransitionalBehaviorState = AIState <= (int)BehaviorState.Idle; - if (inTransitionalBehaviorState) - return false; - - if (NPC.HasValidTarget) - { - Player target = Main.player[NPC.target]; - return target.Center.Y - 8 > NPC.Center.Y; - } - - return base.CanFallThroughPlatforms(); - } - - public override void AI() - { - if (!NPC.HasValidTarget || SearchForTargetEveryFrame) - NPC.TargetClosest(false); - - if (NPC.direction == 0) - NPC.direction = Main.rand.NextBool().ToDirectionInt(); - - // Due to how much Death Mode increases Blood Moon spawn rates, this is kinda required in order for the fight to not be super overwhelming. - if (CalamityWorld.death) - NPC.npcSlots = 40f; - - Player target = Main.player[NPC.target]; - NPC.damage = NPC.defDamage; - NPC.defense = NPC.defDefense; - NPC.noGravity = false; - NPC.noTileCollide = false; - NPC.dontTakeDamage = false; - NPC.chaseable = true; - NPC.spriteDirection = NPC.direction; - - // If the target dies, laugh at them. - if (target.dead && ReadyToPlayLaughingAnimation && NPC.velocity.Y == 0f) - { - ReadyToPlayLaughingAnimation = false; - SwitchBehavior(specificAttack: BehaviorState.LaughAtDeadPlayer); - } - - // If the target is unable to be reached, count up to 5 seconds before switching behavior states and digging towards them. - int tileRange = 64; - Vector2 npcCanHitPosition = NPC.position - new Vector2(tileRange, tileRange); - Vector2 targetCanHitPosition = target.position - new Vector2(tileRange, tileRange); - bool currentlyDoingAnAttack = AIState > (int)BehaviorState.DigTowardsTarget; - bool targetTooHigh = (NPC.Center.Y - target.Center.Y >= 160f && target.velocity.Y == 0f) || NPC.Center.Y - target.Center.Y >= 320f; - bool targetTooFar = NPC.Distance(target.Center) >= 1280f; - bool cantHitTarget = !Collision.CanHit(npcCanHitPosition, NPC.width + tileRange, NPC.height + tileRange, targetCanHitPosition, target.width + tileRange, target.height + tileRange); - if (NPC.HasValidTarget && currentlyDoingAnAttack && (targetTooHigh || targetTooFar || cantHitTarget)) - { - DigTimer++; - if (DigTimer >= 300f && NPC.velocity.Y == 0f) - { - SwitchBehavior(specificAttack: BehaviorState.DigTowardsTarget); - } - } - else - { - if (DigTimer > 0f) - DigTimer--; - } - - // Despawn immediately if it's morning. - if (Main.dayTime && AIState != (int)BehaviorState.DespawnAnimation) - SwitchBehavior(specificAttack: BehaviorState.DespawnAnimation); - - switch ((BehaviorState)AIState) - { - case BehaviorState.EngageAnimation: - MainBehavior_EngageAnimation(target); - break; - - case BehaviorState.LaughAtDeadPlayer: - MainBehavior_LaughADeadPlayer(); - break; - - case BehaviorState.DespawnAnimation: - MainBehavior_DespawnAnimation(); - break; - - case BehaviorState.DeathAnimation: - MainBehavior_DeathAnimation(); - break; - - case BehaviorState.Idle: - MainBehavior_Idle(target); - break; - - case BehaviorState.DigTowardsTarget: - MainBehavior_DigTowardsTarget(target); - break; - - case BehaviorState.ChasePlayer: - MainBehavior_ChasePlayer(target); - break; - - case BehaviorState.HogCharge: - MainBehavior_HogCharge(target); - break; - - case BehaviorState.JumpAndDash: - MainBehavior_JumpAndDash(target); - break; - - case BehaviorState.HorribleHoller: - MainBehavior_HorribleHoller(target); - break; - - case BehaviorState.VomitBarrage: - MainBehavior_VomitBarrage(target); - break; - } - - SquashVector = Vector2.Lerp(SquashVector, SquashVectorTarget, 0.125f); - EyeGlintScale = MathHelper.Lerp(EyeGlintScale, 0f, 0.125f); - NPC.StepUpBlocks(); - Timer++; - } - - #region Non-Attack Behaviors - public void MainBehavior_EngageAnimation(Player target) - { - if (Timer >= 45f) - { - if (Timer == 45f) - SoundEngine.PlaySound(SoundID.ForceRoarPitched, NPC.Center); - - if (Timer % 10f == 0f) - { - PulseRing hogRoar = new(NPC.Center, Vector2.Zero, Color.Red, 0f, 1.2f, 20); - GeneralParticleHandler.SpawnParticle(hogRoar, true); - } - } - - if (Timer >= 120f) - SwitchBehavior(specificAttack: BehaviorState.ChasePlayer); - - NPC.velocity.X *= 0.9f; - NPC.spriteDirection = (target.Center.X > NPC.Center.X).ToDirectionInt(); - } - - public void MainBehavior_LaughADeadPlayer() - { - if (NPC.velocity.Y == 0f) - { - // LMFAOOOOOOOOOOOOOOOOOOOOOOOO - if (!SoundEngine.TryGetActiveSound(DeathLaughSoundSlot, out var _)) - { - DeathLaughSoundSlot = SoundEngine.PlaySound(DeathLaughSound, NPC.Center, (activeSound) => - { - activeSound.Position = NPC.Center; - return AIState == (int)BehaviorState.LaughAtDeadPlayer; - }); - } - - NPC.direction *= -1; - NPC.velocity.Y -= 4f; - } - - SearchForTargetEveryFrame = true; - NPC.defense = 30; - NPC.damage = 0; - NPC.velocity.X *= 0.92f; - - float targetAngle = NPC.direction < 0 ? MathHelper.ToRadians(50f) : MathHelper.ToRadians(-50f); - NPC.rotation = (NPC.velocity.Y != 0f) ? NPC.rotation.AngleLerp(targetAngle, 0.075f) : 0f; - - if (Timer >= 240f || NPC.justHit) - { - BehaviorState nextAttack = NPC.HasValidTarget ? BehaviorState.ChasePlayer : BehaviorState.Idle; - SwitchBehavior(specificAttack: nextAttack); - } - } - - public void MainBehavior_DespawnAnimation() - { - // Jump into the ground and dig away. - if (Timer < DigTowardsTarget_PreJumpTime) - { - NPC.velocity.X *= 0.8f; - HorizontalShakeStrength = Utils.Remap(Timer, 0, DigTowardsTarget_PreJumpTime - 5, 0f, 6f, true); - SetSquashVectors(new Vector2(1.24f, 0.84f)); - } - - if (Timer == DigTowardsTarget_PreJumpTime) - { - NPC.velocity.Y -= 6f; - NPC.velocity.X += 4f * NPC.direction; - HorizontalShakeStrength = 0f; - - SoundEngine.PlaySound(IdleSound, NPC.Center); - SetSquashVectors(); - } - - if (Timer > DigTowardsTarget_PreJumpTime) - { - if (NPC.velocity.Y == 0f) - { - int dustAmt = Main.rand.Next(10, 15); - for (int i = 0; i < dustAmt; i++) - { - Vector2 dustPosition = NPC.Bottom + Main.rand.NextVector2Circular(NPC.width, 0f); - Vector2 dustVelocity = new Vector2(Main.rand.NextFloat(-4f, 4f), Main.rand.NextFloat(-4f, -2f)); - Dust.NewDust(dustPosition, 1, 1, DustID.Dirt, dustVelocity.X, dustVelocity.Y, Scale: Main.rand.NextFloat(0.8f, 1.2f)); - } - - int dustCloudAmt = Main.rand.Next(9, 13); - for (int i = 0; i < dustCloudAmt; i++) - { - Vector2 spawnPosition = NPC.Bottom + Main.rand.NextVector2Circular(NPC.width, 0f); - Vector2 velocity = new Vector2(Main.rand.NextFloat(-3f, 3f), Main.rand.NextFloat(-2f, -1f)); - Color color = Color.Lerp(Color.SandyBrown, Color.SaddleBrown, Main.rand.NextFloat()); - float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); - - TimedSmokeParticle dustCloud = new(spawnPosition, velocity, color, color, Main.rand.NextFloat(1.2f, 1.4f), 1f, Main.rand.Next(45, 55), rotationSpeed); - GeneralParticleHandler.SpawnParticle(dustCloud, true); - } - - CalamityUtils.AddScreenshakeAt(NPC.Center, 5f); - SoundEngine.PlaySound(SoundID.Item70, NPC.Center); - - NPC.active = false; - NPC.netUpdate = true; - } - } - - float idealRotation = (NPC.velocity.Y != 0f) ? NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi) : 0f; - NPC.rotation = idealRotation; - } - - public void MainBehavior_DeathAnimation() - { - if (Timer == 240f) - { - // Create smoke and throw up a big green "5000" on death just like the pigs in Angry Birds - for (int i = 0; i < 17; i++) - { - int goreType = Main.rand.Next(GoreID.Smoke1, GoreID.Smoke3 + 1); - Gore.NewGorePerfect(NPC.position, Main.rand.NextVector2Circular(2f, 2f), goreType); - } - - CombatText.NewText(NPC.Hitbox, Color.LawnGreen, 5000); - SoundEngine.PlaySound(DeathSound, NPC.Center); - - NPC.life = 0; - NPC.checkDead(); - NPC.HitEffect(); - NPC.netUpdate = true; - } - - NPC.damage = 0; - NPC.dontTakeDamage = true; - - if (NPC.velocity.Y == 0f) - NPC.velocity.X *= 0.96f; - } - - public void MainBehavior_Idle(Player target) - { - bool targetIsVisible = target.Distance(NPC.Center) <= EngageDistance && Collision.CanHit(NPC, target); - bool wasHitByNearestTarget = NPC.HasValidTarget && NPC.justHit; - if (targetIsVisible || wasHitByNearestTarget) - { - SwitchBehavior(specificAttack: BehaviorState.EngageAnimation); - RunEyeGlintEffect(0.4f); - } - - // Standing still, occasionally switch directions. - if (LocalAIState == 0f) - { - if (Timer > 0f && Timer % 45f == 0f && Main.rand.NextBool(12)) - { - Timer = 0f; - LocalAIState = 1f; - NPC.netUpdate = true; - } - - if (NPC.velocity.Y == 0f) - NPC.velocity.X *= 0.8f; - - if (Timer % 45f == 0f && Main.rand.NextBool(4)) - NPC.direction *= -1; - } - - // Walking around aimlessly. - if (LocalAIState == 1f) - { - if (Timer > 0f && Timer % 45f == 0f && Main.rand.NextBool(6)) - { - Timer = 0f; - LocalAIState = 0f; - NPC.netUpdate = true; - } - - if (MathF.Abs(NPC.velocity.X) < Idle_MaxSpeed) - NPC.velocity.X += Idle_MaxAcceleration * NPC.direction; - - bool shouldJump = NPC.collideX || IsNPCApproachingHole(); - if (NPC.velocity.Y == 0f && shouldJump) - NPC.velocity.Y -= 6f; - } - - // Idle sounds. - if (NPC.soundDelay == 0f && Main.rand.NextBool(250)) - { - SetSquashVectors(squashVector: new Vector2(1.24f, 0.84f)); - SoundEngine.PlaySound(IdleSound, NPC.Center); - NPC.soundDelay = Main.rand.Next(30, 45); - } - - NPC.chaseable = false; - SearchForTargetEveryFrame = true; - } - - public void MainBehavior_DigTowardsTarget(Player target) - { - // Initial animation. - if (LocalAIState == 0f) - { - if (Timer < DigTowardsTarget_PreJumpTime) - { - NPC.velocity.X *= 0.8f; - HorizontalShakeStrength = Utils.Remap(Timer, 0, DigTowardsTarget_PreJumpTime - 5, 0f, 6f, true); - SetSquashVectors(new Vector2(1.24f, 0.84f)); - } - - if (Timer == DigTowardsTarget_PreJumpTime) - { - NPC.velocity.Y -= 6f; - HorizontalShakeStrength = 0f; - SetSquashVectors(squashVector: new Vector2(0.84f, 1.24f)); - } - - if (Timer > DigTowardsTarget_PreJumpTime) - { - if (NPC.velocity.Y == 0f) - { - int dustAmt = Main.rand.Next(10, 15); - for (int i = 0; i < dustAmt; i++) - { - Vector2 dustPosition = NPC.Bottom + Main.rand.NextVector2Circular(NPC.width, 0f); - Vector2 dustVelocity = new Vector2(Main.rand.NextFloat(-4f, 4f), Main.rand.NextFloat(-4f, -2f)); - Dust.NewDust(dustPosition, 1, 1, DustID.Dirt, dustVelocity.X, dustVelocity.Y, Scale: Main.rand.NextFloat(0.8f, 1.2f)); - } - - int dustCloudAmt = Main.rand.Next(9, 13); - for (int i = 0; i < dustCloudAmt; i++) - { - Vector2 spawnPosition = NPC.Bottom + Main.rand.NextVector2Circular(NPC.width, 0f); - Vector2 velocity = new Vector2(Main.rand.NextFloat(-3f, 3f), Main.rand.NextFloat(-2f, -1f)); - Color color = Color.Lerp(Color.SandyBrown, Color.SaddleBrown, Main.rand.NextFloat()); - float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); - - TimedSmokeParticle dustCloud = new(spawnPosition, velocity, color, color, Main.rand.NextFloat(1.2f, 1.4f), 1f, Main.rand.Next(45, 55), rotationSpeed); - GeneralParticleHandler.SpawnParticle(dustCloud, true); - } - - SoundEngine.PlaySound(SoundID.Item70, NPC.Center); - LocalAIState = 1f; - Timer = 0f; - SetSquashVectors(); - NPC.netUpdate = true; - } - } - } - - // Search for a position around the player to emerge. - if (LocalAIState == 1f) - { - NPC.damage = 0; - NPC.dontTakeDamage = true; - NPC.Opacity = 0f; - - // Find closest spot around player. - if (Timer <= DigTowardsTarget_FindSuitablePositionTime) - { - DiggingEmergeSpot = FindSuitableGround(target.Bottom.ToTileCoordinates()).ToWorldCoordinates(); - } - else - { - float distanceInterpolant = Utils.GetLerpValue(800f, 200f, target.Distance(DiggingEmergeSpot), true); - float screenshake = Utils.Remap(Timer, DigTowardsTarget_FindSuitablePositionTime, DigTowardsTraget_MaxDiggingTime, 1f, 4f, true) * distanceInterpolant; - target.SetScreenshake(screenshake); - } - - if (Main.rand.NextBool(3)) - { - int dustAmt = Main.rand.Next(1, 3); - for (int i = 0; i < dustAmt; i++) - { - Vector2 dustPosition = DiggingEmergeSpot + Main.rand.NextVector2Circular(NPC.width, 0f); - Vector2 dustVelocity = new Vector2(Main.rand.NextFloat(-2f, 2f), Main.rand.NextFloat(-5f, -3f)); - Dust.NewDust(dustPosition, 1, 1, DustID.Dirt, dustVelocity.X, dustVelocity.Y, Scale: Main.rand.NextFloat(0.8f, 1.2f)); - } - } - - int dustCloudAmt = Main.rand.Next(1, 3); - for (int i = 0; i < dustCloudAmt; i++) - { - Vector2 spawnPosition = DiggingEmergeSpot + Main.rand.NextVector2Circular(NPC.width, 0f); - Vector2 velocity = new Vector2(Main.rand.NextFloat(-2f, 2f), Main.rand.NextFloat(-5f, -3f)); - Color color = Color.Lerp(Color.SandyBrown, Color.SaddleBrown, Main.rand.NextFloat()); - float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); - - TimedSmokeParticle dustCloud = new(spawnPosition, velocity, color, color, Main.rand.NextFloat(0.6f, 0.8f), 1f, Main.rand.Next(25, 45), rotationSpeed); - GeneralParticleHandler.SpawnParticle(dustCloud, true, Enums.GeneralDrawLayer.BeforeSolidTiles); - } - - // Play digging sounds. - if (Timer <= DigTowardsTarget_FindSuitablePositionTime) - { - if (!SoundEngine.TryGetActiveSound(DiggingSoundSlot, out _)) - { - DiggingSoundSlot = SoundEngine.PlaySound(DiggingSlowSound, NPC.Center, (activeSound) => - { - activeSound.Position = DiggingEmergeSpot; - return AIState == (int)BehaviorState.DigTowardsTarget && Timer <= 120; - }); - } - } - else - { - if (!SoundEngine.TryGetActiveSound(DiggingSoundSlot, out _)) - { - DiggingSoundSlot = SoundEngine.PlaySound(DiggingFastSound, NPC.Center, (activeSound) => - { - activeSound.Position = DiggingEmergeSpot; - activeSound.Volume = 1.5f; - return AIState == (int)BehaviorState.DigTowardsTarget && Timer >= 120 && Timer <= 180; - }); - } - } - - // Jump out. - if (Timer >= DigTowardsTraget_MaxDiggingTime) - { - CalamityUtils.AddScreenshakeAt(DiggingEmergeSpot, 4f); - SoundEngine.PlaySound(SoundID.Item70, DiggingEmergeSpot); - - NPC.Center = DiggingEmergeSpot; - NPC.velocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(NPC.Center, target.Center, NPC.gravity, 7f) * new Vector2(1f, 1.45f); - SpawnJumpParticles(); - - LocalAIState = 2f; - Timer = 0f; - NPC.netUpdate = true; - } - - AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); - NPC.rotation = NPC.rotation.AngleLerp(0f, 0.075f); - SpriteRotation = SpriteRotation.AngleLerp(0f, 0.075f); - } - - // Land after jumping and go back to attacking. - if (LocalAIState == 2f) - { - NPC.Opacity = MathHelper.Lerp(NPC.Opacity, 1f, 0.085f); - if (NPC.velocity.Y == 0f && Timer > 2f) - { - RunEyeGlintEffect(0.4f); - SwitchBehavior(specificAttack: BehaviorState.ChasePlayer); - } - - float idealRotation = (NPC.velocity.Y != 0f) ? NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi) : 0f; - NPC.rotation = idealRotation; - NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); - } - - DigTimer = 0f; - SearchForTargetEveryFrame = true; - } - #endregion - - #region Attacks - public void MainBehavior_ChasePlayer(Player target) - { - // Whenever the player is able to be hit, don't modify velocity mid-air. - // Otherwise, move as any grounded NPC would in order to get back towards the player. - bool canHitPlayer = NPC.velocity.Y == 0f && Collision.CanHit(NPC, target); - if (canHitPlayer || !Collision.CanHit(NPC, target)) - { - NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); - GroundedMovement(target.Center, ChasePlayer_MaxSpeed, ChasePlayer_MaxAcceleration); - } - - bool jumpUpToPlayer = Main.expertMode && NPC.Center.Y - target.Center.Y >= 64f; - bool closeToPlayer = MathHelper.Distance(NPC.Center.X, target.Center.X) < 112f; - if (NPC.velocity.Y == 0f && jumpUpToPlayer && closeToPlayer) - NPC.velocity.Y -= 8f; - - bool closeEnoughToAttack = MathHelper.Distance(NPC.Center.X, target.Center.X) <= 64f; - if (Timer >= ChaseTime || (closeEnoughToAttack && Timer >= 120f && NPC.velocity.Y == 0f)) - { - List possibleAttacks = [BehaviorState.JumpAndDash]; - if (NPC.Center.Y - target.Center.Y < 128) - possibleAttacks.Add(BehaviorState.HogCharge); - SwitchBehavior(BehaviorState.ChasePlayer, null, [.. possibleAttacks]); - } - - float idealRotation = (NPC.velocity.Y != 0f) ? NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi) : 0f; - NPC.rotation = idealRotation; - } - - public void MainBehavior_HogCharge(Player target) - { - if (LocalAIState == 0f) - { - if (Timer <= HogCharge_PreChargeTime) - { - if (NPC.velocity.Y == 0f) - { - if (MathF.Abs(NPC.velocity.X) > 0.4f) - NPC.velocity.X *= 0.9f; - else - NPC.velocity.X -= 0.08f * NPC.direction; - } - - NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); - } - - if (Timer >= HogCharge_PreChargeTime) - { - Timer = 0f; - LocalAIState = 1f; - NPC.netUpdate = true; - } - - NPC.rotation = 0f; - } - - if (LocalAIState == 1f) - { - bool finishedWithCharges = Timer >= HogCharge_ChargingTime || MiscAttackCounter >= HogCharge_MaxCharges; - if (Timer <= 0f) - { - // Kill the hitbox when slowing down. - KillChargeHitboxProjectile(); - - if (NPC.velocity.Y == 0f) - NPC.velocity.X *= 0.93f; - NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); - NPC.rotation = 0f; - - Vector2 dustPosition = new(NPC.Bottom.X + Main.rand.NextFloat(-NPC.width * 0.5f, NPC.width * 0.5f), NPC.Bottom.Y); - Dust.NewDustPerfect(dustPosition, DustID.Cloud, new Vector2(NPC.velocity.X * 0.4f, Main.rand.NextFloat(-0.38f, 0.38f)), 120, Color.LightGray, Main.rand.NextFloat(1f, 1.2f)); - if (Timer % 2 == 0f) - SoundEngine.PlaySound(SoundID.Item55 with { Pitch = -0.4f, Identifier = "Horrible Hog Slowdown" }, NPC.Center); - - AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); - if (Timer == -10 && !finishedWithCharges) - RunEyeGlintEffect(0.4f); - } - else - { - // Spawn an artificial hitbox that can knockback and hit both hostile and friendly enemies alongside the player. - if (!CalamityUtils.AnyProjectiles(ModContent.ProjectileType()) && Main.netMode != NetmodeID.MultiplayerClient) - { - float knockback = 20f; - Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Center, Vector2.Zero, ModContent.ProjectileType(), Damage_HogCharge, knockback, ai0: NPC.whoAmI); - } - - float maxSpeed = MathHelper.Lerp(HogCharge_MaxSpeed, HogCharge_MaxSpeed + 3.5f, MiscAttackCounter / HogCharge_MaxCharges); - float maxAcceleration = MathHelper.Lerp(HogCharge_MaxAcceleration, HogCharge_MaxAcceleration + 0.35f, MiscAttackCounter / HogCharge_MaxCharges); - if (MathF.Abs(NPC.velocity.X) < maxSpeed) - NPC.velocity.X += maxAcceleration * NPC.direction; - - // Turn around if the player jumps over to the other side of it. - bool turnLeft = NPC.direction == 1 && (NPC.Center.X - target.Center.X) > HogCharge_MaxSlowdownDistance; - bool turnRight = NPC.direction == -1 && (NPC.Center.X - target.Center.X) < -HogCharge_MaxSlowdownDistance; - bool hitAWall = NPC.collideX && MathF.Abs(NPC.velocity.X) >= maxSpeed * 0.8f; - if (((turnLeft || turnRight) && Timer > 30f) || finishedWithCharges || hitAWall) - { - if (hitAWall) - { - NPC.velocity.X = NPC.oldVelocity.X * -0.64f; - NPC.velocity.Y -= 5f; - } - - Timer = HogCharge_ChargeCooldownTime; - MiscAttackCounter++; - if (finishedWithCharges && PhaseTwo) - AltAttackVariant = Main.rand.Next(2); - NPC.netUpdate = true; - } - - Vector2 dustPosition = new(NPC.Bottom.X + Main.rand.NextFloat(-NPC.width * 0.5f, NPC.width * 0.5f), NPC.Bottom.Y); - Dust.NewDustPerfect(dustPosition, DustID.Cloud, new Vector2(NPC.velocity.X * 0.2f, Main.rand.NextFloat(-0.3f, 0.3f)), 120, Color.LightGray, Main.rand.NextFloat(1f, 1.2f)); - if (Timer % 7 == 0f && NPC.velocity.Y == 0f) - SoundEngine.PlaySound(SoundID.Run with { Pitch = -0.4f, Identifier = "Horrible Hog Run" }, NPC.Center); - - AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 1f, 0.15f); - - if (MiscAttackCounter >= HogCharge_MaxCharges + 1) - { - KillChargeHitboxProjectile(); - if (PhaseTwo && AltAttackVariant == 1f) - { - LocalAIState = 2f; - Timer = 0f; - NPC.netUpdate = true; - } - else - { - List possibleAttacks = [BehaviorState.HorribleHoller, BehaviorState.JumpAndDash, BehaviorState.VomitBarrage]; - SwitchBehavior(BehaviorState.HogCharge, null, [.. possibleAttacks]); - } - } - - NPC.damage = 0; - NPC.rotation = 0f; - } - } - - // Alt attack in phase two. - // Same jump and dash but with a smaller shockwave. - if (LocalAIState == 2f) - { - if (Timer == 0f) - { - NPC.velocity.Y = -JumpAndDash_MaxJumpHeight * 1.2f; - NPC.velocity.X += JumpAndDash_MaxDashSpeed * 0.4f * NPC.direction; - SpawnJumpParticles(); - } - - if (Timer <= HogCharge_PreDashTime) - { - NPC.velocity.Y *= 0.98f; - NPC.velocity.X *= 0.96f; - - SetSquashVectors(new Vector2(1.06f, 0.94f)); - NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); - SpriteRotation -= (MathHelper.TwoPi / 20f) * NPC.direction; - - if (Timer <= HogCharge_PreDashTime - 10) - { - NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); - LastPlayerPosition = target.Center; - if (Timer == HogCharge_PreDashTime - 10) - RunEyeGlintEffect(0.6f); - } - } - - if (Timer == HogCharge_PreDashTime) - { - NPC.noGravity = true; - NPC.velocity = NPC.SafeDirectionTo(LastPlayerPosition) * JumpAndDash_MaxDashSpeed; - - SetSquashVectors(new Vector2(1.12f, 0.96f)); - SpriteRotation = 0f; - NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); - } - - if (Timer >= HogCharge_PreDashTime && Timer <= HogCharge_PreDashTime + HogCharge_DashTime) - { - if (NPC.collideX || NPC.collideY || Collision.SolidCollision(NPC.position, NPC.width, NPC.height)) - { - // Spawn shockwave on tile impact. - if (Main.netMode != NetmodeID.MultiplayerClient) - { - for (int i = 0; i < 2; i++) - SpawnShockwave(2, 6, (i > 0).ToDirectionInt(), 2f); - } - - CalamityUtils.AddScreenshakeAt(NPC.Center, 6f); - Collision.HitTiles(NPC.position, NPC.velocity, NPC.width, NPC.height); - NPC.velocity.X = NPC.DirectionFrom(target.Center).SafeNormalize(Vector2.UnitX).X * 3f; - NPC.velocity.Y = -10f; - LocalAIState = 3f; - Timer = 0f; - NPC.netUpdate = true; - } - - NPC.noGravity = true; - NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); - } - - if (Timer >= HogCharge_PreDashTime + HogCharge_DashTime) - { - if (NPC.velocity.Y == 0f) - { - SetSquashVectors(); - LocalAIState = 3f; - Timer = 0f; - NPC.netUpdate = true; - } - - NPC.GravityMultiplier *= 3f; - NPC.velocity.X *= 0.95f; - SpriteRotation = 0f; - } - - SetSquashVectors(VelocityBasedSquashNStretch); - } - - // Rebounding, land and switch attacks. - if (LocalAIState == 3f) - { - if (NPC.velocity.Y == 0f && Timer > 2f) - { - List possibleAttacks = [BehaviorState.HorribleHoller, BehaviorState.JumpAndDash, BehaviorState.VomitBarrage]; - SwitchBehavior(BehaviorState.HogCharge, null, [.. possibleAttacks]); - } - - NPC.rotation = NPC.rotation.AngleLerp(0f, 0.075f); - SpriteRotation = SpriteRotation.AngleLerp(0f, 0.075f); - } - } - - public void MainBehavior_JumpAndDash(Player target) - { - // Stop, jump and dash towards the target. - if (LocalAIState == 0f) - { - if (Timer <= JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime) - { - NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); - if (Timer < JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime - 15) - LastPlayerPosition = target.Center; - } - - if (Timer <= JumpAndDash_PreJumpTime) - { - GroundedMovement(target.Center, ChasePlayer_MaxSpeed, ChasePlayer_MaxAcceleration, slowdownDistance: 160f); - float targetAngle = (NPC.velocity.Y != 0f) ? NPC.velocity.X * 0.175f * (NPC.velocity.Y < 0).ToDirectionInt() : 0f; - NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.075f); - - int preJumpVisualsTime = JumpAndDash_PreJumpTime - 30; - if (Timer >= preJumpVisualsTime) - { - NPC.velocity.X *= 0.96f; - float interpolant = Utils.GetLerpValue(preJumpVisualsTime, VomitBarrage_PreJumpTime, Timer, true); - HorizontalShakeStrength = MathHelper.Lerp(0f, 6f, interpolant); - SetSquashVectors(new Vector2(1.24f, 0.84f)); - } - } - - if (Timer == JumpAndDash_PreJumpTime) - { - NPC.velocity.Y = -JumpAndDash_MaxJumpHeight; - NPC.velocity.X += JumpAndDash_MaxDashSpeed * 0.2f * NPC.direction; - - SpawnJumpParticles(); - SetSquashVectors(new Vector2(0.84f, 1.14f)); - HorizontalShakeStrength = 0f; - } - - if (Timer >= JumpAndDash_PreJumpTime && Timer <= JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime) - { - NPC.velocity.Y *= 0.98f; - NPC.velocity.X *= 0.96f; - - NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); - SpriteRotation -= (MathHelper.TwoPi / 20f) * NPC.direction; - AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 1f, 0.15f); - if (Timer == JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime - 10) - RunEyeGlintEffect(0.4f); - } - - if (Timer == JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime) - { - NPC.noGravity = true; - NPC.velocity = NPC.SafeDirectionTo(LastPlayerPosition) * JumpAndDash_MaxDashSpeed; - - SpriteRotation = 0f; - NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); - } - - if (Timer >= JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime && Timer <= JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime + JumpAndDash_DashTime) - { - if (NPC.collideX || NPC.collideY || Collision.SolidCollision(NPC.position, NPC.width, NPC.height)) - { - // Spawn shockwave on tile impact. - if (Main.netMode != NetmodeID.MultiplayerClient) - { - for (int i = 0; i < 2; i++) - { - int shockwaveAmt = PhaseTwo ? 14 : 8; - SpawnShockwave(2, shockwaveAmt, (i > 0).ToDirectionInt(), 3f); - } - } - - CalamityUtils.AddScreenshakeAt(NPC.Center, 6f); - Collision.HitTiles(NPC.position, NPC.velocity, NPC.width, NPC.height); - NPC.velocity.X = NPC.DirectionFrom(target.Center).SafeNormalize(Vector2.UnitX).X * 5f; - NPC.velocity.Y = PhaseTwo ? -16f : -12f; - LocalAIState = 1f; - Timer = 0f; - AltAttackVariant = Main.rand.Next(2); - NPC.netUpdate = true; - } - - NPC.noGravity = true; - NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); - } - - if (Timer >= JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime + JumpAndDash_DashTime) - { - if (NPC.velocity.Y == 0f) - { - LocalAIState = 2f; - Timer = 0f; - NPC.netUpdate = true; - } - - NPC.GravityMultiplier *= 3f; - NPC.velocity.X *= 0.95f; - AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); - } - - if (Timer > JumpAndDash_PreJumpTime) - SetSquashVectors(VelocityBasedSquashNStretch); - } - - // Rebounding after ground collision. - if (LocalAIState == 1f) - { - // Randomly perform two smaller attacks right after the main dash in Phase two. - if (PhaseTwo) - { - // Shoot vomit chunks at the player. - // Shoot more in higher difficulties. - if (AltAttackVariant == 0f) - { - if (Timer <= JumpAndDash_PreVomitTime) - { - NPC.velocity *= 0.98f; - NPC.GravityMultiplier *= 0.84f; - if (Timer == JumpAndDash_PreVomitTime - 10) - RunEyeGlintEffect(0.6f); - } - - if (Timer >= JumpAndDash_PreVomitTime) - { - if (Timer % JumpAndDash_VomitTimeInterval == 0f && MiscAttackCounter < JumpAndDash_MaxVomitChunks) - { - if (Main.netMode != NetmodeID.MultiplayerClient) - { - int maxVomitPerShot = 2; - for (int i = 0; i < maxVomitPerShot; i++) - { - Vector2 chunkVelocity = NPC.SafeDirectionTo(target.Center).RotatedBy(MathHelper.ToRadians(MathHelper.Lerp(-22f, 22f, i / (maxVomitPerShot - 1)))) * 14f; - Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Center, chunkVelocity, ModContent.ProjectileType(), Damage_VomitChunkProjectile, 0f); - } - } - - Vector2 knockbackVelocity = NPC.DirectionFrom(target.Center).SafeNormalize(-Vector2.UnitY); - NPC.velocity = knockbackVelocity * new Vector2(3f, 5f); - - SoundEngine.PlaySound(SoundID.DD2_OgreSpit, NPC.Center); - MiscAttackCounter++; - NPC.netUpdate = true; - } - - if (MiscAttackCounter >= JumpAndDash_MaxVomitChunks && NPC.velocity.Y == 0f) - { - LocalAIState = 2f; - Timer = 0f; - NPC.netUpdate = true; - } - } - - SetSquashVectors(); - NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); - NPC.rotation = NPC.rotation.AngleLerp(NPC.AngleTo(target.Center) + (NPC.direction > 0 ? 0f : -MathHelper.Pi), 0.15f); - SpriteRotation = 0f; - AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); - } - - // Bounce on the ground near the player predictively. - // In Death Mode and above, perform a large ground pound after the last bounce. - if (AltAttackVariant == 1f) - { - // Using plus 1 here cause the first bounce is coming off of the rebound. - if (MiscAttackCounter <= JumpAndDash_MaxBounces) - { - if (NPC.velocity.Y == 0f) - { - if (MiscAttackCounter == JumpAndDash_MaxBounces) - { - if (!CalamityWorld.death) - { - LocalAIState = 2f; - } - else - { - // Try to bounce in front of the player for the ground pound. - Vector2 bounceVelocity = (target.Center.X > NPC.Center.X) ? new Vector2(18f, -20f) : new Vector2(-18f, -20f); - NPC.velocity = bounceVelocity; - } - - Timer = 0f; - } - else - { - float speedByDistance = Utils.Remap(MathHelper.Distance(target.Center.X, NPC.Center.X), 60f, 600f, 4f, 10f, true); - float xVelocity = speedByDistance * (target.Center.X > NPC.Center.X).ToDirectionInt(); - NPC.velocity = new Vector2(xVelocity, -11.25f); - } - - if (Main.netMode != NetmodeID.MultiplayerClient && MiscAttackCounter > 0f) - { - for (int i = 0; i < 2; i++) - SpawnShockwave(2, 4, (i > 0).ToDirectionInt(), 2f); - - for (int i = 0; i < MiscAttackCounter; i++) - { - Vector2 rubbleVelocityRight = new Vector2(2f + i * 3f, -8f - i * 1.25f); - Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Bottom, rubbleVelocityRight, ModContent.ProjectileType(), Damage_ShockwaveProjectile, 1f); - Vector2 rubbleVelocityLeft = new Vector2(-2f - i * 3f, -8f - i * 1.25f); - Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Bottom, rubbleVelocityLeft, ModContent.ProjectileType(), Damage_ShockwaveProjectile, 1f); - } - } - - CalamityUtils.AddScreenshakeAt(NPC.Center, 4f); - MiscAttackCounter++; - NPC.netUpdate = true; - } - - if (NPC.velocity.Y > 1f && NPC.velocity.Y < 24f && MiscAttackCounter > 0f) - { - NPC.velocity.Y *= 1.12f; - NPC.velocity.X *= 0.96f; - NPC.noGravity = true; - } - } - - // Ground pound attack in Death Mode. - if (CalamityWorld.death && MiscAttackCounter >= JumpAndDash_MaxBounces + 1) - { - if (Timer < JumpAndDash_PreGroundPoundTime) - { - NPC.velocity *= 0.96f; - NPC.GravityMultiplier *= 0.4f; - if (Timer == JumpAndDash_PreGroundPoundTime - 10) - RunEyeGlintEffect(0.6f); - } - else - { - NPC.noGravity = true; - } - - if (Timer == JumpAndDash_PreGroundPoundTime) - { - NPC.velocity.Y = 30f; - NPC.velocity.X *= 0f; - } - - if (Timer > JumpAndDash_PreGroundPoundTime && NPC.velocity.Y == 0f) - { - if (Main.netMode != NetmodeID.MultiplayerClient) - SpawnShockwave(2, 20, (target.Center.X > NPC.Center.X).ToDirectionInt(), 8f); - - CalamityUtils.AddScreenshakeAt(NPC.Center, 8f); - Collision.HitTiles(NPC.position, NPC.velocity, NPC.width, NPC.height); - NPC.velocity.X = NPC.DirectionFrom(target.Center).SafeNormalize(Vector2.UnitX).X * 4f; - NPC.velocity.Y = -12f; - LocalAIState = 2f; - Timer = 0f; - NPC.netUpdate = true; - } - } - - NPC.damage = 0; - NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); - SpriteRotation -= (MathHelper.TwoPi / 20f) * NPC.direction; - SetSquashVectors(VelocityBasedSquashNStretch); - } - } - else - { - if (NPC.collideY && Timer > 2f) - { - LocalAIState = 2f; - Timer = 0f; - NPC.netUpdate = true; - } - - SetSquashVectors(); - SpriteRotation -= (MathHelper.TwoPi / 20f) * NPC.direction; - NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); - AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); - } - } - - // Landed back on the ground. - if (LocalAIState == 2f) - { - NPC.velocity.X *= 0.94f; - if (NPC.velocity.Y == 0f) - { - NPC.rotation = 0f; - SpriteRotation = 0f; - } - - AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); - NPC.rotation = NPC.rotation.AngleLerp(0f, 0.075f); - SpriteRotation = SpriteRotation.AngleLerp(0f, 0.075f); - SetSquashVectors(); - - if (Timer >= JumpAndDash_CooldownTime && NPC.velocity.Y == 0f) - { - List possibleAttacks = [BehaviorState.VomitBarrage, BehaviorState.HorribleHoller]; - if (NPC.Center.Y - target.Center.Y < 128) - possibleAttacks.Add(BehaviorState.HogCharge); - - SwitchBehavior(BehaviorState.JumpAndDash, null, [.. possibleAttacks]); - } - } - } - - public void MainBehavior_HorribleHoller(Player target) - { - NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); - if (NPC.velocity.Y == 0f) - NPC.velocity.X *= 0.9f; - - if (Timer <= HorribleHoller_RoarTime) - { - if (Timer == HorribleHoller_RoarTime - 30) - { - SoundEngine.PlaySound(SoundID.Roar, NPC.Center); - CalamityUtils.AddScreenshakeAt(NPC.Center, 6f); - NPC.velocity.Y -= 6f; - } - - // Spawn the Zombie Spawner projectiles on top of tiles. - if (Timer == HorribleHoller_RoarTime) - { - for (int i = 0; i < HorribleHoller_MaxZombies; i++) - { - int maxTileRange = 12; - Vector2 zombieSpawnPosition = NPC.Center + new Vector2(Main.rand.Next(-maxTileRange * 16, (maxTileRange + 1) * 16), 0f); - Vector2 actualSpawnPosition = FindSuitableGround(zombieSpawnPosition.ToTileCoordinates()).ToWorldCoordinates() + Vector2.UnitY * 16f; - - if (Main.netMode != NetmodeID.MultiplayerClient) - { - int maxTime = 150 + Main.rand.Next(31); - Projectile.NewProjectile(NPC.GetSource_FromThis(), actualSpawnPosition, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, Main.myPlayer, 0f, maxTime); - } - } - } - } - - float targetAngle = (NPC.velocity.Y != 0f) ? NPC.velocity.X * 0.125f * (NPC.velocity.Y < 0).ToDirectionInt() : 0f; - if (Timer >= HorribleHoller_RoarTime - 30 && Timer <= HorribleHoller_RoarTime) - targetAngle = (NPC.velocity.Y != 0f) ? (NPC.direction < 0 ? MathHelper.ToRadians(50f) : MathHelper.ToRadians(-50f)) : 0f; - - NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.125f); - - if (Timer >= HorribleHoller_RoarTime + HorribleHoller_PostRoarCooldownTime) - { - List possibleAttacks = [BehaviorState.ChasePlayer, BehaviorState.VomitBarrage]; - SwitchBehavior(BehaviorState.HorribleHoller, null, [.. possibleAttacks]); - } - } - - public void MainBehavior_VomitBarrage(Player target) - { - if (LocalAIState == 0f) - { - if (Timer == 1f) - { - SoundEngine.PlaySound(SoundID.DD2_DrakinBreathIn, NPC.Center); - if (PhaseTwo && CalamityWorld.revenge) - { - AltAttackVariant = Main.rand.Next(2); - NPC.netUpdate = true; - } - } - - // Move away from the player. - if (Timer <= VomitBarrage_PreJumpTime) - { - NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); - GroundedMovement(target.Center, VomitBarrage_MaxSpeed, ChasePlayer_MaxAcceleration, slowdownDistance: 200f); - - float targetAngle = (NPC.velocity.Y != 0f) ? NPC.velocity.X * 0.135f * (NPC.velocity.Y < 0).ToDirectionInt() : 0f; - NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.125f); - - int preJumpVisualsTime = VomitBarrage_PreJumpTime - 30; - if (Timer >= preJumpVisualsTime) - { - NPC.velocity.X *= 0.96f; - float interpolant = Utils.GetLerpValue(preJumpVisualsTime, VomitBarrage_PreJumpTime, Timer, true); - HorizontalShakeStrength = MathHelper.Lerp(0f, 6f, interpolant); - SetSquashVectors(new Vector2(1.24f, 0.84f)); - } - } - - // Jump and shoot a bunch of vomit projectiles shortly afterwards. - if (Timer == VomitBarrage_PreJumpTime) - { - SetSquashVectors(squashVector: new Vector2(0.84f, 1.14f)); - NPC.velocity.Y = -JumpAndDash_MaxJumpHeight; - NPC.velocity.X = -12f * NPC.direction; - HorizontalShakeStrength = 0f; - SpawnJumpParticles(6, 9); - } - - if (Timer >= VomitBarrage_PreJumpTime && Timer <= VomitBarrage_PreJumpTime + VomitBarrage_VomitTime) - { - NPC.velocity.Y *= 0.98f; - NPC.velocity.X *= 0.96f; - - float targetAngle = NPC.direction < 0 ? MathHelper.ToRadians(50f) : MathHelper.ToRadians(-50f); - NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.075f); - } - - if (Timer == JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime) - { - bool spawnEyeballs = PhaseTwo && CalamityWorld.revenge && AltAttackVariant == 1f; - if (Main.netMode != NetmodeID.MultiplayerClient) - { - for (int i = 0; i < VomitBarrage_MaxVomitChunks; i++) - { - int projectileType = ModContent.ProjectileType(); - int damage = Damage_VomitChunkProjectile; - - // Randomly replace chunks with bombs in Expert and above. - bool vomitBombFloorNotReached = MiscAttackCounter < VomitBarrage_MinVomitBombs; - bool vomitBombCeilingNotReached = Main.rand.NextBool(4) && MiscAttackCounter >= VomitBarrage_MinVomitBombs && MiscAttackCounter < VomitBarrage_MaxVomitBombs; - if (Main.expertMode && (vomitBombFloorNotReached || vomitBombCeilingNotReached)) - { - projectileType = ModContent.ProjectileType(); - damage = Damage_VomitBombProjectile; - MiscAttackCounter++; - } - - // Replace chunks with homing Demon Eyes in Rev+ during phase two when the alt attack is picked. - if (spawnEyeballs) - { - projectileType = ModContent.ProjectileType(); - damage = Damage_VomitEyeProjectile; - } - - Vector2 vomitVelocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(NPC.Center, target.Center + new Vector2(Main.rand.NextFloat(-16f, 16f), 0f), 0.125f, Main.rand.NextFloat(5f, 8f)); - vomitVelocity.X *= Main.rand.NextFloat(0.25f, 2.25f); - int vomit = Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Center, vomitVelocity, projectileType, damage, 0f); - if (spawnEyeballs) - Main.projectile[vomit].ai[0] = Main.rand.Next(45, 75); - if (projectileType == ModContent.ProjectileType()) - Main.projectile[vomit].ai[1] = NPC.whoAmI; - } - } - - SoundEngine.PlaySound(SoundID.DD2_DrakinShot, NPC.Center); - NPC.velocity.X = 6f * -NPC.direction; - NPC.velocity.Y += 2f; - } - - if (Timer > JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime && NPC.velocity.Y == 0f) - { - LocalAIState = 1f; - Timer = 0f; - NPC.netUpdate = true; - } - } - - if (LocalAIState == 1f) - { - if (Timer >= VomitBarrage_PostVomitCooldown) - { - List possibleAttacks = [BehaviorState.HorribleHoller, BehaviorState.JumpAndDash]; - if (NPC.Center.Y - target.Center.Y < 128) - possibleAttacks.Add(BehaviorState.HogCharge); - SwitchBehavior(BehaviorState.VomitBarrage, null, [.. possibleAttacks]); - } - - if (NPC.velocity.Y == 0f) - NPC.velocity.X *= 0.9f; - - float targetAngle = (NPC.velocity.Y != 0f) ? NPC.velocity.X * 0.135f * (NPC.velocity.Y < 0).ToDirectionInt() : 0f; - NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.125f); - NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); - } - } - #endregion - - public void SwitchBehavior(BehaviorState? attackToRecord = null, BehaviorState? specificAttack = null, params BehaviorState[] attacksToChooseFrom) - { - // Reset all the previous attack counters and weights in order to start a new cycle once the maximum amount of attacks overall has been reached. - if (MainAttackCounter >= MaxAttacksPerCycle) - { - // Also search for the nearest target again once the attack cycle resets. - NPC.TargetClosest(false); - - foreach (BehaviorState attack in PreviousAttackCounters.Keys) - PreviousAttackCounters[attack] = 0; - ResetAttackWeights(); - MainAttackCounter = 0f; - } - - if (attackToRecord.HasValue) - { - // Record the last attack to a dictionary and increment how many times it has been performed. - if (!PreviousAttackCounters.ContainsKey(attackToRecord.Value)) - PreviousAttackCounters[attackToRecord.Value] = 0; - PreviousAttackCounters[attackToRecord.Value]++; - - // Increase the weight of other attacks and lower this one. - AttackWeights[attackToRecord.Value] -= 0.33f; - foreach (BehaviorState attack in AttackWeights.Keys) - AttackWeights[attack] += 0.33f; - - MainAttackCounter++; - } - - // Default to returning to idling in the event there are no nearby targets after performing an attack. - BehaviorState nextAttack = BehaviorState.Idle; - - // Switch to a specific behavior state if one is specified. - // Otherwise, pick from the random attack array. - if (specificAttack.HasValue) - { - nextAttack = specificAttack.Value; - } - else if (NPC.HasValidTarget && attacksToChooseFrom.Length > 0) - { - WeightedRandom possibleAttacks = new(); - for (int i = 0; i < attacksToChooseFrom.Length; i++) - { - // Don't add attacks to the attack pool if they've been performed their maximum amount of times. - if (PreviousAttackCounters.TryGetValue(attacksToChooseFrom[i], out var timesPerformed) && timesPerformed >= GetMaxAttackValue(attacksToChooseFrom[i])) - continue; - - possibleAttacks.Add(attacksToChooseFrom[i], AttackWeights[attacksToChooseFrom[i]]); - } - - // Pick a random attack. - nextAttack = possibleAttacks; - } - - // Reset so this once Hog has another player to target so it doesn't loop. - if (NPC.HasValidTarget) - ReadyToPlayLaughingAnimation = true; - - // Switch and reset certain fields. - AIState = (int)nextAttack; - LocalAIState = 0f; - Timer = 0f; - MiscAttackCounter = 0f; - AltAttackVariant = 0f; - SpriteRotation = 0f; - AfterimageTrailOpacity = 0f; - SearchForTargetEveryFrame = false; - - SetSquashVectors(); - KillChargeHitboxProjectile(); - - NPC.netUpdate = true; - } - - private int GetMaxAttackValue(BehaviorState attack) - { - int maxValue = attack switch - { - BehaviorState.ChasePlayer => MaxAttacks_ChasePlayer, - BehaviorState.HogCharge => MaxAttacks_HogCharge, - BehaviorState.JumpAndDash => MaxAttacks_JumpAndDash, - BehaviorState.HorribleHoller => MaxAttacks_HorribleHoller, - BehaviorState.VomitBarrage => MaxAttacks_VomitBarrage, - _ => 1 - }; - - // Every attack can be used one more time in phase two. - if (PhaseTwo) - maxValue += 1; - - return maxValue; - } - - private void ResetAttackWeights() - { - AttackWeights[BehaviorState.ChasePlayer] = 1f; - AttackWeights[BehaviorState.HogCharge] = 0.33f; - AttackWeights[BehaviorState.JumpAndDash] = 1f; - AttackWeights[BehaviorState.HorribleHoller] = 0.33f; - AttackWeights[BehaviorState.VomitBarrage] = 0.66f; - } - - private void GroundedMovement(Vector2 targetPosition, float maxSpeed, float maxAcceleration, float jumpHeight = 10f, float? slowdownDistance = null) - { - float distanceToPlayer = MathF.Abs(NPC.Center.X - targetPosition.X); - if (targetPosition.X > NPC.Center.X) - { - if (slowdownDistance.HasValue) - { - if (distanceToPlayer > slowdownDistance.Value) - NPC.velocity.X += maxAcceleration; - else - NPC.velocity.X -= maxAcceleration; - } - else - { - NPC.velocity.X += maxAcceleration; - } - - } - else if (targetPosition.X < NPC.Center.X) - { - if (slowdownDistance.HasValue) - { - if (distanceToPlayer > slowdownDistance.Value) - NPC.velocity.X -= maxAcceleration; - else - NPC.velocity.X += maxAcceleration; - } - else - { - NPC.velocity.X -= maxAcceleration; - } - } - - if (NPC.velocity.Y == 0f) - { - if (NPC.collideX || IsNPCApproachingHole()) - NPC.velocity.Y -= jumpHeight; - } - - NPC.velocity.X = MathHelper.Clamp(NPC.velocity.X, -maxSpeed, maxSpeed); - } - - private bool IsNPCApproachingHole() - { - int npcWidthInTiles = NPC.width / 16; - int tileX = (int)(NPC.Center.X / 16f) - npcWidthInTiles; - if (NPC.velocity.X > 0) - tileX += npcWidthInTiles; - - int tileY = (int)((NPC.position.Y + NPC.height) / 16f); - for (int y = tileY; y < tileY + 2; y++) - { - for (int x = tileX; x < tileX + npcWidthInTiles; x++) - { - if (Main.tile[x, y].HasTile) - { - return false; - } - } - } - return true; - } - - private Point FindSuitableGround(Point basePoint) - { - // Tile is solid. Check to ensure the tile above is also isn't solid and move up if it is. - if (WorldGen.ActiveAndWalkableTile(basePoint.X, basePoint.Y)) - { - while (WorldGen.ActiveAndWalkableTile(basePoint.X, basePoint.Y - 1) && basePoint.Y >= 1) - basePoint.Y--; - } - // Tile isn't solid. Check to ensure the tile under it is solid and move down if it isn't. - else - { - while (!WorldGen.ActiveAndWalkableTile(basePoint.X, basePoint.Y + 1) && basePoint.Y < Main.maxTilesY) - basePoint.Y++; - } - - return basePoint; - } - - private void SpawnShockwave(int spawnImterval, int maxShockwaves, int direction, float heightMultiplier) - { - int spawnerIndex = Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Bottom, Vector2.Zero, ModContent.ProjectileType(), Damage_ShockwaveProjectile, 0f); - Main.projectile[spawnerIndex].ai[1] = spawnImterval; - Main.projectile[spawnerIndex].ai[2] = maxShockwaves; - Main.projectile[spawnerIndex].localAI[1] = direction; - Main.projectile[spawnerIndex].localAI[2] = heightMultiplier; - Main.projectile[spawnerIndex].ModProjectile().OwnerIndex = NPC.whoAmI; - Main.projectile[spawnerIndex].netUpdate = true; - } - - private void SpawnJumpParticles(int dustCloudMin = 10, int dustCloudMax = 14, int dirtDustMin = 14, int dirtDustMax = 18) - { - // Do fart in a jar visuals when Hog does a jump mid-air. - float tileCollisionDistance = CalamityUtils.DistanceToTileCollisionHit(NPC.Bottom, Vector2.UnitY, 10) ?? 9999f; - if (tileCollisionDistance > 18f) - { - int fartCloudAmt = Main.rand.Next(dustCloudMin, dustCloudMax + 1); - for (int i = 0; i < fartCloudAmt; i++) - { - Vector2 spawnPosition = NPC.Bottom + Main.rand.NextVector2Circular(32f, 0f); - Vector2 velocity = Main.rand.NextVector2Circular(2f, 2f); - int goreType = Main.rand.Next(GoreID.FartCloud1, GoreID.FartCloud3 + 1); - Gore.NewGore(spawnPosition, velocity, goreType); - } - - int fartDustAmt = Main.rand.Next(dirtDustMin, dirtDustMax + 1); - for (int i = 0; i < fartDustAmt; i++) - { - Vector2 velocity = Main.rand.NextVector2Circular(2f, 2f); - Dust.NewDust(NPC.Bottom, 0, 0, DustID.FartInAJar, velocity.X, velocity.Y, Scale: Main.rand.NextFloat(0.8f, 1.2f)); - } - - SoundEngine.PlaySound(SoundID.Item16, NPC.Center); - } - else - { - int dustCloudAmt = Main.rand.Next(dustCloudMin, dustCloudMax + 1); - for (int i = 0; i < dustCloudAmt; i++) - { - Vector2 spawnPosition = NPC.Bottom + Main.rand.NextVector2Circular(32f, 0f); - Vector2 velocity = NPC.velocity * (Main.rand.NextFloat(0.1f, 0.2f) + i * 0.1f); - Color color = Color.Lerp(Color.SaddleBrown, Color.SandyBrown, Main.rand.NextFloat()); - float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); - - TimedSmokeParticle launchCloud = new(spawnPosition, velocity, color, color, Main.rand.NextFloat(0.4f, 0.6f), Main.rand.NextFloat(0.6f, 0.8f), Main.rand.Next(30, 45), rotationSpeed); - GeneralParticleHandler.SpawnParticle(launchCloud, true, Enums.GeneralDrawLayer.BeforeSolidTiles); - } - - int dustAmt = Main.rand.Next(dirtDustMin, dirtDustMax + 1); - for (int i = 0; i < dustAmt; i++) - { - Vector2 velocity = NPC.velocity * (Main.rand.NextFloat(0.1f, 0.2f) + i * 0.025f); - Dust.NewDust(NPC.Bottom, 0, 0, DustID.Dirt, velocity.X, velocity.Y); - } - } - } - - private void KillChargeHitboxProjectile() - { - if (CalamityUtils.AnyProjectiles(ModContent.ProjectileType())) - { - int hitboxIndex = CalamityUtils.FindFirstProjectile(ModContent.ProjectileType()); - if (Main.projectile.IndexInRange(hitboxIndex) && Main.projectile[hitboxIndex].ai[0] == NPC.whoAmI) - { - Main.projectile[hitboxIndex].Kill(); - Main.projectile[hitboxIndex].netUpdate = true; - } - } - } - - public override float SpawnChance(NPCSpawnInfo spawnInfo) - { - if (Main.bloodMoon && NPC.downedBoss1 && NPC.CountNPCS(Type) < 1) - { - float spawnChanceMultiplier = CalamityWorld.death ? 0.0075f : 0.025f; - return SpawnCondition.OverworldNightMonster.Chance * spawnChanceMultiplier; - } - return 0f; - } - - public override void HitEffect(NPC.HitInfo hit) - { - // Death effects spawned in MainBehavior_DeathAnimation. - if (NPC.life <= 0) - return; - - int dustAmt = Main.rand.Next(3, 7); - if (hit.Crit) - dustAmt += Main.rand.Next(2, 5); - - for (int i = 0; i < dustAmt; i++) - { - int dustType = Utils.SelectRandom(Main.rand, DustID.ToxicBubble, DustID.GreenBlood, DustID.Blood); - Vector2 velocity = new Vector2(hit.HitDirection * Main.rand.NextFloat(1f, 2f), Main.rand.NextFloat(-2f, 2f)); - float scale = Main.rand.NextFloat(0.8f, 1.2f); - if (hit.Crit) - { - velocity *= Main.rand.NextFloat(1.25f, 1.75f); - scale += Main.rand.NextFloat(0.25f, 0.5f); - } - - Dust.NewDust(NPC.position, NPC.width, NPC.height, dustType, velocity.X, velocity.Y, Scale: scale); - } - } - - public override void ModifyNPCLoot(NPCLoot npcLoot) - { - npcLoot.Add(ModContent.ItemType()); - } - - public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) - { - if (NPC.IsABestiaryIconDummy) - return true; - - Texture2D baseTexture = TextureAssets.Npc[Type].Value; - SpriteEffects effects = NPC.spriteDirection > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; - Vector2 scale = NPC.scale * SquashVector; - - float yOffset = scale.Y * baseTexture.Height * 0.05f; - Vector2 drawPosition = NPC.Center + new Vector2(0f, NPC.gfxOffY - yOffset) - screenPos; - - // Horrible Hog and its afterimage trail. - using (spriteBatch.Scope()) - { - Effect rotateSpriteShader = CalamityShaders.RotateSprite.Value; - rotateSpriteShader.Parameters["rotation"].SetValue(SpriteRotation); - - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, rotateSpriteShader, Main.GameViewMatrix.TransformationMatrix); - - if (CalamityClientConfig.Instance.Afterimages && AfterimageTrailOpacity > 0.05f) - { - for (int i = 0; i < NPC.oldPos.Length; i++) - { - Color afterimageColor = Color.Red * AfterimageTrailOpacity * 0.76f; - afterimageColor *= (float)(NPC.oldPos.Length - i) / (float)NPC.oldPos.Length; - Vector2 afterimageDrawPosition = NPC.oldPos[i] - Vector2.UnitY * yOffset + NPC.Size * 0.5f - screenPos; - spriteBatch.Draw(baseTexture, afterimageDrawPosition, NPC.frame, NPC.GetAlpha(afterimageColor), NPC.rotation, NPC.frame.Size() * 0.5f, scale, effects, 0f); - } - } - spriteBatch.Draw(baseTexture, drawPosition + Main.rand.NextVector2Circular(HorizontalShakeStrength, 0f), NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, NPC.frame.Size() * 0.5f, scale, effects, 0f); - - spriteBatch.End(); - } - - //string attack = $"{(BehaviorState)AIState}"; - //Vector2 stringDrawPosition = drawPosition - Vector2.UnitY * 64f; - //ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.MouseText.Value, attack, stringDrawPosition, Color.LawnGreen, 0f, Vector2.One, Vector2.One); - - // Eye glint. - if (EyeGlintScale > 0.05f) - { - Vector2 eyeGlintDrawPosition = drawPosition + new Vector2(6f * NPC.spriteDirection, -2f).RotatedBy(NPC.rotation) + Main.rand.NextVector2Circular(HorizontalShakeStrength, 0f); - - spriteBatch.SetBlendState(CalamityUtils.SubtractiveBlending); - for (int i = 0; i < 2; i++) - spriteBatch.Draw(ShineFlare.Value, eyeGlintDrawPosition, null, NPC.GetAlpha(Color.White) * 0.7f, NPC.rotation, ShineFlare.Size() * 0.5f, EyeGlintScale, 0, 0f); - spriteBatch.SetBlendState(BlendState.AlphaBlend); - - spriteBatch.Draw(ShineFlare.Value, eyeGlintDrawPosition, null, NPC.GetAlpha(Color.Red) with { A = 0 }, NPC.rotation, ShineFlare.Size() * 0.5f, EyeGlintScale * 0.8f, 0, 0f); - spriteBatch.Draw(ShineFlare.Value, eyeGlintDrawPosition, null, NPC.GetAlpha(Color.White) with { A = 0 }, NPC.rotation, ShineFlare.Size() * 0.5f, EyeGlintScale * 0.4f, 0, 0f); - } - - return false; - } - - private void SetSquashVectors(Vector2? squashVectorTarget = null, Vector2? squashVector = null) - { - SquashVectorTarget = squashVectorTarget ?? Vector2.One; - if (squashVector.HasValue) - SquashVector = squashVector.Value; - } - - private void RunEyeGlintEffect(float scale) - { - EyeGlintScale = scale; - float pitch = Utils.Remap(scale, 0.4f, 1f, 0.7f, 0.9f, true); - float volume = Utils.Remap(scale, 0.4f, 1f, 1.3f, 1.6f, true); - SoundEngine.PlaySound(SoundID.Item4 with { Volume = volume, Pitch = pitch }, NPC.Center); - } - } -} diff --git a/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Attacks.cs b/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Attacks.cs new file mode 100644 index 0000000000..ca07d9d6bc --- /dev/null +++ b/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Attacks.cs @@ -0,0 +1,776 @@ +using System; +using System.Collections.Generic; +using CalamityMod.Projectiles.Enemy; +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.NormalNPCs.HorribleHog +{ + public partial class HorribleHog + { + public void MainBehavior_ChasePlayer(Player target) + { + // Whenever the player is able to be hit, don't modify velocity mid-air. + // Otherwise, move as any grounded NPC would in order to get back towards the player. + bool canHitPlayer = NPC.velocity.Y == 0f && Collision.CanHit(NPC, target); + if (canHitPlayer || !Collision.CanHit(NPC, target)) + { + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + GroundedMovement(target.Center, ChasePlayer_MaxSpeed, ChasePlayer_MaxAcceleration); + } + + bool jumpUpToPlayer = Main.expertMode && NPC.Center.Y - target.Center.Y >= 64f; + bool closeToPlayer = MathHelper.Distance(NPC.Center.X, target.Center.X) < 112f; + if (NPC.velocity.Y == 0f && jumpUpToPlayer && closeToPlayer) + { + NPC.velocity.Y -= 8f; + SoundEngine.PlaySound(JumpSound, NPC.Center); + } + + bool closeEnoughToAttack = MathHelper.Distance(NPC.Center.X, target.Center.X) <= 64f; + if (Timer >= ChaseTime || (closeEnoughToAttack && Timer >= 120f && NPC.velocity.Y == 0f)) + { + List possibleAttacks = [BehaviorState.JumpAndDash]; + if (NPC.Center.Y - target.Center.Y < 128) + possibleAttacks.Add(BehaviorState.HogCharge); + SwitchBehavior(BehaviorState.ChasePlayer, null, [.. possibleAttacks]); + } + + float idealRotation = (NPC.velocity.Y != 0f) ? NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi) : 0f; + NPC.rotation = idealRotation; + } + + public void MainBehavior_HogCharge(Player target) + { + if (LocalAIState == 0f) + { + if (Timer <= HogCharge_PreChargeTime) + { + float backupSpeed = MathHelper.Lerp(0.08f, 0.16f, Timer / HogCharge_PreChargeTime); + if (NPC.velocity.Y == 0f) + { + if (MathF.Abs(NPC.velocity.X) > 0.4f) + NPC.velocity.X *= 0.9f; + else + NPC.velocity.X -= backupSpeed * NPC.direction; + } + + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + } + + if (Timer >= HogCharge_PreChargeTime) + { + Timer = 0f; + LocalAIState = 1f; + SoundEngine.PlaySound(DashGruntSound, NPC.Center); + NPC.netUpdate = true; + } + + NPC.rotation = 0f; + if (Timer % 15f == 0f && NPC.velocity.Y == 0f) + SoundEngine.PlaySound(SoundID.Run with { Pitch = -0.8f, Identifier = "Horrible Hog Run" }, NPC.Center); + } + + if (LocalAIState == 1f) + { + bool finishedWithCharges = Timer >= HogCharge_ChargingTime || MiscAttackCounter >= HogCharge_MaxCharges; + if (Timer <= 0f) + { + // Kill the hitbox when slowing down. + KillChargeHitboxProjectile(); + + if (NPC.velocity.Y == 0f) + NPC.velocity.X *= 0.93f; + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + NPC.rotation = 0f; + + Vector2 dustPosition = new(NPC.Bottom.X + Main.rand.NextFloat(-NPC.width * 0.5f, NPC.width * 0.5f), NPC.Bottom.Y); + Dust.NewDustPerfect(dustPosition, DustID.Cloud, new Vector2(NPC.velocity.X * 0.4f, Main.rand.NextFloat(-0.38f, 0.38f)), 120, Color.LightGray, Main.rand.NextFloat(1f, 1.2f)); + + AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); + if (Timer == -10 && !finishedWithCharges) + RunEyeGlintEffect(0.4f); + } + else + { + // Spawn an artificial hitbox that can knockback and hit both hostile and friendly enemies alongside the player. + if (!CalamityUtils.AnyProjectiles(ModContent.ProjectileType()) && Main.netMode != NetmodeID.MultiplayerClient) + { + float knockback = 20f; + Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Center, Vector2.Zero, ModContent.ProjectileType(), Damage_HogCharge, knockback, ai0: NPC.whoAmI); + } + + float maxSpeed = MathHelper.Lerp(HogCharge_MaxSpeed, HogCharge_MaxSpeed + 3.5f, MiscAttackCounter / HogCharge_MaxCharges); + float maxAcceleration = MathHelper.Lerp(HogCharge_MaxAcceleration, HogCharge_MaxAcceleration + 0.35f, MiscAttackCounter / HogCharge_MaxCharges); + if (MathF.Abs(NPC.velocity.X) < maxSpeed) + NPC.velocity.X += maxAcceleration * NPC.direction; + + // Turn around if the player jumps over to the other side of it. + bool turnLeft = NPC.direction == 1 && (NPC.Center.X - target.Center.X) > HogCharge_MaxSlowdownDistance; + bool turnRight = NPC.direction == -1 && (NPC.Center.X - target.Center.X) < -HogCharge_MaxSlowdownDistance; + bool hitAWall = NPC.collideX && MathF.Abs(NPC.velocity.X) >= maxSpeed * 0.8f; + if (((turnLeft || turnRight) && Timer > 30f) || finishedWithCharges || hitAWall) + { + if (hitAWall) + { + NPC.velocity.X = NPC.oldVelocity.X * -0.64f; + NPC.velocity.Y -= 5f; + } + + Timer = HogCharge_ChargeCooldownTime; + MiscAttackCounter++; + if (finishedWithCharges && PhaseTwo) + AltAttackVariant = Main.rand.Next(2); + + NPC.netUpdate = true; + } + + Vector2 dustPosition = new(NPC.Bottom.X + Main.rand.NextFloat(-NPC.width * 0.5f, NPC.width * 0.5f), NPC.Bottom.Y); + Dust.NewDustPerfect(dustPosition, DustID.Cloud, new Vector2(NPC.velocity.X * 0.2f, Main.rand.NextFloat(-0.3f, 0.3f)), 120, Color.LightGray, Main.rand.NextFloat(1f, 1.2f)); + if (Timer % 7 == 0f && NPC.velocity.Y == 0f) + SoundEngine.PlaySound(SoundID.Run with { Pitch = -0.4f, Identifier = "Horrible Hog Run" }, NPC.Center); + + AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 1f, 0.15f); + + if (MiscAttackCounter >= HogCharge_MaxCharges + 1) + { + KillChargeHitboxProjectile(); + if (PhaseTwo && AltAttackVariant == 1f) + { + LocalAIState = 2f; + Timer = 0f; + NPC.netUpdate = true; + } + else + { + List possibleAttacks = [BehaviorState.HorribleHoller, BehaviorState.JumpAndDash, BehaviorState.VomitBarrage]; + SwitchBehavior(BehaviorState.HogCharge, null, [.. possibleAttacks]); + } + } + + NPC.damage = 0; + NPC.rotation = 0f; + } + } + + // Alt attack in phase two. + // Same jump and dash but with a smaller shockwave. + if (LocalAIState == 2f) + AltBehavior_HogCharge_JumpAndDash(target); + + // Rebounding, land and switch attacks. + if (LocalAIState == 3f) + { + if (NPC.velocity.Y == 0f && Timer > 2f) + { + List possibleAttacks = [BehaviorState.HorribleHoller, BehaviorState.JumpAndDash, BehaviorState.VomitBarrage]; + SwitchBehavior(BehaviorState.HogCharge, null, [.. possibleAttacks]); + } + + NPC.rotation = NPC.rotation.AngleLerp(0f, 0.075f); + SpriteRotation = SpriteRotation.AngleLerp(0f, 0.075f); + } + } + + public void AltBehavior_HogCharge_JumpAndDash(Player target) + { + if (Timer == 0f) + { + NPC.velocity.Y = -JumpAndDash_MaxJumpHeight * 1.2f; + NPC.velocity.X += JumpAndDash_MaxDashSpeed * 0.4f * NPC.direction; + SpawnJumpParticles(); + SoundEngine.PlaySound(JumpSound, NPC.Center); + } + + if (Timer <= HogCharge_PreDashTime) + { + NPC.velocity.Y *= 0.98f; + NPC.velocity.X *= 0.96f; + + SetSquashVectors(new Vector2(1.06f, 0.94f)); + NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); + SpriteRotation -= (MathHelper.TwoPi / 20f) * NPC.direction; + + if (Timer <= HogCharge_PreDashTime - 10) + { + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + LastPlayerPosition = target.Center; + if (Timer == HogCharge_PreDashTime - 10) + RunEyeGlintEffect(0.6f); + } + } + + if (Timer == HogCharge_PreDashTime) + { + NPC.noGravity = true; + NPC.velocity = NPC.SafeDirectionTo(LastPlayerPosition) * JumpAndDash_MaxDashSpeed; + + SetSquashVectors(new Vector2(1.12f, 0.96f)); + SpriteRotation = 0f; + NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); + SoundEngine.PlaySound(DashGruntSound, NPC.Center); + } + + if (Timer >= HogCharge_PreDashTime && Timer <= HogCharge_PreDashTime + HogCharge_DashTime) + { + if (NPC.collideX || NPC.collideY || Collision.SolidCollision(NPC.position, NPC.width, NPC.height)) + { + // Spawn shockwave on tile impact. + if (Main.netMode != NetmodeID.MultiplayerClient) + { + for (int i = 0; i < 2; i++) + SpawnShockwave(2, 6, (i > 0).ToDirectionInt(), 1f, 2f); + } + + CalamityUtils.AddScreenshakeAt(NPC.Center, 6f); + Collision.HitTiles(NPC.position, NPC.velocity, NPC.width, NPC.height); + SoundEngine.PlaySound(GroundImpactSound, NPC.Center); + + NPC.velocity.X = NPC.DirectionFrom(target.Center).SafeNormalize(Vector2.UnitX).X * 3f; + NPC.velocity.Y = -10f; + LocalAIState = 3f; + Timer = 0f; + NPC.netUpdate = true; + } + + NPC.noGravity = true; + NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); + } + + if (Timer >= HogCharge_PreDashTime + HogCharge_DashTime) + { + if (NPC.velocity.Y == 0f) + { + SetSquashVectors(); + LocalAIState = 3f; + Timer = 0f; + NPC.netUpdate = true; + } + + NPC.GravityMultiplier *= 3f; + NPC.velocity.X *= 0.95f; + SpriteRotation = 0f; + } + + SetSquashVectors(VelocityBasedSquashNStretch); + } + + public void MainBehavior_JumpAndDash(Player target) + { + // Stop, jump and dash towards the target. + if (LocalAIState == 0f) + { + if (Timer <= JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime) + { + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + if (Timer < JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime - 15) + LastPlayerPosition = target.Center; + } + + if (Timer <= JumpAndDash_PreJumpTime) + { + GroundedMovement(target.Center, ChasePlayer_MaxSpeed, ChasePlayer_MaxAcceleration, slowdownDistance: 160f); + float targetAngle = (NPC.velocity.Y != 0f) ? NPC.velocity.X * 0.175f * (NPC.velocity.Y < 0).ToDirectionInt() : 0f; + NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.075f); + + int preJumpVisualsTime = JumpAndDash_PreJumpTime - 30; + if (Timer >= preJumpVisualsTime) + { + NPC.velocity.X *= 0.96f; + float interpolant = Utils.GetLerpValue(preJumpVisualsTime, VomitBarrage_PreJumpTime, Timer, true); + HorizontalShakeStrength = MathHelper.Lerp(0f, 6f, interpolant); + SetSquashVectors(new Vector2(1.24f, 0.84f)); + } + } + + if (Timer == JumpAndDash_PreJumpTime) + { + NPC.velocity.Y = -JumpAndDash_MaxJumpHeight; + NPC.velocity.X += JumpAndDash_MaxDashSpeed * 0.2f * NPC.direction; + + SpawnJumpParticles(); + SetSquashVectors(new Vector2(0.84f, 1.14f)); + SoundEngine.PlaySound(JumpSound, NPC.Center); + HorizontalShakeStrength = 0f; + } + + if (Timer >= JumpAndDash_PreJumpTime && Timer <= JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime) + { + NPC.velocity.Y *= 0.98f; + NPC.velocity.X *= 0.96f; + + NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); + SpriteRotation -= (MathHelper.TwoPi / 20f) * NPC.direction; + AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 1f, 0.15f); + if (Timer == JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime - 10) + RunEyeGlintEffect(0.4f); + } + + if (Timer == JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime) + { + NPC.noGravity = true; + NPC.velocity = NPC.SafeDirectionTo(LastPlayerPosition) * JumpAndDash_MaxDashSpeed; + + SpriteRotation = 0f; + NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); + SoundEngine.PlaySound(DashGruntSound, NPC.Center); + } + + if (Timer >= JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime && Timer <= JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime + JumpAndDash_DashTime) + { + if (NPC.collideX || NPC.collideY || Collision.SolidCollision(NPC.position, NPC.width, NPC.height)) + { + // Spawn shockwave on tile impact. + if (Main.netMode != NetmodeID.MultiplayerClient) + { + for (int i = 0; i < 2; i++) + { + int shockwaveAmt = PhaseTwo ? 14 : 8; + SpawnShockwave(2, shockwaveAmt, (i > 0).ToDirectionInt(), 1f, 3f); + } + } + + NPC.velocity.X = NPC.DirectionFrom(target.Center).SafeNormalize(Vector2.UnitX).X * 5f; + NPC.velocity.Y = PhaseTwo ? -16f : -12f; + LocalAIState = 1f; + Timer = 0f; + AltAttackVariant = Main.rand.Next(2); + + CalamityUtils.AddScreenshakeAt(NPC.Center, 6f); + Collision.HitTiles(NPC.position, NPC.velocity, NPC.width, NPC.height); + SoundEngine.PlaySound(GroundImpactSound, NPC.Center); + + NPC.netUpdate = true; + } + + NPC.noGravity = true; + NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); + } + + if (Timer >= JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime + JumpAndDash_DashTime) + { + if (NPC.velocity.Y == 0f) + { + LocalAIState = 2f; + Timer = 0f; + NPC.netUpdate = true; + } + + NPC.GravityMultiplier *= 3f; + NPC.velocity.X *= 0.95f; + AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); + } + + if (Timer > JumpAndDash_PreJumpTime) + SetSquashVectors(VelocityBasedSquashNStretch); + } + + // Rebounding after ground collision. + if (LocalAIState == 1f) + { + // Randomly perform two smaller attacks right after the main dash in Phase two. + if (PhaseTwo) + { + // Alt attck #1: + // Shoot vomit chunks at the player. + // Shoot more in higher difficulties. + // + // Alt attack #2: + // Bounce on the ground near the player predictively. + // In Death Mode and above, perform a large ground pound after the last bounce. + + if (AltAttackVariant == 0f) + AltBehavior_JumpAndDash_VomitChunks(target); + else if (AltAttackVariant == 1f) + AltBehavior_JumpAndDash_GroundPound(target); + } + else + { + if (NPC.collideY && Timer > 2f) + { + LocalAIState = 2f; + Timer = 0f; + NPC.netUpdate = true; + } + + SetSquashVectors(); + SpriteRotation -= (MathHelper.TwoPi / 20f) * NPC.direction; + NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); + AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); + } + } + + // Landed back on the ground. + if (LocalAIState == 2f) + { + NPC.velocity.X *= 0.94f; + if (NPC.velocity.Y == 0f) + { + NPC.rotation = 0f; + SpriteRotation = 0f; + } + + AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); + NPC.rotation = NPC.rotation.AngleLerp(0f, 0.075f); + SpriteRotation = SpriteRotation.AngleLerp(0f, 0.075f); + SetSquashVectors(); + + if (Timer >= JumpAndDash_CooldownTime && NPC.velocity.Y == 0f) + { + List possibleAttacks = [BehaviorState.VomitBarrage, BehaviorState.HorribleHoller]; + if (NPC.Center.Y - target.Center.Y < 128) + possibleAttacks.Add(BehaviorState.HogCharge); + + SwitchBehavior(BehaviorState.JumpAndDash, null, [.. possibleAttacks]); + } + } + } + + public void AltBehavior_JumpAndDash_VomitChunks(Player target) + { + if (Timer <= JumpAndDash_PreVomitTime) + { + NPC.velocity *= 0.98f; + NPC.GravityMultiplier *= 0.84f; + if (Timer == JumpAndDash_PreVomitTime - 10) + RunEyeGlintEffect(0.6f); + } + + if (Timer >= JumpAndDash_PreVomitTime) + { + if (Timer % JumpAndDash_VomitTimeInterval == 0f && MiscAttackCounter < JumpAndDash_MaxVomitChunks) + { + if (Main.netMode != NetmodeID.MultiplayerClient) + { + int maxVomitPerShot = 2; + for (int i = 0; i < maxVomitPerShot; i++) + { + Vector2 chunkVelocity = NPC.SafeDirectionTo(target.Center).RotatedBy(MathHelper.ToRadians(MathHelper.Lerp(-22f, 22f, i / (maxVomitPerShot - 1)))) * 14f; + Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Center, chunkVelocity, ModContent.ProjectileType(), Damage_VomitChunkProjectile, 0f); + } + } + + Vector2 knockbackVelocity = NPC.DirectionFrom(target.Center).SafeNormalize(-Vector2.UnitY); + NPC.velocity = knockbackVelocity * new Vector2(3f, 5f); + + SoundEngine.PlaySound(SoundID.DD2_OgreSpit, NPC.Center); + MiscAttackCounter++; + NPC.netUpdate = true; + } + + if (MiscAttackCounter >= JumpAndDash_MaxVomitChunks && NPC.velocity.Y == 0f) + { + LocalAIState = 2f; + Timer = 0f; + NPC.netUpdate = true; + } + } + + SetSquashVectors(); + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + NPC.rotation = NPC.rotation.AngleLerp(NPC.AngleTo(target.Center) + (NPC.direction > 0 ? 0f : -MathHelper.Pi), 0.15f); + SpriteRotation = 0f; + AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); + } + + public void AltBehavior_JumpAndDash_GroundPound(Player target) + { + // Using plus 1 here cause the first bounce is coming off of the rebound. + if (MiscAttackCounter <= JumpAndDash_MaxBounces) + { + if (NPC.velocity.Y == 0f) + { + if (MiscAttackCounter == JumpAndDash_MaxBounces) + { + if (!CalamityWorld.death) + { + LocalAIState = 2f; + } + else + { + // Try to bounce in front of the player for the ground pound. + Vector2 bounceVelocity = (target.Center.X > NPC.Center.X) ? new Vector2(18f, -20f) : new Vector2(-18f, -20f); + NPC.velocity = bounceVelocity; + } + + Timer = 0f; + } + else + { + float speedByDistance = Utils.Remap(MathHelper.Distance(target.Center.X, NPC.Center.X), 60f, 600f, 4f, 10f, true); + float xVelocity = speedByDistance * (target.Center.X > NPC.Center.X).ToDirectionInt(); + NPC.velocity = new Vector2(xVelocity, -11.25f); + } + + if (Main.netMode != NetmodeID.MultiplayerClient && MiscAttackCounter > 0f) + { + for (int i = 0; i < 2; i++) + SpawnShockwave(2, 4, (i > 0).ToDirectionInt(), 1f, 2f); + + for (int i = 0; i < MiscAttackCounter; i++) + { + Vector2 rubbleVelocityRight = new Vector2(2f + i * 3f, -8f - i * 1.25f); + Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Bottom, rubbleVelocityRight, ModContent.ProjectileType(), Damage_ShockwaveProjectile, 1f); + Vector2 rubbleVelocityLeft = new Vector2(-2f - i * 3f, -8f - i * 1.25f); + Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Bottom, rubbleVelocityLeft, ModContent.ProjectileType(), Damage_ShockwaveProjectile, 1f); + } + } + + CalamityUtils.AddScreenshakeAt(NPC.Center, 4f); + SoundEngine.PlaySound(HitSound with { Pitch = -0.4f }, NPC.Center); + MiscAttackCounter++; + NPC.netUpdate = true; + } + + if (NPC.velocity.Y > 1f && NPC.velocity.Y < 24f && MiscAttackCounter > 0f) + { + NPC.velocity.Y *= 1.12f; + NPC.velocity.X *= 0.96f; + NPC.noGravity = true; + } + } + + // Ground pound attack in Death Mode. + if (CalamityWorld.death && MiscAttackCounter >= JumpAndDash_MaxBounces + 1) + { + if (Timer < JumpAndDash_PreGroundPoundTime) + { + NPC.velocity *= 0.96f; + NPC.GravityMultiplier *= 0.4f; + if (Timer == JumpAndDash_PreGroundPoundTime - 10) + RunEyeGlintEffect(0.6f); + } + else + { + NPC.noGravity = true; + } + + if (Timer == JumpAndDash_PreGroundPoundTime) + { + NPC.velocity.Y = 30f; + NPC.velocity.X *= 0f; + } + + if (Timer > JumpAndDash_PreGroundPoundTime && NPC.velocity.Y == 0f) + { + if (Main.netMode != NetmodeID.MultiplayerClient) + SpawnShockwave(2, 20, (target.Center.X > NPC.Center.X).ToDirectionInt(), 1f, 8f); + + NPC.velocity.X = NPC.DirectionFrom(target.Center).SafeNormalize(Vector2.UnitX).X * 4f; + NPC.velocity.Y = -12f; + LocalAIState = 2f; + Timer = 0f; + + CalamityUtils.AddScreenshakeAt(NPC.Center, 8f); + Collision.HitTiles(NPC.position, NPC.velocity, NPC.width, NPC.height); + SoundEngine.PlaySound(GroundImpactSound, NPC.Center); + + NPC.netUpdate = true; + } + } + + NPC.damage = 0; + NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); + SpriteRotation -= (MathHelper.TwoPi / 20f) * NPC.direction; + SetSquashVectors(VelocityBasedSquashNStretch); + } + + public void MainBehavior_HorribleHoller(Player target) + { + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + if (NPC.velocity.Y == 0f) + NPC.velocity.X *= 0.9f; + + if (Timer <= HorribleHoller_RoarTime) + { + if (Timer == HorribleHoller_RoarTime - 30) + { + SoundEngine.PlaySound(SoundID.Roar, NPC.Center); + CalamityUtils.AddScreenshakeAt(NPC.Center, 6f); + NPC.velocity.Y -= 6f; + } + + // Spawn the Zombie Spawner projectiles on top of tiles. + if (Timer == HorribleHoller_RoarTime) + { + for (int i = 0; i < HorribleHoller_MaxZombies; i++) + { + int maxTileRange = 12; + Vector2 zombieSpawnPosition = NPC.Center + new Vector2(Main.rand.Next(-maxTileRange * 16, (maxTileRange + 1) * 16), 0f); + Vector2 actualSpawnPosition = FindSuitableGround(zombieSpawnPosition.ToTileCoordinates()).ToWorldCoordinates() + Vector2.UnitY * 16f; + + if (Main.netMode != NetmodeID.MultiplayerClient) + { + int maxTime = 150 + Main.rand.Next(31); + Projectile.NewProjectile(NPC.GetSource_FromThis(), actualSpawnPosition, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, Main.myPlayer, 0f, maxTime); + } + } + } + } + + float targetAngle = (NPC.velocity.Y != 0f) ? NPC.velocity.X * 0.125f * (NPC.velocity.Y < 0).ToDirectionInt() : 0f; + if (Timer >= HorribleHoller_RoarTime - 30 && Timer <= HorribleHoller_RoarTime) + targetAngle = (NPC.velocity.Y != 0f) ? (NPC.direction < 0 ? MathHelper.ToRadians(50f) : MathHelper.ToRadians(-50f)) : 0f; + + NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.125f); + + if (Timer >= HorribleHoller_RoarTime + HorribleHoller_PostRoarCooldownTime) + { + List possibleAttacks = [BehaviorState.ChasePlayer, BehaviorState.VomitBarrage]; + SwitchBehavior(BehaviorState.HorribleHoller, null, [.. possibleAttacks]); + } + } + + public void MainBehavior_VomitBarrage(Player target) + { + if (LocalAIState == 0f) + { + if (Timer == 1f) + { + SoundEngine.PlaySound(VomitChargeUpSound, NPC.Center); + if (PhaseTwo && CalamityWorld.revenge) + { + AltAttackVariant = Main.rand.Next(2); + NPC.netUpdate = true; + } + } + + // Move away from the player. + if (Timer <= VomitBarrage_PreJumpTime) + { + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + GroundedMovement(target.Center, VomitBarrage_MaxSpeed, ChasePlayer_MaxAcceleration, slowdownDistance: 200f); + + float targetAngle = (NPC.velocity.Y != 0f) ? NPC.velocity.X * 0.135f * (NPC.velocity.Y < 0).ToDirectionInt() : 0f; + NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.125f); + + int preJumpVisualsTime = VomitBarrage_PreJumpTime - 30; + if (Timer >= preJumpVisualsTime) + { + NPC.velocity.X *= 0.96f; + float interpolant = Utils.GetLerpValue(preJumpVisualsTime, VomitBarrage_PreJumpTime, Timer, true); + HorizontalShakeStrength = MathHelper.Lerp(0f, 6f, interpolant); + SetSquashVectors(new Vector2(1.24f, 0.84f)); + } + } + + // Jump and shoot a bunch of vomit projectiles shortly afterwards. + if (Timer == VomitBarrage_PreJumpTime) + { + NPC.velocity.Y = -JumpAndDash_MaxJumpHeight; + NPC.velocity.X = -12f * NPC.direction; + + HorizontalShakeStrength = 0f; + SpawnJumpParticles(6, 9); + SetSquashVectors(squashVector: new Vector2(0.84f, 1.14f)); + SoundEngine.PlaySound(JumpSound, NPC.Center); + } + + if (Timer >= VomitBarrage_PreJumpTime && Timer <= VomitBarrage_PreJumpTime + VomitBarrage_VomitTime) + { + NPC.velocity.Y *= 0.98f; + NPC.velocity.X *= 0.96f; + + float targetAngle = NPC.direction < 0 ? MathHelper.ToRadians(50f) : MathHelper.ToRadians(-50f); + NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.075f); + } + + if (Timer == JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime) + { + bool spawnEyeballs = PhaseTwo && CalamityWorld.revenge && AltAttackVariant == 1f; + if (Main.netMode != NetmodeID.MultiplayerClient) + { + for (int i = 0; i < VomitBarrage_MaxVomitChunks; i++) + { + int projectileType = ModContent.ProjectileType(); + int damage = Damage_VomitChunkProjectile; + + // Randomly replace chunks with bombs in Expert and above. + bool vomitBombFloorNotReached = MiscAttackCounter < VomitBarrage_MinVomitBombs; + bool vomitBombCeilingNotReached = Main.rand.NextBool(4) && MiscAttackCounter >= VomitBarrage_MinVomitBombs && MiscAttackCounter < VomitBarrage_MaxVomitBombs; + if (Main.expertMode && (vomitBombFloorNotReached || vomitBombCeilingNotReached)) + { + projectileType = ModContent.ProjectileType(); + damage = Damage_VomitBombProjectile; + MiscAttackCounter++; + } + + // Replace chunks with homing Demon Eyes in Rev+ during phase two when the alt attack is picked. + if (spawnEyeballs) + { + projectileType = ModContent.ProjectileType(); + damage = Damage_VomitEyeProjectile; + } + + Vector2 vomitVelocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(NPC.Center, target.Center + new Vector2(Main.rand.NextFloat(-16f, 16f), 0f), 0.125f, Main.rand.NextFloat(5f, 8f)); + vomitVelocity.X *= Main.rand.NextFloat(0.25f, 2.25f); + int vomit = Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Center, vomitVelocity, projectileType, damage, 0f); + if (spawnEyeballs) + Main.projectile[vomit].ai[0] = Main.rand.Next(45, 75); + if (projectileType == ModContent.ProjectileType()) + Main.projectile[vomit].ai[1] = NPC.whoAmI; + } + } + + SoundEngine.PlaySound(VomitSound with { Volume = 1.3f }, NPC.Center); + NPC.velocity.X = 6f * -NPC.direction; + NPC.velocity.Y += 2f; + } + + if (Timer > JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime && NPC.velocity.Y == 0f) + { + LocalAIState = 1f; + Timer = 0f; + NPC.netUpdate = true; + } + } + + if (LocalAIState == 1f) + { + if (Timer >= VomitBarrage_PostVomitCooldown) + { + List possibleAttacks = [BehaviorState.HorribleHoller, BehaviorState.JumpAndDash]; + if (NPC.Center.Y - target.Center.Y < 128) + possibleAttacks.Add(BehaviorState.HogCharge); + SwitchBehavior(BehaviorState.VomitBarrage, null, [.. possibleAttacks]); + } + + if (NPC.velocity.Y == 0f) + NPC.velocity.X *= 0.9f; + + float targetAngle = (NPC.velocity.Y != 0f) ? NPC.velocity.X * 0.135f * (NPC.velocity.Y < 0).ToDirectionInt() : 0f; + NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.125f); + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + } + } + + private void SpawnShockwave(int spawnImterval, int maxShockwaves, int direction, float minHeightMultiplier, float maxHeightMultiplier) + { + int spawnerIndex = Projectile.NewProjectile(NPC.GetSource_FromThis(), NPC.Bottom, Vector2.Zero, ModContent.ProjectileType(), Damage_ShockwaveProjectile, 0f); + Main.projectile[spawnerIndex].ModProjectile().OwnerIndex = NPC.whoAmI; + Main.projectile[spawnerIndex].ai[0] = spawnImterval; + Main.projectile[spawnerIndex].ai[1] = maxShockwaves; + Main.projectile[spawnerIndex].ai[2] = direction; + Main.projectile[spawnerIndex].localAI[0] = minHeightMultiplier; + Main.projectile[spawnerIndex].localAI[1] = maxHeightMultiplier; + Main.projectile[spawnerIndex].netUpdate = true; + } + + private void KillChargeHitboxProjectile() + { + if (CalamityUtils.AnyProjectiles(ModContent.ProjectileType())) + { + int hitboxIndex = CalamityUtils.FindFirstProjectile(ModContent.ProjectileType()); + if (Main.projectile.IndexInRange(hitboxIndex) && Main.projectile[hitboxIndex].ai[0] == NPC.whoAmI) + { + Main.projectile[hitboxIndex].Kill(); + Main.projectile[hitboxIndex].netUpdate = true; + } + } + } + } +} diff --git a/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Transitionals.cs b/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Transitionals.cs new file mode 100644 index 0000000000..5959a6a521 --- /dev/null +++ b/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Transitionals.cs @@ -0,0 +1,365 @@ +using System; +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.ID; + +namespace CalamityMod.NPCs.NormalNPCs.HorribleHog +{ + public partial class HorribleHog + { + public void MainBehavior_EngageAnimation(Player target) + { + if (Timer >= 45f) + { + if (Timer == 45f) + SoundEngine.PlaySound(SoundID.ForceRoarPitched, NPC.Center); + + if (Timer % 10f == 0f) + { + PulseRing hogRoar = new(NPC.Center, Vector2.Zero, Color.Red, 0f, 1.2f, 20); + GeneralParticleHandler.SpawnParticle(hogRoar, true); + } + } + + if (Timer >= 120f) + SwitchBehavior(specificAttack: BehaviorState.ChasePlayer); + + NPC.velocity.X *= 0.9f; + NPC.spriteDirection = (target.Center.X > NPC.Center.X).ToDirectionInt(); + } + + public void MainBehavior_LaughADeadPlayer() + { + if (NPC.velocity.Y == 0f) + { + // LMFAOOOOOOOOOOOOOOOOOOOOOOOO + if (!SoundEngine.TryGetActiveSound(DeathLaughSoundSlot, out var _)) + { + DeathLaughSoundSlot = SoundEngine.PlaySound(CackleSound, NPC.Center, (activeSound) => + { + activeSound.Position = NPC.Center; + return AIState == (int)BehaviorState.LaughAtDeadPlayer; + }); + } + + NPC.direction *= -1; + NPC.velocity.Y -= 4f; + } + + SearchForTargetEveryFrame = true; + NPC.defense = 30; + NPC.damage = 0; + NPC.velocity.X *= 0.92f; + + float targetAngle = NPC.direction < 0 ? MathHelper.ToRadians(50f) : MathHelper.ToRadians(-50f); + NPC.rotation = (NPC.velocity.Y != 0f) ? NPC.rotation.AngleLerp(targetAngle, 0.075f) : 0f; + + if (Timer >= 130f || NPC.justHit) + { + BehaviorState nextAttack = NPC.HasValidTarget ? BehaviorState.ChasePlayer : BehaviorState.Idle; + SwitchBehavior(specificAttack: nextAttack); + } + } + + public void MainBehavior_DespawnAnimation() + { + // Jump into the ground and dig away. + if (Timer < DigTowardsTarget_PreJumpTime) + { + NPC.velocity.X *= 0.8f; + HorizontalShakeStrength = Utils.Remap(Timer, 0, DigTowardsTarget_PreJumpTime - 5, 0f, 6f, true); + SetSquashVectors(new Vector2(1.24f, 0.84f)); + } + + if (Timer == DigTowardsTarget_PreJumpTime) + { + NPC.velocity.Y -= 6f; + NPC.velocity.X += 4f * NPC.direction; + HorizontalShakeStrength = 0f; + + SoundEngine.PlaySound(RetreatSound, NPC.Center); + SetSquashVectors(); + } + + if (Timer > DigTowardsTarget_PreJumpTime) + { + if (NPC.velocity.Y == 0f) + { + int dustAmt = Main.rand.Next(10, 15); + for (int i = 0; i < dustAmt; i++) + { + Vector2 dustPosition = NPC.Bottom + Main.rand.NextVector2Circular(NPC.width, 0f); + Vector2 dustVelocity = new Vector2(Main.rand.NextFloat(-4f, 4f), Main.rand.NextFloat(-4f, -2f)); + Dust.NewDust(dustPosition, 1, 1, DustID.Dirt, dustVelocity.X, dustVelocity.Y, Scale: Main.rand.NextFloat(0.8f, 1.2f)); + } + + int dustCloudAmt = Main.rand.Next(9, 13); + for (int i = 0; i < dustCloudAmt; i++) + { + Vector2 spawnPosition = NPC.Bottom + Main.rand.NextVector2Circular(NPC.width, 0f); + Vector2 velocity = new Vector2(Main.rand.NextFloat(-3f, 3f), Main.rand.NextFloat(-2f, -1f)); + Color color = Color.Lerp(Color.SandyBrown, Color.SaddleBrown, Main.rand.NextFloat()); + float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); + + TimedSmokeParticle dustCloud = new(spawnPosition, velocity, color, color, Main.rand.NextFloat(1.2f, 1.4f), 1f, Main.rand.Next(45, 55), rotationSpeed); + GeneralParticleHandler.SpawnParticle(dustCloud, true); + } + + CalamityUtils.AddScreenshakeAt(NPC.Center, 5f); + SoundEngine.PlaySound(SoundID.Item70, NPC.Center); + + NPC.active = false; + NPC.netUpdate = true; + } + } + + float idealRotation = (NPC.velocity.Y != 0f) ? NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi) : 0f; + NPC.rotation = idealRotation; + } + + public void MainBehavior_DeathAnimation() + { + if (Timer == 240f) + { + // Create smoke and throw up a big green "5000" on death just like the pigs in Angry Birds + for (int i = 0; i < 17; i++) + { + int goreType = Main.rand.Next(GoreID.Smoke1, GoreID.Smoke3 + 1); + Gore.NewGorePerfect(NPC.position, Main.rand.NextVector2Circular(2f, 2f), goreType); + } + + CombatText.NewText(NPC.Hitbox, Color.LawnGreen, 5000); + SoundEngine.PlaySound(NPC.DeathSound, NPC.Center); + + NPC.life = 0; + NPC.checkDead(); + NPC.HitEffect(); + NPC.netUpdate = true; + } + + NPC.damage = 0; + NPC.dontTakeDamage = true; + + if (NPC.velocity.Y == 0f) + NPC.velocity.X *= 0.96f; + } + + public void MainBehavior_Idle(Player target) + { + bool targetIsVisible = target.Distance(NPC.Center) <= EngageDistance && Collision.CanHit(NPC, target); + bool wasHitByNearestTarget = NPC.HasValidTarget && NPC.justHit; + if (targetIsVisible || wasHitByNearestTarget) + { + SwitchBehavior(specificAttack: BehaviorState.EngageAnimation); + RunEyeGlintEffect(0.4f); + } + + // Standing still, occasionally switch directions. + if (LocalAIState == 0f) + { + //if (Timer > 0f && Timer % 45f == 0f && Main.rand.NextBool(12)) + //{ + // Timer = 0f; + // LocalAIState = 1f; + // NPC.netUpdate = true; + //} + + if (NPC.velocity.Y == 0f) + NPC.velocity.X *= 0.8f; + + if (Timer % 45f == 0f && Main.rand.NextBool(4)) + NPC.direction *= -1; + } + + // Walking around aimlessly. + if (LocalAIState == 1f) + { + if (Timer > 0f && Timer % 45f == 0f && Main.rand.NextBool(6)) + { + Timer = 0f; + LocalAIState = 0f; + NPC.netUpdate = true; + } + + if (MathF.Abs(NPC.velocity.X) < Idle_MaxSpeed) + NPC.velocity.X += Idle_MaxAcceleration * NPC.direction; + + bool shouldJump = NPC.collideX || IsNPCApproachingHole(); + if (NPC.velocity.Y == 0f && shouldJump) + NPC.velocity.Y -= 6f; + } + + // Idle sounds. + if (NPC.soundDelay == 0f && Main.rand.NextBool(250)) + { + SetSquashVectors(squashVector: new Vector2(1.24f, 0.84f)); + SoundEngine.PlaySound(IdleSound, NPC.Center); + NPC.soundDelay = Main.rand.Next(30, 45); + } + + NPC.chaseable = false; + SearchForTargetEveryFrame = true; + } + + public void MainBehavior_DigTowardsTarget(Player target) + { + // Initial animation. + if (LocalAIState == 0f) + { + if (Timer < DigTowardsTarget_PreJumpTime) + { + NPC.velocity.X *= 0.8f; + HorizontalShakeStrength = Utils.Remap(Timer, 0, DigTowardsTarget_PreJumpTime - 5, 0f, 6f, true); + SetSquashVectors(new Vector2(1.24f, 0.84f)); + } + + if (Timer == DigTowardsTarget_PreJumpTime) + { + NPC.velocity.Y -= 6f; + HorizontalShakeStrength = 0f; + SetSquashVectors(squashVector: new Vector2(0.84f, 1.24f)); + SoundEngine.PlaySound(JumpSound, NPC.Center); + } + + if (Timer > DigTowardsTarget_PreJumpTime) + { + if (NPC.velocity.Y == 0f) + { + int dustAmt = Main.rand.Next(10, 15); + for (int i = 0; i < dustAmt; i++) + { + Vector2 dustPosition = NPC.Bottom + Main.rand.NextVector2Circular(NPC.width, 0f); + Vector2 dustVelocity = new Vector2(Main.rand.NextFloat(-4f, 4f), Main.rand.NextFloat(-4f, -2f)); + Dust.NewDust(dustPosition, 1, 1, DustID.Dirt, dustVelocity.X, dustVelocity.Y, Scale: Main.rand.NextFloat(0.8f, 1.2f)); + } + + int dustCloudAmt = Main.rand.Next(9, 13); + for (int i = 0; i < dustCloudAmt; i++) + { + Vector2 spawnPosition = NPC.Bottom + Main.rand.NextVector2Circular(NPC.width, 0f); + Vector2 velocity = new Vector2(Main.rand.NextFloat(-3f, 3f), Main.rand.NextFloat(-2f, -1f)); + Color color = Color.Lerp(Color.SandyBrown, Color.SaddleBrown, Main.rand.NextFloat()); + float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); + + TimedSmokeParticle dustCloud = new(spawnPosition, velocity, color, color, Main.rand.NextFloat(1.2f, 1.4f), 1f, Main.rand.Next(45, 55), rotationSpeed); + GeneralParticleHandler.SpawnParticle(dustCloud, true); + } + + SoundEngine.PlaySound(SoundID.Item70, NPC.Center); + LocalAIState = 1f; + Timer = 0f; + SetSquashVectors(); + NPC.netUpdate = true; + } + } + } + + // Search for a position around the player to emerge. + if (LocalAIState == 1f) + { + NPC.damage = 0; + NPC.dontTakeDamage = true; + NPC.Opacity = 0f; + + // Find closest spot around player. + if (Timer <= DigTowardsTarget_FindSuitablePositionTime) + { + DiggingEmergeSpot = FindSuitableGround(target.Bottom.ToTileCoordinates()).ToWorldCoordinates(); + } + else + { + float distanceInterpolant = Utils.GetLerpValue(800f, 200f, target.Distance(DiggingEmergeSpot), true); + float screenshake = Utils.Remap(Timer, DigTowardsTarget_FindSuitablePositionTime, DigTowardsTraget_MaxDiggingTime, 1f, 4f, true) * distanceInterpolant; + target.SetScreenshake(screenshake); + } + + if (Main.rand.NextBool(3)) + { + int dustAmt = Main.rand.Next(1, 3); + for (int i = 0; i < dustAmt; i++) + { + Vector2 dustPosition = DiggingEmergeSpot + Main.rand.NextVector2Circular(NPC.width, 0f); + Vector2 dustVelocity = new Vector2(Main.rand.NextFloat(-2f, 2f), Main.rand.NextFloat(-5f, -3f)); + Dust.NewDust(dustPosition, 1, 1, DustID.Dirt, dustVelocity.X, dustVelocity.Y, Scale: Main.rand.NextFloat(0.8f, 1.2f)); + } + } + + int dustCloudAmt = Main.rand.Next(1, 3); + for (int i = 0; i < dustCloudAmt; i++) + { + Vector2 spawnPosition = DiggingEmergeSpot + Main.rand.NextVector2Circular(NPC.width, 0f); + Vector2 velocity = new Vector2(Main.rand.NextFloat(-2f, 2f), Main.rand.NextFloat(-5f, -3f)); + Color color = Color.Lerp(Color.SandyBrown, Color.SaddleBrown, Main.rand.NextFloat()); + float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); + + TimedSmokeParticle dustCloud = new(spawnPosition, velocity, color, color, Main.rand.NextFloat(0.6f, 0.8f), 1f, Main.rand.Next(25, 45), rotationSpeed); + GeneralParticleHandler.SpawnParticle(dustCloud, true, Enums.GeneralDrawLayer.BeforeSolidTiles); + } + + // Play digging sounds. + if (Timer <= DigTowardsTarget_FindSuitablePositionTime) + { + if (!SoundEngine.TryGetActiveSound(DiggingSoundSlot, out _)) + { + DiggingSoundSlot = SoundEngine.PlaySound(DiggingSlowSound, NPC.Center, (activeSound) => + { + activeSound.Position = DiggingEmergeSpot; + return AIState == (int)BehaviorState.DigTowardsTarget && Timer <= 120; + }); + } + } + else + { + if (!SoundEngine.TryGetActiveSound(DiggingSoundSlot, out _)) + { + DiggingSoundSlot = SoundEngine.PlaySound(DiggingFastSound, NPC.Center, (activeSound) => + { + activeSound.Position = DiggingEmergeSpot; + activeSound.Volume = 1.5f; + return AIState == (int)BehaviorState.DigTowardsTarget && Timer >= 120 && Timer <= 180; + }); + } + } + + // Jump out. + if (Timer >= DigTowardsTraget_MaxDiggingTime) + { + CalamityUtils.AddScreenshakeAt(DiggingEmergeSpot, 4f); + SoundEngine.PlaySound(SoundID.Item70, DiggingEmergeSpot); + + NPC.Center = DiggingEmergeSpot; + NPC.velocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(NPC.Center, target.Center, NPC.gravity, 7f) * new Vector2(1f, 1.45f); + SpawnJumpParticles(); + + LocalAIState = 2f; + Timer = 0f; + NPC.netUpdate = true; + } + + AfterimageTrailOpacity = MathHelper.Lerp(AfterimageTrailOpacity, 0f, 0.15f); + NPC.rotation = NPC.rotation.AngleLerp(0f, 0.075f); + SpriteRotation = SpriteRotation.AngleLerp(0f, 0.075f); + } + + // Land after jumping and go back to attacking. + if (LocalAIState == 2f) + { + NPC.Opacity = MathHelper.Lerp(NPC.Opacity, 1f, 0.085f); + if (NPC.velocity.Y == 0f && Timer > 2f) + { + RunEyeGlintEffect(0.4f); + SwitchBehavior(specificAttack: BehaviorState.ChasePlayer); + } + + float idealRotation = (NPC.velocity.Y != 0f) ? NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi) : 0f; + NPC.rotation = idealRotation; + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + } + + DigTimer = 0f; + SearchForTargetEveryFrame = true; + } + } +} diff --git a/NPCs/NormalNPCs/HorribleHog/HorribleHog.cs b/NPCs/NormalNPCs/HorribleHog/HorribleHog.cs new file mode 100644 index 0000000000..1a9d5b9c6d --- /dev/null +++ b/NPCs/NormalNPCs/HorribleHog/HorribleHog.cs @@ -0,0 +1,876 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.DataStructures; +using CalamityMod.Effects; +using CalamityMod.Items.Materials; +using CalamityMod.Items.Tools; +using CalamityMod.Particles; +using CalamityMod.Projectiles.Enemy; +using CalamityMod.Utilities.Daybreak; +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using ReLogic.Utilities; +using Terraria; +using Terraria.Audio; +using Terraria.Chat; +using Terraria.GameContent; +using Terraria.GameContent.Bestiary; +using Terraria.GameContent.ItemDropRules; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ModLoader.IO; +using Terraria.ModLoader.Utilities; +using Terraria.UI.Chat; +using Terraria.Utilities; +using Terraria.WorldBuilding; + +namespace CalamityMod.NPCs.NormalNPCs.HorribleHog +{ + public partial class HorribleHog : ModNPC + { + public enum BehaviorState + { + // Transitional behaviors. + EngageAnimation = -4, + LaughAtDeadPlayer = -3, + DespawnAnimation = -2, + DeathAnimation = -1, + Idle, + DigTowardsTarget, + + // Attacks. + ChasePlayer, + HogCharge, + JumpAndDash, + HorribleHoller, + VomitBarrage, + } + + private static Asset BloomCircle; + private static Asset ShineFlare; + private static Asset VortexTexture; + private static Asset VortexTextureSecondary; + private static Asset VortexDistortionTexture; + + private static SoundStyle HitSound = new("CalamityMod/Sounds/NPCHit/HorribleHogHit", 3); + private static SoundStyle DeathSound = new("CalamityMod/Sounds/NPCKilled/HorribleHogDeath"); + private static SoundStyle CackleSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogCackle"); + private static SoundStyle DashGruntSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogDashGrunt"); + private static SoundStyle JumpSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogJump", 2); + private static SoundStyle GroundImpactSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogGroundImpact", 2); + private static SoundStyle VomitChargeUpSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogVomitChargeUp", 2); + private static SoundStyle VomitSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogVomit", 2); + private static SoundStyle RetreatSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogRetreat"); + private static SoundStyle IdleSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogIdle", 2) + { + PitchVariance = 0.25f, + }; + private static SoundStyle DiggingSlowSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogDiggingSlow") + { + IsLooped = true, + PauseBehavior = PauseBehavior.PauseWithGame, + MaxInstances = 0 + }; + private static SoundStyle DiggingFastSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogDiggingFast") + { + IsLooped = true, + PauseBehavior = PauseBehavior.PauseWithGame, + MaxInstances = 0 + }; + private static SoundStyle DevilsTongueLoopingSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogNearbyLoop") + { + IsLooped = true, + PauseBehavior = PauseBehavior.PauseWithGame, + MaxInstances = 0 + }; + + public Dictionary PreviousAttackCounters = []; + + public Dictionary AttackWeights = []; + + public bool SearchForTargetEveryFrame; + + public bool HasPlayedEngageAnimation; + + public bool HasPlayedDeathAnimation; + + public bool ReadyToPlayLaughingAnimation; + + public float EyeGlintScale; + + public float AfterimageTrailOpacity; + + public float PriitiveTrailOpacity; + + public float HorizontalShakeStrength; + + public float DevilsTongueVolumeMultiplier; + + /// + /// Used as a shader parameter to rotate the already-drawn sprite of Horrible Hog directly regardless of the rotation value of .

+ /// Used in cases where Horrible Hog needs to spin while also squashing and stretching. is used for the spritebatch-drawn texture

+ /// and needs to rotate towards the NPC's velocity in order for the squashed sprite to face the correct direction. This parameter is then used and a shader is

+ /// then applied to the spritebatch to rotate the sprite differently from the value passed in spritebatch's Draw call. + ///
+ public float SpriteRotation; + + public Vector2 LastPlayerPosition; + + public Vector2 DiggingEmergeSpot; + + public Vector2 SquashVector; + + public Vector2 SquashVectorTarget; + + public SlotId DeathLaughSoundSlot; + + public SlotId DiggingSoundSlot; + + public SlotId DevilsTongueSlot; + + #region Static Behavior Properties + public static int MaxAttacks_ChasePlayer => 2; + public static int MaxAttacks_HogCharge => Main.expertMode ? 2 : 1; + public static int MaxAttacks_HorribleHoller => 1; + public static int MaxAttacks_JumpAndDash => Main.expertMode ? 3 : 2; + public static int MaxAttacks_VomitBarrage => Main.expertMode ? 2 : 1; + public static int MaxAttacksPerCycle => CalamityWorld.revenge ? 5 : Main.expertMode ? 4 : 3; + + public static int Damage_HogCharge => 10; + public static int Damage_ShockwaveProjectile => 10; + public static int Damage_ShockwaveRubbleProjectile => 12; + public static int Damage_VomitChunkProjectile => 12; + public static int Damage_VomitBombProjectile => 18; + public static int Damage_VomitEyeProjectile => 14; + + public static float EngageDistance => 300f; + public static float Idle_MaxSpeed => 2f; + public static float Idle_MaxAcceleration => 0.125f; + + public static int MaxTimeToStartDigging => 300; + + public static int DigTowardsTarget_PreJumpTime => 30; + public static int DigTowardsTarget_FindSuitablePositionTime => 120; + public static int DigTowardsTraget_MaxDiggingTime => 180; + + public static int ChaseTime => 180; + public static float ChasePlayer_MaxSpeed => 5f; + public static float ChasePlayer_MaxAcceleration => 0.3f; + + public static int HogCharge_PreChargeTime => 75; + public static int HogCharge_ChargingTime => 240; + public static int HogCharge_ChargeCooldownTime => CalamityWorld.revenge ? -20 : Main.expertMode ? -30 : -45; + public static int HogCharge_PreDashTime => 45; + public static int HogCharge_DashTime => 20; + public static int HogCharge_MaxCharges => CalamityWorld.revenge ? 4 : Main.expertMode ? 3 : 2; + public static float HogCharge_MaxSpeed => CalamityWorld.revenge ? 18f : Main.expertMode ? 15f : 12f; + public static float HogCharge_MaxAcceleration => CalamityWorld.revenge ? 0.425f : Main.expertMode ? 0.4f : 0.375f; + public static float HogCharge_MaxSlowdownDistance => CalamityWorld.revenge ? 64f : Main.expertMode ? 96f : 128f; + + public static int JumpAndDash_PreJumpTime => 75; + public static int JumpAndDash_JumpPreDashTime => 45; + public static int JumpAndDash_DashTime => 20; + public static int JumpAndDash_CooldownTime => 60; + public static int JumpAndDash_PreVomitTime => 60; + public static int JumpAndDash_PreGroundPoundTime => 45; + public static int JumpAndDash_MaxVomitChunks => CalamityWorld.revenge ? 5 : Main.expertMode ? 4 : 3; + public static int JumpAndDash_VomitTimeInterval => CalamityWorld.revenge ? 10 : 15; + public static int JumpAndDash_MaxBounces => Main.expertMode ? 3 : 2; + public static float JumpAndDash_MaxJumpHeight => 14f; + public static float JumpAndDash_MaxDashSpeed => 20f; + public static float JumpAndDash_MaxBounceSpeed => CalamityWorld.revenge ? 16f : Main.expertMode ? 14f : 12f; + + public static int HorribleHoller_RoarTime => 75; + public static int HorribleHoller_PostRoarCooldownTime => 30; + public static int HorribleHoller_MaxZombies => 3; + + public static int VomitBarrage_PreJumpTime => 75; + public static int VomitBarrage_VomitTime => 25; + public static int VomitBarrage_PostVomitCooldown => 100; + public static int VomitBarrage_MaxVomitChunks => CalamityWorld.revenge ? 10 : Main.expertMode ? 8 : 6; + public static int VomitBarrage_MinVomitBombs => CalamityWorld.death ? 3 : CalamityWorld.revenge ? 2 : 0; + public static int VomitBarrage_MaxVomitBombs => CalamityWorld.death ? 6 : CalamityWorld.revenge ? 5 : Main.expertMode ? 3 : 4; + public static float VomitBarrage_MaxSpeed => 8f; + public static float VomitBarrage_MaxAcceleration => 0.45f; + #endregion + + public ref float Timer => ref NPC.ai[0]; + + public ref float AIState => ref NPC.ai[1]; + + public ref float LocalAIState => ref NPC.ai[2]; + + public ref float MainAttackCounter => ref NPC.ai[3]; + + public ref float MiscAttackCounter => ref NPC.localAI[0]; + + public ref float AltAttackVariant => ref NPC.localAI[1]; + + public ref float DigTimer => ref NPC.localAI[2]; + + public Vector2 VelocityBasedSquashNStretch + { + get + { + float stretch = MathHelper.Clamp(NPC.velocity.Length() / 20f * 0.1f, 1f, 1.05f); + Vector2 stretchedVector = new(1f * stretch, 1f - 1f * stretch * 0.3f); + return stretchedVector; + } + } + + public bool PhaseTwo + { + get + { + if (CalamityWorld.death || Main.getGoodWorld) + return NPC.life <= NPC.lifeMax * 0.7f; + + if (CalamityWorld.revenge) + return NPC.life <= NPC.lifeMax * 0.6f; + + return Main.expertMode && NPC.life <= NPC.lifeMax * 0.5f; + } + } + + public override void Load() + { + if (!Main.dedServ) + { + BloomCircle = ModContent.Request("CalamityMod/Particles/BloomCircle"); + ShineFlare = ModContent.Request("CalamityMod/ExtraTextures/ShineFlare"); + VortexTexture = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/Neurons2"); + VortexTextureSecondary = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/EternityStreak"); + VortexDistortionTexture = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/Perlin"); + } + } + + public override void SetStaticDefaults() + { + NPCID.Sets.TrailCacheLength[Type] = 5; + NPCID.Sets.TrailingMode[Type] = 0; + NPCID.Sets.CantTakeLunchMoney[Type] = true; + } + + public override void SetDefaults() + { + NPC.width = 40; + NPC.height = 28; + NPC.damage = 20; + NPC.defense = 14; + NPC.lifeMax = 600; + NPC.knockBackResist = 0f; + NPC.npcSlots = 5f; + NPC.rarity = 4; + NPC.value = Item.buyPrice(0, 3, 0, 0); + NPC.HitSound = HitSound; + NPC.DeathSound = DeathSound; + NPC.noGravity = false; + NPC.noTileCollide = false; + NPC.dontTakeDamage = false; + + SquashVector = Vector2.One; + SquashVectorTarget = Vector2.One; + ResetAttackWeights(); + } + + public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) + { + bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] + { + BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Events.BloodMoon, + new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.HorribleHog") + }); + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write((byte)PreviousAttackCounters.Count); + foreach (var pair in PreviousAttackCounters) + { + writer.Write((byte)pair.Key); + writer.Write((byte)pair.Value); + } + + writer.Write((byte)AttackWeights.Count); + foreach (var pair in AttackWeights) + { + writer.Write((byte)pair.Key); + writer.Write((byte)pair.Value); + } + + writer.WriteFlags(SearchForTargetEveryFrame, HasPlayedEngageAnimation, HasPlayedDeathAnimation, ReadyToPlayLaughingAnimation); + writer.WritePackedWorldPosition(LastPlayerPosition); + writer.WritePackedWorldPosition(DiggingEmergeSpot); + + for (int i = 0; i < 3; i++) + writer.Write(NPC.localAI[i]); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + int attackCountersLength = reader.ReadByte(); + for (int i = 0; i < attackCountersLength; i++) + PreviousAttackCounters.Add((BehaviorState)reader.ReadByte(), (int)reader.ReadByte()); + + int attackWeightsLength = reader.ReadByte(); + for (int i = 0; i < attackWeightsLength; i++) + AttackWeights.Add((BehaviorState)reader.ReadByte(), (float)reader.ReadByte()); + + reader.ReadFlags(out SearchForTargetEveryFrame, out HasPlayedEngageAnimation, out HasPlayedDeathAnimation, out ReadyToPlayLaughingAnimation); + LastPlayerPosition = reader.ReadPackedWorldPosition(); + DiggingEmergeSpot = reader.ReadPackedWorldPosition(); + + for (int i = 0; i < 3; i++) + NPC.localAI[i] = reader.ReadSingle(); + } + + public override bool CheckDead() + { + if (!HasPlayedDeathAnimation) + { + NPC.life = NPC.lifeMax; + HasPlayedDeathAnimation = true; + SwitchBehavior(specificAttack: BehaviorState.DeathAnimation); + return false; + } + + return true; + } + + public override bool? CanFallThroughPlatforms() + { + // If Hog is not in any of the transitional behavior states, don't fall through platforms. + bool inTransitionalBehaviorState = AIState <= (int)BehaviorState.Idle; + if (inTransitionalBehaviorState) + return false; + + if (NPC.HasValidTarget) + { + Player target = Main.player[NPC.target]; + return target.Center.Y - 8 > NPC.Center.Y; + } + + return base.CanFallThroughPlatforms(); + } + + public override void AI() + { + if (!NPC.HasValidTarget || SearchForTargetEveryFrame) + NPC.TargetClosest(false); + + if (NPC.direction == 0) + NPC.direction = Main.rand.NextBool().ToDirectionInt(); + + // Due to how much Death Mode increases Blood Moon spawn rates, this is kinda required in order for the fight to not be super overwhelming. + if (CalamityWorld.death) + NPC.npcSlots = 40f; + + Player target = Main.player[NPC.target]; + NPC.damage = NPC.defDamage; + NPC.defense = NPC.defDefense; + NPC.noGravity = false; + NPC.noTileCollide = false; + NPC.dontTakeDamage = false; + NPC.chaseable = true; + NPC.spriteDirection = NPC.direction; + + // Despawn immediately if it's morning. + if (Main.dayTime && AIState != (int)BehaviorState.DespawnAnimation) + SwitchBehavior(specificAttack: BehaviorState.DespawnAnimation); + + // If the current target dies, laugh at them. + if (target.dead && ReadyToPlayLaughingAnimation && NPC.velocity.Y == 0f) + { + ReadyToPlayLaughingAnimation = false; + SwitchBehavior(specificAttack: BehaviorState.LaughAtDeadPlayer); + } + + // If the target is unable to be reached, count up to 5 seconds before switching behavior states and digging towards them. + int tileRange = 64; + Vector2 npcCanHitPosition = NPC.position - new Vector2(tileRange, tileRange); + Vector2 targetCanHitPosition = target.position - new Vector2(tileRange, tileRange); + bool currentlyDoingAnAttack = AIState > (int)BehaviorState.DigTowardsTarget; + bool targetTooHigh = (NPC.Center.Y - target.Center.Y >= 160f && target.velocity.Y == 0f) || NPC.Center.Y - target.Center.Y >= 320f; + bool targetTooFar = NPC.Distance(target.Center) >= 1280f; + bool cantHitTarget = !Collision.CanHit(npcCanHitPosition, NPC.width + tileRange, NPC.height + tileRange, targetCanHitPosition, target.width + tileRange, target.height + tileRange); + if (NPC.HasValidTarget && currentlyDoingAnAttack && (targetTooHigh || targetTooFar || cantHitTarget)) + { + DigTimer++; + if (DigTimer >= 300f && NPC.velocity.Y == 0f) + SwitchBehavior(specificAttack: BehaviorState.DigTowardsTarget); + } + else + { + if (DigTimer > 0f) + DigTimer--; + } + + // Adjust volume correctly depending on the behavior state and play the nearby loop sound. + float volumeTarget = AIState == (int)BehaviorState.Idle ? 1f : 0f; + DevilsTongueVolumeMultiplier = MathHelper.Lerp(DevilsTongueVolumeMultiplier, volumeTarget, 0.075f); + PlayNearbyLoopingSound(); + + switch ((BehaviorState)AIState) + { + case BehaviorState.EngageAnimation: + MainBehavior_EngageAnimation(target); + break; + + case BehaviorState.LaughAtDeadPlayer: + MainBehavior_LaughADeadPlayer(); + break; + + case BehaviorState.DespawnAnimation: + MainBehavior_DespawnAnimation(); + break; + + case BehaviorState.DeathAnimation: + MainBehavior_DeathAnimation(); + break; + + case BehaviorState.Idle: + MainBehavior_Idle(target); + break; + + case BehaviorState.DigTowardsTarget: + MainBehavior_DigTowardsTarget(target); + break; + + case BehaviorState.ChasePlayer: + MainBehavior_ChasePlayer(target); + break; + + case BehaviorState.HogCharge: + MainBehavior_HogCharge(target); + break; + + case BehaviorState.JumpAndDash: + MainBehavior_JumpAndDash(target); + break; + + case BehaviorState.HorribleHoller: + MainBehavior_HorribleHoller(target); + break; + + case BehaviorState.VomitBarrage: + MainBehavior_VomitBarrage(target); + break; + } + + SquashVector = Vector2.Lerp(SquashVector, SquashVectorTarget, 0.125f); + EyeGlintScale = MathHelper.Lerp(EyeGlintScale, 0f, 0.125f); + NPC.StepUpBlocks(); + Timer++; + } + + public void SwitchBehavior(BehaviorState? attackToRecord = null, BehaviorState? specificAttack = null, params BehaviorState[] attacksToChooseFrom) + { + // Reset all the previous attack counters and weights in order to start a new cycle once the maximum amount of attacks overall has been reached. + if (MainAttackCounter >= MaxAttacksPerCycle) + { + // Also search for the nearest target again once the attack cycle resets. + NPC.TargetClosest(false); + + foreach (BehaviorState attack in PreviousAttackCounters.Keys) + PreviousAttackCounters[attack] = 0; + ResetAttackWeights(); + MainAttackCounter = 0f; + } + + if (attackToRecord.HasValue) + { + // Record the last attack to a dictionary and increment how many times it has been performed. + if (!PreviousAttackCounters.ContainsKey(attackToRecord.Value)) + PreviousAttackCounters[attackToRecord.Value] = 0; + PreviousAttackCounters[attackToRecord.Value]++; + + // Increase the weight of other attacks and lower this one. + AttackWeights[attackToRecord.Value] -= 0.33f; + foreach (BehaviorState attack in AttackWeights.Keys) + AttackWeights[attack] += 0.33f; + + MainAttackCounter++; + } + + // Default to returning to idling in the event there are no nearby targets after performing an attack. + BehaviorState nextAttack = BehaviorState.Idle; + + // Switch to a specific behavior state if one is specified. + // Otherwise, pick from the random attack array. + if (specificAttack.HasValue) + { + nextAttack = specificAttack.Value; + } + else if (NPC.HasValidTarget && attacksToChooseFrom.Length > 0) + { + WeightedRandom possibleAttacks = new(); + for (int i = 0; i < attacksToChooseFrom.Length; i++) + { + // Don't add attacks to the attack pool if they've been performed their maximum amount of times. + if (PreviousAttackCounters.TryGetValue(attacksToChooseFrom[i], out var timesPerformed) && timesPerformed >= GetMaxAttackValue(attacksToChooseFrom[i])) + continue; + + possibleAttacks.Add(attacksToChooseFrom[i], AttackWeights[attacksToChooseFrom[i]]); + } + + // Pick a random attack. + nextAttack = possibleAttacks; + } + + // Reset so this once Hog has another player to target so it doesn't loop. + if (NPC.HasValidTarget) + ReadyToPlayLaughingAnimation = true; + + // Switch and reset certain fields. + AIState = (int)nextAttack; + LocalAIState = 0f; + Timer = 0f; + MiscAttackCounter = 0f; + AltAttackVariant = 0f; + SpriteRotation = 0f; + AfterimageTrailOpacity = 0f; + SearchForTargetEveryFrame = false; + + SetSquashVectors(); + KillChargeHitboxProjectile(); + + NPC.netUpdate = true; + } + + private int GetMaxAttackValue(BehaviorState attack) + { + int maxValue = attack switch + { + BehaviorState.ChasePlayer => MaxAttacks_ChasePlayer, + BehaviorState.HogCharge => MaxAttacks_HogCharge, + BehaviorState.JumpAndDash => MaxAttacks_JumpAndDash, + BehaviorState.HorribleHoller => MaxAttacks_HorribleHoller, + BehaviorState.VomitBarrage => MaxAttacks_VomitBarrage, + _ => 1 + }; + + // Every attack can be used one more time in phase two. + if (PhaseTwo) + maxValue += 1; + + return maxValue; + } + + private void ResetAttackWeights() + { + AttackWeights[BehaviorState.ChasePlayer] = 1f; + AttackWeights[BehaviorState.HogCharge] = 0.33f; + AttackWeights[BehaviorState.JumpAndDash] = 1f; + AttackWeights[BehaviorState.HorribleHoller] = 0.33f; + AttackWeights[BehaviorState.VomitBarrage] = 0.66f; + } + + private void GroundedMovement(Vector2 targetPosition, float maxSpeed, float maxAcceleration, float jumpHeight = 10f, float? slowdownDistance = null) + { + float distanceToPlayer = MathF.Abs(NPC.Center.X - targetPosition.X); + if (targetPosition.X > NPC.Center.X) + { + if (slowdownDistance.HasValue) + { + if (distanceToPlayer > slowdownDistance.Value) + NPC.velocity.X += maxAcceleration; + else + NPC.velocity.X -= maxAcceleration; + } + else + { + NPC.velocity.X += maxAcceleration; + } + + } + else if (targetPosition.X < NPC.Center.X) + { + if (slowdownDistance.HasValue) + { + if (distanceToPlayer > slowdownDistance.Value) + NPC.velocity.X -= maxAcceleration; + else + NPC.velocity.X += maxAcceleration; + } + else + { + NPC.velocity.X -= maxAcceleration; + } + } + + if (NPC.velocity.Y == 0f) + { + if (NPC.collideX || IsNPCApproachingHole()) + NPC.velocity.Y -= jumpHeight; + } + + NPC.velocity.X = MathHelper.Clamp(NPC.velocity.X, -maxSpeed, maxSpeed); + } + + private bool IsNPCApproachingHole() + { + int npcWidthInTiles = NPC.width / 16; + int tileX = (int)(NPC.Center.X / 16f) - npcWidthInTiles; + if (NPC.velocity.X > 0) + tileX += npcWidthInTiles; + + int tileY = (int)((NPC.position.Y + NPC.height) / 16f); + for (int y = tileY; y < tileY + 2; y++) + { + for (int x = tileX; x < tileX + npcWidthInTiles; x++) + { + if (Main.tile[x, y].HasTile) + { + return false; + } + } + } + return true; + } + + private Point FindSuitableGround(Point basePoint) + { + // Tile is solid. Check to ensure the tile above is also isn't solid and move up if it is. + if (WorldGen.ActiveAndWalkableTile(basePoint.X, basePoint.Y)) + { + while (WorldGen.ActiveAndWalkableTile(basePoint.X, basePoint.Y - 1) && basePoint.Y >= 1) + basePoint.Y--; + } + // Tile isn't solid. Check to ensure the tile under it is solid and move down if it isn't. + else + { + while (!WorldGen.ActiveAndWalkableTile(basePoint.X, basePoint.Y + 1) && basePoint.Y < Main.maxTilesY) + basePoint.Y++; + } + + return basePoint; + } + + private void PlayNearbyLoopingSound() + { + if (DevilsTongueVolumeMultiplier < 0.05f) + return; + + // "Devil's Tongue" looping sound. + // Similar to Divine Swine; gets louder and lowers music volume based on proximity. + if (!SoundEngine.TryGetActiveSound(DevilsTongueSlot, out _)) + DevilsTongueSlot = SoundEngine.PlaySound(DevilsTongueLoopingSound, NPC.Center, DevilsTongueLoopCallback); + + float musicVolumeInterpolant = Utils.Remap(NPC.Distance(Main.LocalPlayer.Center), 600f, 100f, 1f, 0.05f, true); + Main.musicFade[Main.curMusic] = MathHelper.Lerp(1f, musicVolumeInterpolant, DevilsTongueVolumeMultiplier); + } + + private bool DevilsTongueLoopCallback(ActiveSound soundInstance) + { + soundInstance.Position = NPC.Center; + float volumeInterpolant = Utils.Remap(NPC.Distance(Main.LocalPlayer.Center), 600f, 100f, 0.1f, 0.7f, true) * DevilsTongueVolumeMultiplier; + soundInstance.Volume = volumeInterpolant; + return NPC.active && DevilsTongueVolumeMultiplier >= 0.05f; + } + + private void SpawnJumpParticles(int dustCloudMin = 10, int dustCloudMax = 14, int dirtDustMin = 14, int dirtDustMax = 18) + { + // Do fart in a jar visuals when Hog does a jump mid-air. + float tileCollisionDistance = CalamityUtils.DistanceToTileCollisionHit(NPC.Bottom, Vector2.UnitY, 10) ?? 9999f; + if (tileCollisionDistance > 18f) + { + int fartCloudAmt = Main.rand.Next(dustCloudMin, dustCloudMax + 1); + for (int i = 0; i < fartCloudAmt; i++) + { + Vector2 spawnPosition = NPC.Bottom + Main.rand.NextVector2Circular(32f, 0f); + Vector2 velocity = Main.rand.NextVector2Circular(2f, 2f); + int goreType = Main.rand.Next(GoreID.FartCloud1, GoreID.FartCloud3 + 1); + Gore.NewGore(spawnPosition, velocity, goreType); + } + + int fartDustAmt = Main.rand.Next(dirtDustMin, dirtDustMax + 1); + for (int i = 0; i < fartDustAmt; i++) + { + Vector2 velocity = Main.rand.NextVector2Circular(2f, 2f); + Dust.NewDust(NPC.Bottom, 0, 0, DustID.FartInAJar, velocity.X, velocity.Y, Scale: Main.rand.NextFloat(0.8f, 1.2f)); + } + + SoundEngine.PlaySound(SoundID.Item16, NPC.Center); + } + else + { + int dustCloudAmt = Main.rand.Next(dustCloudMin, dustCloudMax + 1); + for (int i = 0; i < dustCloudAmt; i++) + { + Vector2 spawnPosition = NPC.Bottom + Main.rand.NextVector2Circular(32f, 0f); + Vector2 velocity = NPC.velocity * (Main.rand.NextFloat(0.1f, 0.2f) + i * 0.1f); + Color color = Color.Lerp(Color.SaddleBrown, Color.SandyBrown, Main.rand.NextFloat()); + float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); + + TimedSmokeParticle launchCloud = new(spawnPosition, velocity, color, color, Main.rand.NextFloat(0.4f, 0.6f), Main.rand.NextFloat(0.6f, 0.8f), Main.rand.Next(30, 45), rotationSpeed); + GeneralParticleHandler.SpawnParticle(launchCloud, true, Enums.GeneralDrawLayer.BeforeSolidTiles); + } + + int dustAmt = Main.rand.Next(dirtDustMin, dirtDustMax + 1); + for (int i = 0; i < dustAmt; i++) + { + Vector2 velocity = NPC.velocity * (Main.rand.NextFloat(0.1f, 0.2f) + i * 0.025f); + Dust.NewDust(NPC.Bottom, 0, 0, DustID.Dirt, velocity.X, velocity.Y); + } + } + } + + public override float SpawnChance(NPCSpawnInfo spawnInfo) + { + if (Main.bloodMoon && NPC.downedBoss1 && NPC.CountNPCS(Type) < 1) + { + float spawnChanceMultiplier = CalamityWorld.death ? 0.0075f : 0.025f; + return SpawnCondition.OverworldNightMonster.Chance * spawnChanceMultiplier; + } + return 0f; + } + + public override void HitEffect(NPC.HitInfo hit) + { + // Death effects spawned in MainBehavior_DeathAnimation. + if (NPC.life <= 0) + return; + + int dustAmt = Main.rand.Next(3, 7); + if (hit.Crit) + dustAmt += Main.rand.Next(2, 5); + + for (int i = 0; i < dustAmt; i++) + { + int dustType = Utils.SelectRandom(Main.rand, DustID.ToxicBubble, DustID.GreenBlood, DustID.Blood); + Vector2 velocity = new Vector2(hit.HitDirection * Main.rand.NextFloat(1f, 2f), Main.rand.NextFloat(-2f, 2f)); + float scale = Main.rand.NextFloat(0.8f, 1.2f); + if (hit.Crit) + { + velocity *= Main.rand.NextFloat(1.25f, 1.75f); + scale += Main.rand.NextFloat(0.25f, 0.5f); + } + + Dust.NewDust(NPC.position, NPC.width, NPC.height, dustType, velocity.X, velocity.Y, Scale: scale); + } + } + + public override void ModifyNPCLoot(NPCLoot npcLoot) + { + npcLoot.Add(ModContent.ItemType()); + LeadingConditionRule postEoC = npcLoot.DefineConditionalDropSet(DropHelper.PostEoC()); + postEoC.Add(ModContent.ItemType(), 1, 10, 12); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + if (NPC.IsABestiaryIconDummy) + return true; + + Texture2D baseTexture = TextureAssets.Npc[Type].Value; + SpriteEffects effects = NPC.spriteDirection > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + Vector2 scale = NPC.scale * SquashVector; + + float yOffset = scale.Y * baseTexture.Height * 0.05f; + Vector2 drawPosition = NPC.Center + new Vector2(0f, NPC.gfxOffY - yOffset) - screenPos; + + // Background effect when Horrible Hog is idling and its nearby loop is playing. + if (DevilsTongueVolumeMultiplier > 0.05f) + { + using (spriteBatch.Scope()) + { + float radiusBasedOpacity = Utils.Remap(Main.LocalPlayer.Distance(NPC.Center), 250f, 750f, 1f, 0.15f, true); + + Effect auraShader = CalamityShaders.HorribleHogAuraShader.Value; + auraShader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly); + auraShader.Parameters["colorPaletteLimit"].SetValue(16f); + auraShader.Parameters["spiralArms"].SetValue(5f); + auraShader.Parameters["spiralAdditionalAngle"].SetValue(6f); + auraShader.Parameters["minPixelFadeDistance"].SetValue(0.125f); + auraShader.Parameters["maxPixelFadeDistance"].SetValue(0.485f); + auraShader.Parameters["pixelationFactor"].SetValue(Main.ScreenSize.ToVector2() * 0.25f); + auraShader.Parameters["spiralTimeOffset"].SetValue(new Vector2(-0.08f, -0.05f)); + auraShader.Parameters["vortexDarkColor"].SetValue(new Color(40, 40, 40).ToVector3()); + auraShader.Parameters["vortexBrightColor"].SetValue(Color.Crimson.ToVector3()); + + Main.graphics.GraphicsDevice.Textures[1] = VortexTextureSecondary.Value; + Main.graphics.GraphicsDevice.SamplerStates[1] = SamplerState.PointWrap; + + Main.graphics.GraphicsDevice.Textures[2] = VortexDistortionTexture.Value; + Main.graphics.GraphicsDevice.SamplerStates[2] = SamplerState.LinearWrap; + + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, Main.Rasterizer, auraShader, Main.GameViewMatrix.TransformationMatrix); + + spriteBatch.Draw(VortexTexture.Value, drawPosition, null, Color.White * radiusBasedOpacity * DevilsTongueVolumeMultiplier, 0f, VortexTexture.Size() * 0.5f, 1f, 0, 0f); + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + float bloomCircleOpacity = MathHelper.Lerp(0.6f, 0.9f, MathF.Sin((float)Main.timeForVisualEffects / 75f + NPC.whoAmI * 0.5f + 0.5f)) * radiusBasedOpacity; + spriteBatch.Draw(BloomCircle.Value, drawPosition, null, Color.Crimson with { A = 0 } * bloomCircleOpacity * DevilsTongueVolumeMultiplier, 0f, BloomCircle.Size() * 0.5f, 1.2f, 0, 0f); + + spriteBatch.End(); + } + } + + // Horrible Hog and its afterimage trail. + using (spriteBatch.Scope()) + { + Effect rotateSpriteShader = CalamityShaders.RotateSprite.Value; + rotateSpriteShader.Parameters["rotation"].SetValue(SpriteRotation); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, rotateSpriteShader, Main.GameViewMatrix.TransformationMatrix); + + if (CalamityClientConfig.Instance.Afterimages && AfterimageTrailOpacity > 0.05f) + { + for (int i = 0; i < NPC.oldPos.Length; i++) + { + Color afterimageColor = Color.Red * AfterimageTrailOpacity * 0.76f; + afterimageColor *= (float)(NPC.oldPos.Length - i) / (float)NPC.oldPos.Length; + Vector2 afterimageDrawPosition = NPC.oldPos[i] - Vector2.UnitY * yOffset + NPC.Size * 0.5f - screenPos; + spriteBatch.Draw(baseTexture, afterimageDrawPosition, NPC.frame, NPC.GetAlpha(afterimageColor), NPC.rotation, NPC.frame.Size() * 0.5f, scale, effects, 0f); + } + } + spriteBatch.Draw(baseTexture, drawPosition + Main.rand.NextVector2Circular(HorizontalShakeStrength, 0f), NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, NPC.frame.Size() * 0.5f, scale, effects, 0f); + + spriteBatch.End(); + } + + // Debugging text for tracking attacks. + //string attack = $"{(BehaviorState)AIState}"; + //Vector2 stringDrawPosition = drawPosition - Vector2.UnitY * 64f; + //ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.MouseText.Value, attack, stringDrawPosition, Color.LawnGreen, 0f, Vector2.One, Vector2.One); + + // Eye glint. + if (EyeGlintScale > 0.05f) + { + Vector2 eyeGlintDrawPosition = drawPosition + new Vector2(6f * NPC.spriteDirection, -2f).RotatedBy(NPC.rotation) + Main.rand.NextVector2Circular(HorizontalShakeStrength, 0f); + + spriteBatch.SetBlendState(CalamityUtils.SubtractiveBlending); + for (int i = 0; i < 2; i++) + spriteBatch.Draw(ShineFlare.Value, eyeGlintDrawPosition, null, NPC.GetAlpha(Color.White) * 0.7f, NPC.rotation, ShineFlare.Size() * 0.5f, EyeGlintScale, 0, 0f); + spriteBatch.SetBlendState(BlendState.AlphaBlend); + + spriteBatch.Draw(ShineFlare.Value, eyeGlintDrawPosition, null, NPC.GetAlpha(Color.Red) with { A = 0 }, NPC.rotation, ShineFlare.Size() * 0.5f, EyeGlintScale * 0.8f, 0, 0f); + spriteBatch.Draw(ShineFlare.Value, eyeGlintDrawPosition, null, NPC.GetAlpha(Color.White) with { A = 0 }, NPC.rotation, ShineFlare.Size() * 0.5f, EyeGlintScale * 0.4f, 0, 0f); + } + + return false; + } + + private void SetSquashVectors(Vector2? squashVectorTarget = null, Vector2? squashVector = null) + { + SquashVectorTarget = squashVectorTarget ?? Vector2.One; + if (squashVector.HasValue) + SquashVector = squashVector.Value; + } + + private void RunEyeGlintEffect(float scale) + { + EyeGlintScale = scale; + float pitch = Utils.Remap(scale, 0.4f, 1f, 0.7f, 0.9f, true); + float volume = Utils.Remap(scale, 0.4f, 1f, 1.3f, 1.6f, true); + SoundEngine.PlaySound(SoundID.Item4 with { Volume = volume, Pitch = pitch }, NPC.Center); + } + } +} diff --git a/NPCs/NormalNPCs/HorribleHog.png b/NPCs/NormalNPCs/HorribleHog/HorribleHog.png similarity index 100% rename from NPCs/NormalNPCs/HorribleHog.png rename to NPCs/NormalNPCs/HorribleHog/HorribleHog.png diff --git a/NPCs/NormalNPCs/Piggy.cs b/NPCs/NormalNPCs/Piggy.cs index 268f4db586..d63bc96132 100644 --- a/NPCs/NormalNPCs/Piggy.cs +++ b/NPCs/NormalNPCs/Piggy.cs @@ -2,6 +2,7 @@ using CalamityMod.Effects; using CalamityMod.Items.Critters; using CalamityMod.Items.Placeables.Banners; +using CalamityMod.NPCs.NormalNPCs.HorribleHog; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; @@ -357,7 +358,7 @@ namespace CalamityMod.NPCs.NormalNPCs // Reminder to do short transformation animations for these later. if (projectile.type == ProjectileID.VilePowder || projectile.type == ProjectileID.ViciousPowder) { - npc.Transform(ModContent.NPCType()); + npc.Transform(ModContent.NPCType()); } else if (projectile.type == ProjectileID.PurificationPowder) { diff --git a/Projectiles/Enemy/HorribleHogChargeHitbox.cs b/Projectiles/Enemy/HorribleHogChargeHitbox.cs index 2ebf00db4f..b98444cdde 100644 --- a/Projectiles/Enemy/HorribleHogChargeHitbox.cs +++ b/Projectiles/Enemy/HorribleHogChargeHitbox.cs @@ -1,4 +1,4 @@ -using CalamityMod.NPCs.NormalNPCs; +using CalamityMod.NPCs.NormalNPCs.HorribleHog; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; diff --git a/Projectiles/Enemy/HorribleHogShockwaveSpawner.cs b/Projectiles/Enemy/HorribleHogShockwaveSpawner.cs index 6bc98eb900..c1308fb433 100644 --- a/Projectiles/Enemy/HorribleHogShockwaveSpawner.cs +++ b/Projectiles/Enemy/HorribleHogShockwaveSpawner.cs @@ -12,17 +12,19 @@ namespace CalamityMod.Projectiles.Enemy { public int OwnerIndex; - public ref float Timer => ref Projectile.ai[0]; + public int ShockwaveCounter; - public ref float SpawnInterval => ref Projectile.ai[1]; + public int Timer; - public ref float MaxShockwaves => ref Projectile.ai[2]; + public ref float SpawnInterval => ref Projectile.ai[0]; - public ref float ShockwaveCounter => ref Projectile.localAI[0]; + public ref float MaxShockwaves => ref Projectile.ai[1]; - public ref float Direction => ref Projectile.localAI[1]; + public ref float Direction => ref Projectile.ai[2]; - public ref float MaxHeightMultiplier => ref Projectile.localAI[2]; + public ref float MinHeightMultiplier => ref Projectile.localAI[0]; + + public ref float MaxHeightMultiplier => ref Projectile.localAI[1]; public new string LocalizationCategory => "Projectiles.Enemy"; @@ -41,11 +43,15 @@ namespace CalamityMod.Projectiles.Enemy public override void SendExtraAI(BinaryWriter writer) { writer.Write(OwnerIndex); + writer.Write(ShockwaveCounter); + writer.Write(Timer); } public override void ReceiveExtraAI(BinaryReader reader) { OwnerIndex = reader.ReadInt32(); + ShockwaveCounter = reader.ReadInt32(); + Timer = reader.ReadInt32(); } public override bool ShouldUpdatePosition() => false; @@ -101,8 +107,8 @@ namespace CalamityMod.Projectiles.Enemy if (Main.netMode != NetmodeID.MultiplayerClient) { - float heightMultiplier = MathHelper.Lerp(1f, MaxHeightMultiplier, ShockwaveCounter / MaxShockwaves); - Projectile.NewProjectile(Projectile.GetItemSource_FromThis(), shockwaveSpawnPosition, Vector2.Zero, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, ai1: heightMultiplier, ai2: OwnerIndex); + float shockwaveHeight = MathHelper.Lerp(MinHeightMultiplier, MaxHeightMultiplier, ShockwaveCounter / MaxShockwaves); + Projectile.NewProjectile(Projectile.GetItemSource_FromThis(), shockwaveSpawnPosition, Vector2.Zero, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, ai1: shockwaveHeight, ai2: OwnerIndex); } ShockwaveCounter++; diff --git a/Projectiles/Enemy/HorribleHogZombieSpawner.cs b/Projectiles/Enemy/HorribleHogZombieSpawner.cs index 371241ff37..aafb9a330b 100644 --- a/Projectiles/Enemy/HorribleHogZombieSpawner.cs +++ b/Projectiles/Enemy/HorribleHogZombieSpawner.cs @@ -18,6 +18,8 @@ namespace CalamityMod.Projectiles.Enemy private static Asset ZombieArmTexture; private static Asset BackglowTexture; + private static SoundStyle ZombieEmergeSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogZombieEmerge"); + public List Zombies = new() { NPCID.Zombie, @@ -165,8 +167,7 @@ namespace CalamityMod.Projectiles.Enemy GeneralParticleHandler.SpawnParticle(dustCloud, true); } - SoundEngine.PlaySound(SoundID.Item70, Projectile.Center); - SoundEngine.PlaySound(SoundID.ZombieMoan, Projectile.Center); + SoundEngine.PlaySound(ZombieEmergeSound, Projectile.Center); } public override void DrawBehind(int index, List behindNPCsAndTiles, List behindNPCs, List behindProjectiles, List overPlayers, List overWiresUI) diff --git a/Sounds/Custom/HorribleHog/HorribleHogCackle.ogg b/Sounds/Custom/HorribleHog/HorribleHogCackle.ogg new file mode 100644 index 0000000000..0970efd21c Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogCackle.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogDashGrunt.ogg b/Sounds/Custom/HorribleHog/HorribleHogDashGrunt.ogg new file mode 100644 index 0000000000..e222b6edb4 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogDashGrunt.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogDeathLaugh1.ogg b/Sounds/Custom/HorribleHog/HorribleHogDeathLaugh1.ogg deleted file mode 100644 index f1ecc5a2ef..0000000000 Binary files a/Sounds/Custom/HorribleHog/HorribleHogDeathLaugh1.ogg and /dev/null differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogDeathLaugh2.ogg b/Sounds/Custom/HorribleHog/HorribleHogDeathLaugh2.ogg deleted file mode 100644 index cec4db5a51..0000000000 Binary files a/Sounds/Custom/HorribleHog/HorribleHogDeathLaugh2.ogg and /dev/null differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogGroundImpact1.ogg b/Sounds/Custom/HorribleHog/HorribleHogGroundImpact1.ogg new file mode 100644 index 0000000000..e303907f68 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogGroundImpact1.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogGroundImpact2.ogg b/Sounds/Custom/HorribleHog/HorribleHogGroundImpact2.ogg new file mode 100644 index 0000000000..cbfb66e2fb Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogGroundImpact2.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogIdle1.ogg b/Sounds/Custom/HorribleHog/HorribleHogIdle1.ogg new file mode 100644 index 0000000000..fe60871337 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogIdle1.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogIdle2.ogg b/Sounds/Custom/HorribleHog/HorribleHogIdle2.ogg new file mode 100644 index 0000000000..e3cece7166 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogIdle2.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogJump1.ogg b/Sounds/Custom/HorribleHog/HorribleHogJump1.ogg new file mode 100644 index 0000000000..fd223e0d2f Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogJump1.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogJump2.ogg b/Sounds/Custom/HorribleHog/HorribleHogJump2.ogg new file mode 100644 index 0000000000..1518f255e1 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogJump2.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogNearbyLoop.ogg b/Sounds/Custom/HorribleHog/HorribleHogNearbyLoop.ogg new file mode 100644 index 0000000000..63b4993d77 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogNearbyLoop.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogRetreat.ogg b/Sounds/Custom/HorribleHog/HorribleHogRetreat.ogg new file mode 100644 index 0000000000..f2cf0ec66e Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogRetreat.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogVomit1.ogg b/Sounds/Custom/HorribleHog/HorribleHogVomit1.ogg new file mode 100644 index 0000000000..fe278eeef1 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogVomit1.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogVomit2.ogg b/Sounds/Custom/HorribleHog/HorribleHogVomit2.ogg new file mode 100644 index 0000000000..f777b2b800 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogVomit2.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogVomitChargeUp1.ogg b/Sounds/Custom/HorribleHog/HorribleHogVomitChargeUp1.ogg new file mode 100644 index 0000000000..9b0b260136 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogVomitChargeUp1.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogVomitChargeUp2.ogg b/Sounds/Custom/HorribleHog/HorribleHogVomitChargeUp2.ogg new file mode 100644 index 0000000000..b0318c2a9c Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogVomitChargeUp2.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogZombieEmerge.ogg b/Sounds/Custom/HorribleHog/HorribleHogZombieEmerge.ogg new file mode 100644 index 0000000000..9b718e2509 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogZombieEmerge.ogg differ diff --git a/Sounds/NPCHit/HorribleHogHit1.ogg b/Sounds/NPCHit/HorribleHogHit1.ogg new file mode 100644 index 0000000000..2fd18dc979 Binary files /dev/null and b/Sounds/NPCHit/HorribleHogHit1.ogg differ diff --git a/Sounds/NPCHit/HorribleHogHit2.ogg b/Sounds/NPCHit/HorribleHogHit2.ogg new file mode 100644 index 0000000000..272db7cd30 Binary files /dev/null and b/Sounds/NPCHit/HorribleHogHit2.ogg differ diff --git a/Sounds/NPCHit/HorribleHogHit3.ogg b/Sounds/NPCHit/HorribleHogHit3.ogg new file mode 100644 index 0000000000..4627517b48 Binary files /dev/null and b/Sounds/NPCHit/HorribleHogHit3.ogg differ diff --git a/Sounds/NPCKilled/HorribleHogDeath.ogg b/Sounds/NPCKilled/HorribleHogDeath.ogg index 3dd2a79cd4..20989e8a83 100644 Binary files a/Sounds/NPCKilled/HorribleHogDeath.ogg and b/Sounds/NPCKilled/HorribleHogDeath.ogg differ