diff --git a/Backgrounds/SunkenSeaBurrowsBG.cs b/Backgrounds/SunkenSeaBurrowsBG.cs index b8de0ce754..9588037dd2 100644 --- a/Backgrounds/SunkenSeaBurrowsBG.cs +++ b/Backgrounds/SunkenSeaBurrowsBG.cs @@ -182,15 +182,17 @@ namespace CalamityMod.Backgrounds Main.spriteBatch.End(); Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, Main.Rasterizer, distortionShader.Shader, CalamityUtils.BackgroundMatrix); - const float distortionXSpeed = -0.012f; - const float distortionYSpeed = 0.02f; - const float noiseScale = 0.075f; - const float noiseStrength = 0.035f; - Vector2 timeOffset = new Vector2(distortionXSpeed, distortionYSpeed) * Main.GlobalTimeWrappedHourly * noiseScale; - Vector2 noiseScaleStrength = new Vector2(noiseScale, noiseStrength); - distortionShader.Shader.Parameters["timeOffset"].SetValue(timeOffset); - distortionShader.Shader.Parameters["noiseScaleStrength"].SetValue(noiseScaleStrength); - distortionShader.SetShaderTexture(distortionTexture); + float distortionXSpeed = -0.012f; + float distortionYSpeed = 0.02f; + float noiseScale = 0.075f; + float noiseStrength = 0.035f; + + distortionShader.Shader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly); + distortionShader.Shader.Parameters["noiseScale"].SetValue(noiseScale); + distortionShader.Shader.Parameters["distortionStrength"].SetValue(noiseStrength); + distortionShader.Shader.Parameters["timeOffset"].SetValue(new Vector2(distortionXSpeed, distortionYSpeed)); + Main.graphics.GraphicsDevice.Textures[1] = distortionTexture.Value; + Main.graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearWrap; Main.spriteBatch.Draw(WaterDistortionTarget.Target, new Rectangle(16, 16, Main.screenWidth, Main.screenHeight), Color.White); } diff --git a/Balancing/BalancingChangesManager.cs b/Balancing/BalancingChangesManager.cs index 3bc64026d3..992b94ff5e 100644 --- a/Balancing/BalancingChangesManager.cs +++ b/Balancing/BalancingChangesManager.cs @@ -4,6 +4,7 @@ using CalamityMod.Items.Weapons.Ranged; using CalamityMod.NPCs.AstrumAureus; using CalamityMod.NPCs.CeaselessVoid; using CalamityMod.NPCs.Crabulon; +using CalamityMod.NPCs.NormalNPCs.HorribleHog; using CalamityMod.NPCs.OldDuke; using CalamityMod.NPCs.ProfanedGuardians; using CalamityMod.NPCs.Providence; @@ -54,6 +55,13 @@ namespace CalamityMod.Balancing NPCSpecificBalancingChanges = new List(); + // ENEMIES + #region Horrible Hog + // Take 300% damage from Finch Staff. + NPCSpecificBalancingChanges.Add(new NPCBalancingChange(NPCType(), Do(new ProjectileResistBalancingRule(3f, ProjectileID.BabyBird)))); + #endregion + + // BOSSES #region Crabulon // 20% resist to true melee. NPCSpecificBalancingChanges.Add(new NPCBalancingChange(NPCType(), ResistTrueMelee(0.8f))); diff --git a/Buffs/Pets/BeldumBuff.cs b/Buffs/Pets/BeldumBuff.cs new file mode 100644 index 0000000000..7ee2658caa --- /dev/null +++ b/Buffs/Pets/BeldumBuff.cs @@ -0,0 +1,27 @@ +using CalamityMod.Projectiles.Pets; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Buffs.Pets +{ + public class BeldumBuff : ModBuff + { + public override void SetStaticDefaults() + { + Main.buffNoTimeDisplay[Type] = true; + Main.vanityPet[Type] = true; + } + + public override void Update(Player player, ref int buffIndex) + { + player.buffTime[buffIndex] = 18000; + player.Calamity().beldum = true; + bool PetProjectileNotSpawned = player.ownedProjectileCounts[ModContent.ProjectileType()] <= 0; + if (PetProjectileNotSpawned && player.whoAmI == Main.myPlayer) + { + Projectile.NewProjectile(player.GetSource_Buff(buffIndex), player.Center, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, player.whoAmI, 0f, 0f); + } + } + } +} diff --git a/Buffs/Pets/BeldumBuff.png b/Buffs/Pets/BeldumBuff.png new file mode 100644 index 0000000000..610a378258 Binary files /dev/null and b/Buffs/Pets/BeldumBuff.png differ diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 9ff7fdca31..986e2399c3 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -36,6 +36,7 @@ using CalamityMod.Items.Armor.TitanHeart; using CalamityMod.Items.Armor.Victide; using CalamityMod.Items.Armor.Wulfrum; using CalamityMod.Items.Dyes; +using CalamityMod.Items.Fishing; using CalamityMod.Items.Materials; using CalamityMod.Items.Mounts; using CalamityMod.Items.Mounts.Minecarts; @@ -600,6 +601,7 @@ namespace CalamityMod.CalPlayer public bool lordePet = false; public bool frostyBat = false; public bool toastyBat = false; + public bool beldum = false; public bool starSwallowerPetFroge = false; #endregion @@ -2306,6 +2308,7 @@ namespace CalamityMod.CalPlayer lordePet = false; frostyBat = false; toastyBat = false; + beldum = false; starSwallowerPetFroge = false; onyxExcavator = false; @@ -6338,6 +6341,9 @@ namespace CalamityMod.CalPlayer if (it.type == ItemType()) playerUsingWeapon = false; + if (it.type == ItemType()) + playerUsingWeapon = false; + // Animation check depends on whether the item is "clockwork", like Clockwork Assault Rifle. // "Clockwork" weapons can chain-fire multiple stealth strikes (really only 2 max) until you run out of stealth. bool animationCheck = it.useAnimation == it.useTime diff --git a/CalPlayer/CalamityPlayerFishing.cs b/CalPlayer/CalamityPlayerFishing.cs index 2726952268..c8d9deee3a 100644 --- a/CalPlayer/CalamityPlayerFishing.cs +++ b/CalPlayer/CalamityPlayerFishing.cs @@ -323,6 +323,16 @@ namespace CalamityMod.CalPlayer itemDrop = ModContent.ItemType(); } + // Lower chance of Spadefish in Hardmode + if (underground) // Underground + { + int chance = Main.hardMode ? 10 : 4; + if (attempt.veryrare && Main.rand.NextBool(chance)) + { + itemDrop = ModContent.ItemType(); + } + } + if (ZoneAstral) { if (attempt.legendary) diff --git a/CalPlayer/CalamityPlayerOnHit.cs b/CalPlayer/CalamityPlayerOnHit.cs index 2beeabed24..979cee740d 100644 --- a/CalPlayer/CalamityPlayerOnHit.cs +++ b/CalPlayer/CalamityPlayerOnHit.cs @@ -212,6 +212,11 @@ namespace CalamityMod.CalPlayer if (Player.whoAmI != Main.myPlayer) return; + // Don't activate for non-friendly projectiles (obviously). + // Override CanHitNPC if you want a hostile projectile that can also damage enemies. + if (!proj.friendly) + return; + //Undo raider crit after hit if (!proj.Calamity().stealthStrike && !proj.Calamity().stealthStrikeSubProjectile && raiderCritLifespan > 0f) { diff --git a/Effects/BasicTextureDistortionShader.fx b/Effects/BasicTextureDistortionShader.fx index a9e45abb3a..4bb930454c 100644 --- a/Effects/BasicTextureDistortionShader.fx +++ b/Effects/BasicTextureDistortionShader.fx @@ -1,14 +1,16 @@ sampler baseTexture : register(s0); sampler distortionTexture : register(s1); +float time; +float noiseScale; +float distortionStrength; float2 timeOffset; -float2 noiseScaleStrength; float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR { - float2 distortedCoords = coords * noiseScaleStrength.x + timeOffset; - float distortion = tex2D(distortionTexture, distortedCoords).r * noiseScaleStrength.y; - return tex2D(baseTexture, coords + distortion) * sampleColor.a; + float2 distortedCoords = coords + float2(time * timeOffset.x, time * timeOffset.y); + float distortion = tex2D(distortionTexture, distortedCoords * noiseScale).r; + return tex2D(baseTexture, coords + distortion * distortionStrength); } technique Technique1 diff --git a/Effects/BasicTextureDistortionShader.xnb b/Effects/BasicTextureDistortionShader.xnb index b556cca62c..4eca078ba2 100644 Binary files a/Effects/BasicTextureDistortionShader.xnb and b/Effects/BasicTextureDistortionShader.xnb differ diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 18993d5e2d..7bda59d4a4 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -257,6 +257,15 @@ namespace CalamityMod.Effects // The shader effect used for Voidragon's Abyssal Fire laser projectile. internal static Asset AbyssalFireShader; + + // A simple chromatic abberation effect shader with support for custom abberation colors. + internal static Asset ChromaticAbberationShader; + + // 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 @@ -519,6 +528,15 @@ namespace CalamityMod.Effects AbyssalFireShader = LoadShader("AbyssalFireShader"); RegisterMiscShader(AbyssalFireShader, "LaserPass", "AbyssalFire"); + + ChromaticAbberationShader = LoadShader("ChromaticAbberationShader"); + RegisterMiscShader(ChromaticAbberationShader, "ChormaAbberationPass", "ChromaticAbberation"); + + 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/ChromaticAbberationShader.fx b/Effects/ChromaticAbberationShader.fx new file mode 100644 index 0000000000..73ee7a5a06 --- /dev/null +++ b/Effects/ChromaticAbberationShader.fx @@ -0,0 +1,48 @@ +sampler baseTexture : register(s0); + +bool useCustomColors; +float abberationStrength; +float2 impactPosition; +float3 primaryAbberationColor; +float3 secondaryAbberationColor; +float3 tertiaryAbberationColor; + +float3 ChromaticAbberation(sampler2D samplerTexture, float2 coords) +{ + // Calculate the distortion level of each color. + float separation = abberationStrength / distance(coords, impactPosition); + float rColor = tex2D(samplerTexture, coords + float2(-1, -1) * separation).r; + float gColor = tex2D(samplerTexture, coords + float2(1, -1) * separation).g; + float bColor = tex2D(samplerTexture, coords + float2(0, 1) * separation).b; + + // Return the three calculations as one singular color. + float3 returnColor = float3(rColor, gColor, bColor); + return returnColor; +} + +float3 ChromaticAbberation_CustomColors(sampler2D samplerTexture, float2 coords) +{ + // Calculate the distortion level of each color. + float separation = abberationStrength / distance(coords, impactPosition); + float4 pColor = tex2D(samplerTexture, coords + float2(-1, -1) * separation) * float4(primaryAbberationColor, 1); + float4 sColor = tex2D(samplerTexture, coords + float2(1, -1) * separation) * float4(primaryAbberationColor, 1); + float4 tColor = tex2D(samplerTexture, coords + float2(0, 1) * separation) * float4(primaryAbberationColor, 1); + + // Return the three calculations as one singular color. + float3 returnColor = saturate(pColor + sColor + tColor); + return returnColor; +} + +float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0 +{ + float3 color = useCustomColors ? ChromaticAbberation_CustomColors(baseTexture, coords) : ChromaticAbberation(baseTexture, coords); + return sampleColor * float4(color, 1.0); +} + +technique Technique1 +{ + pass ChormaAbberationPass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/ChromaticAbberationShader.xnb b/Effects/ChromaticAbberationShader.xnb new file mode 100644 index 0000000000..2c992a1046 Binary files /dev/null and b/Effects/ChromaticAbberationShader.xnb differ 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/Effects/RotateSprite.fx b/Effects/RotateSprite.fx index bd91a83ed0..8da18993da 100644 --- a/Effects/RotateSprite.fx +++ b/Effects/RotateSprite.fx @@ -1,9 +1,7 @@ -float rotation; // The rotation of the sprite. -float4 color; - - -texture sampleTexture; -sampler2D Texture1Sampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = wrap; AddressV = wrap; }; +sampler baseTexture : register(s0); +float rotation; // The rotation of the sprite. +float2 spriteDimensions; // Dimensions of the sprite. +float4 spriteRectangle; // For use with animated sprites. float realCos(float value) { @@ -11,7 +9,7 @@ float realCos(float value) } //This only works on square sprites. -float4 main(float2 uv : TEXCOORD) : COLOR +float4 main(float4 sampleColor : COLOR0, float2 uv : TEXCOORD0) : COLOR0 { float2x2 rotate = float2x2(realCos(rotation), -sin(rotation), sin(rotation), realCos(rotation)); float spriteDiagonal = 1 / (sqrt(2) / 2); @@ -19,14 +17,14 @@ float4 main(float2 uv : TEXCOORD) : COLOR uv += float2(-0.5, -0.5); //remap the uv to (-0.5, -0.5) - (0.5, 0.5) for trig to work. uv = mul(uv, rotate); - uv = mul(uv, downscale); + //uv = mul(uv, downscale); uv += float2(0.5, 0.5); //remap the uv properly //Crop (Attempting to sample a texture with coordinates that arent between 0 to 1 wraps it around if (uv.x < 0 || uv.x >= 1 || uv.y < 0 || uv.y >= 1) return float4(0, 0, 0, 0); - return tex2D(Texture1Sampler, uv) * color; + return tex2D(baseTexture, uv) * sampleColor; } technique Technique1 diff --git a/Effects/RotateSprite.xnb b/Effects/RotateSprite.xnb index fd51404d21..8208af3e57 100644 Binary files a/Effects/RotateSprite.xnb and b/Effects/RotateSprite.xnb differ diff --git a/Effects/SineWaveDistortionShader.fx b/Effects/SineWaveDistortionShader.fx new file mode 100644 index 0000000000..8b2b18ffa4 --- /dev/null +++ b/Effects/SineWaveDistortionShader.fx @@ -0,0 +1,27 @@ +sampler baseTexture : register(s0); + +float time; +float waveAmplitude; +float waveFrequency; +bool distortHorizontally; + +float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0 +{ + float2 horizontalDistortion = sin(coords.x * waveFrequency + time) * waveAmplitude; + float2 verticalDistortion = sin(coords.y * waveFrequency + time) * waveAmplitude; + + if (distortHorizontally) + coords.y += horizontalDistortion; + else + coords.x += verticalDistortion; + + return tex2D(baseTexture, coords) * sampleColor; +} + +technique Technique1 +{ + pass SinePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/SineWaveDistortionShader.xnb b/Effects/SineWaveDistortionShader.xnb new file mode 100644 index 0000000000..752479a1a4 Binary files /dev/null and b/Effects/SineWaveDistortionShader.xnb differ diff --git a/ExtraTextures/BloomFlare.png b/ExtraTextures/BloomFlare.png new file mode 100644 index 0000000000..c92cf061d2 Binary files /dev/null and b/ExtraTextures/BloomFlare.png differ diff --git a/ExtraTextures/FadedStarRing.png b/ExtraTextures/FadedStarRing.png new file mode 100644 index 0000000000..29536fb0d7 Binary files /dev/null and b/ExtraTextures/FadedStarRing.png differ diff --git a/ExtraTextures/MagicStarCircle.png b/ExtraTextures/MagicStarCircle.png new file mode 100644 index 0000000000..594256e368 Binary files /dev/null and b/ExtraTextures/MagicStarCircle.png differ diff --git a/ExtraTextures/ShineFlare.png b/ExtraTextures/ShineFlare.png new file mode 100644 index 0000000000..5e8c572de2 Binary files /dev/null and b/ExtraTextures/ShineFlare.png differ diff --git a/Gores/Piggy.png b/Gores/Piggy.png new file mode 100644 index 0000000000..576706349c Binary files /dev/null and b/Gores/Piggy.png differ diff --git a/Gores/Piggy2.png b/Gores/Piggy2.png new file mode 100644 index 0000000000..add55f0216 Binary files /dev/null and b/Gores/Piggy2.png differ diff --git a/Items/Accessories/Laudanum.cs b/Items/Accessories/Laudanum.cs index 716d7a8cf2..3ba0a52e6f 100644 --- a/Items/Accessories/Laudanum.cs +++ b/Items/Accessories/Laudanum.cs @@ -12,19 +12,13 @@ namespace CalamityMod.Items.Accessories public Color? TooltipExtensionColor => new(195, 223, 255); - public override void SetStaticDefaults() - { - ItemID.Sets.ShimmerTransformToItem[Type] = ModContent.ItemType(); - } - public override void SetDefaults() { Item.width = 26; Item.height = 26; - Item.value = CalamityGlobalItem.RarityOrangeBuyPrice; - Item.rare = ItemRarityID.Orange; + Item.value = CalamityGlobalItem.RarityGreenBuyPrice; + Item.rare = ItemRarityID.Green; Item.accessory = true; - Item.SetRevExclusive(); } public override void UpdateAccessory(Player player, bool hideVisual) diff --git a/Items/Accessories/ScionsCurio.cs b/Items/Accessories/ScionsCurio.cs index 66e34b7350..bf739b81de 100644 --- a/Items/Accessories/ScionsCurio.cs +++ b/Items/Accessories/ScionsCurio.cs @@ -14,7 +14,7 @@ namespace CalamityMod.Items.Accessories public class ScionsCurio : ModItem, ILocalizedModType { - public static int postHitDamage = 45; + public static int postHitDamage = 20; public new string LocalizationCategory => "Items.Accessories"; public override void SetDefaults() { diff --git a/Items/Accessories/StressPills.cs b/Items/Accessories/StressPills.cs index b7a3dd4452..c8c8e3f299 100644 --- a/Items/Accessories/StressPills.cs +++ b/Items/Accessories/StressPills.cs @@ -10,7 +10,7 @@ namespace CalamityMod.Items.Accessories public new string LocalizationCategory => "Items.Accessories"; public override void SetStaticDefaults() { - ItemID.Sets.ShimmerTransformToItem[Type] = ModContent.ItemType(); + ItemID.Sets.ShimmerTransformToItem[Type] = ModContent.ItemType(); } public override void SetDefaults() diff --git a/Items/Critters/PiggyGoldItem.cs b/Items/Critters/PiggyGoldItem.cs new file mode 100644 index 0000000000..39ca391053 --- /dev/null +++ b/Items/Critters/PiggyGoldItem.cs @@ -0,0 +1,24 @@ +using CalamityMod.NPCs.NormalNPCs; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Critters +{ + public class PiggyGoldItem : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Misc"; + + public override void SetStaticDefaults() + { + Item.ResearchUnlockCount = 5; + } + + public override void SetDefaults() + { + Item.DefaultToCapturedCritter(ModContent.NPCType()); + Item.value = Item.sellPrice(gold: 10); + Item.rare = ItemRarityID.Orange; + } + } +} diff --git a/Items/Critters/PiggyGoldItem.png b/Items/Critters/PiggyGoldItem.png new file mode 100644 index 0000000000..ab41e817d5 Binary files /dev/null and b/Items/Critters/PiggyGoldItem.png differ diff --git a/Items/Critters/PiggyItem.cs b/Items/Critters/PiggyItem.cs index 3388b74cff..7f54dcc8d7 100644 --- a/Items/Critters/PiggyItem.cs +++ b/Items/Critters/PiggyItem.cs @@ -8,6 +8,7 @@ namespace CalamityMod.Items.Critters public class PiggyItem : ModItem, ILocalizedModType { public new string LocalizationCategory => "Items.Misc"; + public override void SetStaticDefaults() { Item.ResearchUnlockCount = 5; @@ -16,7 +17,7 @@ namespace CalamityMod.Items.Critters public override void SetDefaults() { Item.DefaultToCapturedCritter(ModContent.NPCType()); - Item.value = Item.sellPrice(gold: 10); + Item.value = Item.sellPrice(silver: 5); Item.rare = ItemRarityID.Blue; Item.Calamity().donorItem = true; } diff --git a/Items/Critters/PiggyItem.png b/Items/Critters/PiggyItem.png index 34c9df0b9a..0628198b73 100644 Binary files a/Items/Critters/PiggyItem.png and b/Items/Critters/PiggyItem.png differ diff --git a/Items/Fishing/Spadefish.cs b/Items/Fishing/Spadefish.cs new file mode 100644 index 0000000000..a2172c962b --- /dev/null +++ b/Items/Fishing/Spadefish.cs @@ -0,0 +1,409 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using CalamityMod.Items.Weapons.Rogue; +using CalamityMod.Utilities.Daybreak; +using CalamityMod.Utilities.Daybreak.Buffers; +using Microsoft.CodeAnalysis; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.GameContent; +using Terraria.GameContent.Achievements; +using Terraria.Graphics.Renderers; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ModLoader.IO; + +namespace CalamityMod.Items.Fishing +{ + public class Spadefish : RogueWeapon, ILocalizedModType + { + public static float SpinsToThrow => 3; + + public static float SpinDamageMult => 0.33f; + + public static float SpinAccel => 1.0175f; + + public static float SpinThrowVelocityMult => 1.5f; + + public override float StealthDamageMultiplier => 2f; + + public static int PickPower => 50; + public new string LocalizationCategory => "Items.Fishing"; + public override void SetDefaults() + { + Item.width = 46; + Item.height = 44; + Item.damage = 30; + Item.knockBack = 2f; + Item.useTime = 40; + Item.useAnimation = 40; + Item.shootSpeed = 12; + Item.DamageType = RogueDamageClass.Instance; + Item.useStyle = ItemUseStyleID.Swing; + Item.value = CalamityGlobalItem.RarityGreenBuyPrice; + Item.rare = ItemRarityID.Green; + Item.UseSound = SoundID.Item1; + Item.autoReuse = true; + Item.shoot = ModContent.ProjectileType(); + Item.noMelee = true; + Item.noUseGraphic = true; + Item.pick = PickPower; + + } + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + if (player.Calamity().StealthStrikeAvailable()) + { + type = ModContent.ProjectileType(); + Projectile.NewProjectile(source, position, velocity, type, damage, knockback, player.whoAmI); //This proj sets StealthStrike on its own setdefaults + + player.Calamity().ConsumeStealthByAttacking(); //Due to the holdout, we manually consume stealth here and on spam. + return false; + } + player.Calamity().rogueStealth = 0; + return true; + } + + + #region Toggleable Mining + + public bool CanMine = false; + public override void ModifyTooltips(List tooltips) + { + tooltips.FindAndReplace("[TOGGLE]", CanMine ? this.GetLocalizedValue("TextWhileEnabled") : this.GetLocalizedValue("TextWhileDisabled")); + } + public override bool CanRightClick() => Main.keyState.PressingShift(); + public override void RightClick(Player player) + { + CanMine = !CanMine; + Item.NetStateChanged(); + } + public override bool ConsumeItem(Player player) => false; + public override void SaveData(TagCompound tag) + { + tag.Add("CanMine", CanMine); + } + + public override void LoadData(TagCompound tag) + { + CanMine = tag.GetBool("CanMine"); + } + + public override void NetSend(BinaryWriter writer) + { + writer.Write(CanMine); + } + + public override void NetReceive(BinaryReader reader) + { + CanMine = reader.ReadBoolean(); + } + Asset texture; + public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + if (CanMine) + { + var tex = CalamityUtils.GetTextureEfficient(ref texture, "Terraria/Images/Extra_48").Value; + var dotFrame = tex.Frame(8, 39, 4, 23); + spriteBatch.Draw(tex, position + new Vector2(16, 16) * Main.inventoryScale, dotFrame, Color.White, 0, dotFrame.Size() * 0.5f, Main.inventoryScale, SpriteEffects.None, 0); + } + } + #endregion + } + + public class SpadefishThrown : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Rogue"; + public override string Texture => "CalamityMod/Items/Fishing/Spadefish"; + public override void SetDefaults() + { + Projectile.DamageType = RogueDamageClass.Instance; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = -1; + Projectile.penetrate = 3; + Projectile.width = 16; + Projectile.height = 16; + Projectile.friendly = true; + Projectile.stopsDealingDamageAfterPenetrateHits = true; + Projectile.timeLeft = 480; + Projectile.MaxUpdates = 2; + Projectile.ignoreWater = true; + } + bool frameOne = true; + public override void AI() + { + if (frameOne) + { + Projectile.velocity /= Projectile.MaxUpdates; + frameOne = false; + } + if (Projectile.ai[0] <= 1 && Projectile.timeLeft < 450) + Projectile.velocity.Y += 0.08f; + if (Projectile.ai[0] == 0) + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver4; + else if (Projectile.ai[0] == 1) + Projectile.rotation += Projectile.velocity.X * 0.15f; + + if (Projectile.timeLeft < 60) + { + Projectile.Opacity = Projectile.timeLeft / 60f; + } + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + + if (Projectile.ai[0] == 1) + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver4; + Projectile.velocity = Vector2.Zero; + Projectile.Center += oldVelocity; + Projectile.ai[0] = 2; + SoundEngine.PlaySound(SoundID.Dig, Projectile.Center); + Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); + if (Main.myPlayer == Projectile.owner && Main.LocalPlayer.HeldItem.ModItem is Spadefish s && s.CanMine) + for (var j = -1; j < 2; j++) + for (var k = -1; k < 2; k++) + Dig(Spadefish.PickPower, Projectile.Center.ToTileCoordinates() + new Point(j, k)); + return false; + } + + public static void Dig(int pickPower, Point point) + { + var tile = Main.tile[point]; + var x = tile.X(); + var y = tile.Y(); + + if (!tile.HasTile || Main.tileAxe[tile.TileType] || Main.tileHammer[tile.TileType]) + return; + + int hitIndex = Main.LocalPlayer.hitTile.HitObject(x, y, 1); + + if (tile.TileType == TileID.MysticSnakeRope) + return; + + int pickDmg = Main.LocalPlayer.GetPickaxeDamage(x, y, pickPower, hitIndex, tile); + + + if (!WorldGen.CanKillTile(x, y)) + pickDmg = 0; + + if (Main.getGoodWorld) + pickDmg *= 2; + + if (Main.LocalPlayer.DoesPickTargetTransformOnKill(Main.LocalPlayer.hitTile, pickDmg, x, y, pickPower, hitIndex, tile)) + pickDmg = 0; + + if (Main.LocalPlayer.hitTile.AddDamage(hitIndex, pickDmg) >= 100) + { + AchievementsHelper.CurrentlyMining = true; + Main.LocalPlayer.ClearMiningCacheAt(x, y, 1); + if (Main.netMode == NetmodeID.MultiplayerClient && Main.tileContainer[tile.TileType]) + { + if (tile.TileType == TileID.DisplayDoll || tile.TileType == TileID.HatRack) + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 20, x, y); + else + { + WorldGen.KillTile(x, y, fail: true); + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 0, x, y, 1f); + } + if (tile.TileType == TileID.Containers) + { + NetMessage.SendData(MessageID.ChestUpdates, -1, -1, null, 1, x, y); + } + if (tile.TileType == TileID.Containers2) + { + NetMessage.SendData(MessageID.ChestUpdates, -1, -1, null, 5, x, y); + } + if (tile.TileType == TileID.Dressers) + { + NetMessage.SendData(MessageID.ChestUpdates, -1, -1, null, 3, x, y); + } + } + else + { + bool flag = tile.HasTile; + WorldGen.KillTile(x, y); + if (!Main.dedServ && flag && !tile.HasTile) + { + AchievementsHelper.HandleMining(); + } + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 0, x, y); + } + } + AchievementsHelper.CurrentlyMining = false; + } + else + { + WorldGen.KillTile(x, y, fail: true); + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 0, x, y, 1f); + NetMessage.SendData(MessageID.SyncTilePicking, -1, -1, null, Main.myPlayer, x, y, pickDmg); + } + } + if (pickDmg != 0) + { + Main.LocalPlayer.hitTile.Prune(); + } + } + + + + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) + { + SoundEngine.PlaySound(SoundID.Item178 with { Pitch = -0.5f + 0.25f * Projectile.numHits + (Projectile.Calamity().stealthStrike ? 1f : 0f) }, Projectile.Center); + + Projectile.velocity.X = -Projectile.velocity.X.DirectionalSign(); + Projectile.velocity.Y = -2f; + Projectile.ai[0] = 1; + Projectile.damage /= 2; + Projectile.netUpdate = true; + } + + public override bool PreDraw(ref Color lightColor) + { + var tex = TextureAssets.Projectile[Type]; + Main.EntitySpriteDraw(tex.Value, Projectile.Center - Main.screenPosition, null, lightColor * Projectile.Opacity, Projectile.rotation, tex.Size() * 0.5f, Projectile.scale, 0); + return false; + } + } + + public class SpadefishHoldout : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Rogue"; + public override string Texture => "CalamityMod/Items/Fishing/Spadefish"; + + ref float spin => ref Projectile.ai[0]; + ref float startingDir => ref Projectile.ai[1]; + + float throwSpeed = 12; //changing this does nothing, as this is set in the code. This is just a fallback value if something breaks. + + bool reset = false; + + float oldSpin = 0; + int digDir = 0; + + float spinSin => MathF.Sin(spin); + public override void SetDefaults() + { + Projectile.DamageType = RogueDamageClass.Instance; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = -1; + Projectile.width = 64; + Projectile.height = 64; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.Calamity().stealthStrike = true; + Projectile.tileCollide = false; + } + + public override void Load() + { + On_LegacyPlayerRenderer.DrawPlayer += spinThePlayer; + } + + private void spinThePlayer(On_LegacyPlayerRenderer.orig_DrawPlayer orig, LegacyPlayerRenderer self, Terraria.Graphics.Camera camera, Player drawPlayer, Vector2 position, float rotation, Vector2 rotationOrigin, float shadow, float scale) + { + var t = ModContent.ProjectileType(); + if (drawPlayer.ownedProjectileCounts[t] <= 0) + { + orig(self, camera, drawPlayer, position, rotation, rotationOrigin, shadow, scale); + return; + } + + var Spade = Main.projectile.FirstOrDefault(p => p.active && p.owner == drawPlayer.whoAmI && p.type == t)?.ModProjectile(); + + if (Spade is null || Spade.startingDir == 0) + { + orig(self, camera, drawPlayer, position, rotation, rotationOrigin, shadow, scale); + return; + } + + using var lease = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice); + using (lease.Scope(clearColor: Color.Transparent)) + { + orig(self, camera, drawPlayer, position, rotation, rotationOrigin, shadow, scale); + + bool flip = (Spade.spinSin * Spade.startingDir) < 0; + var tex = TextureAssets.Projectile[Type]; + Main.EntitySpriteDraw(tex.Value, drawPlayer.Center + new Vector2(40, 0) - Main.screenPosition, null, Lighting.GetColor(Spade.Projectile.Center.ToTileCoordinates()), Spade.Projectile.rotation - (flip ? MathHelper.PiOver2 : 0), tex.Size() * 0.5f, new Vector2(Spade.Projectile.scale, Spade.Projectile.scale), flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None); + } + float width = Spade.spinSin * Spade.startingDir * drawPlayer.direction; + + using (Main.spriteBatch.Scope()) + { + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Matrix.identity); + Main.spriteBatch.Draw(lease.Target, position - Main.screenPosition, null, Color.White, 0, position - Main.screenPosition, new Vector2(MathF.Abs(width), 1), width < 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0f); + Main.spriteBatch.End(); + } + } + + public override void AI() + { + var player = Main.player[Projectile.owner]; + if (startingDir == 0) + { + startingDir = Projectile.velocity.X.DirectionalSign(); + throwSpeed = Projectile.velocity.Length(); + Projectile.velocity = Vector2.Zero; + } + player.direction = 1; + player.SetDummyItemTime((int)(player.HeldItem.useTime * player.GetWeaponAttackSpeed(player.HeldItem))); + Projectile.Center = player.Center + new Vector2(48 * spinSin, 0 * MathF.Cos(spin)) * startingDir; + Projectile.rotation = Projectile.DirectionFrom(player.Center).ToRotation() + MathHelper.PiOver4; + if (spin == 0) + { + spin = MathHelper.TwoPi; + } + spin *= Spadefish.SpinAccel; + + int res = reset ? -1 : 1; + if (res != spinSin.DirectionalSign()) + { + Projectile.ResetLocalNPCHitImmunity(); + reset = !reset; + } + + if (Projectile.timeLeft % 5 == 0 && Main.myPlayer == Projectile.owner && Main.LocalPlayer.HeldItem.ModItem is Spadefish s && s.CanMine) + for (var j = -1; j < 2; j++) + for (var k = -1; k < 2; k++) + SpadefishThrown.Dig(Spadefish.PickPower, Projectile.Center.ToTileCoordinates() + new Point(j, k)); + + if (spin > MathHelper.TwoPi * (1 + Spadefish.SpinsToThrow)) + { + player.direction = (int)startingDir; + if (Main.myPlayer == Projectile.owner) + { + var p = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), player.Center, player.Calamity().mouseRotationFromPlayer.ToRotationVector2() * throwSpeed * Spadefish.SpinThrowVelocityMult, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, player.whoAmI); + p.Calamity().stealthStrike = true; + } + Projectile.Kill(); + } + } + + public override bool PreDraw(ref Color lightColor) + { + return false; + } + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) + { + SoundEngine.PlaySound(SoundID.Item178 with { pitch = (spin-MathHelper.TwoPi) / (MathHelper.TwoPi * Spadefish.SpinsToThrow) - 0.5f }, Projectile.Center); + } + + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + { + modifiers.SourceDamage *= Spadefish.SpinDamageMult; + } + } +} diff --git a/Items/Fishing/Spadefish.png b/Items/Fishing/Spadefish.png new file mode 100644 index 0000000000..87e8d5a6fb Binary files /dev/null and b/Items/Fishing/Spadefish.png differ diff --git a/Items/Pets/IronBall.cs b/Items/Pets/IronBall.cs new file mode 100644 index 0000000000..d30b185c3d --- /dev/null +++ b/Items/Pets/IronBall.cs @@ -0,0 +1,30 @@ +using CalamityMod.Buffs.Pets; +using CalamityMod.Projectiles.Pets; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Pets +{ + public class IronBall : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Pets"; + public override void SetDefaults() + { + Item.DefaultToVanitypet(ModContent.ProjectileType(), ModContent.BuffType()); + Item.UseSound = SoundID.NPCHit4; + Item.value = Item.sellPrice(gold: 2); + Item.rare = ItemRarityID.Orange; + Item.Calamity().donorItem = true; + } + + public override void UseStyle(Player player, Rectangle heldItemFrame) + { + if (player.whoAmI == Main.myPlayer && player.itemTime == 0) + { + player.AddBuff(Item.buffType, 15, true); + } + } + } +} diff --git a/Items/Pets/IronBall.png b/Items/Pets/IronBall.png new file mode 100644 index 0000000000..5987ebb2e1 Binary files /dev/null and b/Items/Pets/IronBall.png differ diff --git a/Items/Placeables/Banners/HorribleHogBanner.cs b/Items/Placeables/Banners/HorribleHogBanner.cs new file mode 100644 index 0000000000..7b588fd920 --- /dev/null +++ b/Items/Placeables/Banners/HorribleHogBanner.cs @@ -0,0 +1,7 @@ +namespace CalamityMod.Items.Placeables.Banners +{ + public class HorribleHogBanner : BaseBanner + { + public override int BannerTileID => 152; + } +} diff --git a/Items/Placeables/Banners/HorribleHogBanner.png b/Items/Placeables/Banners/HorribleHogBanner.png new file mode 100644 index 0000000000..a0d8790fc3 Binary files /dev/null and b/Items/Placeables/Banners/HorribleHogBanner.png differ diff --git a/Items/Placeables/Banners/PiggyBanner.png b/Items/Placeables/Banners/PiggyBanner.png index e6cd993b29..8d755b0036 100644 Binary files a/Items/Placeables/Banners/PiggyBanner.png and b/Items/Placeables/Banners/PiggyBanner.png differ diff --git a/Items/Placeables/Furniture/Paintings/ThankYouPainting.cs b/Items/Placeables/Furniture/Paintings/ThankYouPainting.cs index c6cf5f5a1c..e9d47d8eef 100644 --- a/Items/Placeables/Furniture/Paintings/ThankYouPainting.cs +++ b/Items/Placeables/Furniture/Paintings/ThankYouPainting.cs @@ -79,6 +79,7 @@ namespace CalamityMod.Items.Placeables.Furniture.Paintings "Fluffy", "fryzahh", "Gpscorpion", + "Hugekraken", "jasper", "LordMetarex", "Moonburn", @@ -143,7 +144,6 @@ namespace CalamityMod.Items.Placeables.Furniture.Paintings "Grox the Great", "Heart Plus Up!", "Hectique", - "Hugekraken", "Huggles", "Ian-1KV", "IbanPlay", diff --git a/Items/Placeables/Furniture/PiggyCage.png b/Items/Placeables/Furniture/PiggyCage.png index 80435d34b5..773901f3b5 100644 Binary files a/Items/Placeables/Furniture/PiggyCage.png and b/Items/Placeables/Furniture/PiggyCage.png differ diff --git a/Items/Placeables/VernalSoil.cs b/Items/Placeables/VernalSoil.cs index c97b7bf940..1affd5ae89 100644 --- a/Items/Placeables/VernalSoil.cs +++ b/Items/Placeables/VernalSoil.cs @@ -1,4 +1,5 @@ -using Terraria.ModLoader; +using Terraria.ID; +using Terraria.ModLoader; namespace CalamityMod.Items.Placeables { @@ -11,5 +12,14 @@ namespace CalamityMod.Items.Placeables } public override void SetDefaults() => Item.DefaultToPlaceableTile(ModContent.TileType()); + + public override void AddRecipes() + { + CreateRecipe(25). + AddIngredient(ItemID.MudBlock, 25). + AddIngredient(ItemID.JungleSpores). + AddTile(TileID.Anvils). + Register(); + } } } diff --git a/Items/Potions/Food/DeliciousMeat.cs b/Items/Potions/Food/DeliciousMeat.cs index fcc87fc022..0a1d717b6f 100644 --- a/Items/Potions/Food/DeliciousMeat.cs +++ b/Items/Potions/Food/DeliciousMeat.cs @@ -12,7 +12,6 @@ namespace CalamityMod.Items.Potions.Food public new string LocalizationCategory => "Items.Potions"; public override void SetStaticDefaults() { - ItemID.Sets.ShimmerTransformToItem[Type] = ModContent.ItemType(); Item.ResearchUnlockCount = 5; Main.RegisterItemAnimation(Type, new DrawAnimationVertical(int.MaxValue, 3)); ItemID.Sets.FoodParticleColors[Type] = new Color[2] { diff --git a/Items/Potions/Food/DivineMeat.cs b/Items/Potions/Food/DivineMeat.cs new file mode 100644 index 0000000000..26cd66a626 --- /dev/null +++ b/Items/Potions/Food/DivineMeat.cs @@ -0,0 +1,117 @@ +using System; +using CalamityMod.Effects; +using CalamityMod.Items.Tools; +using CalamityMod.Particles; +using CalamityMod.Systems.Graphic.PixelationSystem; +using CalamityMod.Utilities.Daybreak; +using CalamityMod.Utilities.Daybreak.Buffers; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Potions.Food +{ + public class DivineMeat : ModItem, ILocalizedModType + { + private static Asset FadedStarRing; + private static Asset BloomFlare; + + public new string LocalizationCategory => "Items.Potions"; + + public override void Load() + { + if (!Main.dedServ) + { + BloomFlare = ModContent.Request("CalamityMod/ExtraTextures/BloomFlare"); + FadedStarRing = ModContent.Request("CalamityMod/ExtraTextures/FadedStarRing"); + } + } + + public override void SetStaticDefaults() + { + Item.ResearchUnlockCount = 1; + Main.RegisterItemAnimation(Type, new DrawAnimationVertical(int.MaxValue, 3)); + + ItemID.Sets.IsFood[Type] = true; + ItemID.Sets.FoodParticleColors[Type] = new Color[4] { + new Color(27, 103, 155), + new Color(164, 255, 253), + new Color(250, 219, 127), + new Color(248, 211, 179), + }; + } + + public override void SetDefaults() + { + Item.width = 30; + Item.height = 40; + Item.useAnimation = Item.useTime = 17; + Item.rare = ItemRarityID.Blue; + Item.value = Item.buyPrice(silver: 50); + Item.maxStack = 1; + Item.UseSound = SoundID.Item2; + Item.useStyle = ItemUseStyleID.EatFood; + Item.buffType = BuffID.WellFed2; + Item.buffTime = CalamityUtils.MinutesToFrames(30); + Item.useTurn = true; + Item.consumable = false; + } + + public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) + { + // Spawn some cute sparkles for added effect when dropped in the world. + if (Main.rand.NextBool(45)) + { + int sparkleAmt = Main.rand.Next(1, 3); + for (int i = 0; i < sparkleAmt; i++) + { + Vector2 spawnPosition = Item.Center + Main.rand.NextVector2Circular(Item.width, Item.height); + Color drawColorBlue = Color.Lerp(new Color(44, 166, 247), new Color(123, 197, 247), Main.rand.NextFloat()); + Color drawColorYellow = Color.Lerp(new Color(249, 197, 42), new Color(249, 221, 142), Main.rand.NextFloat()); + Color sparkleColor = Utils.SelectRandom(Main.rand, drawColorBlue, drawColorYellow); + + QuickSparkleParticle sparkle = new(spawnPosition, Vector2.Zero, sparkleColor, Main.rand.NextFloat(0.2f, 0.3f), Main.rand.Next(30, 45)); + GeneralParticleHandler.QueueParticleForNextFrame(sparkle, true); + } + } + + // Additional glowy effects similar to Divine Swine itself. + Main.GetItemDrawFrame(Item.type, out _, out Rectangle itemFrame); + Vector2 origin = itemFrame.Size() * 0.5f; + Vector2 drawPosition = Item.Bottom - Main.screenPosition - new Vector2(0f, origin.Y); + float sineWave = MathF.Sin((float)Main.timeForVisualEffects / 180f) * 0.5f + 0.5f; + Color drawColor = Color.White * MathHelper.Lerp(0.7f, 0f, sineWave); + + spriteBatch.End(out var snapshot); + + using var pixelationLease = RenderTargetPool.Shared.Rent(Main.graphics.GraphicsDevice, Main.screenWidth / 2, Main.screenHeight / 2, RenderTargetDescriptor.Default); + using (pixelationLease.Scope(clearColor: Color.Transparent)) + { + Effect chromaAbberShader = CalamityShaders.ChromaticAbberationShader.Value; + chromaAbberShader.Parameters["abberationStrength"].SetValue(10f); + chromaAbberShader.Parameters["impactPosition"].SetValue(drawPosition); + + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, chromaAbberShader, PixelationManager.PixelationMatrix); + + float starCircleScale = MathHelper.Lerp(0.3f, 0.15f, sineWave); + float starCircleRotation = (float)(Main.timeForVisualEffects / 720f) + whoAmI; + spriteBatch.Draw(FadedStarRing.Value, drawPosition, null, drawColor with { A = 0 }, starCircleRotation, FadedStarRing.Size() * 0.5f, starCircleScale, 0, 0f); + + float bloomFlareScale = MathHelper.Lerp(0.15f, 0.05f, sineWave); + float bloomFlareRotation = (float)(Main.timeForVisualEffects / 540f) + whoAmI; + spriteBatch.Draw(BloomFlare.Value, drawPosition, null, drawColor with { A = 0 }, -bloomFlareRotation, BloomFlare.Size() * 0.5f, bloomFlareScale, 0, 0f); + + spriteBatch.End(); + } + + spriteBatch.Begin(snapshot); + spriteBatch.Draw(pixelationLease.Target, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 2f, 0, 0f); + + return true; + } + } +} diff --git a/Items/Potions/Food/DivineMeat.png b/Items/Potions/Food/DivineMeat.png new file mode 100644 index 0000000000..5e64fa4c49 Binary files /dev/null and b/Items/Potions/Food/DivineMeat.png differ diff --git a/Items/SummonItems/ProfanedCore.cs b/Items/SummonItems/ProfanedCore.cs index c61306273d..0176a2ae0c 100644 --- a/Items/SummonItems/ProfanedCore.cs +++ b/Items/SummonItems/ProfanedCore.cs @@ -38,7 +38,7 @@ namespace CalamityMod.Items.SummonItems { var Prov = CalamityGlobalNPC.holyBoss; bool canPissOffProvi = Prov != -1 && Main.npc[Prov].life >= (Main.npc[Prov].lifeMax * 0.95f) && Main.npc[Prov].Calamity().newAI[3] >= 180f && !Main.npc[Prov].Calamity().CurrentlyEnraged; - return (!NPC.AnyNPCs(ModContent.NPCType()) || canPissOffProvi) && (player.ZoneHallow || player.ZoneUnderworldHeight) && !BossRushEvent.BossRushActive; + return ((!NPC.AnyNPCs(ModContent.NPCType()) && (player.ZoneHallow || player.ZoneUnderworldHeight)) || canPissOffProvi) && !BossRushEvent.BossRushActive; } public override bool? UseItem(Player player) diff --git a/Items/Tools/DisgustingMeat.cs b/Items/Tools/DisgustingMeat.cs index 8a32de7347..5bb7a439c9 100644 --- a/Items/Tools/DisgustingMeat.cs +++ b/Items/Tools/DisgustingMeat.cs @@ -1,6 +1,19 @@ -using CalamityMod.Items.PermanentBoosters; +using System; +using CalamityMod.Effects; +using CalamityMod.Items.PermanentBoosters; using CalamityMod.Items.Potions.Food; +using CalamityMod.Packets; +using CalamityMod.Packets.Worlds; +using CalamityMod.Particles; +using CalamityMod.Systems.Graphic.PixelationSystem; +using CalamityMod.Utilities.Daybreak; +using CalamityMod.Utilities.Daybreak.Buffers; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; @@ -8,90 +21,344 @@ namespace CalamityMod.Items.Tools { public class DisgustingMeat : ModItem, ILocalizedModType { + private static Asset SmallGreyscaleCircle; + public new string LocalizationCategory => "Items.Tools"; + public override void Load() + { + if (!Main.dedServ) + { + SmallGreyscaleCircle = ModContent.Request("CalamityMod/ExtraTextures/SmallGreyscaleCircle"); + } + } + public override void SetStaticDefaults() { - ItemID.Sets.ShimmerTransformToItem[Type] = ModContent.ItemType(); + ItemID.Sets.FoodParticleColors[Type] = new Color[6] { + new Color(61, 69, 41), + new Color(91, 100, 48), + new Color(122, 123, 67), + new Color(128, 69, 46), + new Color(183, 116, 80), + new Color(95, 59, 46), + }; } + public override void SetDefaults() { Item.DefaultToFood(26, 36, 0, 0); Item.value = 0; - Item.UseSound = SoundID.NPCDeath13; - Item.maxStack = 1; - Item.consumable = false; + Item.UseSound = SoundID.NPCHit20; } public override bool AltFunctionUse(Player player) => true; + + public override bool CanUseItem(Player player) + { + DisgustingMeatPlayer modPlayer = player.GetModPlayer(); + return !modPlayer.DoingVomitAnimation; + } + public override bool? UseItem(Player player) { if (player.ItemTimeIsZero) { - var calPlayer = player.Calamity(); + DisgustingMeatPlayer modPlayer = player.GetModPlayer(); if (player.altFunctionUse == 2) - { - TryDropBoosterItem(player, ref calPlayer.rageBoostOne, ModContent.ItemType()); - TryDropBoosterItem(player, ref calPlayer.rageBoostTwo, ModContent.ItemType()); - TryDropBoosterItem(player, ref calPlayer.rageBoostThree, ModContent.ItemType()); - TryDropBoosterItem(player, ref calPlayer.adrenalineBoostOne, ModContent.ItemType()); - TryDropBoosterItem(player, ref calPlayer.adrenalineBoostTwo, ModContent.ItemType()); - TryDropBoosterItem(player, ref calPlayer.adrenalineBoostThree, ModContent.ItemType()); - } - else - { - if (calPlayer.sTangerine || calPlayer.mFruit || calPlayer.tCloudberry || calPlayer.sStrawberry) - { - TryDropBoosterItem(player, ref calPlayer.sTangerine, ModContent.ItemType()); - TryDropBoosterItem(player, ref calPlayer.mFruit, ModContent.ItemType()); - TryDropBoosterItem(player, ref calPlayer.tCloudberry, ModContent.ItemType()); - TryDropBoosterItem(player, ref calPlayer.sStrawberry, ModContent.ItemType()); - } - else - { - for (int i = 0; i < player.ConsumedLifeFruit; i++) - { - int drop = Item.NewItem(player.GetSource_DropAsItem(), player.Hitbox, ItemID.LifeFruit); - Main.item[drop].noGrabDelay = 100; - } - player.ConsumedLifeFruit = 0; - for (int j = 0; j < player.ConsumedLifeCrystals; j++) - { - int drop = Item.NewItem(player.GetSource_DropAsItem(), player.Hitbox, ItemID.LifeCrystal); - Main.item[drop].noGrabDelay = 100; - } - player.ConsumedLifeCrystals = 0; - } + modPlayer.EjectMiscUpgrades = true; + modPlayer.DoingVomitAnimation = true; - if (calPlayer.cShard || calPlayer.eCore || calPlayer.pHeart) - { - TryDropBoosterItem(player, ref calPlayer.cShard, ModContent.ItemType()); - TryDropBoosterItem(player, ref calPlayer.eCore, ModContent.ItemType()); - TryDropBoosterItem(player, ref calPlayer.pHeart, ModContent.ItemType()); - } - else - { - for (int k = 0; k < player.ConsumedManaCrystals; k++) - { - int drop = Item.NewItem(player.GetSource_DropAsItem(), player.Hitbox, ItemID.ManaCrystal); - Main.item[drop].noGrabDelay = 100; - } - player.ConsumedManaCrystals = 0; - } - } return true; } return null; } - private static void TryDropBoosterItem(Player player, ref bool condition, int itemType) + public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI) + { + // Stink particles and flies coming off of the item while it's in the world (yuck!!) ((:sick:)) + if (Main.rand.NextBool(25)) + { + int stinkFumesAmt = Main.rand.Next(1, 3); + for (int i = 0; i < stinkFumesAmt; i++) + { + Vector2 fumesSpawnPosition = Item.Center + Main.rand.NextVector2Circular(Item.width - 8, Item.height - 8); + Color fumesInitialColor = Color.Lerp(Color.OliveDrab, Color.DarkGreen, Main.rand.NextFloat()); + Color fumesFadeColor = Color.Lerp(fumesInitialColor, Color.GhostWhite, Main.rand.NextFloat(0.3f, 0.5f)); + TimedSmokeParticle fumes = new(fumesSpawnPosition, Vector2.Zero, fumesInitialColor, fumesFadeColor, Main.rand.NextFloat(0.15f, 0.2f), Main.rand.NextFloat(0.4f, 0.6f), Main.rand.Next(45, 60), 0.002f * Main.rand.NextBool().ToDirectionInt(), true); + GeneralParticleHandler.QueueParticleForNextFrame(fumes); + } + } + + if (Main.rand.NextBool(150)) + { + Vector2 flyGroupSpawnPosition = Item.Top + new Vector2(Main.rand.NextFloat(-16f, 16f), Main.rand.NextFloat(-8f, 0f)); + int fliesAmt = Main.rand.Next(1, 4); + for (int i = 0; i < fliesAmt; i++) + { + Vector2 flySpawnPosition = flyGroupSpawnPosition + Main.rand.NextVector2Circular(8f, 8f); + float flyScale = Main.rand.NextFloat(0.8f, 1f); + int flyLifetime = Main.rand.Next(360, 480); + FlyParticle fly = new(flySpawnPosition, flyScale, flyLifetime, Item); + GeneralParticleHandler.QueueParticleForNextFrame(fly); + } + } + + // Stink lines. + spriteBatch.End(out var snapshot); + + using var pixelationLease = RenderTargetPool.Shared.Rent(Main.graphics.GraphicsDevice, Main.screenWidth / 2, Main.screenHeight / 2, RenderTargetDescriptor.Default); + using (pixelationLease.Scope(clearColor: Color.Transparent)) + { + Effect sineWaveDistortion = CalamityShaders.SineWaveDistortionShader.Value; + sineWaveDistortion.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly * 6f + whoAmI); + sineWaveDistortion.Parameters["waveAmplitude"].SetValue(0.25f); + sineWaveDistortion.Parameters["waveFrequency"].SetValue(20f); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, sineWaveDistortion, PixelationManager.PixelationMatrix); + + Main.GetItemDrawFrame(Item.type, out _, out Rectangle itemFrame); + Vector2 baseItemDrawOrigin = itemFrame.Size() * 0.5f; + Vector2 stinkLineScale = new(0.125f, 0.6f); + + int stinkLineAmt = 2; + for (int i = 0; i < stinkLineAmt; i++) + { + float riseAndFall = MathHelper.Lerp(4f, -4f, MathF.Sin((float)Main.timeForVisualEffects / 120f + whoAmI + (i * 14)) * 0.5f + 0.5f); + Vector2 stinkLineDrawPosition = Item.Bottom + new Vector2(Utils.Remap(i, 0, stinkLineAmt - 1, -8f, 8f, true) - 4f, -24f + riseAndFall); + spriteBatch.Draw(SmallGreyscaleCircle.Value, stinkLineDrawPosition - Main.screenPosition - new Vector2(0f, baseItemDrawOrigin.Y), null, Color.DarkOliveGreen * 0.82f, 0f, SmallGreyscaleCircle.Size() * 0.5f, stinkLineScale * 0.7f * Item.scale, 0, 0f); + } + + spriteBatch.End(); + } + + spriteBatch.Begin(snapshot); + spriteBatch.Draw(pixelationLease.Target, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 2f, 0, 0f); + } + } + + public class DisgustingMeatPlayer : ModPlayer + { + public static int VomitEjectTime => 75; + + public static int VomitMaxTime => 130; + + public bool DoingVomitAnimation = false; + + public bool EjectMiscUpgrades = false; + + public int VomitTime = 0; + + public override void SyncPlayer(int toWho, int fromWho, bool newPlayer) => DisgustingMeatPlayerSyncPacket.Send(this, toWho, fromWho); + + public override void CopyClientState(ModPlayer targetCopy) + { + DisgustingMeatPlayer clientClone = (DisgustingMeatPlayer)targetCopy; + clientClone.DoingVomitAnimation = DoingVomitAnimation; + clientClone.EjectMiscUpgrades = EjectMiscUpgrades; + clientClone.VomitTime = VomitTime; + clientClone.Player.eyeHelper.CurrentEyeFrame = Player.eyeHelper.CurrentEyeFrame; + } + + public override void SendClientChanges(ModPlayer clientPlayer) + { + DisgustingMeatPlayer clientClone = (DisgustingMeatPlayer)clientPlayer; + if (clientClone.DoingVomitAnimation != DoingVomitAnimation) + DisgustingMeatPlayerSyncPacket.Send(this); + } + + public override void UpdateDead() + { + DoingVomitAnimation = false; + EjectMiscUpgrades = false; + VomitTime = 0; + } + + public override void PostUpdateMiscEffects() + { + if (Player.whoAmI == Main.myPlayer && DoingVomitAnimation) + { + // Eject all necessary items at once. + if (VomitTime == VomitEjectTime) + { + EjectPermanentUpgrades(); + SoundEngine.PlaySound(SoundID.NPCDeath13, Player.Center); + } + + if (VomitTime >= VomitMaxTime) + { + VomitTime = 0; + DoingVomitAnimation = false; + EjectMiscUpgrades = false; + } + + VomitTime++; + } + + // Vomit particles bleeehhhhggghghghgh + if (VomitTime >= VomitEjectTime && VomitTime <= VomitMaxTime) + { + if (Main.rand.NextBool(2)) + { + int 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 spawnPosition = Player.Center + new Vector2(9f * Player.direction, -8f); + Vector2 velocity = Vector2.UnitX.RotatedByRandom(MathHelper.ToRadians(20f) + Player.headRotation) * Main.rand.NextFloat(6f, 8f) * Player.direction; + Dust.NewDust(spawnPosition, 1, 1, dustType, velocity.X, velocity.Y, Scale: Main.rand.NextFloat(0.8f, 1.2f)); + } + } + + if (Main.rand.NextBool(3)) + { + Vector2 spawnPosition = Player.Center - new Vector2(9f * Player.direction, 8f); + Vector2 velocity = Vector2.UnitX.RotatedByRandom(MathHelper.ToRadians(20f) + Player.headRotation) * Main.rand.NextFloat(6f, 8f) * Player.direction; + Color color = Color.Lerp(Color.DarkOliveGreen, Color.Green, Main.rand.NextFloat()); + float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); + + TimedSmokeParticle vomit = new(spawnPosition, velocity, color, color, Main.rand.NextFloat(0.3f, 0.5f), Main.rand.NextFloat(0.8f, 1f), Main.rand.Next(30, 45), rotationSpeed); + GeneralParticleHandler.SpawnParticle(vomit, true); + } + } + } + + public override void ModifyDrawInfo(ref PlayerDrawSet drawInfo) + { + if (DoingVomitAnimation) + { + // Rapidly shift between random angles while vomiting. + float interpolant = Utils.GetLerpValue(0f, VomitEjectTime, VomitTime, true) * Utils.GetLerpValue(VomitMaxTime, VomitMaxTime - 15, VomitTime, true); + float idealRotationDegrees = MathHelper.Lerp(0f, 15f, interpolant); + Player.headRotation = MathHelper.ToRadians(Main.rand.NextFloat(-idealRotationDegrees, idealRotationDegrees)); + + // Close the eyes as well. + Player.eyeHelper.CurrentEyeFrame = Terraria.GameContent.PlayerEyeHelper.EyeFrame.EyeHalfClosed; + if (VomitTime >= VomitEjectTime) + Player.eyeHelper.CurrentEyeFrame = Terraria.GameContent.PlayerEyeHelper.EyeFrame.EyeClosed; + } + } + + private void EjectPermanentUpgrades() + { + var calPlayer = Player.Calamity(); + if (EjectMiscUpgrades) + { + // Rage and Adrenaline upgrades. + TryDropBoosterItem(ref calPlayer.rageBoostOne, ModContent.ItemType()); + TryDropBoosterItem(ref calPlayer.rageBoostTwo, ModContent.ItemType()); + TryDropBoosterItem(ref calPlayer.rageBoostThree, ModContent.ItemType()); + TryDropBoosterItem(ref calPlayer.adrenalineBoostOne, ModContent.ItemType()); + TryDropBoosterItem(ref calPlayer.adrenalineBoostTwo, ModContent.ItemType()); + TryDropBoosterItem(ref calPlayer.adrenalineBoostThree, ModContent.ItemType()); + + // Celestal Onion. + TryDropBoosterItem(ref calPlayer.extraAccessoryML, ModContent.ItemType()); + + // Demon Heart. + TryDropBoosterItem(ref Player.extraAccessory, ItemID.DemonHeart); + + // Shimmer upgrades. + if (Player.usedAegisCrystal || Player.usedAegisFruit || Player.usedArcaneCrystal || Player.usedAmbrosia || Player.usedGalaxyPearl || Player.usedGummyWorm || NPC.peddlersSatchelWasUsed || NPC.combatBookWasUsed || NPC.combatBookVolumeTwoWasUsed) + { + TryDropBoosterItem(ref Player.usedAegisCrystal, ItemID.AegisCrystal); + TryDropBoosterItem(ref Player.usedAegisFruit, ItemID.AegisFruit); + TryDropBoosterItem(ref Player.usedArcaneCrystal, ItemID.ArcaneCrystal); + TryDropBoosterItem(ref Player.usedAmbrosia, ItemID.Ambrosia); + TryDropBoosterItem(ref Player.usedGalaxyPearl, ItemID.GalaxyPearl); + TryDropBoosterItem(ref Player.usedGummyWorm, ItemID.GummyWorm); + + // Sync the world data immediately for these three specifically since they aren't fully player side. + bool hadSatchel = NPC.peddlersSatchelWasUsed; + TryDropBoosterItem(ref NPC.peddlersSatchelWasUsed, ItemID.PeddlersSatchel); + if (hadSatchel && Main.netMode != NetmodeID.SinglePlayer) + DisableNPCUpgradesSyncPacket.Send(0); + + bool hadCombatBook = NPC.combatBookWasUsed; + TryDropBoosterItem(ref NPC.combatBookWasUsed, ItemID.CombatBook); + if (hadCombatBook && Main.netMode != NetmodeID.SinglePlayer) + DisableNPCUpgradesSyncPacket.Send(1); + + bool hadCombatBookTwo = NPC.combatBookVolumeTwoWasUsed; + TryDropBoosterItem(ref NPC.combatBookVolumeTwoWasUsed, ItemID.CombatBookVolumeTwo); + if (hadCombatBookTwo && Main.netMode != NetmodeID.SinglePlayer) + DisableNPCUpgradesSyncPacket.Send(2); + } + + // Artisan Loaf. + TryDropBoosterItem(ref Player.ateArtisanBread, ItemID.ArtisanLoaf); + } + else + { + // Calamity health booster fruits. + if (calPlayer.sTangerine || calPlayer.mFruit || calPlayer.tCloudberry || calPlayer.sStrawberry) + { + TryDropBoosterItem(ref calPlayer.sTangerine, ModContent.ItemType()); + TryDropBoosterItem(ref calPlayer.mFruit, ModContent.ItemType()); + TryDropBoosterItem(ref calPlayer.tCloudberry, ModContent.ItemType()); + TryDropBoosterItem(ref calPlayer.sStrawberry, ModContent.ItemType()); + } + + // Life fruit. + if (Player.ConsumedLifeFruit > 0) + { + for (int i = 0; i < Player.ConsumedLifeFruit; i++) + { + int drop = Player.QuickSpawnItem(Player.GetSource_DropAsItem(), ItemID.LifeFruit); + Main.item[drop].noGrabDelay = 100; + Main.item[drop].velocity = new Vector2(Main.rand.NextFloat(3f, 9f) * Player.direction, Main.rand.NextFloat(-6f, -4f)); + } + Player.ConsumedLifeFruit = 0; + } + + // Heart crystals. + if (Player.ConsumedLifeCrystals > 0) + { + for (int j = 0; j < Player.ConsumedLifeCrystals; j++) + { + int drop = Player.QuickSpawnItem(Player.GetSource_DropAsItem(), ItemID.LifeCrystal); + Main.item[drop].noGrabDelay = 100; + Main.item[drop].velocity = new Vector2(Main.rand.NextFloat(3f, 9f) * Player.direction, Main.rand.NextFloat(-6f, -4f)); + } + Player.ConsumedLifeCrystals = 0; + } + + // Calamity mana upgrades. + if (calPlayer.cShard || calPlayer.eCore || calPlayer.pHeart) + { + TryDropBoosterItem(ref calPlayer.cShard, ModContent.ItemType()); + TryDropBoosterItem(ref calPlayer.eCore, ModContent.ItemType()); + TryDropBoosterItem(ref calPlayer.pHeart, ModContent.ItemType()); + } + + // Mana Crystals. + if (Player.ConsumedManaCrystals > 0) + { + for (int k = 0; k < Player.ConsumedManaCrystals; k++) + { + int drop = Player.QuickSpawnItem(Player.GetSource_DropAsItem(), ItemID.ManaCrystal); + Main.item[drop].noGrabDelay = 100; + Main.item[drop].velocity = new Vector2(Main.rand.NextFloat(3f, 9f) * Player.direction, Main.rand.NextFloat(-6f, -4f)); + } + Player.ConsumedManaCrystals = 0; + } + } + + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendData(MessageID.SyncPlayer, -1, -1, null, Player.whoAmI); + DisgustingMeatPlayerSyncPacket.Send(this); + } + } + + private void TryDropBoosterItem(ref bool condition, int itemType) { if (condition) { condition = false; - int drop = Item.NewItem(player.GetSource_DropAsItem(), player.Hitbox, itemType); + int drop = Player.QuickSpawnItem(Player.GetSource_DropAsItem(), itemType); Main.item[drop].noGrabDelay = 100; + Main.item[drop].velocity = new Vector2(Main.rand.NextFloat(3f, 9f) * Player.direction, Main.rand.NextFloat(-6f, -4f)); } } } diff --git a/Localization/en-US/Mods.CalamityMod.Bestiary.hjson b/Localization/en-US/Mods.CalamityMod.Bestiary.hjson index 6ff98a622a..f65bd18d92 100644 --- a/Localization/en-US/Mods.CalamityMod.Bestiary.hjson +++ b/Localization/en-US/Mods.CalamityMod.Bestiary.hjson @@ -76,9 +76,11 @@ GemCrawler: Relatives to the Ilmeran Sea's prismbacks. The aquatic lizards ended BlightSlime: Slimes that have absorbed some of the blighted godly essence. Riddled with impurity, they are now more putrid flesh than gelatin and, having taken in such an amount that they seem ready to burst. Yet unlike most slimes which have relatively basic minds, these seem to be collecting mass with a purpose. Cryon: Archmage Permafrost went through great pains to not take part in combat himself, instead molding cryons to act as his personal guardians. Noticing the spread of godly essence just as many other creatures have, they have come out of stasis to combat any signs of it so that they may defend their master. CryoSlime: Slimes enchanted by the Archmage, as a host to crystallize the frozen power of the tundra into a magical metal. He cast a spell to hide away most of his creations and research soon after leaving the Godseeker's side, well aware that Yharim may attempt to exploit his previous work. +DivineSwine: A pig ascended by divine blessing. It flies beautifully through the skies, having become a shining beacon to the sun's primordial light. Incredibly rare, legends say that they reward those who give them a bountiful offering of money. Eidolist: Once members of the dragon cult, they now beg the favor of a new master. They are able to live in the abyss indefinitely thanks to their wyrm-like form, allowing them to serve a new purpose. FearlessGoldfishWarrior: Though Goldfish thrive in their ponds and lakes, many take to land during storms to feed on the worms that have also surfaced. There are even accounts of aquatic warriors who carry daggers of shimmering gold, though most consider these tales far too fishy to be credible. Frogfish: Well-camouflaged and prepared to strike at any moment, Frogfish show that the ocean is rarely as serene as it seems. There are few places where one can find true peace here in the heart of what once was an empire unrivaled. +HorribleHog: A hog corrupted by divine blight. It waddles maliciously beneath the scarlet light of the Blood Moon, leading the horde with its hideous bellow. Thankfully, it is not lost, and can be returned to its swine pristinity with the right tools. EarthElemental: After the Brimstone Elemental became dormant, the forgemasters of Azafure used clockwork and crystal to bind the powers of an elemental to a mechanical body. While formidable, it seems the dream of creating a true replacement for an elemental died unfulfilled with Azafure itself. IceClasper: Though their exact origins are an enigma, what is known is that these ethereal beings seek to stamp out any and all sources of warmth that exist in their home. Due to this fact, and taking into account the fossil record, many speculate that ice claspers may have played a vital role in the tundra's creation. ImpiousImmolator: An idol carved in the image of Her, it is lit ablaze with the crafter's lifeforce. After all, what weight does one's life hold when one wishes to see the world wreathed in Her holy flames? @@ -86,7 +88,7 @@ MantisShrimp: Though a variety of answers are given when one asks adventurers ab OverloadedSoldier: A body given life again, overflowing with the souls of warriors that perished during the Crusade who were unable to find peace. Their ravenous hunger for battle has been reignited due to sensing godly essences in the land once more. PerennialSlime: These slimes have seized a small amount of the Goddess of Life's essence. Despite her reimprisonment in the deepest depths of the Abyss, the tendrils of her influence now stretch far into the world beyond. PhantomSpirit: The spirits within the Dungeon only vaguely recall their lives, and yet there is one thing each and all clearly remember, that drives them to chaos: the man responsible for locking them in these cursed walls, and his overwhelming power– power that they have been reminded of, due to one ever growing in strength roaming their halls. -Piggy: These little swines waddle their little legs across these lands with little purpose, but they are happy with just that. Yet, little is known about how their little stomach carries a not-so-little amount of fat and muscle. +Piggy: Little swines that waddle their little legs across these lands with little purpose. They are strangely reactive to their surroundings, particularly to divine influence. Little is known about why, but that has never stopped all kinds of people from keeping them as cute little pets. ProfanedEnergyBody: Those most devout to Her travel the world, being planted into societies and acting as spies and assassins. Among their duties is constructing shrines in Her honor infused with Her divine power, that She might bless pagans blinded by darkness with visions of Her new age of light. Rimehound: These hounds were bred and trained to survive in the tundra's hostile conditions by Yharim's forces, so that they may act as scouts. Most were simply abandoned by their masters out of either necessity or choice, and were resigned to roam forever without purpose. Rotdog: Fast and furious, these hounds prowl the night, hunting prey with their razor sharp teeth. They are similar in nature to the demon eyes, both being spawned from the same vile mire, yet these creatures are tailored made to end those who have proven themselves a threat to it. diff --git a/Localization/en-US/Mods.CalamityMod.Buffs.hjson b/Localization/en-US/Mods.CalamityMod.Buffs.hjson index a72b93cc96..8df247cb7f 100644 --- a/Localization/en-US/Mods.CalamityMod.Buffs.hjson +++ b/Localization/en-US/Mods.CalamityMod.Buffs.hjson @@ -507,6 +507,11 @@ BearBuff: { Description: A guardian angel is following you } +BeldumBuff: { + DisplayName: Iron Ball + Description: Extra shiny! +} + BloodBound: { DisplayName: Blood Bound Description: You must be desperate for company diff --git a/Localization/en-US/Mods.CalamityMod.Items.Fishing.hjson b/Localization/en-US/Mods.CalamityMod.Items.Fishing.hjson index 7516ad942d..15badc04e9 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Fishing.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Fishing.hjson @@ -261,6 +261,20 @@ HydrothermalCrate: { Tooltip: "{$CommonItemTooltip.RightClickToOpen}" } +Spadefish: { + DisplayName: Spadefish + Tooltip: + ''' + Throws a spadefish at enemies + Stealth Strikes cause you to spin the spade before throwing, damaging nearby enemies + [c/aaaaaa:Shift- this item in your inventory to [TOGGLE] breaking tiles] + 'How can a fish be used to dig through the ground? + Some questions are best left unanswered...' + ''' + TextWhileEnabled: disable + TextWhileDisabled: enable +} + StuffedFish: { DisplayName: Stuffed Fish Tooltip: Press to extract [HERBS] herbs and [SEEDS] seeds diff --git a/Localization/en-US/Mods.CalamityMod.Items.Misc.hjson b/Localization/en-US/Mods.CalamityMod.Items.Misc.hjson index dd1317d330..c42e3caa72 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Misc.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Misc.hjson @@ -128,6 +128,11 @@ PiggyItem: { Tooltip: "" } +PiggyGoldItem: { + DisplayName: "{$NPCs.PiggyGold.DisplayName}" + Tooltip: "" +} + PrismaticGuppyBlueItem: { DisplayName: Blue Prismatic Guppy Tooltip: "" diff --git a/Localization/en-US/Mods.CalamityMod.Items.Pets.hjson b/Localization/en-US/Mods.CalamityMod.Items.Pets.hjson index 36ea72fa67..c774e5f087 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Pets.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Pets.hjson @@ -106,6 +106,16 @@ HermitsBoxofOneHundredMedicines: { ''' } +IronBall: { + DisplayName: Iron Ball + Tooltip: + ''' + Summons a living iron ball + the pet to pet it + the pet to have it sit on your shoulder + ''' +} + JoyfulHeart: { DisplayName: Joyful Heart Tooltip: It's oddly warm. Attracts the forbidden one diff --git a/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson b/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson index ad3d764607..5bad76a855 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson @@ -4681,6 +4681,8 @@ GreedPot: { Tooltip: Offer your treasures to the Urn, and your avarice may at last be satiated } +HorribleHogBanner.DisplayName: Horrible Hog Banner + EutrophicSandWall: { DisplayName: Unsafe Eutrophic Sand Wall Tooltip: "" diff --git a/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson b/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson index 45672e252e..9a4185f25d 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Potions.hjson @@ -561,6 +561,16 @@ Cometfruit: { ''' } +DivineMeat: { + DisplayName: Divine Meat + Tooltip: + ''' + {$CommonItemTooltip.MinorStats} + Not consumabale + 'A blessed strip of pork that never seems to be entirely consumed...' + ''' +} + Jackfruit: { DisplayName: Jackfruit Tooltip: "{$CommonItemTooltip.MinorStats}" diff --git a/Localization/en-US/Mods.CalamityMod.Items.Tools.hjson b/Localization/en-US/Mods.CalamityMod.Items.Tools.hjson index c80e1430d7..cf7d1954bf 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Tools.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Tools.hjson @@ -187,7 +187,7 @@ DisgustingMeat: { Tooltip: ''' will remove health and mana upgrades, use with no Calamity upgrades to remove vanilla upgrades - will remove rage and adrenaline upgrades, plus other miscellaneous boosters + will remove Rage and Adrenaline upgrades, plus other miscellaneous boosters such as Demon Heart Removed boosters will be vomited out of you as items ''' } diff --git a/Localization/en-US/Mods.CalamityMod.NPCs.hjson b/Localization/en-US/Mods.CalamityMod.NPCs.hjson index fc92088285..e7f4c3f26e 100644 --- a/Localization/en-US/Mods.CalamityMod.NPCs.hjson +++ b/Localization/en-US/Mods.CalamityMod.NPCs.hjson @@ -172,6 +172,7 @@ CrawlerTopaz.DisplayName: Topaz Crawler CrimulanBlightSlime.DisplayName: Crimulan Blight Slime Cryon.DisplayName: Cryon CryoSlime.DisplayName: Cryo Slime +DivineSwine.DisplayName: Divine Swine EbonianBlightSlime.DisplayName: Ebonian Blight Slime Eidolist.DisplayName: Eidolist FearlessGoldfishWarrior.DisplayName: Fearless Goldfish Warrior @@ -186,6 +187,7 @@ OverloadedSoldier.DisplayName: Overloaded Soldier PerennialSlime.DisplayName: Perennial Slime PhantomSpirit.DisplayName: Phantom Spirit Piggy.DisplayName: Piggy +PiggyGold.DisplayName: Gold Piggy PlanterasFreeTentacle.DisplayName: Plantera's Tentacle ProfanedEnergyBody.DisplayName: Profaned Energy Rimehound.DisplayName: Rimehound @@ -576,3 +578,5 @@ TownPiggy: { 2: Snort! } } + +HorribleHog.DisplayName: Horrible Hog diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Enemy.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Enemy.hjson index 4f2e7b90d0..800b3e48a8 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Enemy.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Enemy.hjson @@ -19,6 +19,14 @@ GammaAcid.DisplayName: Acid GammaBeam.DisplayName: Gamma Ray GammaRayBurst.DisplayName: G-FUEL BEAM GhostBellShock.DisplayName: Electrical Field +HorribleHogChargeHitbox.DisplayName: Horrible Hog +HorribleHogRubble.DisplayName: Rubble +HorribleHogShockwave.DisplayName: Sinister Swine Shockwave +HorribleHogShockwaveSpawner.DisplayName: Horrible Hog Shockwave Spawner +HorribleHogVomitBomb.DisplayName: Barf Bomb +HorribleHogVomitChunk.DisplayName: Horrible Hog's Leftovers +HorribleHogVomitEye.DisplayName: Regurgitated Demon Eye +HorribleHogZombieSpawner.DisplayName: Horrible Hog Zombie Spawner HorsPoisonBlast.DisplayName: Poisonous Spit HorsWaterBlast.DisplayName: Water IceClasperEnemyProjectile.DisplayName: Ice Shard diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Pets.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Pets.hjson index 1add4e568b..fc30ef1be4 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Pets.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Pets.hjson @@ -2,6 +2,7 @@ Akato.DisplayName: Akato Astrophage.DisplayName: Astrophage BabyGhostBell.DisplayName: Baby Ghost Bell Bear.DisplayName: Bear +Beldum.DisplayName: Beldum BendyPet.DisplayName: Dreamfog Dragon BrimlingPet.DisplayName: Brimling ChibiiDoggo.DisplayName: Chibii Devourer diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson index eef5834868..51aca3ab1b 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Rogue.hjson @@ -345,3 +345,5 @@ WulfrumKnifeProj.DisplayName: Wulfrum Knife NanoblackLightspeedCarveSlashVisual.DisplayName: Nanoblack Light-speed Carve Visuals LemonNadeHoldout.DisplayName: Lemon 'nade LemonNadeProjectile.DisplayName: Lemon 'nade +SpadefishHoldout.DisplayName: Spinfish +SpadefishThrown.DisplayName: Spadefish diff --git a/Localization/en-US/Mods.CalamityMod.UI.hjson b/Localization/en-US/Mods.CalamityMod.UI.hjson index 92531f5615..bd0c8302a5 100644 --- a/Localization/en-US/Mods.CalamityMod.UI.hjson +++ b/Localization/en-US/Mods.CalamityMod.UI.hjson @@ -664,6 +664,7 @@ Abyss: Disposing of Silva's remains SulphurSea2: Irradiating one of the oceans Roxcalibur: I wanna rock AuricLandMines: Setting god killing traps +IronBall: Adding a bit more iron // Hold Shift tooltip default HoldShiftTooltipExtensionIndicator: Hold Shift for more HoldShiftTooltipReplacementIndicator: Hold Shift for details diff --git a/NPCs/NormalNPCs/DivineSwine.cs b/NPCs/NormalNPCs/DivineSwine.cs new file mode 100644 index 0000000000..77b6aaecb5 --- /dev/null +++ b/NPCs/NormalNPCs/DivineSwine.cs @@ -0,0 +1,988 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Effects; +using CalamityMod.Enums; +using CalamityMod.Graphics.Metaballs; +using CalamityMod.Items.Ammo; +using CalamityMod.Items.Critters; +using CalamityMod.Items.Placeables.Banners; +using CalamityMod.Items.Potions.Food; +using CalamityMod.Packets; +using CalamityMod.Particles; +using CalamityMod.Systems.Graphic.PixelationSystem; +using CalamityMod.Utilities.Daybreak; +using CalamityMod.Utilities.Daybreak.Buffers; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using ReLogic.Utilities; +using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.GameContent; +using Terraria.GameContent.Bestiary; +using Terraria.GameInput; +using Terraria.ID; +using Terraria.ModLoader; +using static System.Net.Mime.MediaTypeNames; + +namespace CalamityMod.NPCs.NormalNPCs +{ + public class DivineSwine : ModNPC + { + public enum BehaviorState + { + PiggyTransformation = -1, + IdleAndFly, + OfferingAccepted, + OfferingFailed + } + + private static Asset BloomCircle; + private static Asset BloomFlare; + private static Asset ShineFlare; + private static Asset MagicStarCircle; + private static Asset FadedStarRing; + private static Asset DistortionTexture; + private static Asset DivineMeatTexture; + + private static SoundStyle IdleSound = new("CalamityMod/Sounds/Custom/DivineSwine/DivineSwineIdle", 4); + private static SoundStyle CoinFailSound = new("CalamityMod/Sounds/Custom/DivineSwine/DivineSwineCoinFail", 3); + private static SoundStyle CoinPassSound = new("CalamityMod/Sounds/Custom/DivineSwine/DivineSwineCoinPass", 2); + private static SoundStyle SwineSpeakLoopingSound = new("CalamityMod/Sounds/Custom/DivineSwine/DivineSwineNearbyLoop") + { + IsLooped = true, + PauseBehavior = PauseBehavior.PauseWithGame, + MaxInstances = 0, + }; + + public int FrameY; + + public bool ShouldTurnAway; + + public Vector2 SquashVector; + + public Vector2 IdleMovementVector; + + public SlotId SwineSpeakSoundSlot; + + public static float MaxSpeed => 0.38f; + public static float MaxAcceleration => 0.06f; + + public static Color DivineBlue => new(166, 238, 247); + public static Color DivineYellow => new(247, 242, 166); + + 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 IdleMovementTimer => ref NPC.ai[3]; + + public ref float AdditionalBrightness => ref NPC.localAI[0]; + + public ref float GlowingVisualScale => ref NPC.localAI[1]; + + public ref float DivineSwineTintStrength => ref NPC.localAI[2]; + + public override void Load() + { + On_Main.HoverOverNPCs += DivineSwineRightClickInteraction; + On_Main.DrawInfoAccs_AdjustInfoTextColorsForNPC += AdjustLifeformAnalyzerTextColor; + + if (!Main.dedServ) + { + BloomCircle = ModContent.Request("CalamityMod/Particles/BloomCircle"); + BloomFlare = ModContent.Request("CalamityMod/ExtraTextures/BloomFlare"); + ShineFlare = ModContent.Request("CalamityMod/ExtraTextures/ShineFlare"); + MagicStarCircle = ModContent.Request("CalamityMod/ExtraTextures/MagicStarCircle"); + FadedStarRing = ModContent.Request("CalamityMod/ExtraTextures/FadedStarRing"); + DistortionTexture = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/Smudges"); + DivineMeatTexture = ModContent.Request("CalamityMod/Items/Potions/Food/DivineMeat"); + } + } + + public override void SetStaticDefaults() + { + Main.npcFrameCount[Type] = 14; + NPCID.Sets.CountsAsCritter[Type] = true; + NPCID.Sets.CantTakeLunchMoney[Type] = true; + NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 3, Type); + } + + public override void SetDefaults() + { + NPC.damage = 0; + NPC.width = 32; + NPC.height = 34; + NPC.lifeMax = 5; + NPC.defense = 99999999; + NPC.rarity = 5; + NPC.aiStyle = -1; + NPC.knockBackResist = 0.1f; + NPC.HitSound = SoundID.NPCHit1; + NPC.DeathSound = SoundID.NPCDeath1; + NPC.immortal = true; + NPC.noGravity = true; + NPC.Calamity().VulnerableToHeat = true; + NPC.Calamity().VulnerableToCold = true; + NPC.Calamity().VulnerableToSickness = true; + } + + public override void OnSpawn(IEntitySource source) + { + SquashVector = Vector2.One; + } + + public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) + { + bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] + { + BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Sky, + new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.DivineSwine") + }); + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(FrameY); + writer.Write(ShouldTurnAway); + writer.WriteVector2(SquashVector); + writer.WriteVector2(IdleMovementVector); + + for (int i = 0; i < 3; i++) + writer.Write(NPC.localAI[i]); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + FrameY = reader.ReadInt32(); + ShouldTurnAway = reader.ReadBoolean(); + SquashVector = reader.ReadVector2(); + IdleMovementVector = reader.ReadVector2(); + + for (int i = 0; i < 3; i++) + NPC.localAI[i] = reader.ReadSingle(); + } + + public override void AI() + { + switch ((BehaviorState)AIState) + { + case BehaviorState.PiggyTransformation: + MainBehavior_PiggyTransformation(); + break; + + case BehaviorState.IdleAndFly: + MainBehavior_IdleAndFly(); + break; + + case BehaviorState.OfferingAccepted: + MainBehavior_OfferingAccepted(); + break; + + case BehaviorState.OfferingFailed: + MainBehavior_OfferingFailed(); + break; + } + + SoundEffects(); + AmbientParticles(); + AnimateSprite(); + + Lighting.AddLight(NPC.Center, DivineYellow.ToVector3() * NPC.scale * 0.825f); + + if (AIState != (int)BehaviorState.PiggyTransformation && AIState != (int)BehaviorState.OfferingAccepted && AIState != (int)BehaviorState.OfferingFailed) + { + AdditionalBrightness = MathHelper.Lerp(AdditionalBrightness, 0f, 0.05f); + GlowingVisualScale = MathHelper.Lerp(GlowingVisualScale, 1f, 0.05f); + } + + SquashVector = Vector2.Lerp(SquashVector, Vector2.One, 0.05f); + ShouldTurnAway = NPC.ArcCollisionCheck(-0.3f, 0.3f, 0.05f, optionalCollisionCheckOverride: (arcBasePoint, arcPoint) => + { + return !Collision.CanHitLine(arcBasePoint, 1, 1, arcPoint, 1, 1) || Collision.WetCollision(arcPoint, 1, 1); + }); + + NPC.rotation = NPC.velocity.X * 0.12f; + Timer++; + } + + public void MainBehavior_PiggyTransformation() + { + NPC.velocity *= 0f; + NPC.ShowNameOnHover = false; + NPC.dontTakeDamage = true; + + // Shrink the sigil and start tinting white. + float dissolveStrength = CalamityUtils.SineInOutEasing(Utils.GetLerpValue(0f, 240f, Timer, true), 1); + DivineSwineTintStrength = dissolveStrength; + GlowingVisualScale = 1f - dissolveStrength; + AdditionalBrightness = MathHelper.Lerp(0f, 50f, dissolveStrength); + + // Shake the screen slightly while the player is near Divine Swine. + float distanceFromSwine = Main.LocalPlayer.Distance(NPC.Center); + if (distanceFromSwine < 400f) + { + float shakeStrength = Utils.Remap(distanceFromSwine, 400f, 100f, 0f, 3f, true) * Utils.GetLerpValue(0f, 180f, Timer, true); + Main.LocalPlayer.SetScreenshake(shakeStrength); + } + + // Typical glowy particle VFX. + float particleStrengthInterpolant = Utils.GetLerpValue(0f, 180f, Timer, true); + int lightSpawnRate = (int)MathHelper.Lerp(8, 1, particleStrengthInterpolant); + if (Main.rand.NextBool(lightSpawnRate)) + { + int lightAmt = (int)MathHelper.Lerp(1, 6, particleStrengthInterpolant); + for (int i = 0; i < Main.rand.Next(1, lightAmt + 1); i++) + { + float lightSpeed = MathHelper.Lerp(6f, 12f, particleStrengthInterpolant); + float lightScale = MathHelper.Lerp(0.5f, 0.8f, particleStrengthInterpolant) * Main.rand.NextFloat(0.5f, 1f); + + SquishyLightParticle transformLight = new(NPC.Center, Main.rand.NextVector2Circular(lightSpeed, lightSpeed), lightScale, Color.White, Main.rand.Next(30, 45)); + GeneralParticleHandler.SpawnParticle(transformLight, true, Enums.GeneralDrawLayer.BeforeNPCs); + } + } + + if (Main.rand.NextBool(lightSpawnRate + 2)) + { + int sparkleAmt = (int)MathHelper.Lerp(1, 5, particleStrengthInterpolant); + for (int i = 0; i < Main.rand.Next(1, sparkleAmt + 1); i++) + { + float sparkleSpeed = MathHelper.Lerp(8f, 18f, particleStrengthInterpolant); + float sparkleScale = MathHelper.Lerp(0.2f, 0.5f, particleStrengthInterpolant) * Main.rand.NextFloat(0.5f, 1f); + Color drawColorBlue = Color.Lerp(new Color(44, 166, 247), new Color(123, 197, 247), Main.rand.NextFloat()); + Color drawColorYellow = Color.Lerp(new Color(249, 197, 42), new Color(249, 221, 142), Main.rand.NextFloat()); + Color sparkleColor = Utils.SelectRandom(Main.rand, drawColorBlue, drawColorYellow); + + QuickSparkleParticle transformSparkle = new(NPC.Center, Main.rand.NextVector2Circular(sparkleSpeed, sparkleSpeed), sparkleColor, sparkleScale, Main.rand.Next(30, 45)); + GeneralParticleHandler.SpawnParticle(transformSparkle, true, Enums.GeneralDrawLayer.BeforeNPCs); + } + } + + if (Timer >= 180f && Timer % 15f == 0f) + { + float glowRingScale = Utils.Remap(Timer, 180f, 240f, 1.6f, 2.2f, true); + CustomPulse transformRing = new(NPC.Center, Vector2.Zero, Color.White, "CalamityMod/Particles/BloomRing", Vector2.One, 0f, 0f, glowRingScale, 45); + GeneralParticleHandler.SpawnParticle(transformRing, false, Enums.GeneralDrawLayer.AfterNPCs); + } + + if (Timer >= 240f) + { + CustomPulse glowRing = new(NPC.Center, Vector2.Zero, Color.White, "CalamityMod/Particles/BloomRing", Vector2.One, 0f, 0f, 3f, 75); + GeneralParticleHandler.SpawnParticle(glowRing, false, Enums.GeneralDrawLayer.AfterNPCs); + + BloomParticle bloom = new(NPC.Center, Vector2.Zero, Color.White, 0f, 2f, 125); + for (int i = 0; i < 3; i++) + GeneralParticleHandler.SpawnParticle(bloom, false, Enums.GeneralDrawLayer.AfterNPCs); + + for (int i = 0; i < 25; i++) + { + QuickSparkleParticle sparkle = new(NPC.Center, Main.rand.NextVector2Circular(20f, 20f), Color.White, Main.rand.NextFloat(0.6f, 0.8f), Main.rand.Next(45, 60)); + SquishyLightParticle light = new(NPC.Center, Main.rand.NextVector2Circular(10f, 10f), Main.rand.NextFloat(0.6f, 0.8f), Color.White, Main.rand.Next(45, 60)); + GeneralParticleHandler.SpawnParticle(Main.rand.NextBool() ? sparkle : light, true, Enums.GeneralDrawLayer.AfterNPCs); + } + + SoundEngine.PlaySound(SoundID.Item29 with { Volume = 0.1f }, NPC.Center); + SoundEngine.PlaySound(IdleSound, NPC.Center); + if (SoundEngine.TryGetActiveSound(SwineSpeakSoundSlot, out var activeSound)) + activeSound.Stop(); + + if (Main.netMode != NetmodeID.MultiplayerClient) + { + NPC.Transform(ModContent.NPCType()); + NPC.netUpdate = true; + } + } + } + + public void MainBehavior_IdleAndFly() + { + // Flying around. + if (LocalAIState == 0f) + { + if (Timer > 0f && Timer % 120f == 0f && Main.rand.NextBool(6)) + { + Timer = 0f; + LocalAIState = 1f; + NPC.netUpdate = true; + } + + Point tileAhead = (NPC.Center + NPC.velocity * 16f).ToTileCoordinates(); + bool leavingWorldTop = tileAhead.Y <= 40; + bool leavingWorldBottom = tileAhead.Y >= Main.maxTilesY - 40; + bool leavingWorldLeft = tileAhead.X <= 40; + bool leavingWorldRight = tileAhead.X >= Main.maxTilesX - 40; + if (ShouldTurnAway || leavingWorldTop || leavingWorldBottom || leavingWorldLeft || leavingWorldRight) + { + AvoidTileCollision(MaxSpeed + 0.6f, ref leavingWorldTop, ref leavingWorldBottom, ref leavingWorldLeft, ref leavingWorldRight); + IdleMovementTimer = 0f; + } + else + { + if (IdleMovementTimer == 0f) + { + IdleMovementVector = new Vector2(Main.rand.NextFloat(-100f, 101f)); + IdleMovementTimer = Main.rand.Next(240, 360); + NPC.netUpdate = true; + } + + float idealSpeed = MaxSpeed / IdleMovementVector.Length(); + NPC.velocity = Vector2.Lerp(NPC.velocity, IdleMovementVector * idealSpeed, MaxAcceleration); + IdleMovementTimer--; + + if (NPC.velocity.Y < 2.2f) + NPC.velocity.Y += 0.022f; + } + + NPC.spriteDirection = (NPC.velocity.X > 0).ToDirectionInt(); + } + + // Stop and occasionally switch directions. + if (LocalAIState == 1f) + { + if (Timer > 0f && Timer % 120f == 0f && Main.rand.NextBool(6)) + { + Timer = 0f; + LocalAIState = 0f; + NPC.netUpdate = true; + } + + NPC.velocity *= 0.9f; + if (Timer > 0f && Timer % 75f == 0f && Main.rand.NextBool(4)) + NPC.spriteDirection *= -1; + } + } + + public void MainBehavior_OfferingAccepted() + { + // Spawn particles and do a lil animation and whateva + if (Timer <= 210f) + { + float lightSpawnDistance = MathHelper.Lerp(52f, 84f, Timer / 210f); + float glowRingScale = MathHelper.Lerp(0.3f, 0.9f, Timer / 210f); + + int lightAmt = Main.rand.Next(1, 2); + for (int i = 0; i < lightAmt; i++) + { + Vector2 lightSpawnPosition = NPC.Center + Main.rand.NextVector2Unit() * lightSpawnDistance * Main.rand.NextFloat(0.7f, 1f); + Vector2 lightVelocity = (NPC.Center - lightSpawnPosition).SafeNormalize(Vector2.UnitY) * Main.rand.NextFloat(3f, 4f); + float lightScale = Utils.Remap(Timer, 0f, 180f, 0.3f, 0.9f, true); + Color lightColor = Color.Lerp(DivineBlue, DivineYellow, Main.rand.NextFloat()); + + SquishyLightParticle meatLight = new(lightSpawnPosition, lightVelocity, lightScale, lightColor, Main.rand.Next(30, 45)); + GeneralParticleHandler.SpawnParticle(meatLight, true, Enums.GeneralDrawLayer.BeforeNPCs); + } + + int sparkleSpawnRate = (int)Utils.Remap(Timer, 0f, 180f, 45, 5, true); + if (Main.rand.NextBool(sparkleSpawnRate)) + { + int sparkleAmt = Main.rand.Next(1, 3); + for (int i = 0; i < sparkleAmt; i++) + { + Vector2 spawnPosition = NPC.Center + Main.rand.NextVector2Unit() * lightSpawnDistance * Main.rand.NextFloat(0.8f, 1.2f); + Color drawColorBlue = Color.Lerp(new Color(44, 166, 247), new Color(123, 197, 247), Main.rand.NextFloat()); + Color drawColorYellow = Color.Lerp(new Color(249, 197, 42), new Color(249, 221, 142), Main.rand.NextFloat()); + Color sparkleColor = Utils.SelectRandom(Main.rand, drawColorBlue, drawColorYellow); + float sparkleScale = Utils.Remap(Timer, 0f, 180f, 0.2f, 0.8f, true); + + QuickSparkleParticle sparkle = new(spawnPosition, Vector2.Zero, sparkleColor, sparkleScale * Main.rand.NextFloat(0.5f, 1f), Main.rand.Next(20, 30)); + GeneralParticleHandler.SpawnParticle(sparkle, true); + } + } + + if (Timer % 15f == 0f) + { + CustomPulse meatLightRing = new(NPC.Center, Vector2.Zero, DivineBlue, "CalamityMod/Particles/BloomRing", Vector2.One, 0f, glowRingScale, 0f, 25); + GeneralParticleHandler.SpawnParticle(meatLightRing, true, Enums.GeneralDrawLayer.BeforeNPCs); + } + } + + // Divine meat granted + if (Timer == 210f) + { + if (Main.netMode != NetmodeID.MultiplayerClient) + { + int meat = Item.NewItem(NPC.GetSource_GiftOrReward(), NPC.Center, ModContent.ItemType()); + Main.item[meat].velocity = Vector2.UnitY * -3f; + } + + CustomPulse meatLightRing = new(NPC.Center, Vector2.Zero, DivineBlue, "CalamityMod/Particles/BloomRing", Vector2.One, 0f, 0f, 3f, 75); + GeneralParticleHandler.SpawnParticle(meatLightRing, false, Enums.GeneralDrawLayer.AfterNPCs); + + BloomParticle meatBloom = new(NPC.Center, Vector2.Zero, Color.White, 0f, 3f, 125); + for (int i = 0; i < 3; i++) + GeneralParticleHandler.SpawnParticle(meatBloom, false, Enums.GeneralDrawLayer.AfterNPCs); + + for (int i = 0; i < 25; i++) + { + Color drawColorBlue = Color.Lerp(new Color(44, 166, 247), new Color(123, 197, 247), Main.rand.NextFloat()); + Color drawColorYellow = Color.Lerp(new Color(249, 197, 42), new Color(249, 221, 142), Main.rand.NextFloat()); + Color sparkleColor = Utils.SelectRandom(Main.rand, drawColorBlue, drawColorYellow); + QuickSparkleParticle meatSparkle = new(NPC.Center, Vector2.One.RotatedByRandom(MathHelper.TwoPi) * Main.rand.NextFloat(13f, 15f), sparkleColor, Main.rand.NextFloat(0.6f, 0.8f), Main.rand.Next(45, 60)); + + Color lightColor = Color.Lerp(DivineBlue, DivineYellow, Main.rand.NextFloat()); + SquishyLightParticle meatLight = new(NPC.Center, Vector2.One.RotatedByRandom(MathHelper.TwoPi) * Main.rand.NextFloat(3f, 5f), Main.rand.NextFloat(1.4f, 1.8f), lightColor, Main.rand.Next(45, 60)); + + GeneralParticleHandler.SpawnParticle(Main.rand.NextBool() ? meatSparkle : meatLight, true, Enums.GeneralDrawLayer.AfterNPCs); + } + + // Despawn immediately afterwards. + NPC.checkDead(); + NPC.active = false; + } + + GlowingVisualScale = Utils.Remap(Timer, 0f, 210f, 1f, 0f, true); + AdditionalBrightness = Utils.Remap(Timer, 0f, 45f, 1f, 0f, true); + NPC.scale *= 0.96f; + NPC.velocity *= 0.9f; + NPC.ShowNameOnHover = false; + } + + public void MainBehavior_OfferingFailed() + { + if (Timer >= 75f) + { + CustomPulse meatLightRing = new(NPC.Center, Vector2.Zero, Color.White, "CalamityMod/Particles/BloomRing", Vector2.One, 0f, 0f, 2f, 75); + GeneralParticleHandler.SpawnParticle(meatLightRing, false, Enums.GeneralDrawLayer.AfterNPCs); + + BloomParticle meatBloom = new(NPC.Center, Vector2.Zero, Color.White, 0f, 2f, 125); + for (int i = 0; i < 3; i++) + GeneralParticleHandler.SpawnParticle(meatBloom, false, Enums.GeneralDrawLayer.AfterNPCs); + + for (int i = 0; i < 25; i++) + { + QuickSparkleParticle meatSparkle = new(NPC.Center, Main.rand.NextVector2Circular(15f, 15f), Color.White, Main.rand.NextFloat(0.6f, 0.8f), Main.rand.Next(45, 60)); + SquishyLightParticle meatLight = new(NPC.Center, Main.rand.NextVector2Circular(5f, 5f), Main.rand.NextFloat(0.6f, 0.8f), Color.White, Main.rand.Next(45, 60)); + + GeneralParticleHandler.SpawnParticle(Main.rand.NextBool() ? meatSparkle : meatLight, true, Enums.GeneralDrawLayer.AfterNPCs); + } + + SoundEngine.PlaySound(SoundID.Item29 with { Volume = 0.1f }, NPC.Center); + SoundEngine.PlaySound(IdleSound, NPC.Center); + + NPC.checkDead(); + NPC.active = false; + return; + } + + if (Timer <= 45f) + { + DivineSwineTintStrength = MathHelper.Lerp(0f, 1f, CalamityUtils.PolyInOutEasing(Timer / 45f, 2)); + GlowingVisualScale = MathHelper.Lerp(1f, 0f, CalamityUtils.PolyInOutEasing(Timer / 45f, 2)); + } + + int lightAmt = Main.rand.Next(2, 3); + for (int i = 0; i < lightAmt; i++) + { + float lightScale = Main.rand.NextFloat(0.15f, 0.3f); + SquishyLightParticle meatLight = new(NPC.Center, Main.rand.NextVector2Circular(2f, 2f), lightScale, Color.White, Main.rand.Next(30, 45)); + GeneralParticleHandler.SpawnParticle(meatLight, true, Enums.GeneralDrawLayer.BeforeNPCs); + } + + NPC.velocity *= 0.9f; + NPC.ShowNameOnHover = false; + } + + public void TransformIntoPiggy() + { + AIState = (int)BehaviorState.PiggyTransformation; + LocalAIState = 0f; + Timer = 0f; + NPC.netUpdate = true; + } + + public bool TryTransformingIntoPiggy() + { + if (AIState == (int)BehaviorState.PiggyTransformation) + return false; + return true; + } + + public void AvoidTileCollision(float maxSpeed, ref bool leavingWorldTop, ref bool leavingWorldBottom, ref bool leavingWorldLeft, ref bool leavingWorldRight, float turnAwayStrength = 0.125f) + { + float distanceToCollisionLeft = CalamityUtils.DistanceToTileCollisionHit(NPC.Center, NPC.velocity.RotatedBy(MathHelper.PiOver2), 32, ShouldAvoidTile) ?? 10000f; + float distanceToCollisionRight = CalamityUtils.DistanceToTileCollisionHit(NPC.Center, NPC.velocity.RotatedBy(-MathHelper.PiOver2), 32, ShouldAvoidTile) ?? 10000f; + int directionToMove = (distanceToCollisionLeft > distanceToCollisionRight).ToDirectionInt(); + + Vector2 idealVelocity = NPC.velocity.SafeNormalize(Vector2.Zero).RotatedBy(MathHelper.PiOver2 * directionToMove) * (maxSpeed - NPC.velocity.Length()); + if (leavingWorldTop) + idealVelocity = Vector2.UnitY * 2f; + if (leavingWorldBottom) + idealVelocity = Vector2.UnitY * -2f; + if (leavingWorldLeft) + idealVelocity = Vector2.UnitX * 2f; + if (leavingWorldRight) + idealVelocity = Vector2.UnitX * -2f; + + NPC.velocity = Vector2.Lerp(NPC.velocity, idealVelocity, turnAwayStrength); + } + + public void AmbientParticles() + { + if (AIState != (int)BehaviorState.IdleAndFly) + return; + + // Feathers, both falling and non falling ones. + if (Main.rand.NextBool(70)) + { + int featherAmt = Main.rand.Next(1, 3); + for (int i = 0; i < featherAmt; i++) + { + Vector2 spawnPosition = NPC.Center + Main.rand.NextVector2Circular(NPC.width, NPC.height); + Vector2 velocity = Vector2.UnitY * Main.rand.NextFloat(0.25f, 0.75f); + Color featherColor = Color.Lerp(Color.Lerp(new Color(27, 103, 155), new Color(83, 184, 255), Main.rand.NextFloat()), new Color(221, 253, 255), Main.rand.NextFloat(0.4f)); + float scale = Main.rand.NextFloat(0.8f, 1f); + FeatherParticle feather = new(spawnPosition, velocity, featherColor, scale, Main.rand.Next(360, 480), null, 0.8f, true, false, true); + + GeneralDrawLayer featherLayer = Utils.SelectRandom(Main.rand, GeneralDrawLayer.BeforeNPCs, GeneralDrawLayer.AfterNPCs); + GeneralParticleHandler.SpawnParticle(feather, manualDrawLayerOverride: featherLayer); + } + } + + // Small sparkles. + if (Main.rand.NextBool(45)) + { + int sparkleAmt = Main.rand.Next(1, 3); + for (int i = 0; i < sparkleAmt; i++) + { + Vector2 spawnPosition = NPC.Center + Main.rand.NextVector2Unit() * Main.rand.NextFloat(80f, 160f); + Color drawColorBlue = Color.Lerp(new Color(44, 166, 247), new Color(123, 197, 247), Main.rand.NextFloat()); + Color drawColorYellow = Color.Lerp(new Color(249, 197, 42), new Color(249, 221, 142), Main.rand.NextFloat()); + Color sparkleColor = Utils.SelectRandom(Main.rand, drawColorBlue, drawColorYellow); + + QuickSparkleParticle sparkle = new(spawnPosition, Vector2.Zero, sparkleColor, Main.rand.NextFloat(0.2f, 0.3f), Main.rand.Next(30, 45)); + GeneralParticleHandler.SpawnParticle(sparkle, true); + } + } + } + + public void AnimateSprite() + { + if (Timer % 5 == 0f) + { + FrameY++; + if (FrameY >= Main.npcFrameCount[Type] - 1) + FrameY = 0; + + if (FrameY == 5) + NPC.velocity.Y -= (NPC.velocity.X != 0f) ? 2.2f : 0.46f; + } + } + + public void SoundEffects() + { + if (NPC.soundDelay == 0 && Main.rand.NextBool(200) && AIState == (int)BehaviorState.IdleAndFly) + { + SoundEngine.PlaySound(IdleSound, NPC.Center); + SquashVector = Utils.SelectRandom(Main.rand, new Vector2(1.4f, 0.7f), new Vector2(0.7f, 1.4f)); + AdditionalBrightness = Main.rand.NextFloat(0.3f, 0.4f); + NPC.soundDelay = Main.rand.Next(60, 120); + NPC.netUpdate = true; + } + + if (!SoundEngine.TryGetActiveSound(SwineSpeakSoundSlot, out _)) + SwineSpeakSoundSlot = SoundEngine.PlaySound(SwineSpeakLoopingSound, NPC.Center, SoundCallbackMethod); + + // Fade the music depending on the distance between the player and Divine Swine. + float musicVolumeInterpolant = Utils.Remap(NPC.Distance(Main.LocalPlayer.Center), 600f, 100f, 1f, 0.2f, true); + Main.musicFade[Main.curMusic] = musicVolumeInterpolant; + } + + private bool SoundCallbackMethod(ActiveSound soundInstance) + { + soundInstance.Position = NPC.Center; + + float idealPitch = 0f; + bool raisePitchDuringBehavior = AIState == (int)BehaviorState.OfferingAccepted || AIState == (int)BehaviorState.PiggyTransformation; + if (raisePitchDuringBehavior) + idealPitch = 0.4f; + + float volumeInterpolant = Utils.Remap(NPC.Distance(Main.LocalPlayer.Center), 600f, 100f, 0.1f, 0.7f, true) * GlowingVisualScale; + soundInstance.Volume = volumeInterpolant; + soundInstance.Pitch = MathHelper.Lerp(soundInstance.Pitch, idealPitch, 0.075f); + return NPC.active; + } + + public void AcceptOffering(bool accepted) + { + SoundStyle offeringSound = accepted ? CoinPassSound : CoinFailSound; + SoundEngine.PlaySound(offeringSound, NPC.Center); + if (accepted) + SoundEngine.PlaySound(SoundID.Coins, NPC.Center); + + AIState = accepted ? (int)BehaviorState.OfferingAccepted : (int)BehaviorState.OfferingFailed; + Timer = 0f; + LocalAIState = 0f; + NPC.netUpdate = true; + NetMessage.SendData(MessageID.WorldData); + } + + private bool ShouldAvoidTile(Tile tile) => WorldGen.SolidTile(tile) || (tile.HasUnactuatedTile && Main.tileSolidTop[tile.TileType]) || tile.LiquidAmount >= 255; + + public override float SpawnChance(NPCSpawnInfo spawnInfo) + { + if (spawnInfo.Sky && NPC.CountNPCS(Type) < 1) + return 0.001f; + return 0f; + } + + private static void DivineSwineRightClickInteraction(On_Main.orig_HoverOverNPCs orig, Main self, Rectangle mouseRectangle) + { + orig(self, mouseRectangle); + + Player player = Main.LocalPlayer; + foreach (NPC npc in Main.ActiveNPCs) + { + if (npc.type != ModContent.NPCType()) + continue; + + if ((!npc.ShowNameOnHover || !(npc.active & (npc.shimmerTransparency == 0f || npc.CanApplyHunterPotionEffects())))) + continue; + + Main.instance.LoadNPC(npc.whoAmI); + npc.position += npc.netOffset; + + Rectangle npcRectangle = new((int)(npc.Bottom.X - npc.frame.Width * 0.5f), (int)(npc.Bottom.Y - npc.frame.Height), npc.frame.Width, npc.frame.Height); + NPCLoader.ModifyHoverBoundingBox(npc, ref npcRectangle); + + bool hoveringOverHitbox = mouseRectangle.Intersects(npcRectangle); + bool canBeInteractedWith = hoveringOverHitbox || (Main.SmartInteractShowingGenuine && Main.SmartInteractNPC == npc.whoAmI); + if (canBeInteractedWith && npc.ai[1] != 1) + { + player.cursorItemIconEnabled = true; + player.cursorItemIconID = ItemID.PlatinumCoin; + player.cursorItemIconText = ""; + player.noThrow = 2; + + PlayerInput.SetZoom_MouseInWorld(); + if (Main.mouseRight && Main.npcChatRelease) + { + Main.npcChatRelease = false; + if (PlayerInput.UsingGamepad) + player.releaseInventory = false; + + if (player.talkNPC != npc.whoAmI && !player.tileInteractionHappened) + { + bool offeringState = TryOfferingPlatinumToSwine(); + npc.ModNPC().AcceptOffering(offeringState); + if (Main.netMode == NetmodeID.MultiplayerClient) + DivineSwineOfferingPacket.Send(npc.ModNPC(), offeringState); + } + } + npc.position -= npc.netOffset; + } + + // Change the mouse display to just show the name and not the text. + if (hoveringOverHitbox && !player.mouseInterface) + { + self.MouseTextHackZoom(npc.GivenOrTypeName); + Main.mouseText = true; + npc.position -= npc.netOffset; + } + npc.position -= npc.netOffset; + } + } + + private static bool TryOfferingPlatinumToSwine() + { + Player player = Main.LocalPlayer; + bool inPiggyBank = false; + + int inventoryIndexSlot = player.FindItem(ItemID.PlatinumCoin); + int piggyBankIndexSlot = player.FindItem(ItemID.PlatinumCoin, player.bank.item); + if (piggyBankIndexSlot != -1) + inPiggyBank = true; + + if (inventoryIndexSlot == -1 && piggyBankIndexSlot == -1) + return false; + + Item foundItem = inPiggyBank ? player.bank.item[piggyBankIndexSlot] : player.inventory[inventoryIndexSlot]; + if (--foundItem.stack <= 0) + foundItem.TurnToAir(); + + Recipe.FindRecipes(); + return true; + } + + private static void AdjustLifeformAnalyzerTextColor(On_Main.orig_DrawInfoAccs_AdjustInfoTextColorsForNPC orig, Main self, NPC npc, ref Color infoTextColor, ref Color infoTextShadowColor) + { + orig(self, npc, ref infoTextColor, ref infoTextShadowColor); + if (npc.type == ModContent.NPCType()) + { + infoTextColor = Color.Lerp(DivineBlue, DivineYellow, MathF.Sin((float)Main.timeForVisualEffects / 45f) * 0.5f + 0.5f); + infoTextShadowColor = infoTextColor * 0.1f; + infoTextColor.A = Main.mouseTextColor; + infoTextShadowColor.A = Main.mouseTextColor; + } + } + + public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position) => false; + + public override void FindFrame(int frameHeight) + { + if (NPC.IsABestiaryIconDummy) + { + NPC.frameCounter += 1; + if (NPC.frameCounter >= 5) + { + if (NPC.frame.Y / frameHeight >= Main.npcFrameCount[Type] - 1) + NPC.frame.Y = 0; + else + NPC.frame.Y += frameHeight; + + NPC.frameCounter = 0; + } + + Timer++; + if (Timer >= 3600) + Timer = 0f; + + return; + } + + NPC.frame.Y = frameHeight * FrameY; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + if (NPC.IsABestiaryIconDummy) + { + Draw_BestiaryPortrait(spriteBatch); + return false; + } + + spriteBatch.End(out var snapshot); + + Texture2D baseTexture = TextureAssets.Npc[Type].Value; + Vector2 drawPosition = NPC.Center - screenPos + Vector2.UnitY * NPC.gfxOffY; + SpriteEffects spriteEffects = NPC.spriteDirection < 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + + // Draw the cool glowing sigil behind the Divine Swine. + Draw_DivineSigiliGlowyBullshit(spriteBatch, drawPosition); + + // Subtractive backing images. + spriteBatch.SetBlendState(CalamityUtils.SubtractiveBlending); + + int backShadowCount = 3; + for (int i = 0; i < backShadowCount; i++) + { + float rotation = (float)(Main.timeForVisualEffects / MathHelper.Pi * 0.08f) + NPC.whoAmI; + Vector2 backglowDrawPosition = drawPosition + Vector2.UnitX.RotatedBy(i * MathHelper.TwoPi / backShadowCount + rotation) * 6f; + spriteBatch.Draw(baseTexture, backglowDrawPosition, NPC.frame, NPC.GetAlpha(Color.White) * 0.9f, NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale * GlowingVisualScale, spriteEffects, 0f); + } + + int backShadowCount2 = 6; + for (int i = 0; i < backShadowCount2; i++) + { + float rotation = (float)(Main.timeForVisualEffects / MathHelper.Pi * 0.06f) + NPC.whoAmI; + Vector2 backglowDrawPosition = drawPosition + Vector2.UnitX.RotatedBy(i * MathHelper.TwoPi / backShadowCount2 + rotation) * 12f; + spriteBatch.Draw(baseTexture, backglowDrawPosition, NPC.frame, NPC.GetAlpha(Color.White) * 0.7f, NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale * GlowingVisualScale, spriteEffects, 0f); + } + + // Actual Divine Swine. + Effect tintShader = CalamityShaders.BasicTintShader.Value; + tintShader.Parameters["uColor"].SetValue(Color.White.ToVector3()); + tintShader.Parameters["uOpacity"].SetValue(DivineSwineTintStrength); + + spriteBatch.EnterShaderRegion(effect: tintShader); + spriteBatch.Draw(baseTexture, drawPosition, NPC.frame, NPC.GetAlpha(Color.White), NPC.rotation, NPC.frame.Size() * 0.5f, SquashVector * NPC.scale, spriteEffects, 0f); + + spriteBatch.End(); + + // Offering accept visual of the reward item being conjured. + Draw_OfferingAcceptedVisual(spriteBatch, drawPosition); + + spriteBatch.Begin(snapshot); + return false; + } + + public void Draw_DivineSigiliGlowyBullshit(SpriteBatch spriteBatch, Vector2 drawPosition) + { + using var glowingBullshitLease = RenderTargetPool.Shared.Rent(Main.graphics.GraphicsDevice, Main.screenWidth, Main.screenHeight, RenderTargetDescriptor.Default); + using var pixelationLease = RenderTargetPool.Shared.Rent(Main.graphics.GraphicsDevice, Main.screenWidth / 2, Main.screenHeight / 2, RenderTargetDescriptor.Default); + + // Buncha yellow-colored bloom stuff to look like a glowing sun. + using (spriteBatch.Scope()) + { + using (glowingBullshitLease.Scope(clearColor: Color.Transparent)) + { + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Matrix.Identity); + + float bloomFlareScale = MathHelper.Lerp(0.4f, 0.7f, MathF.Sin((float)Main.timeForVisualEffects / 60f) * 0.5f + 0.5f) * GlowingVisualScale; + spriteBatch.Draw(BloomFlare.Value, drawPosition, null, NPC.GetAlpha(DivineYellow with { A = 0 }) * (0.8f + AdditionalBrightness), MathHelper.PiOver4, BloomFlare.Size() * 0.5f, bloomFlareScale, 0, 0f); + + spriteBatch.Draw(ShineFlare.Value, drawPosition, null, NPC.GetAlpha(DivineYellow with { A = 0 }) * (1f + AdditionalBrightness), 0f, MagicStarCircle.Size() * 0.5f, bloomFlareScale, 0, 0f); + spriteBatch.Draw(MagicStarCircle.Value, drawPosition, null, NPC.GetAlpha(DivineYellow with { A = 0 }) * (0.8f + AdditionalBrightness), 0f, MagicStarCircle.Size() * 0.5f, 0.5f * GlowingVisualScale, 0, 0f); + + spriteBatch.End(); + + Effect chromaAbberShader = CalamityShaders.ChromaticAbberationShader.Value; + chromaAbberShader.Parameters["abberationStrength"].SetValue(10f); + chromaAbberShader.Parameters["impactPosition"].SetValue(drawPosition); + + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, chromaAbberShader, Matrix.Identity); + + float starRingScale = MathHelper.Lerp(0.7f, 1f, MathF.Sin((float)Main.timeForVisualEffects / 180f) * 0.5f + 0.5f) * GlowingVisualScale; + spriteBatch.Draw(FadedStarRing.Value, drawPosition, null, NPC.GetAlpha(DivineBlue with { A = 0 }) * (0.7f + AdditionalBrightness), (float)(Main.timeForVisualEffects / 720f) + NPC.whoAmI, FadedStarRing.Size() * 0.5f, starRingScale, 0, 0f); + + spriteBatch.End(); + } + } + + float distortionStrength = 0.034f; + using (spriteBatch.Scope()) + { + using (pixelationLease.Scope(clearColor: Color.Transparent)) + { + Effect distortionShader = CalamityShaders.BasicTextureDistortionShader.Value; + distortionShader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly); + distortionShader.Parameters["noiseScale"].SetValue(1.3f); + distortionShader.Parameters["distortionStrength"].SetValue(distortionStrength); + distortionShader.Parameters["timeOffset"].SetValue(new Vector2(-0.02f, 0.01f)); + + Main.graphics.GraphicsDevice.Textures[1] = DistortionTexture.Value; + Main.graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearWrap; + + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, distortionShader, PixelationManager.PixelationMatrix); + spriteBatch.Draw(glowingBullshitLease.Target, Vector2.Zero, Color.White); + spriteBatch.End(); + } + } + + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + Vector2 targetDrawPosition = Main.ScreenSize.ToVector2() * 0.5f * distortionStrength; + spriteBatch.Draw(pixelationLease.Target, targetDrawPosition, null, Color.White, 0f, Vector2.Zero, 2f, 0, 0f); + } + + public void Draw_OfferingAcceptedVisual(SpriteBatch spriteBatch, Vector2 drawPosition) + { + if (AIState != (int)BehaviorState.OfferingAccepted) + return; + + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + float bloomRotation = (float)(Main.timeForVisualEffects / MathHelper.Pi * 0.03f) + NPC.whoAmI; + float bloomMultiplier = CalamityUtils.PolyOutEasing(Utils.Remap(Timer, 0f, 30f, 0f, 1f, true), 2); + spriteBatch.Draw(BloomFlare.Value, drawPosition, null, NPC.GetAlpha(Color.White with { A = 0 }) * bloomMultiplier, bloomRotation, BloomFlare.Size() * 0.5f, 0.2f * bloomMultiplier, SpriteEffects.None, 0f); + spriteBatch.Draw(BloomFlare.Value, drawPosition, null, NPC.GetAlpha(Color.White with { A = 0 }) * 0.8f * bloomMultiplier, -bloomRotation * 0.5f, BloomFlare.Size() * 0.5f, 0.3f * bloomMultiplier, SpriteEffects.FlipVertically, 0f); + + spriteBatch.SetBlendState(CalamityUtils.SubtractiveBlending); + + int backShadowCount = 6; + float backShadowInterpolant = Utils.GetLerpValue(0f, 150f, Timer, true); + float backShadowDistance = MathHelper.Lerp(36f, 4f, backShadowInterpolant); + for (int i = 0; i < backShadowCount; i++) + { + float rotation = (float)(Main.timeForVisualEffects / MathHelper.Pi * 0.08f) + NPC.whoAmI; + Vector2 backglowDrawPosition = drawPosition + Vector2.UnitX.RotatedBy(i * MathHelper.TwoPi / backShadowCount + rotation) * backShadowDistance; + spriteBatch.Draw(DivineMeatTexture.Value, backglowDrawPosition, DivineMeatTexture.Value.Frame(1, 3), NPC.GetAlpha(Color.White) * backShadowInterpolant, NPC.rotation, DivineMeatTexture.Value.Frame(1, 3).Size() * 0.5f, 1f, 0, 0f); + } + + spriteBatch.SetBlendState(BlendState.AlphaBlend); + + float shineInterpolant = Utils.GetLerpValue(150f, 210f, Timer, true); + float shineScale = CalamityUtils.SineOutEasing(0.8f * shineInterpolant, 0); + spriteBatch.Draw(BloomCircle.Value, drawPosition, null, NPC.GetAlpha(Color.White with { A = 0 }), NPC.rotation, BloomCircle.Size() * 0.5f, shineScale, 0, 0f); + spriteBatch.Draw(ShineFlare.Value, drawPosition, null, NPC.GetAlpha(Color.White with { A = 0 }), NPC.rotation, ShineFlare.Size() * 0.5f, shineScale - 0.4f, 0, 0f); + + spriteBatch.End(); + } + + public void Draw_BestiaryPortrait(SpriteBatch spriteBatch) + { + Texture2D baseTexture = TextureAssets.Npc[Type].Value; + float floatHeight = MathHelper.Lerp(-8f, 8f, MathF.Sin((float)Timer / 150f) * 0.5f + 0.5f); + Vector2 drawPosition = NPC.Center + Vector2.UnitY * floatHeight; + Matrix pixelationMatrix = Matrix.CreateScale(0.5f, 0.5f, 1f); + + RasterizerState previousRasterizerState = spriteBatch.GraphicsDevice.RasterizerState; + Rectangle previousScissorRectangle = spriteBatch.GraphicsDevice.ScissorRectangle; + using (spriteBatch.Scope()) + { + var device = Main.graphics.GraphicsDevice; + using var glowingBullshitLease = RenderTargetPool.Shared.Rent(device, Main.screenWidth, Main.screenHeight, RenderTargetDescriptor.Default); + using var pixelationLease = RenderTargetPool.Shared.Rent(device, Main.screenWidth / 2, Main.screenHeight / 2, RenderTargetDescriptor.Default); + using (glowingBullshitLease.Scope(clearColor: Color.Transparent)) + { + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Matrix.Identity); + + float bloomFlareScale = MathHelper.Lerp(0.15f, 0.3f, MathF.Sin((float)Main.timeForVisualEffects / 60f) * 0.5f + 0.5f); + spriteBatch.Draw(BloomFlare.Value, drawPosition, null, NPC.GetAlpha(DivineYellow) with { A = 0 } * 0.4f, MathHelper.PiOver4, BloomFlare.Size() * 0.5f, bloomFlareScale, 0, 0f); + + spriteBatch.Draw(ShineFlare.Value, drawPosition, null, NPC.GetAlpha(DivineYellow) with { A = 0 } * 0.7f, 0f, MagicStarCircle.Size() * 0.5f, bloomFlareScale, 0, 0f); + spriteBatch.Draw(MagicStarCircle.Value, drawPosition, null, NPC.GetAlpha(DivineYellow) with { A = 0 } * 0.5f, 0f, MagicStarCircle.Size() * 0.5f, 0.25f, 0, 0f); + + Effect chromaAbberShader = CalamityShaders.ChromaticAbberationShader.Value; + chromaAbberShader.Parameters["abberationStrength"].SetValue(10f); + chromaAbberShader.Parameters["impactPosition"].SetValue(drawPosition); + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, chromaAbberShader, Matrix.Identity); + + float starRingScale = MathHelper.Lerp(0.2f, 0.4f, MathF.Sin((float)Main.timeForVisualEffects / 180f) * 0.5f + 0.5f); + spriteBatch.Draw(FadedStarRing.Value, drawPosition, null, NPC.GetAlpha(DivineBlue) with { A = 0 } * 0.8f, (float)(Main.timeForVisualEffects / 720f) + NPC.whoAmI, FadedStarRing.Size() * 0.5f, starRingScale, 0, 0f); + + spriteBatch.End(); + } + + using (pixelationLease.Scope(clearColor: Color.Transparent)) + { + float distortionStrength = 0.0212f; + Effect distortionShader = CalamityShaders.BasicTextureDistortionShader.Value; + distortionShader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly); + distortionShader.Parameters["noiseScale"].SetValue(2.3f); + distortionShader.Parameters["distortionStrength"].SetValue(distortionStrength); + distortionShader.Parameters["timeOffset"].SetValue(new Vector2(-0.02f, 0.01f)); + + Main.graphics.GraphicsDevice.Textures[1] = DistortionTexture.Value; + Main.graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearWrap; + + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, distortionShader, pixelationMatrix); + + Vector2 targetDrawPosition = Main.ScreenSize.ToVector2() * 0.5f * distortionStrength; + spriteBatch.Draw(glowingBullshitLease.Target, targetDrawPosition, Color.White with { A = 0 }); + + spriteBatch.End(); + } + + spriteBatch.GraphicsDevice.RasterizerState = previousRasterizerState; + spriteBatch.GraphicsDevice.ScissorRectangle = previousScissorRectangle; + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, previousRasterizerState, null, Main.UIScaleMatrix); + + spriteBatch.Draw(pixelationLease.Target, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 2f, 0, 0f); + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, CalamityUtils.SubtractiveBlending, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.UIScaleMatrix); + + int backShadowCount = 3; + for (int i = 0; i < backShadowCount; i++) + { + float rotation = (float)(Main.timeForVisualEffects / MathHelper.Pi * 0.08f) + NPC.whoAmI; + Vector2 backglowDrawPosition = drawPosition + Vector2.UnitX.RotatedBy(i * MathHelper.TwoPi / backShadowCount + rotation) * 6f; + spriteBatch.Draw(baseTexture, backglowDrawPosition, NPC.frame, NPC.GetAlpha(Color.White) * 0.9f, NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, 0, 0f); + } + + int backShadowCount2 = 6; + for (int i = 0; i < backShadowCount2; i++) + { + float rotation = (float)(Main.timeForVisualEffects / MathHelper.Pi * 0.06f) + NPC.whoAmI; + Vector2 backglowDrawPosition = drawPosition + Vector2.UnitX.RotatedBy(i * MathHelper.TwoPi / backShadowCount2 + rotation) * 12f; + spriteBatch.Draw(baseTexture, backglowDrawPosition, NPC.frame, NPC.GetAlpha(Color.White) * 0.7f, NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, 0, 0f); + } + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.UIScaleMatrix); + spriteBatch.Draw(baseTexture, drawPosition, NPC.frame, NPC.GetAlpha(Color.White), NPC.rotation, NPC.frame.Size() * 0.5f, NPC.scale, 0, 0f); + + spriteBatch.End(); + } + } + } +} diff --git a/NPCs/NormalNPCs/DivineSwine.png b/NPCs/NormalNPCs/DivineSwine.png new file mode 100644 index 0000000000..102ea49286 Binary files /dev/null and b/NPCs/NormalNPCs/DivineSwine.png differ diff --git a/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Attacks.cs b/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Attacks.cs new file mode 100644 index 0000000000..154d589240 --- /dev/null +++ b/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Attacks.cs @@ -0,0 +1,901 @@ +using System; +using System.Collections.Generic; +using CalamityMod.Graphics.Metaballs; +using CalamityMod.Particles; +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 + { + #region Static Behavior Properties + 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 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 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; + + int frameSpeed = (int)Utils.Remap(MathF.Abs(NPC.velocity.X), 0f, ChasePlayer_MaxSpeed, 9, 3, true); + Animate(MinFrame_Walking, MaxFrame_Walking, frameSpeed, true, dynamicChanges: true); + } + + 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; + } + + Animate(MinFrame_Walking, MaxFrame_Walking, 7, true, dynamicChanges: true); + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + } + + if (Timer >= HogCharge_PreChargeTime) + { + Timer = 0f; + LocalAIState = 1f; + SoundEngine.PlaySound(SoundID.Zombie38, 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) + DoEyeGlintEffect(0.4f); + + FrameY = 20; + } + 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]); + } + } + + int frameSpeed = (int)Utils.Remap(MathF.Abs(NPC.velocity.X), 0f, maxSpeed, 6, 2, true); + Animate(MinFrame_Walking, MaxFrame_Walking, frameSpeed, true, dynamicChanges: true); + + 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; + DoJumpEffects(); + UseBalledSprite = true; + } + + 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) + DoEyeGlintEffect(0.6f); + } + } + + if (Timer == HogCharge_PreDashTime) + { + NPC.noGravity = true; + NPC.velocity = NPC.SafeDirectionTo(LastPlayerPosition) * JumpAndDash_MaxDashSpeed; + + UseBalledSprite = false; + FrameY = JumpFrame; + SetSquashVectors(new Vector2(1.12f, 0.96f)); + SpriteRotation = 0f; + NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); + SoundEngine.PlaySound(SoundID.Zombie38, 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); + + UseBalledSprite = true; + 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); + FrameY = JumpFrame; + } + + if (Timer >= HogCharge_PreDashTime + HogCharge_DashTime) + { + if (NPC.velocity.Y == 0f) + { + UseBalledSprite = false; + FrameY = IdleFrame; + SetSquashVectors(); + LocalAIState = 3f; + Timer = 0f; + NPC.netUpdate = true; + } + + NPC.GravityMultiplier *= 3f; + NPC.velocity.X *= 0.95f; + SpriteRotation = 0f; + UseBalledSprite = true; + } + + 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)); + FrameY = BalledUpFrame; + } + + int frameSpeed = (int)Utils.Remap(MathF.Abs(NPC.velocity.X), 0f, ChasePlayer_MaxSpeed, 8, 2, true); + Animate(MinFrame_Walking, MaxFrame_Walking, frameSpeed, true, dynamicChanges: true); + } + + if (Timer == JumpAndDash_PreJumpTime) + { + NPC.velocity.Y = -JumpAndDash_MaxJumpHeight; + NPC.velocity.X += JumpAndDash_MaxDashSpeed * 0.2f * NPC.direction; + + DoJumpEffects(); + UseBalledSprite = true; + 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) + DoEyeGlintEffect(0.4f); + } + + if (Timer == JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime) + { + NPC.noGravity = true; + NPC.velocity = NPC.SafeDirectionTo(LastPlayerPosition) * JumpAndDash_MaxDashSpeed; + + UseBalledSprite = false; + SpriteRotation = 0f; + NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); + SoundEngine.PlaySound(SoundID.Zombie38, 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); + + UseBalledSprite = true; + 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); + FrameY = JumpFrame; + } + + if (Timer >= JumpAndDash_JumpPreDashTime + JumpAndDash_PreJumpTime + JumpAndDash_DashTime) + { + if (NPC.velocity.Y == 0f) + { + UseBalledSprite = false; + FrameY = IdleFrame; + 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) + { + UseBalledSprite = false; + 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(); + FrameY = IdleFrame; + + 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) + DoEyeGlintEffect(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); + + FrameY = VomitFrame; + SoundEngine.PlaySound(SoundID.DD2_OgreSpit, NPC.Center); + MiscAttackCounter++; + NPC.netUpdate = true; + } + + if (MiscAttackCounter >= JumpAndDash_MaxVomitChunks && NPC.velocity.Y == 0f) + { + FrameY = JumpFrame; + LocalAIState = 2f; + Timer = 0f; + NPC.netUpdate = true; + } + + FrameY = JumpFrame; + } + + 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) + DoEyeGlintEffect(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); + UseBalledSprite = true; + } + + 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); + } + } + } + + if (Timer >= HorribleHoller_RoarTime - 30) + Animate(MinFrame_Roar, MaxFrame_Roar, HorribleHoller_RoarTime / (MaxFrame_Roar + 1), true, MaxFrame_Roar - 1); + } + + if (Timer >= HorribleHoller_RoarTime) + Animate(MinFrame_RoarFinish, MaxFrame_RoarFinish, 4, false); + + 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)); + } + + int frameSpeed = (int)Utils.Remap(MathF.Abs(NPC.velocity.X), 0f, VomitBarrage_MaxSpeed, 9, 3, true); + Animate(MinFrame_Walking, MaxFrame_Walking, frameSpeed, true, dynamicChanges: true); + } + + // 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; + DoJumpEffects(6, 9); + SetSquashVectors(squashVector: new Vector2(0.84f, 1.14f)); + } + + 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; + } + } + + int vomitAmt = Main.rand.Next(12, 19); + for (int i = 0; i < vomitAmt; i++) + { + Vector2 velocity = CalamityUtils.GetProjectilePhysicsFiringVelocity(NPC.Center, target.Center + new Vector2(Main.rand.NextFloat(-16f, 16f), 0f), 0.125f, Main.rand.NextFloat(5f, 8f)); + velocity.X *= Main.rand.NextFloat(1f, 2f); + int dustType = Utils.SelectRandom(Main.rand, DustID.ToxicBubble, DustID.GreenBlood, DustID.Blood); + + Dust.NewDust(NPC.Center, 1, 1, dustType, velocity.X, velocity.Y, Scale: Main.rand.NextFloat(1.8f, 2.4f)); + } + + FrameY = VomitFrame; + 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) + { + FrameY = IdleFrame; + 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]); + } + + // Do a small hiccup/burp after the attack. + int burpTime = VomitBarrage_PostVomitCooldown / 2; + if (Timer == burpTime) + { + SoundEngine.PlaySound(HiccupSound with { Volume = 1.25f }, NPC.Center); + SetSquashVectors(squashVector: new Vector2(0.84f, 1.14f)); + NPC.velocity.Y = -4.25f; + + int burpDustAmt = Main.rand.Next(6, 10); + for (int i = 0; i < burpDustAmt; i++) + { + Vector2 spawnPosition = NPC.Center + new Vector2(8f * NPC.direction, -8f); + Vector2 velocity = Vector2.UnitX.RotatedByRandom(MathHelper.ToRadians(20f) + NPC.rotation) * Main.rand.NextFloat(3f, 5f) * NPC.direction; + Dust.NewDust(spawnPosition, 1, 1, DustID.FartInAJar, velocity.X, velocity.Y, Scale: Main.rand.NextFloat(0.8f, 1.2f)); + } + } + + 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; + if (Timer >= burpTime && Timer <= VomitBarrage_PostVomitCooldown) + targetAngle = (NPC.velocity.Y != 0f) ? (NPC.direction < 0 ? MathHelper.ToRadians(30f) : MathHelper.ToRadians(-30f)) : 0f; + NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.125f); + NPC.direction = (target.Center.X > NPC.Center.X).ToDirectionInt(); + + int frameSpeed = (int)Utils.Remap(MathF.Abs(NPC.velocity.X), 0f, VomitBarrage_MaxSpeed, 9, 3, true); + Animate(MinFrame_Walking, MaxFrame_Walking, frameSpeed, true, dynamicChanges: true); + } + } + + 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..5d8522b4fe --- /dev/null +++ b/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Transitionals.cs @@ -0,0 +1,550 @@ +using System; +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.NormalNPCs.HorribleHog +{ + public partial class HorribleHog + { + #region Static Behavior Properties + public static float EngageDistance => 300f; + public static float Idle_MaxSpeed => 2f; + public static float Idle_MaxAcceleration => 0.125f; + + public static int DigTowardsTarget_PreJumpTime => 30; + public static int DigTowardsTarget_FindSuitablePositionTime => 120; + public static int DigTowardsTraget_MaxDiggingTime => 180; + #endregion + + public void MainBehavior_PiggyTransformation() + { + NPC.ShowNameOnHover = false; + NPC.dontTakeDamage = true; + NPC.damage = 0; + NPC.velocity.X *= 0.9f; + NPC.rotation *= 0.9f; + SpriteRotation *= 0.9f; + + float volumeMultiplier = Utils.GetLerpValue(0f, 45f, Timer, true) * Utils.GetLerpValue(240f, 190f, Timer, true); + DevilsTongueVolumeMultiplier = volumeMultiplier; + + float tintStrength = Utils.GetLerpValue(0f, 45f, Timer, true); + TintStrength = tintStrength; + TintColorTarget = Color.White; + + float shakeStrength = Utils.Remap(Timer, 0f, 180f, 0f, 5f, true); + HorizontalShakeStrength = shakeStrength; + + float distanceFromHog = Main.LocalPlayer.Distance(NPC.Center); + if (distanceFromHog < 400f) + { + float screenshakeStrength = Utils.Remap(distanceFromHog, 400f, 100f, 0f, 3f, true) * Utils.GetLerpValue(0f, 180f, Timer, true); + Main.LocalPlayer.SetScreenshake(screenshakeStrength); + } + + if (Timer >= 45f) + { + float smokeOpacity = 1.2f * Utils.GetLerpValue(45f, 75f, Timer, true); + int smokeAmt = Main.rand.Next(2, 5); + for (int i = 0; i < smokeAmt; i++) + { + Color color = Color.Lerp(new(30, 30, 30), Color.Crimson, Main.rand.NextBool(3) ? Main.rand.NextFloat(0.2f, 0.8f) : Main.rand.Next(2)); + int lifetime = Main.rand.Next(30, 45); + float scale = Main.rand.NextFloat(1.4f, 1.6f); + + HeavySmokeParticle circlingSmoke = new(NPC.Center, Main.rand.NextVector2Circular(16f, 16f), color, lifetime, scale, smokeOpacity, 0.01f, affectedByLight: true); + GeneralParticleHandler.SpawnParticle(circlingSmoke, true, Enums.GeneralDrawLayer.BeforeNPCs); + } + + float particleStrengthInterpolant = Utils.GetLerpValue(0f, 180f, Timer, true); + int lightSpawnRate = (int)MathHelper.Lerp(8, 1, particleStrengthInterpolant); + if (Main.rand.NextBool(lightSpawnRate)) + { + int lightAmt = (int)MathHelper.Lerp(1, 6, particleStrengthInterpolant); + for (int i = 0; i < Main.rand.Next(1, lightAmt + 1); i++) + { + float lightSpeed = MathHelper.Lerp(2f, 4f, particleStrengthInterpolant) * tintStrength; + float lightScale = MathHelper.Lerp(0.5f, 0.8f, particleStrengthInterpolant) * Main.rand.NextFloat(0.5f, 1f) * tintStrength; + + SquishyLightParticle transformLight = new(NPC.Center, Main.rand.NextVector2Circular(lightSpeed, lightSpeed), lightScale, Color.White, Main.rand.Next(30, 45)); + GeneralParticleHandler.SpawnParticle(transformLight, true, Enums.GeneralDrawLayer.AfterNPCs); + } + } + } + + if (Timer % 30 == 0f) + { + float glowRingScale = Utils.Remap(Timer, 0f, 240f, 0.6f, 1.8f, true); + Color glowRingColor = Color.Lerp(Color.Crimson, Color.White, Utils.GetLerpValue(0f, 240f, Timer, true)); + CustomPulse transformRing = new(NPC.Center, Vector2.Zero, glowRingColor, "CalamityMod/Particles/BloomRing", Vector2.One, 0f, 0f, glowRingScale, 45); + GeneralParticleHandler.SpawnParticle(transformRing, false); + } + + if (Timer >= 240f) + { + BloomParticle bloom = new(NPC.Center, Vector2.Zero, Color.White, 0f, 2.4f, 125); + for (int i = 0; i < 3; i++) + GeneralParticleHandler.SpawnParticle(bloom, false, Enums.GeneralDrawLayer.AfterNPCs); + + CustomPulse glowRing = new(NPC.Center, Vector2.Zero, Color.White, "CalamityMod/Particles/BloomRing", Vector2.One, 0f, 0f, 3f, 75); + GeneralParticleHandler.SpawnParticle(glowRing, false, Enums.GeneralDrawLayer.AfterNPCs); + + for (int i = 0; i < 25; i++) + { + QuickSparkleParticle sparkle = new(NPC.Center, Main.rand.NextVector2Circular(16f, 16f), Color.White, Main.rand.NextFloat(0.6f, 0.8f), Main.rand.Next(45, 60)); + SquishyLightParticle light = new(NPC.Center, Main.rand.NextVector2Circular(8f, 8f), Main.rand.NextFloat(0.6f, 0.8f), Color.White, Main.rand.Next(45, 60)); + GeneralParticleHandler.SpawnParticle(Main.rand.NextBool() ? sparkle : light, true, Enums.GeneralDrawLayer.AfterNPCs); + } + + SoundEngine.PlaySound(SoundID.Item29 with { Pitch = 0.25f, Volume = 0.25f }, NPC.Center); + if (SoundEngine.TryGetActiveSound(DevilsTongueSlot, out var activeSound)) + activeSound.Stop(); + + if (Main.netMode != NetmodeID.MultiplayerClient) + { + NPC.Transform(ModContent.NPCType()); + NPC.netUpdate = true; + } + } + + Animate(IdleFrame, IdleFrame, 0, false, dynamicChanges: true); + } + + public void MainBehavior_EngageAnimation(Player target) + { + if (Timer >= 45f) + { + if (Timer == 45f) + { + FrameY = 0; + NPC.frameCounter = 0; + 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); + } + + NPC.frameCounter++; + if (NPC.frameCounter >= 5 && FrameY < MaxFrame_RoarFinish) + { + FrameY++; + NPC.frameCounter = 0; + } + } + + if (Timer >= 120f) + SwitchBehavior(specificAttack: BehaviorState.ChasePlayer); + + NPC.velocity.X *= 0.9f; + NPC.spriteDirection = (target.Center.X > NPC.Center.X).ToDirectionInt(); + } + + public void MainBehavior_LaughAtDeadPlayer() + { + 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 = 60; + 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; + + Animate(MinFrame_Laughing, MaxFrame_Laughing); + + if (Timer >= 130f) + { + BehaviorState nextAttack = NPC.HasValidTarget ? BehaviorState.ChasePlayer : BehaviorState.Idle; + SwitchBehavior(specificAttack: nextAttack); + } + } + + public void MainBehavior_DespawnAnimation() + { + NPC.damage = 0; + + // Wait until Hog hits the ground before running the actual animation. + if (LocalAIState == 0f) + { + if (NPC.velocity.Y == 0f && Timer > 3f) + { + LocalAIState = 1f; + Timer = 0f; + NPC.netUpdate = true; + } + + NPC.GravityMultiplier *= 2f; + } + + if (LocalAIState == 1f) + { + // 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; + 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; + + int frameSpeed = (int)Utils.Remap(MathF.Abs(NPC.velocity.X), 0f, VomitBarrage_MaxSpeed, 120, 8, true); + Animate(MinFrame_Walking, MaxFrame_Walking, frameSpeed, true, dynamicChanges: true); + } + + public void MainBehavior_DeathAnimation() + { + SetSquashVectors(VelocityBasedSquashNStretch); + NPC.rotation = NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi); + SpriteRotation -= (MathHelper.TwoPi / 15f) * NPC.direction; + TintColor = Color.Red; + + if (Timer > 2 && (NPC.collideX || NPC.collideY || Collision.SolidCollision(NPC.position, NPC.width, NPC.height))) + { + if (MiscAttackCounter >= 3) + { + // 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); + Collision.HitTiles(NPC.position, NPC.velocity, NPC.width, NPC.height); + + NPC.life = 0; + NPC.checkDead(); + NPC.HitEffect(); + NPC.netUpdate = true; + } + else + { + SoundEngine.PlaySound(NPC.HitSound, NPC.Center); + TintStrength = 0.75f; + + MiscAttackCounter++; + NPC.velocity.X = NPC.oldVelocity.X * 0.6f; + NPC.velocity.Y = -10f; + + NPC.netUpdate = true; + } + + CalamityUtils.AddScreenshakeAt(NPC.Center, 4f); + } + + UseBalledSprite = true; + NPC.damage = 0; + NPC.GravityMultiplier *= 1.28f; + NPC.dontTakeDamage = true; + } + + 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); + DoEyeGlintEffect(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; + } + + // Animation. + Animate(MinFrame_Walking, MaxFrame_Walking, 5, true, dynamicChanges: true); + NPC.rotation = 0f; + + // 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); + } + + // Spawn ambient mist around itself while it idles. + Rectangle tileWorkSpace = GetTileWorkSpaceForMist(); + int tileWorkSpaceWithWidth = tileWorkSpace.X + tileWorkSpace.Width; + int tileWorkSpaceWithHeight = tileWorkSpace.Y + tileWorkSpace.Height; + for (int x = tileWorkSpace.X; x < tileWorkSpaceWithWidth; x++) + { + for (int y = tileWorkSpace.Y; y < tileWorkSpaceWithHeight; y++) + { + TrySpawningMist(x, y); + } + } + + // Tint slightly black. + TintColor = Color.Black; + TintStrength = 0.6f; + + NPC.chaseable = false; + SearchForTargetEveryFrame = true; + HorizontalShakeStrength = 0f; + } + + 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); + } + + NPC.rotation = 0f; + SoundEngine.PlaySound(SoundID.Item70, NPC.Center); + LocalAIState = 1f; + Timer = 0f; + SetSquashVectors(); + NPC.netUpdate = true; + } + + NPC.rotation = MathHelper.Lerp(NPC.rotation, -MathHelper.PiOver2, 0.175f); + } + } + + // 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); + DoJumpEffects(); + + 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) + { + DoEyeGlintEffect(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(); + } + + int frameSpeed = (int)Utils.Remap(MathF.Abs(NPC.velocity.X), 0f, VomitBarrage_MaxSpeed, 120, 8, true); + Animate(MinFrame_Walking, MaxFrame_Walking, frameSpeed, true, dynamicChanges: true); + + DigTimer = 0f; + SearchForTargetEveryFrame = true; + } + } +} diff --git a/NPCs/NormalNPCs/HorribleHog/HorribleHog.cs b/NPCs/NormalNPCs/HorribleHog/HorribleHog.cs new file mode 100644 index 0000000000..032ce920f8 --- /dev/null +++ b/NPCs/NormalNPCs/HorribleHog/HorribleHog.cs @@ -0,0 +1,1088 @@ +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.Accessories; +using CalamityMod.Items.Materials; +using CalamityMod.Items.Placeables.Banners; +using CalamityMod.Items.Tools; +using CalamityMod.Particles; +using CalamityMod.Projectiles.Enemy; +using CalamityMod.Utilities.Daybreak; +using CalamityMod.Utilities.Daybreak.Buffers; +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. + PiggyTransformation = -5, + EngageAnimation = -4, + LaughAtDeadPlayer = -3, + DespawnAnimation = -2, + DeathAnimation = -1, + Idle, + DigTowardsTarget, + + // Attacks. + ChasePlayer, + HogCharge, + JumpAndDash, + HorribleHoller, + VomitBarrage, + } + + private static Asset HorribleHog_BalledUp; + 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 HiccupSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogHiccup", 2); + 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 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 bool UseBalledSprite; + + public int FrameY; + + public float EyeGlintScale; + + public float AfterimageTrailOpacity; + + public float HorizontalShakeStrength; + + public float DevilsTongueVolumeMultiplier; + + public float TintStrength; + + public float SpriteRotation; + + public Vector2 LastPlayerPosition; + + public Vector2 DiggingEmergeSpot; + + public Vector2 SquashVector; + + public Vector2 SquashVectorTarget; + + public Color TintColor; + + public Color TintColorTarget; + + 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 MaxTimeToStartDigging => 300; + + public static int MinFrame_Roar => 0; + public static int MaxFrame_Roar => 9; + public static int MinFrame_RoarFinish => 10; + public static int MaxFrame_RoarFinish => 13; + public static int MinFrame_Laughing => 8; + public static int MaxFrame_Laughing => 9; + public static int MinFrame_Walking => 15; + public static int MaxFrame_Walking => 23; + public static int JumpFrame => 24; + public static int IdleFrame => 14; + public static int BalledUpFrame => 19; + public static int VomitFrame => 2; + #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 = Utils.Remap(NPC.velocity.Length(), 0f, 20f, 1f, 1.08f); + 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) + { + HorribleHog_BalledUp = ModContent.Request("CalamityMod/NPCs/NormalNPCs/HorribleHog/HorribleHog_BalledUp"); + 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() + { + Main.npcFrameCount[Type] = 25; + NPCID.Sets.TrailCacheLength[Type] = 5; + NPCID.Sets.TrailingMode[Type] = 0; + NPCID.Sets.CantTakeLunchMoney[Type] = true; + + NPCID.Sets.NPCBestiaryDrawModifiers drawModifiers = new(); + drawModifiers.Position.X += 12f; + drawModifiers.PortraitPositionXOverride = 14f; + NPCID.Sets.NPCBestiaryDrawOffset[Type] = drawModifiers; + } + + 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; + + Banner = NPC.type; + BannerItem = ModContent.ItemType(); + + 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[(BehaviorState)reader.ReadByte()] = (int)reader.ReadByte(); + + int attackWeightsLength = reader.ReadByte(); + for (int i = 0; i < attackWeightsLength; i++) + AttackWeights[(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.velocity.X = 6f * -NPC.oldVelocity.X.DirectionalSign(); + NPC.velocity.Y = -10f; + 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 && AIState != (int)BehaviorState.DeathAnimation) + 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.PiggyTransformation: + MainBehavior_PiggyTransformation(); + break; + + case BehaviorState.EngageAnimation: + MainBehavior_EngageAnimation(target); + break; + + case BehaviorState.LaughAtDeadPlayer: + MainBehavior_LaughAtDeadPlayer(); + 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); + TintColor = Color.Lerp(TintColor, TintColorTarget, 0.125f); + TintStrength = MathHelper.Lerp(TintStrength, 0, 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; + UseBalledSprite = false; + + SetSquashVectors(); + KillChargeHitboxProjectile(); + + NPC.netUpdate = true; + } + + public void TransformIntoPiggy() => SwitchBehavior(specificAttack: BehaviorState.PiggyTransformation); + + public bool TryTransformingIntoPiggy() + { + if (AIState == (int)BehaviorState.PiggyTransformation || AIState == (int)BehaviorState.DespawnAnimation || AIState == (int)BehaviorState.DeathAnimation) + return false; + return 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 DoJumpEffects(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); + } + + SoundEngine.PlaySound(JumpSound, NPC.Bottom); + } + } + + private void TrySpawningMist(int x, int y) + { + if (!WorldGen.InWorld(x, y, 10) || Main.tile[x, y] == null) + return; + + Tile tile = Main.tile[x, y]; + if (!tile.HasTile || tile.Slope > 0 || tile.IsHalfBlock || !Main.tileSolid[Main.tile[x, y].TileType]) + return; + + tile = Main.tile[x, y - 1]; + if (tile.LiquidAmount > 0 && tile.Slope <= 0) + { + for (int i = tile.Y() - 1; i > tile.Y() - 50; i--) + { + Tile liquidTile = Main.tile[x, i]; + Tile liquidTileUnderOne = Main.tile[x, i + 1]; + Tile liquidTileUnderTwo = Main.tile[x, i + 2]; + if (liquidTile.LiquidAmount == 0 && !WorldGen.SolidTile(liquidTile) && !WorldGen.SolidTile(liquidTileUnderOne) && !WorldGen.SolidTile(liquidTileUnderTwo)) + { + if (Main.rand.NextBool(240)) + { + SpawnFloorMist(x, i + 1); + if (Main.rand.NextBool(3)) + SpawnFloorMist(x, i + 2); + } + break; + } + } + } + else + { + if (!WorldGen.SolidTile(tile) && Main.rand.NextBool(240)) + { + SpawnFloorMist(x, y + 1); + if (Main.rand.NextBool(3)) + SpawnFloorMist(x, y); + } + } + + } + + private Rectangle GetTileWorkSpaceForMist() + { + Point point = NPC.Center.ToTileCoordinates(); + int width = 30; + int height = 10; + return new Rectangle(point.X - width / 2, point.Y - height / 2, width, height); + } + + private void SpawnFloorMist(int x, int y) + { + int textureIndex = Main.rand.Next(GoreID.AmbientFloorCloud1, GoreID.AmbientFloorCloud4 + 1); + + Vector2 position = new Point(x, y - 1).ToWorldCoordinates(); + Vector2 velocity = Vector2.UnitX * Main.rand.NextFloat(0.2f, 0.4f) * Main.WindForVisuals; + Color mistColor = Color.Lerp(new(30, 30, 30), Color.Crimson, Main.rand.NextBool(3) ? Main.rand.NextFloat(0.2f, 0.8f) : Main.rand.Next(2)); + Color color = Color.Lerp(Lighting.GetColor(new Point(x, y)), mistColor, 0.5f); + + float yOffset = 16f * Main.rand.NextFloat(); + position.Y -= yOffset; + if (yOffset > 4f) + textureIndex = GoreID.AmbientFloorCloud4; + + float scale = Main.rand.NextFloat(0.8f, 1.6f) + Main.rand.NextFloat() * 0.2f; + float baseOpacity = Main.rand.NextFloat(0.8f, 1.2f) * Utils.Remap(Main.LocalPlayer.Distance(NPC.Center), 1200f, 600f, 0.3f, 1f, true); + int lifetime = Main.rand.Next(480, 720); + + GraveyardMistParticle floorMist = new(position, velocity, color, scale, baseOpacity, lifetime, textureIndex); + GeneralParticleHandler.SpawnParticle(floorMist); + } + + 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) + { + //Always drops Disgusting Meat, 50% chance to drop Money Trough, 25%/33% chance to drop Laudanum + npcLoot.Add(ModContent.ItemType()); + npcLoot.Add(ModContent.ItemType(), Main.expertMode ? 3 : 4); + npcLoot.Add(ItemID.MoneyTrough, 2); + + // 10-12 Blood Orbs Post-EoC to match Wandering Eye Fish and Zombie Merman as Blood Moon's faux minibosses. + LeadingConditionRule postEoC = npcLoot.DefineConditionalDropSet(DropHelper.PostEoC()); + postEoC.Add(ModContent.ItemType(), 1, 10, 12); + } + + public override void FindFrame(int frameHeight) + { + if (NPC.IsABestiaryIconDummy) + { + if (FrameY < IdleFrame) + FrameY = IdleFrame; + + NPC.frameCounter++; + if (NPC.frameCounter >= 5) + { + FrameY++; + if (FrameY > MaxFrame_Walking) + FrameY = MinFrame_Walking; + NPC.frameCounter = 0; + } + } + + NPC.frame.Y = FrameY * frameHeight; + } + + public void Animate(int startingFrame, int endingFrame, int frameSpeed = 6, bool loop = true, int? loopStartingFrame = null, bool dynamicChanges = false) + { + bool jumping = dynamicChanges && NPC.velocity.Y != 0f; + bool idling = dynamicChanges && MathF.Abs(NPC.velocity.X) < 0.06f && NPC.velocity.Y == 0f; + if (jumping) + { + FrameY = JumpFrame; + } + else if (idling) + { + FrameY = IdleFrame; + } + else + { + if (FrameY < startingFrame) + FrameY = startingFrame; + + if (NPC.frameCounter % frameSpeed == 0) + { + FrameY++; + if (FrameY > endingFrame) + { + if (loop) + { + if (loopStartingFrame.HasValue) + FrameY = loopStartingFrame.Value; + else + FrameY = startingFrame; + } + else + { + FrameY = endingFrame; + } + } + } + + NPC.frameCounter += 1; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + if (NPC.IsABestiaryIconDummy) + { + Draw_ScaryEvilFuckedUpAura(spriteBatch, screenPos, true); + return true; + } + + Texture2D baseTexture = TextureAssets.Npc[Type].Value; + Texture2D balledTexture = HorribleHog_BalledUp.Value; + SpriteEffects effects = NPC.spriteDirection > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + Vector2 scale = NPC.scale * SquashVector; + + float textureHeight = baseTexture.Height / Main.npcFrameCount[Type]; + float yOffset = scale.Y * textureHeight * 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 && AIState != (int)BehaviorState.PiggyTransformation) + Draw_ScaryEvilFuckedUpAura(spriteBatch, screenPos); + + // Horrible Hog and its afterimage trail. + using (spriteBatch.Scope()) + { + using var lease = RenderTargetPool.Shared.Rent(Main.graphics.GraphicsDevice, Main.screenWidth, Main.screenHeight, RenderTargetDescriptor.Default); + using (lease.Scope(clearColor: Color.Transparent)) + { + if (UseBalledSprite) + { + Rectangle frameRec = balledTexture.Frame(); + Effect rotateSpriteShader = CalamityShaders.RotateSprite.Value; + rotateSpriteShader.Parameters["rotation"].SetValue(SpriteRotation); + rotateSpriteShader.Parameters["spriteDimensions"].SetValue(balledTexture.Size()); + rotateSpriteShader.Parameters["spriteRectangle"].SetValue(new Vector4(frameRec.X, frameRec.Y, frameRec.Width, frameRec.Height)); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, rotateSpriteShader, Matrix.Identity); + + 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(balledTexture, afterimageDrawPosition, null, NPC.GetAlpha(afterimageColor), NPC.rotation, balledTexture.Size() * 0.5f, scale, effects, 0f); + } + } + + spriteBatch.Draw(balledTexture, drawPosition + Main.rand.NextVector2Circular(HorizontalShakeStrength, 0f), frameRec, NPC.GetAlpha(drawColor), NPC.rotation, balledTexture.Size() * 0.5f, scale, effects, 0f); + spriteBatch.End(); + } + else + { + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Matrix.Identity); + + 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(); + } + } + + Effect tintShader = CalamityShaders.BasicTintShader.Value; + tintShader.Parameters["uColor"].SetValue(TintColor.ToVector3()); + tintShader.Parameters["uOpacity"].SetValue(TintStrength); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, tintShader, Main.GameViewMatrix.TransformationMatrix); + spriteBatch.Draw(lease.Target, Vector2.Zero, Color.White); + spriteBatch.End(); + } + + // Eye glint. + if (EyeGlintScale > 0.05f) + { + Vector2 eyeGlintDrawPosition = drawPosition + new Vector2(18f * 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 Draw_ScaryEvilFuckedUpAura(SpriteBatch spriteBatch, Vector2 screenPos, bool bestiary = false) + { + RasterizerState previousRasterizerState = spriteBatch.GraphicsDevice.RasterizerState; + Rectangle previousScissorRectangle = spriteBatch.GraphicsDevice.ScissorRectangle; + + using (spriteBatch.Scope()) + { + Vector2 drawPosition = NPC.Center - screenPos; + float radiusBasedOpacity = Utils.Remap(Main.LocalPlayer.Distance(NPC.Center), 250f, 750f, 1f, 0.15f, true); + float generalEffectOpacity = bestiary ? MathHelper.Lerp(0.5f, 1f, MathF.Sin((float)Main.timeForVisualEffects / 75f) * 0.5f + 0.5f) : radiusBasedOpacity * DevilsTongueVolumeMultiplier; + float generalEffectScale = bestiary ? 0.5f : 1f; + Matrix transformatiomMatrix = bestiary ? Main.UIScaleMatrix : Main.GameViewMatrix.TransformationMatrix; + + 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.145f); + 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(8, 8, 8).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.PointWrap; + + // More accurate pixelation for the bestiary. + if (bestiary) + { + auraShader.Parameters["pixelationFactor"].SetValue(Main.ScreenSize.ToVector2()); + Matrix pixelationMatrix = Matrix.CreateScale(0.5f, 0.5f, 1f); + using var pixelationLease = RenderTargetPool.Shared.Rent(Main.graphics.GraphicsDevice, Main.screenWidth / 2, Main.screenHeight / 2, RenderTargetDescriptor.Default); + using (pixelationLease.Scope(clearColor: Color.Transparent)) + { + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, Main.Rasterizer, auraShader, pixelationMatrix); + + spriteBatch.Draw(VortexTexture.Value, drawPosition, null, Color.White * generalEffectOpacity, 0f, VortexTexture.Size() * 0.5f, 1f * generalEffectScale, 0, 0f); + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, Main.Rasterizer, null, pixelationMatrix); + + float bloomCircleOpacity = MathHelper.Lerp(0.6f, 0.9f, MathF.Sin((float)Main.timeForVisualEffects / 75f + NPC.whoAmI) * 0.5f + 0.5f) * generalEffectOpacity; + spriteBatch.Draw(BloomCircle.Value, drawPosition, null, Color.Crimson with { A = 0 } * bloomCircleOpacity, 0f, BloomCircle.Size() * 0.5f, 1.2f * generalEffectScale, 0, 0f); + + spriteBatch.End(); + } + + spriteBatch.GraphicsDevice.RasterizerState = previousRasterizerState; + spriteBatch.GraphicsDevice.ScissorRectangle = previousScissorRectangle; + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, previousRasterizerState, null, transformatiomMatrix); + + spriteBatch.Draw(pixelationLease.Target, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 2f, 0, 0f); + + spriteBatch.End(); + } + else + { + spriteBatch.GraphicsDevice.RasterizerState = previousRasterizerState; + spriteBatch.GraphicsDevice.ScissorRectangle = previousScissorRectangle; + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, previousRasterizerState, auraShader, transformatiomMatrix); + + spriteBatch.Draw(VortexTexture.Value, drawPosition, null, Color.White * generalEffectOpacity, 0f, VortexTexture.Size() * 0.5f, 1f * generalEffectScale, 0, 0f); + + spriteBatch.End(); + + spriteBatch.GraphicsDevice.RasterizerState = previousRasterizerState; + spriteBatch.GraphicsDevice.ScissorRectangle = previousScissorRectangle; + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, previousRasterizerState, null, transformatiomMatrix); + + float bloomCircleOpacity = MathHelper.Lerp(0.6f, 0.9f, MathF.Sin((float)Main.timeForVisualEffects / 75f + NPC.whoAmI) * 0.5f + 0.5f) * generalEffectOpacity; + spriteBatch.Draw(BloomCircle.Value, drawPosition, null, Color.Crimson with { A = 0 } * bloomCircleOpacity, 0f, BloomCircle.Size() * 0.5f, 1.2f * generalEffectScale, 0, 0f); + + spriteBatch.End(); + } + } + } + + private void SetSquashVectors(Vector2? squashVectorTarget = null, Vector2? squashVector = null) + { + SquashVectorTarget = squashVectorTarget ?? Vector2.One; + if (squashVector.HasValue) + SquashVector = squashVector.Value; + } + + private void DoEyeGlintEffect(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.png b/NPCs/NormalNPCs/HorribleHog/HorribleHog.png new file mode 100644 index 0000000000..5a53ef3357 Binary files /dev/null and b/NPCs/NormalNPCs/HorribleHog/HorribleHog.png differ diff --git a/NPCs/NormalNPCs/HorribleHog/HorribleHog_BalledUp.png b/NPCs/NormalNPCs/HorribleHog/HorribleHog_BalledUp.png new file mode 100644 index 0000000000..32f1ccc66a Binary files /dev/null and b/NPCs/NormalNPCs/HorribleHog/HorribleHog_BalledUp.png differ diff --git a/NPCs/NormalNPCs/Piggy.cs b/NPCs/NormalNPCs/Piggy.cs index d0df599e78..b714ed0655 100644 --- a/NPCs/NormalNPCs/Piggy.cs +++ b/NPCs/NormalNPCs/Piggy.cs @@ -1,56 +1,123 @@ using System; +using System.Security.Policy; +using CalamityMod.Effects; using CalamityMod.Items.Critters; using CalamityMod.Items.Placeables.Banners; +using CalamityMod.NPCs.NormalNPCs.HorribleHog; +using CalamityMod.Particles; +using CalamityMod.Systems.Graphic.PixelationSystem; +using CalamityMod.Utilities.Daybreak; +using CalamityMod.Utilities.Daybreak.Buffers; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using ReLogic.Utilities; using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.GameContent; using Terraria.GameContent.Bestiary; using Terraria.ID; using Terraria.ModLoader; using Terraria.ModLoader.Utilities; + namespace CalamityMod.NPCs.NormalNPCs { public class Piggy : ModNPC { + public enum BehaviorState + { + DivineSwineTransformation = -2, + HorribleHogTransformation = -1, + IdleAndWalk, + Running, + } + + private static Asset SpotlightTexture; + private static Asset BloomCircle; + private static Asset BloomFlare; + private static Asset ShineFlare; + + private static SoundStyle IdleSound_Grunt = new("CalamityMod/Sounds/Custom/Piggy/PiggyIdle_Grunt", 3); + private static SoundStyle IdleSound_SnortYip = new("CalamityMod/Sounds/Custom/Piggy/PiggyIdle_SnortYip", 3); + private static SoundStyle IdleSound_Yip = new("CalamityMod/Sounds/Custom/Piggy/PiggyIdle_Yip", 2); + private static SoundStyle DeathSound = new("CalamityMod/Sounds/NPCKilled/PiggyDeath", 2); + + private static SoundStyle DivineSwine_CoinFailSound = new("CalamityMod/Sounds/Custom/DivineSwine/DivineSwineCoinFail", 3); + private static SoundStyle DivineSwine_SwineSpeakLoopingSound = new("CalamityMod/Sounds/Custom/DivineSwine/DivineSwineNearbyLoop") + { + IsLooped = true, + PauseBehavior = PauseBehavior.PauseWithGame, + MaxInstances = 0, + }; + + private static SoundStyle HorribleHog_CackleSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogCackle"); + private static SoundStyle HorribleHog_IdleSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogIdle", 2) + { + PitchVariance = 0.25f, + }; + private static SoundStyle HorribleHog_DevilsTongueLoopingSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogNearbyLoop") + { + IsLooped = true, + PauseBehavior = PauseBehavior.PauseWithGame, + MaxInstances = 0 + }; + + public Vector2 SquashVector; + + public SlotId NearbySoundSlot; + + public static float MaxAcceleration_Walking => 0.035f; + public static float MaxAcceleration_Running => 0.085f; + public static float MaxSpeed_Walking => 1.2f; + public static float MaxSpeed_Running => 3.6f; + + 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 override void Load() + { + if (Main.dedServ) + return; + + SpotlightTexture = ModContent.Request("Terraria/Images/Extra_60"); + BloomCircle = ModContent.Request("CalamityMod/Particles/BloomCircle"); + BloomFlare = ModContent.Request("CalamityMod/ExtraTextures/BloomFlare"); + ShineFlare = ModContent.Request("CalamityMod/ExtraTextures/ShineFlare"); + } + public override void SetStaticDefaults() { - Main.npcFrameCount[Type] = 5; + Main.npcFrameCount[Type] = 8; Main.npcCatchable[Type] = true; NPCID.Sets.CountsAsCritter[Type] = true; - NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers() - { - SpriteDirection = 1 - }; - NPCID.Sets.NPCBestiaryDrawOffset[Type] = value; NPCID.Sets.CantTakeLunchMoney[Type] = true; - NPCID.Sets.NormalGoldCritterBestiaryPriority.Add(Type); + NPCID.Sets.TakesDamageFromHostilesWithoutBeingFriendly[Type] = true; + NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 1, Type); } public override void SetDefaults() { - NPC.chaseable = false; NPC.damage = 0; - NPC.width = 26; - NPC.height = 26; - NPC.lifeMax = 2000; - NPC.aiStyle = NPCAIStyleID.Passive; - AIType = NPCID.Squirrel; - NPC.knockBackResist = 0.99f; + NPC.width = 42; + NPC.height = 28; + NPC.lifeMax = 300; + NPC.aiStyle = -1; + NPC.knockBackResist = 1.15f; NPC.HitSound = SoundID.NPCHit1; - NPC.DeathSound = SoundID.NPCDeath1; + NPC.DeathSound = DeathSound; + NPC.catchItem = (short)ModContent.ItemType(); Banner = NPC.type; BannerItem = ModContent.ItemType(); - NPC.catchItem = (short)ModContent.ItemType(); + NPC.chaseable = false; NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToCold = true; NPC.Calamity().VulnerableToSickness = true; - } - public override void AI() - { - // Force bestiary unlock - if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) - { - Main.BestiaryTracker.Kills.RegisterKill(NPC); - } + SquashVector = Vector2.One; } public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) @@ -63,13 +130,380 @@ namespace CalamityMod.NPCs.NormalNPCs }); } + public override void AI() + { + // Force bestiary cause this doesn't count as Vanilla's definition of a critter for the Bestiary. + if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) + Main.BestiaryTracker.Kills.SetKillCountDirectly(NPC.GetBestiaryCreditId(), 100); + + if (NPC.direction == 0) + NPC.direction = Utils.SelectRandom(Main.rand, -1, 1); + + switch ((BehaviorState)AIState) + { + case BehaviorState.DivineSwineTransformation: + MainBehavior_DivineSwineTransformation(); + break; + + case BehaviorState.HorribleHogTransformation: + MainBehavior_HorribleHogTransformation(); + break; + + case BehaviorState.IdleAndWalk: + MainBehavior_IdleAndWalk(); + break; + + case BehaviorState.Running: + MainBehavior_Running(); + break; + } + + NPC.StepUpBlocks(); + + SquashVector = Vector2.Lerp(SquashVector, Vector2.One, 0.125f); + Timer++; + } + + public void MainBehavior_DivineSwineTransformation() + { + NPC.velocity.X *= 0.9f; + NPC.rotation = 0f; + if (!SoundEngine.TryGetActiveSound(NearbySoundSlot, out _)) + NearbySoundSlot = SoundEngine.PlaySound(DivineSwine_SwineSpeakLoopingSound, NPC.Center, NearbySoundCallbackMethod); + + float lightSpawnDistance = MathHelper.Lerp(52f, 84f, Timer / 180f); + int lightAmt = Main.rand.Next(1, 2); + for (int i = 0; i < lightAmt; i++) + { + Vector2 lightSpawnPosition = NPC.Center + Main.rand.NextVector2Unit() * lightSpawnDistance * Main.rand.NextFloat(0.7f, 1f); + Vector2 lightVelocity = (NPC.Center - lightSpawnPosition).SafeNormalize(Vector2.UnitY) * Main.rand.NextFloat(3f, 4f); + float lightScale = Utils.Remap(Timer, 0f, 180f, 0.3f, 0.9f, true); + + SquishyLightParticle meatLight = new(lightSpawnPosition, lightVelocity, lightScale, Color.White, Main.rand.Next(30, 45)); + GeneralParticleHandler.SpawnParticle(meatLight, true); + } + + int sparkleSpawnRate = (int)Utils.Remap(Timer, 0f, 180f, 45, 5, true); + if (Main.rand.NextBool(sparkleSpawnRate)) + { + int sparkleAmt = Main.rand.Next(1, 3); + for (int i = 0; i < sparkleAmt; i++) + { + Vector2 spawnPosition = NPC.Center + Main.rand.NextVector2Unit() * lightSpawnDistance * Main.rand.NextFloat(0.8f, 1.2f); + Color drawColorBlue = Color.Lerp(new Color(44, 166, 247), new Color(123, 197, 247), Main.rand.NextFloat()); + Color drawColorYellow = Color.Lerp(new Color(249, 197, 42), new Color(249, 221, 142), Main.rand.NextFloat()); + Color sparkleColor = Utils.SelectRandom(Main.rand, drawColorBlue, drawColorYellow); + float sparkleScale = Utils.Remap(Timer, 0f, 180f, 0.2f, 0.8f, true); + + QuickSparkleParticle sparkle = new(spawnPosition, Vector2.Zero, sparkleColor, sparkleScale * Main.rand.NextFloat(0.5f, 1f), Main.rand.Next(20, 30)); + GeneralParticleHandler.SpawnParticle(sparkle, true); + } + } + + if (Timer >= 30f && Main.rand.NextBool(10)) + { + Vector2 spawnPosition = NPC.Center + new Vector2(Main.rand.NextFloat(-16f, 16f), Main.rand.NextFloat(-144f, -134f)); + Vector2 velocity = Vector2.UnitY * Main.rand.NextFloat(0.25f, 0.75f); + Color featherColor = Color.Lerp(Color.Lerp(new Color(27, 103, 155), new Color(83, 184, 255), Main.rand.NextFloat()), new Color(221, 253, 255), Main.rand.NextFloat(0.4f)); + float scale = Main.rand.NextFloat(0.8f, 1f); + + FeatherParticle feather = new(spawnPosition, velocity, featherColor, scale, Main.rand.Next(75, 90), null, 0.9f, false, false, true); + GeneralParticleHandler.SpawnParticle(feather, manualDrawLayerOverride: Enums.GeneralDrawLayer.BeforeNPCs); + } + + if (Timer >= 180f && Main.netMode != NetmodeID.MultiplayerClient) + { + CustomPulse lightRing = new(NPC.Center, Vector2.Zero, Color.White, "CalamityMod/Particles/BloomRing", Vector2.One, 0f, 0f, 2f, 75); + GeneralParticleHandler.SpawnParticle(lightRing); + + BloomParticle bloom = new(NPC.Center, Vector2.Zero, Color.White, 0f, 2f, 125); + for (int i = 0; i < 3; i++) + GeneralParticleHandler.SpawnParticle(bloom); + + for (int i = 0; i < 25; i++) + { + QuickSparkleParticle sparkle = new(NPC.Center, Main.rand.NextVector2Circular(15f, 15f), Color.White, Main.rand.NextFloat(0.6f, 0.8f), Main.rand.Next(45, 60)); + SquishyLightParticle light = new(NPC.Center, Main.rand.NextVector2Circular(5f, 5f), Main.rand.NextFloat(0.6f, 0.8f), Color.White, Main.rand.Next(45, 60)); + GeneralParticleHandler.SpawnParticle(Main.rand.NextBool() ? sparkle : light, true); + } + + SoundEngine.PlaySound(DivineSwine_CoinFailSound, NPC.Center); + if (SoundEngine.TryGetActiveSound(NearbySoundSlot, out var activeSound)) + activeSound.Stop(); + + NPC.Transform(ModContent.NPCType()); + NPC.netUpdate = true; + } + } + + public void MainBehavior_HorribleHogTransformation() + { + NPC.velocity.X *= 0.9f; + NPC.rotation = 0f; + if (!SoundEngine.TryGetActiveSound(NearbySoundSlot, out _)) + NearbySoundSlot = SoundEngine.PlaySound(HorribleHog_DevilsTongueLoopingSound, NPC.Center, NearbySoundCallbackMethod); + + float smokeOpacity = Utils.GetLerpValue(0f, 45f, Timer, true); + int circlingSmokeAmount = Main.rand.Next(2, 5); + for (int i = 0; i < circlingSmokeAmount; i++) + { + Vector2 spawnDistanceVariance = Main.rand.NextVector2Circular(50f, 50f); + Vector2 spawnPosition = NPC.Center + spawnDistanceVariance; + Vector2 velocity = spawnDistanceVariance.SafeNormalize(Vector2.Zero).RotatedBy(MathHelper.PiOver2) * Main.rand.NextFloat(2f, 5f); + Color color = Color.Lerp(new(30, 30, 30), Color.Crimson, Main.rand.Next(2)); + int lifetime = Main.rand.Next(30, 45); + float scale = Main.rand.NextFloat(1f, 1.2f); + + HeavySmokeParticle circlingSmoke = new(spawnPosition, velocity, color, lifetime, scale, smokeOpacity, 0.01f, affectedByLight: true); + GeneralParticleHandler.SpawnParticle(circlingSmoke, true); + } + + if (Timer >= 180f) + { + SoundEngine.PlaySound(HorribleHog_CackleSound, NPC.Center); + if (SoundEngine.TryGetActiveSound(NearbySoundSlot, out var activeSound)) + activeSound.Stop(); + + if (Main.netMode != NetmodeID.MultiplayerClient) + { + NPC.Transform(ModContent.NPCType()); + NPC.netUpdate = true; + } + } + } + + public void MainBehavior_IdleAndWalk() + { + // Idling. + if (LocalAIState == 0f) + { + if (Timer > 0f) + { + if (Timer % 60f == 0f && Main.rand.NextBool(6)) + { + Timer = 0f; + LocalAIState = 1f; + NPC.netUpdate = true; + } + + if (Timer % 60f == 0f && Main.rand.NextBool(12)) + { + AIState = (int)BehaviorState.Running; + Timer = 0f; + LocalAIState = 0f; + NPC.netUpdate = true; + } + } + + // Stop moving and occasionally switch directions. + if (NPC.velocity.Y == 0f) + { + NPC.velocity.X *= 0.8f; + if (Timer % 15f == 0f && Main.rand.NextBool(12)) + NPC.direction *= -1; + } + } + + // Walking. + if (LocalAIState == 1f) + { + if (Timer > 120f && Timer % 60f == 0f && Main.rand.NextBool(5)) + { + Timer = 0f; + LocalAIState = 0f; + NPC.netUpdate = true; + } + + if (MathF.Abs(NPC.velocity.X) < MaxSpeed_Walking) + NPC.velocity.X += MaxAcceleration_Walking * NPC.direction; + + if (NPC.collideX && NPC.velocity.Y == 0f) + NPC.velocity.Y -= 6f; + } + + // Sound effects. + if (NPC.soundDelay == 0 && Main.rand.NextBool(200)) + { + // Small chance to do a cute lil hop as well. + if (Main.rand.NextBool(5)) + { + NPC.velocity.Y -= Main.rand.NextFloat(2f, 4f); + SquashVector = new Vector2(0.7f, 1.3f); + NPC.netUpdate = true; + } + + var chosenSoundStyle = Utils.SelectRandom(Main.rand, IdleSound_Grunt, IdleSound_SnortYip, IdleSound_Yip); + SoundEngine.PlaySound(chosenSoundStyle, NPC.Center); + NPC.soundDelay = Main.rand.Next(60, 120); + } + + NPC.spriteDirection = NPC.direction; + float targetAngle = (NPC.velocity.Y != 0f) ? NPC.velocity.X * 0.085f * (NPC.velocity.Y < 0).ToDirectionInt() : 0f; + NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.075f); + } + + public void MainBehavior_Running() + { + // Run in a random direction until collision with a wall is made. + if (LocalAIState == 0f) + { + if (MathF.Abs(NPC.velocity.X) < MaxSpeed_Running) + NPC.velocity.X += MaxAcceleration_Running * NPC.direction; + NPC.spriteDirection = NPC.direction; + + // Spawn particles when running at max speed. + if (NPC.velocity.Y == 0f && MathF.Abs(NPC.velocity.X) >= MaxSpeed_Running) + { + int dustType = NPC.type == ModContent.NPCType() ? DustID.Enchanted_Gold : DustID.Cloud; + Vector2 dustPosition = new(NPC.Bottom.X + Main.rand.NextFloat(-NPC.width * 0.5f, NPC.width * 0.5f), NPC.Bottom.Y); + Dust.NewDustPerfect(dustPosition, dustType, new Vector2(NPC.velocity.X * 0.2f, Main.rand.NextFloat(-0.3f, 0.3f)), 0, default, Main.rand.NextFloat(1f, 1.2f)); + if (Timer % 7 == 0f) + SoundEngine.PlaySound(SoundID.Run with { Pitch = 0.3f, Volume = 0.7f, Identifier = "Piggy Run" }, NPC.Center); + } + + if (HoleBelow() && NPC.velocity.Y == 0f) + NPC.velocity.Y -= 6f; + + if (NPC.collideX) + { + SoundEngine.PlaySound(SoundID.Dig with { Volume = 0.7f }, NPC.Center); + SoundEngine.PlaySound(IdleSound_Grunt with { Volume = 1.2f }, NPC.Center); + SquashVector = new Vector2(0.6f, 1f); + + NPC.velocity.X = NPC.oldVelocity.X * -0.86f; + NPC.velocity.Y -= 3f; + Timer = 0f; + LocalAIState = 1f; + NPC.netUpdate = true; + } + // Stop running and go back to idling if 5 seconds has passed without collision. + else if (Timer >= 300f) + { + AIState = (int)BehaviorState.IdleAndWalk; + LocalAIState = Main.rand.Next(1); + Timer = 0f; + NPC.netUpdate = true; + } + + float idealRotation = (NPC.velocity.Y != 0f) ? NPC.velocity.ToRotation() + (NPC.direction > 0 ? 0f : -MathHelper.Pi) : 0f; + NPC.rotation = idealRotation; + } + + if (LocalAIState == 1f) + { + if (NPC.velocity.Y == 0f) + { + NPC.velocity.X *= 0.9f; + if (MathF.Abs(NPC.velocity.X) >= 0.08f && MathF.Abs(NPC.velocity.X) < 0.09f) + { + NPC.velocity.Y = -4f; + var soundStyle = Utils.SelectRandom(Main.rand, IdleSound_SnortYip, IdleSound_Yip); + SoundEngine.PlaySound(soundStyle.WithPitchOffset(0.35f), NPC.Center); + } + } + + if (MathF.Abs(NPC.velocity.X) > 0.09f) + NPC.rotation += NPC.velocity.X * 0.075f; + else + NPC.rotation = NPC.rotation.AngleLerp(0f, 0.125f); + + if (Timer >= 120f) + { + AIState = (int)BehaviorState.IdleAndWalk; + LocalAIState = Main.rand.Next(1); + Timer = 0f; + NPC.netUpdate = true; + } + } + } + + public void TransformIntoVariant(int type) + { + if (type == ModContent.NPCType()) + AIState = (int)BehaviorState.DivineSwineTransformation; + else if (type == ModContent.NPCType()) + AIState = (int)BehaviorState.HorribleHogTransformation; + else + AIState = (int)BehaviorState.IdleAndWalk; + + LocalAIState = 0f; + Timer = 0f; + NPC.netUpdate = true; + } + + public bool TryTransformingIntoVariant() + { + if (AIState == (int)BehaviorState.DivineSwineTransformation || AIState == (int)BehaviorState.HorribleHogTransformation) + return false; + return true; + } + + private bool HoleBelow() + { + 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 bool NearbySoundCallbackMethod(ActiveSound soundInstance) + { + float interpolant = Utils.GetLerpValue(0f, 75f, Timer, true) * Utils.GetLerpValue(180f, 130f, Timer, true); + soundInstance.Position = NPC.Center; + soundInstance.Volume = interpolant; + return NPC.active; + } + public override float SpawnChance(NPCSpawnInfo spawnInfo) { - if (spawnInfo.Player.Calamity().ZoneSulphur || spawnInfo.Player.Calamity().ZoneSunkenSea) + float goldMultiplier = NPC.type == ModContent.NPCType() ? 0.15f : 1f; + bool inAtTown = spawnInfo.Player.townNPCs > 2f && (Main.remixWorld ? spawnInfo.Player.ZoneNormalCaverns : spawnInfo.Player.ZoneForest); + if (inAtTown) + return SpawnCondition.TownCritter.Chance * 0.15f * goldMultiplier; + else if (spawnInfo.Player.ZonePurity) + return (Main.remixWorld ? SpawnCondition.Cavern.Chance * 0.005f : SpawnCondition.OverworldDayGrassCritter.Chance * 0.005f) * goldMultiplier; + + return 0f; + } + + public override void ModifyNPCLoot(NPCLoot npcLoot) => npcLoot.Add(ItemID.Bacon); + + public override void HitEffect(NPC.HitInfo hit) + { + int dustType = Type == ModContent.NPCType() ? DustID.GoldCritter : DustID.Blood; + for (int k = 0; k < 5; k++) { - return 0f; + Dust.NewDust(NPC.position, NPC.width, NPC.height, dustType, hit.HitDirection, -1f, 0, default, 1f); } - return SpawnCondition.TownCritter.Chance * 0.005f; + + if (NPC.life <= 0) + { + for (int k = 0; k < 15; k++) + { + Dust.NewDust(NPC.position, NPC.width, NPC.height, dustType, hit.HitDirection, -1f, 0, default, 1f); + } + + if (!Main.dedServ && Type != ModContent.NPCType()) + { + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("Piggy").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("Piggy2").Type, 1f); + } + } + + NPC.direction = hit.HitDirection; } public override void FindFrame(int frameHeight) @@ -78,15 +512,6 @@ namespace CalamityMod.NPCs.NormalNPCs { if (!NPC.IsABestiaryIconDummy) { - if (NPC.direction == 1) - { - NPC.spriteDirection = -1; - } - if (NPC.direction == -1) - { - NPC.spriteDirection = 1; - } - if (NPC.velocity.X == 0f) { NPC.frame.Y = 0; @@ -94,13 +519,15 @@ namespace CalamityMod.NPCs.NormalNPCs return; } } + NPC.frameCounter += NPC.IsABestiaryIconDummy ? 0.6f : Math.Abs(NPC.velocity.X) * 0.25f; NPC.frameCounter += 1.0; - if (NPC.frameCounter > 12.0) + if (NPC.frameCounter > 7.0) { NPC.frame.Y = NPC.frame.Y + frameHeight; NPC.frameCounter = 0.0; } + if (NPC.frame.Y / frameHeight >= Main.npcFrameCount[Type] - 1) { NPC.frame.Y = frameHeight; @@ -113,21 +540,61 @@ namespace CalamityMod.NPCs.NormalNPCs } } - public override void ModifyNPCLoot(NPCLoot npcLoot) => npcLoot.Add(ItemID.Bacon); - - public override void HitEffect(NPC.HitInfo hit) + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { - for (int k = 0; k < 5; k++) + if (NPC.IsABestiaryIconDummy) + return true; + + Texture2D baseTexture = TextureAssets.Npc[Type].Value; + Vector2 scale = SquashVector * NPC.scale; + SpriteEffects spriteEffects = NPC.spriteDirection < 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + spriteBatch.Draw(baseTexture, NPC.Center - screenPos + Vector2.UnitY * NPC.gfxOffY, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, NPC.frame.Size() * 0.5f, scale, spriteEffects, 0f); + + spriteBatch.End(out var snapshot); + + // Draw the transformation visuals when needed. + if (AIState == (int)BehaviorState.DivineSwineTransformation) + Draw_DivineSwineTransformationVisuals(spriteBatch, screenPos); + + spriteBatch.Begin(snapshot); + return false; + } + + private void Draw_DivineSwineTransformationVisuals(SpriteBatch spriteBatch, Vector2 screenPos) + { + Vector2 baseDrawPosition = NPC.Center - screenPos + Vector2.UnitY * NPC.gfxOffY; + float interpolant = CalamityUtils.SineOutEasing(Utils.GetLerpValue(0f, 120f, Timer, true), 1); + + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + // Spotlight from heaven. + float spotlightOpacity = CalamityUtils.SineInOutEasing(Utils.GetLerpValue(0f, 30f, Timer, true) * Utils.GetLerpValue(180f, 150f, Timer, true), 1); + Vector2 spotlightDrawPosition = baseDrawPosition + Vector2.UnitY * -16f; + Vector2 spotlightScale = new Vector2(1.3f * interpolant, 1.6f); + Vector2 spotlightOrigin = new Vector2(SpotlightTexture.Width() * 0.5f, SpotlightTexture.Height()); + spriteBatch.Draw(SpotlightTexture.Value, spotlightDrawPosition, null, Color.White with { A = 0 } * spotlightOpacity, 0f, spotlightOrigin, spotlightScale, SpriteEffects.FlipVertically, 0f); + + spriteBatch.End(); + + var pixelationLease = RenderTargetPool.Shared.Rent(Main.graphics.GraphicsDevice, Main.screenWidth / 2, Main.screenHeight / 2, RenderTargetDescriptor.Default); + using (pixelationLease.Scope(clearColor: Color.Transparent)) { - Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hit.HitDirection, -1f, 0, default, 1f); - } - if (NPC.life <= 0) - { - for (int k = 0; k < 15; k++) - { - Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hit.HitDirection, -1f, 0, default, 1f); - } + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, PixelationManager.PixelationMatrix); + + // Typical bloom effects. + float flareRotation = (float)(Main.timeForVisualEffects / 150f) + NPC.whoAmI; + spriteBatch.Draw(BloomFlare.Value, baseDrawPosition, null, Color.White with { A = 0 } * interpolant * 0.5f, flareRotation, BloomFlare.Size() * 0.5f, 0.2f * interpolant, 0, 0f); + spriteBatch.Draw(BloomFlare.Value, baseDrawPosition, null, Color.White with { A = 0 } * interpolant, flareRotation * -0.6f, BloomFlare.Size() * 0.5f, 0.15f * interpolant, 0, 0f); + + spriteBatch.Draw(BloomCircle.Value, baseDrawPosition, null, Color.White with { A = 0 } * interpolant, 0f, BloomCircle.Size() * 0.5f, 0.2f * interpolant, 0, 0f); + spriteBatch.Draw(ShineFlare.Value, baseDrawPosition, null, Color.White with { A = 0 } * interpolant, 0f, ShineFlare.Size() * 0.5f, 0.1f * interpolant, 0, 0f); + + spriteBatch.End(); } + + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + spriteBatch.Draw(pixelationLease.Target, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 2f, 0, 0f); + spriteBatch.End(); } } } diff --git a/NPCs/NormalNPCs/Piggy.png b/NPCs/NormalNPCs/Piggy.png index dff2a9af97..7255ad1ca4 100644 Binary files a/NPCs/NormalNPCs/Piggy.png and b/NPCs/NormalNPCs/Piggy.png differ diff --git a/NPCs/NormalNPCs/PiggyGold.cs b/NPCs/NormalNPCs/PiggyGold.cs new file mode 100644 index 0000000000..68cacea0b3 --- /dev/null +++ b/NPCs/NormalNPCs/PiggyGold.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Items.Critters; +using CalamityMod.Items.Placeables.Banners; +using Microsoft.Xna.Framework; +using Terraria.GameContent.Bestiary; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs.NormalNPCs +{ + public class PiggyGold : Piggy + { + public override void SetStaticDefaults() + { + NPCID.Sets.GoldCrittersCollection.Add(Type); + NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 2, Type); + base.SetStaticDefaults(); + } + + public override void SetDefaults() + { + base.SetDefaults(); + NPC.catchItem = (short)ModContent.ItemType(); + Banner = 0; + } + + public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) + { + // All gold critters have the same Bestiary entry. + var flavorText = database.FindEntryByNPCID(NPCID.GoldBunny).Info.Where(info => info is FlavorTextBestiaryInfoElement).FirstOrDefault(); + bestiaryEntry.AddTags( + BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Times.DayTime, + BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Surface, + flavorText); + } + + public override void AI() + { + base.AI(); + NPC.ProduceGoldCritterDust(); + } + } +} diff --git a/NPCs/NormalNPCs/PiggyGold.png b/NPCs/NormalNPCs/PiggyGold.png new file mode 100644 index 0000000000..351dae2e17 Binary files /dev/null and b/NPCs/NormalNPCs/PiggyGold.png differ diff --git a/NPCs/Providence/Providence.cs b/NPCs/Providence/Providence.cs index 39a7dc5f10..c401652674 100644 --- a/NPCs/Providence/Providence.cs +++ b/NPCs/Providence/Providence.cs @@ -834,22 +834,16 @@ namespace CalamityMod.NPCs.Providence if (NPC.Center.X < player.Center.X) { flightPath = 1; - calamityGlobalNPC.newAI[0] = 0f; NPC.netUpdate = true; } else { flightPath = -1; - calamityGlobalNPC.newAI[0] = 0f; NPC.netUpdate = true; } } } - // Increase speed over time if flying in same direction for too long - if (revenge) - calamityGlobalNPC.newAI[0] += 1f; - // Distance needed from target to change direction float changeDirectionThreshold = 800f; @@ -881,7 +875,6 @@ namespace CalamityMod.NPCs.Providence // Velocity and acceleration float speedIncreaseTimer = fullPowerAI ? 75f : death ? 120f : 150f; - bool increaseSpeed = calamityGlobalNPC.newAI[0] > speedIncreaseTimer; float accelerationBoost = death ? 0.3f * (1f - lifeRatio) : 0.2f * (1f - lifeRatio); float velocityBoost = death ? 6f * (1f - lifeRatio) : 4f * (1f - lifeRatio); float acceleration = (expertMode ? 1.1f : 1.05f) + accelerationBoost; @@ -893,14 +886,8 @@ namespace CalamityMod.NPCs.Providence } if (laserPhaseSlow) { - acceleration *= getFuckedAI ? 0.6f : 0.4f; - velocity *= getFuckedAI ? 0.6f : 0.4f; - } - else if (increaseSpeed) - { - velocity += (calamityGlobalNPC.newAI[0] - speedIncreaseTimer) * 0.04f; - if (velocity > 30f) - velocity = 30f; + acceleration *= getFuckedAI ? 0.6f : 0.2f; + velocity *= getFuckedAI ? 0.6f : 0.2f; } if (Main.getGoodWorld) diff --git a/NPCs/Ravager/FlamePillar.cs b/NPCs/Ravager/FlamePillar.cs index 8a7abc4e6c..08c606929d 100644 --- a/NPCs/Ravager/FlamePillar.cs +++ b/NPCs/Ravager/FlamePillar.cs @@ -238,7 +238,7 @@ namespace CalamityMod.NPCs.Ravager public override void ModifyHitByProjectile(Projectile projectile, ref NPC.HitModifiers modifiers) { var item = Main.player[projectile.owner].HeldItem; - if (item.pick > 0 && projectile.CountsAsClass()) + if (item.pick > 0 && !projectile.CountsAsClass()) { modifiers.FlatBonusDamage += -10000; modifiers.FinalDamage.Flat += item.pick-1; diff --git a/NPCs/Ravager/RockPillar.cs b/NPCs/Ravager/RockPillar.cs index ad80d16cc6..4edcd8d1f8 100644 --- a/NPCs/Ravager/RockPillar.cs +++ b/NPCs/Ravager/RockPillar.cs @@ -239,7 +239,7 @@ namespace CalamityMod.NPCs.Ravager public override void ModifyHitByProjectile(Projectile projectile, ref NPC.HitModifiers modifiers) { var item = Main.player[projectile.owner].HeldItem; - if (item.pick > 0 && projectile.CountsAsClass()) + if (item.pick > 0 && !projectile.CountsAsClass()) { modifiers.FlatBonusDamage += -10000; modifiers.FinalDamage.Flat += item.pick - 1; diff --git a/NPCs/TownNPCs/TownPiggy.cs b/NPCs/TownNPCs/TownPiggy.cs index 3c15194e38..d82030f0a7 100644 --- a/NPCs/TownNPCs/TownPiggy.cs +++ b/NPCs/TownNPCs/TownPiggy.cs @@ -54,7 +54,7 @@ namespace CalamityMod.NPCs.TownNPCs AIType = NPCID.TownBunny; NPC.damage = 0; NPC.defense = 0; - NPC.lifeMax = 50; + NPC.lifeMax = 250; NPC.HitSound = SoundID.NPCHit1; NPC.DeathSound = SoundID.NPCDeath1; NPC.knockBackResist = 0.5f; diff --git a/Packets/Entities/DivineSwine/DivineSwineOfferingPacket.cs b/Packets/Entities/DivineSwine/DivineSwineOfferingPacket.cs new file mode 100644 index 0000000000..61278d00ae --- /dev/null +++ b/Packets/Entities/DivineSwine/DivineSwineOfferingPacket.cs @@ -0,0 +1,34 @@ +using System.IO; +using CalamityMod.NPCs.NormalNPCs; +using Terraria; + +namespace CalamityMod.Packets +{ + internal class DivineSwineOfferingPacket : CalamityPacket + { + public static DivineSwineOfferingPacket Instance { get; private set; } + + public static void Send(DivineSwine divineSwine, bool? offeringState = null, int toClient = -1, int ignoreClient = -1) + { + if (divineSwine is null || !offeringState.HasValue) + return; + + var packet = Instance.CreateBasePacket(); + packet.WriteWhoAmI(divineSwine); + packet.Write(offeringState.Value); + packet.Send(toClient, ignoreClient); + } + + public override void HandlePacket(BinaryReader packet, int sender) + { + var divineSwine = packet.ReadModNPC(); + var offeringState = packet.ReadBoolean(); + + if (divineSwine is null) + return; + + if (Main.dedServ) + divineSwine.AcceptOffering(offeringState); + } + } +} diff --git a/Packets/Players/DisgustingMeatPlayerSyncPacket.cs b/Packets/Players/DisgustingMeatPlayerSyncPacket.cs new file mode 100644 index 0000000000..08e818d6db --- /dev/null +++ b/Packets/Players/DisgustingMeatPlayerSyncPacket.cs @@ -0,0 +1,50 @@ +using System; +using System.IO; +using CalamityMod.Items.Tools; +using MonoMod.Core.Platforms; +using Terraria; +using Terraria.GameContent; +using Terraria.ModLoader; + +namespace CalamityMod.Packets +{ + internal class DisgustingMeatPlayerSyncPacket : CalamityPacket + { + public static DisgustingMeatPlayerSyncPacket Instance { get; private set; } + + public static void Send(DisgustingMeatPlayer playerToSync, int toClient = -1, int ignoreClient = -1) + { + if (playerToSync is null) + return; + + var packet = Instance.CreateBasePacket(); + packet.WriteWhoAmI(playerToSync); + packet.Write(playerToSync.DoingVomitAnimation); + packet.Write(playerToSync.EjectMiscUpgrades); + packet.Write(playerToSync.VomitTime); + packet.Write((int)playerToSync.Player.eyeHelper.CurrentEyeFrame); + packet.Send(toClient, ignoreClient); + } + + public override void HandlePacket(BinaryReader packet, int sender) + { + var player = packet.ReadPlayer(); + var doingVomitAnimation = packet.ReadBoolean(); + var ejectMiscUpgrades = packet.ReadBoolean(); + var vomitTime = packet.ReadInt32(); + var currentEyeFrame = packet.ReadInt32(); + + if (player is null) + return; + + var modPlayer = player.GetModPlayer(); + modPlayer.DoingVomitAnimation = doingVomitAnimation; + modPlayer.EjectMiscUpgrades = ejectMiscUpgrades; + modPlayer.VomitTime = vomitTime; + player.eyeHelper.CurrentEyeFrame = (PlayerEyeHelper.EyeFrame)currentEyeFrame; + + if (Main.dedServ) + Send(modPlayer, ignoreClient: sender); + } + } +} diff --git a/Packets/Worlds/DisableNPCUpgradesSyncPacket.cs b/Packets/Worlds/DisableNPCUpgradesSyncPacket.cs new file mode 100644 index 0000000000..7a16feda3a --- /dev/null +++ b/Packets/Worlds/DisableNPCUpgradesSyncPacket.cs @@ -0,0 +1,39 @@ +using System.IO; +using Terraria; +using Terraria.ID; + +namespace CalamityMod.Packets.Worlds +{ + internal class DisableNPCUpgradesSyncPacket : CalamityPacket + { + public static DisableNPCUpgradesSyncPacket Instance { get; private set; } + + public static void Send(int upgradeType = -1, int toClient = -1, int ignoreClient = -1) + { + if (upgradeType < 0 || upgradeType > 2) + return; + + var packet = Instance.CreateBasePacket(); + packet.Write(upgradeType); + packet.Send(toClient, ignoreClient); + } + + public override void HandlePacket(BinaryReader packet, int sender) + { + var upgradeType = packet.ReadInt32(); + + if (upgradeType == 0) + NPC.peddlersSatchelWasUsed = false; + else if (upgradeType == 1) + NPC.combatBookWasUsed = false; + else if (upgradeType == 2) + NPC.combatBookVolumeTwoWasUsed = false; + + // Apply change to everyone + if (Main.netMode == NetmodeID.Server) + { + NetMessage.SendData(MessageID.WorldData); + } + } + } +} diff --git a/Particles/FeatherParticle.cs b/Particles/FeatherParticle.cs new file mode 100644 index 0000000000..54a6bd9ab9 --- /dev/null +++ b/Particles/FeatherParticle.cs @@ -0,0 +1,160 @@ +using System; +using System.Threading; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class FeatherParticle : Particle + { + public float RotationSpeed; + + public float Opacity; + + public float SwayAngleStrength; + + public bool AffectedByWind; + + public bool NoGravity; + + public bool ShouldCollideWithTiles; + + public bool DieWithTileCollision; + + private int DeathTimer; + + public static float WaveAngle => MathHelper.ToRadians(25f); + + public float WaveFrameState { get; private set; } + + public int SwayInterval { get; private set; } + + public bool CurrentlyCollidingWithTiles { get; private set; } + + public FeatherParticle(Vector2 position, Vector2 velocity, Color color, float scale, int lifetime, float? rotationSpeed = null, float swayAngleStrength = 1f, bool affectedByWind = false, bool noGravity = false, bool shouldCollideWithTiles = false, bool dieWithTileCollision = false) + { + Position = position; + Velocity = velocity; + Color = color; + Scale = scale; + Lifetime = lifetime; + RotationSpeed = rotationSpeed ?? Main.rand.NextFloat(120f, 150f) * Main.rand.NextBool().ToDirectionInt(); + SwayAngleStrength = swayAngleStrength; + AffectedByWind = affectedByWind; + NoGravity = noGravity; + ShouldCollideWithTiles = shouldCollideWithTiles; + DieWithTileCollision = dieWithTileCollision; + + Variant = Main.rand.Next(3); + Opacity = 0f; + SwayInterval = Main.rand.Next(75, 150); + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + } + + public override string Texture => "CalamityMod/Particles/FeatherParticle"; + + public override bool SetLifetime => false; + + public override bool UseCustomDraw => true; + + public override int FrameVariants => 3; + + public override void Update() + { + if (!CurrentlyCollidingWithTiles) + Rotation += (MathHelper.Pi / RotationSpeed) + (Velocity.X * 0.01f); + + // Original math from AstralGodRay.cs. + int waveSign = (WaveFrameState > 0f).ToDirectionInt(); + if (Math.Abs(WaveFrameState) < 1f) + { + int dirToUse = WaveFrameState == 0 ? (Main.rand.NextBool() ? -1 : 1) : waveSign; + waveSign = -dirToUse; + WaveFrameState = dirToUse * SwayInterval * 0.5f; + } + + // Switch directions whenever necessary. + else if (Math.Abs(WaveFrameState) > SwayInterval) + WaveFrameState = -waveSign; + else + WaveFrameState += waveSign; + + // Rotate velocity towards the wave angle to appear as if its swaying side to side. + float swayAngle = WaveAngle / (SwayInterval * 0.5f); + Velocity = Velocity.RotatedBy(waveSign * swayAngle * SwayAngleStrength); + + Velocity.X *= 0.98f; + if (Velocity.Y < 0.6f && !NoGravity) + Velocity.Y += 0.005f; + else + Velocity.Y *= 0.98f; + + // Move with wind speed. + if (AffectedByWind) + Velocity.X += Main.windSpeedCurrent / 3f; + + // Tile collision. + if (ShouldCollideWithTiles) + { + CurrentlyCollidingWithTiles = false; + + Vector2 hitboxDimensions = new(12f, 12f); + if (Collision.SolidCollision(Position, (int)hitboxDimensions.X, (int)hitboxDimensions.Y)) + { + Velocity = Collision.TileCollision(Position, Velocity, (int)hitboxDimensions.X, (int)hitboxDimensions.Y); + CurrentlyCollidingWithTiles = true; + } + + if (Collision.WetCollision(Position, (int)hitboxDimensions.X, (int)hitboxDimensions.Y)) + { + Velocity.Y *= 0.8f; + CurrentlyCollidingWithTiles = true; + } + } + + if (DieWithTileCollision && ShouldCollideWithTiles) + { + if (CurrentlyCollidingWithTiles) + { + Opacity = MathHelper.Lerp(1f, 0f, (float)(DeathTimer / 45)); + if (DeathTimer >= 45) + { + Kill(); + return; + } + + DeathTimer++; + } + else + { + Opacity = MathHelper.Clamp(Opacity + 0.075f, 0f, 1f); + } + } + else + { + int fadeInTime = 45 - (int)(Lifetime * 0.2f); + if (fadeInTime < 20) + fadeInTime = 20; + int fadeOutTime = (int)(Lifetime * 0.8f); + Opacity = Utils.GetLerpValue(0, fadeInTime, Time, true) * Utils.GetLerpValue(Lifetime, fadeOutTime, Time); + + if (Time >= Lifetime) + { + Kill(); + return; + } + } + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D texture = GeneralParticleHandler.GetTexture(Type); + Color lightColor = Color.MultiplyRGB(Lighting.GetColor((Position / 16).ToPoint())); + Rectangle frame = texture.Frame(1, FrameVariants, 0, Variant); + spriteBatch.Draw(texture, Position - Main.screenPosition, frame, lightColor * Opacity, Rotation, frame.Size() * 0.5f, Scale, SpriteEffects.None, 0f); + } + } +} diff --git a/Particles/FeatherParticle.png b/Particles/FeatherParticle.png new file mode 100644 index 0000000000..874bccc051 Binary files /dev/null and b/Particles/FeatherParticle.png differ diff --git a/Particles/FlyParticle.cs b/Particles/FlyParticle.cs new file mode 100644 index 0000000000..973441726c --- /dev/null +++ b/Particles/FlyParticle.cs @@ -0,0 +1,94 @@ +using System; +using CalamityMod.Systems.Graphic.TempParticleSystem; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; + +namespace CalamityMod.Particles +{ + public class FlyParticle : Particle + { + public float Opacity; + + private bool WasSpawnedWithAnchor; + + public Entity AnchorEntity { get; private set; } + + public Vector2 StoredPosition { get; private set; } + + public float HeightToNeverGoBelow { get; private set; } + + public FlyParticle(Vector2 position, float scale, int lifetime, Entity anchorEntity = null) + { + Position = position; + Scale = scale; + Lifetime = lifetime; + AnchorEntity = anchorEntity; + + if (anchorEntity == null) + { + StoredPosition = position; + HeightToNeverGoBelow = position.Y + 8f; + WasSpawnedWithAnchor = false; + } + else + { + WasSpawnedWithAnchor = true; + } + + Variant = Main.rand.Next(2); + Color = Color.White; + AffectedByLight = true; + } + + public override string Texture => "Terraria/Images/Extra_262"; + + public override bool SetLifetime => true; + + public override bool UseCustomDraw => true; + + public override int FrameVariants => 2; + + public override void Update() + { + if (WasSpawnedWithAnchor) + { + StoredPosition = AnchorEntity.Top; + HeightToNeverGoBelow = AnchorEntity.Top.Y + 8f; + if (!AnchorEntity.active || AnchorEntity == null) + { + Kill(); + return; + } + } + + Velocity += new Vector2(MathF.Sign(StoredPosition.X - Position.X) * 0.02f, MathF.Sign(StoredPosition.Y - Position.Y) * 0.02f); + if (Time % 30 == 0 && Main.rand.NextBool(2)) + { + Velocity = Main.rand.NextVector2Circular(1f, 1f); + if (Main.rand.NextBool(2)) + Velocity /= 2; + } + + if (Position.Y > HeightToNeverGoBelow) + { + Position.Y = HeightToNeverGoBelow; + if (Velocity.Y > 0f) + Velocity *= -1f; + } + + Variant = Time % 6 / 3; + int fadeInTime = (int)(Lifetime * 0.13f); + int fadeOutTime = (int)(Lifetime * 0.93f); + Opacity = Utils.GetLerpValue(0f, fadeInTime, Time, true) * Utils.GetLerpValue(Lifetime, Lifetime - fadeOutTime, Time, true); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Color lightColor = Color.MultiplyRGB(Lighting.GetColor((Position / 16).ToPoint())); + Rectangle frame = GeneralParticleHandler.GetTexture(Type).Frame(1, FrameVariants, 0, Variant); + SpriteEffects effects = (Velocity.X > 0f) ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + Main.spriteBatch.Draw(GeneralParticleHandler.GetTexture(Type), Position - Main.screenPosition, frame, lightColor * Opacity, Rotation, frame.Size() * 0.5f, Scale, effects, 0f); + } + } +} diff --git a/Particles/GraveyardMistParticle.cs b/Particles/GraveyardMistParticle.cs new file mode 100644 index 0000000000..262597d307 --- /dev/null +++ b/Particles/GraveyardMistParticle.cs @@ -0,0 +1,52 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; + +namespace CalamityMod.Particles +{ + public class GraveyardMistParticle : Particle + { + public float StretchFactor; + + public float BaseOpacity; + + public int Direction; + + public float Opacity { get; private set; } + + public int TextureIndex { get; private set; } + + public GraveyardMistParticle(Vector2 spawnPosition, Vector2 velocity, Color color, float scale, float baseOpacity, int lifetime, int textureIndex) + { + Position = spawnPosition; + Velocity = velocity; + Color = color; + Scale = scale; + BaseOpacity = baseOpacity; + Lifetime = lifetime; + TextureIndex = textureIndex; + StretchFactor = Main.rand.NextFloat(1f, 2f); + } + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override bool SetLifetime => true; + + public override bool UseCustomDraw => true; + + public override void Update() + { + float halfLifetime = Lifetime / 2; + Opacity = BaseOpacity * MathHelper.Lerp(0f, 1f, MathF.Sin(MathHelper.TwoPi * (Time / halfLifetime))); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D mistTexture = Main.Assets.Request("Images/Gore_" + TextureIndex).Value; + SpriteEffects spriteEffects = (Velocity.X > 0) ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + Vector2 scale = new Vector2(StretchFactor, 1f) * Scale; + spriteBatch.Draw(mistTexture, Position - Main.screenPosition, mistTexture.Frame(), Color * Opacity * 0.375f, Rotation, mistTexture.Frame().Size() * 0.5f, scale, spriteEffects, 0f); + } + } +} diff --git a/Particles/QuickSparkleParticle.cs b/Particles/QuickSparkleParticle.cs new file mode 100644 index 0000000000..ab4cad8d43 --- /dev/null +++ b/Particles/QuickSparkleParticle.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class QuickSparkleParticle : Particle + { + public float StoredScale; + + public float LightStrength; + + public bool EmitLight; + + public Vector2 StretchFactor; + + public QuickSparkleParticle(Vector2 position, Vector2 velocity, Color color, float scale, int lifetime, Vector2? stretchFactor = null,bool emitLight = false, float lightStrength = 1.45f) + { + Position = position; + Velocity = velocity; + Color = color; + StoredScale = scale; + Lifetime = lifetime; + StretchFactor = stretchFactor ?? new(0.75f, 1.75f); + EmitLight = emitLight; + LightStrength = lightStrength; + } + + public override bool SetLifetime => true; + + public override bool UseAdditiveBlend => true; + + public override bool UseCustomDraw => true; + + public override string Texture => "CalamityMod/ExtraTextures/ShineFlare"; + + public override void Update() + { + Velocity *= 0.92f; + Scale = MathHelper.Lerp(0f, StoredScale, MathF.Sin(LifetimeCompletion * MathHelper.Pi)); + if (EmitLight) + Lighting.AddLight(Position, Color.ToVector3() * Scale * LightStrength); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + spriteBatch.Draw(GeneralParticleHandler.GetTexture(Type), Position - Main.screenPosition, null, Color.White, Rotation, GeneralParticleHandler.GetTexture(Type).Size() * 0.5f, Scale * StretchFactor * 0.1f, 0, 0f); + spriteBatch.Draw(GeneralParticleHandler.GetTexture(Type), Position - Main.screenPosition, null, Color, Rotation, GeneralParticleHandler.GetTexture(Type).Size() * 0.5f, Scale * StretchFactor * 0.2f, 0, 0f); + } + } +} diff --git a/Particles/TimedSmokeParticle.cs b/Particles/TimedSmokeParticle.cs index 723f1cc0f8..6c869b9763 100644 --- a/Particles/TimedSmokeParticle.cs +++ b/Particles/TimedSmokeParticle.cs @@ -15,8 +15,9 @@ namespace CalamityMod.Particles private Color ColorStart; private Color ColorFade; private float Spin; + private bool FadeIn; - public TimedSmokeParticle(Vector2 position, Vector2 velocity, Color colorStart, Color colorFade, float scale, float opacity, int timeleft, float rotationSpeed = 0f) + public TimedSmokeParticle(Vector2 position, Vector2 velocity, Color colorStart, Color colorFade, float scale, float opacity, int timeleft, float rotationSpeed = 0f, bool fadeIn = false) { Position = position; Velocity = velocity; @@ -27,6 +28,7 @@ namespace CalamityMod.Particles Rotation = Main.rand.NextFloat(MathHelper.TwoPi); Spin = rotationSpeed; Lifetime = timeleft; + FadeIn = fadeIn; Variant = Main.rand.Next(3); } @@ -48,6 +50,9 @@ namespace CalamityMod.Particles Velocity -= Vector2.UnitY * 0.08f; float opacityMult = 1 - (float)Math.Pow(LifetimeCompletion, 2); + if (FadeIn) + opacityMult = 1f * MathF.Sin(LifetimeCompletion * MathHelper.Pi); + Color = Color.Lerp(ColorStart, ColorFade, opacityMult) * (Opacity * opacityMult); } } diff --git a/Projectiles/Enemy/HorribleHogChargeHitbox.cs b/Projectiles/Enemy/HorribleHogChargeHitbox.cs new file mode 100644 index 0000000000..b98444cdde --- /dev/null +++ b/Projectiles/Enemy/HorribleHogChargeHitbox.cs @@ -0,0 +1,56 @@ +using CalamityMod.NPCs.NormalNPCs.HorribleHog; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Enemy +{ + public class HorribleHogChargeHitbox : ModProjectile, ILocalizedModType + { + public ref float HogIndex => ref Projectile.ai[0]; + + public new string LocalizationCategory => "Projectiles.Enemy"; + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetDefaults() + { + Projectile.width = 40; + Projectile.height = 28; + Projectile.penetrate = -1; + Projectile.hostile = true; + Projectile.hide = true; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + Projectile.usesIDStaticNPCImmunity = true; + Projectile.idStaticNPCHitCooldown = 15; + } + + public override bool ShouldUpdatePosition() => false; + + public override bool? CanHitNPC(NPC target) => target.whoAmI != (int)HogIndex; + + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) => modifiers.FinalDamage *= 5f; + + public override void ModifyHitPlayer(Player target, ref Player.HurtModifiers modifiers) => modifiers.Knockback *= 0f; + + public override void OnHitPlayer(Player target, Player.HurtInfo info) + { + target.velocity.X += 8f * info.HitDirection; + target.velocity.Y -= 3f; + } + + public override void AI() + { + if (!Main.npc.IndexInRange((int)HogIndex) || !Main.npc[(int)HogIndex].active || Main.npc[(int)HogIndex].type != ModContent.NPCType()) + { + Projectile.Kill(); + return; + } + + Projectile.Center = Main.npc[(int)HogIndex].Center; + Projectile.velocity = Main.npc[(int)HogIndex].velocity; + } + } +} diff --git a/Projectiles/Enemy/HorribleHogRubble.cs b/Projectiles/Enemy/HorribleHogRubble.cs new file mode 100644 index 0000000000..addde8fd5c --- /dev/null +++ b/Projectiles/Enemy/HorribleHogRubble.cs @@ -0,0 +1,100 @@ +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.DataStructures; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Enemy +{ + public class HorribleHogRubble : ModProjectile, ILocalizedModType + { + public int FrameX; + + public new string LocalizationCategory => "Projectiles.Enemy"; + + public override string Texture => "Terraria/Images/Projectile_" + ProjectileID.DeerclopsRangedProjectile; + + public override void SetStaticDefaults() + { + Main.projFrames[Type] = 4; + ProjectileID.Sets.TrailCacheLength[Type] = 8; + ProjectileID.Sets.TrailingMode[Type] = 0; + } + + public override void SetDefaults() + { + Projectile.width = 24; + Projectile.height = 24; + Projectile.penetrate = 1; + Projectile.timeLeft = 300; + Projectile.scale = 0f; + Projectile.hostile = true; + } + + public override void OnSpawn(IEntitySource source) + { + Projectile.spriteDirection = Main.rand.NextBool().ToDirectionInt(); + FrameX = Main.rand.Next(3); + } + + public override void AI() + { + Projectile.scale = MathHelper.Lerp(Projectile.scale, 1f, 0.25f); + Projectile.ExpandHitboxBy(Projectile.scale); + + Projectile.rotation += Projectile.velocity.X * 0.035f; + if (Projectile.velocity.Y < 8f) + Projectile.velocity.Y += 0.165f; + + if (Projectile.timeLeft <= 250) + Projectile.velocity.X *= 0.92f; + } + + public override void OnKill(int timeLeft) + { + int dustCloudAmt = Main.rand.Next(3, 6); + for (int i = 0; i < dustCloudAmt; i++) + { + Vector2 spawnPosition = Projectile.Center + Main.rand.NextVector2Circular(8f, 8f); + Vector2 velocity = Main.rand.NextVector2Circular(3f, 3f); + Color color = Color.Lerp(Color.SaddleBrown, Color.SandyBrown, Main.rand.NextFloat()); + float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); + + SmallSmokeParticle dustCloud = new(spawnPosition, velocity, color, color, Main.rand.NextFloat(1.6f, 1.8f), Main.rand.Next(75, 100), rotationSpeed); + GeneralParticleHandler.SpawnParticle(dustCloud, true); + } + + int dustAmt = Main.rand.Next(6, 9); + for (int i = 0; i < dustAmt; i++) + { + Vector2 spawnPosition = Projectile.Center + Main.rand.NextVector2Circular(8f, 8f); + Vector2 velocity = Main.rand.NextVector2Circular(3f, 3f); + Dust.NewDust(spawnPosition, 0, 0, DustID.Dirt, velocity.X, velocity.Y, Scale: Main.rand.NextFloat(0.8f, 1.2f)); + } + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Rectangle frame = texture.Frame(3, Main.projFrames[Type], FrameX, Projectile.frame); + Vector2 origin = frame.Size() * 0.5f; + SpriteEffects spriteEffects = Projectile.spriteDirection < 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + + if (CalamityClientConfig.Instance.Afterimages) + { + for (int i = 0; i < Projectile.oldPos.Length; ++i) + { + Vector2 drawPos = Projectile.oldPos[i] + Projectile.Size * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); + float interpolant = ((float)(Projectile.oldPos.Length - i) / (float)Projectile.oldPos.Length); + Main.spriteBatch.Draw(texture, drawPos, frame, Projectile.GetAlpha(lightColor) * 0.3f * interpolant, Projectile.rotation, origin, Projectile.scale * interpolant, spriteEffects, 0f); + } + } + + Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition, frame, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, spriteEffects, 0f); + return false; + } + } +} diff --git a/Projectiles/Enemy/HorribleHogShockwave.cs b/Projectiles/Enemy/HorribleHogShockwave.cs new file mode 100644 index 0000000000..778b36dd6f --- /dev/null +++ b/Projectiles/Enemy/HorribleHogShockwave.cs @@ -0,0 +1,132 @@ +using System; +using CalamityMod.Items.Potions.Alcohol; +using CalamityMod.NPCs.NormalNPCs; +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Enemy +{ + public class HorribleHogShockwave : ModProjectile, ILocalizedModType + { + public ref float Timer => ref Projectile.ai[0]; + + public ref float HeightMultiplier => ref Projectile.ai[1]; + + public ref float HogIndex => ref Projectile.ai[2]; + + public float CurrentHeight => 32f * MathHelper.Lerp(1f, HeightMultiplier, Timer / 9f); + + public new string LocalizationCategory => "Projectiles.Enemy"; + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetDefaults() + { + Projectile.width = 32; + Projectile.height = 32; + Projectile.penetrate = -1; + Projectile.alpha = 255; + Projectile.hostile = true; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + Projectile.usesIDStaticNPCImmunity = true; + Projectile.idStaticNPCHitCooldown = 15; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float _ = 0f; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Projectile.Center, Projectile.Center - Vector2.UnitY * CurrentHeight * Projectile.scale, Projectile.width * Projectile.scale, ref _); + } + + public override bool? CanHitNPC(NPC target) => target.whoAmI != (int)HogIndex; + + // Player knockback is constant and applies whenever any damage is dealt, regardless of if a projectile spawned deals zero knockback or not. + // Therefore, the knockback stat modifier here needs to be multiplied by zero in order for any custom knockback effect to take place. + // This isn't the same for NPCs, so they don't need it so long as the projectile is spawned with zero knockback. + public override void ModifyHitPlayer(Player target, ref Player.HurtModifiers modifiers) => modifiers.Knockback *= 0f; + + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) => modifiers.FinalDamage *= 5f; + + public override void OnHitPlayer(Player target, Player.HurtInfo info) => target.velocity.Y -= MathHelper.Clamp(8f + (CurrentHeight * 0.1f), 8f, 16f); + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.velocity.Y -= MathHelper.Clamp(8f + (CurrentHeight * 0.1f) * target.knockBackResist, 8f, 16f); + + public override void AI() + { + if (Timer >= 9f) + { + Projectile.Kill(); + return; + } + + if (Timer == 1f) + SoundEngine.PlaySound(SoundID.Item70, Projectile.Center); + + Projectile.velocity = Vector2.Zero; + + Point topLeft = Projectile.TopLeft.ToTileCoordinates(); + Point bottomRight = Projectile.BottomRight.ToTileCoordinates(); + int halfWidth = Projectile.width / 2; + int dustSpawnInterval = (int)Projectile.ai[0] / 3; + + Timer++; + if (Timer % 3 != 0f) + return; + + float heightMulti = MathHelper.Lerp(1f, HeightMultiplier, Timer / 9f); + int dustCloudAmt = Main.rand.Next(4, 7); + for (int i = 0; i < dustCloudAmt; i++) + { + Vector2 dustCloudPosition = Projectile.Bottom + Main.rand.NextVector2Circular(24f, 0f); + Vector2 dustVelocity = Vector2.UnitY * -1.3f * heightMulti * i * Main.rand.NextFloat(0.8f, 1.2f); + Color dustCloudColor = Color.Lerp(Color.SandyBrown, Color.SandyBrown, Main.rand.NextFloat()); + float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); + TimedSmokeParticle dustCloud = new(dustCloudPosition, dustVelocity, dustCloudColor, dustCloudColor, Main.rand.NextFloat(0.7f, 0.8f), Main.rand.NextFloat(0.72f, 0.84f), Main.rand.Next(30, 45), rotationSpeed); + GeneralParticleHandler.SpawnParticle(dustCloud, true, Enums.GeneralDrawLayer.BeforeSolidTiles); + } + + for (int i = topLeft.X; i <= bottomRight.X; i++) + { + for (int j = topLeft.Y; j <= bottomRight.Y; j++) + { + if (Vector2.Distance(Projectile.Center, new Vector2(i * 16f, j * 16f)) > halfWidth) + continue; + + Tile tile = Framing.GetTileSafely(i, j); + if (!tile.HasTile || !Main.tileSolid[tile.TileType] || Main.tileSolidTop[tile.TileType] || Main.tileFrameImportant[tile.TileType]) + continue; + + Tile tileAbove = Framing.GetTileSafely(i, j - 1); + if (tileAbove.HasTile && Main.tileSolid[tileAbove.TileType] && !Main.tileSolidTop[tileAbove.TileType]) + continue; + + int dustCountFromTile = WorldGen.KillTile_GetTileDustAmount(fail: true, tile, i, j); + for (int k = 0; k < dustCountFromTile; k++) + { + Dust dust = Main.dust[WorldGen.KillTile_MakeTileDust(i, j, tile)]; + dust.velocity.Y -= 3f + dustSpawnInterval * 1.5f * HeightMultiplier; + dust.velocity.Y *= Main.rand.NextFloat(); + dust.velocity.Y *= 0.75f; + dust.scale += dustSpawnInterval * 0.03f; + } + + if (dustSpawnInterval >= 2) + { + for (int m = 0; m < dustCountFromTile - 1; m++) + { + Dust dust = Main.dust[WorldGen.KillTile_MakeTileDust(i, j, tile)]; + dust.velocity.Y -= 1f + dustSpawnInterval * HeightMultiplier; + dust.velocity.Y *= Main.rand.NextFloat(); + dust.velocity.Y *= 0.75f; + } + } + } + } + } + } +} diff --git a/Projectiles/Enemy/HorribleHogShockwaveSpawner.cs b/Projectiles/Enemy/HorribleHogShockwaveSpawner.cs new file mode 100644 index 0000000000..c1308fb433 --- /dev/null +++ b/Projectiles/Enemy/HorribleHogShockwaveSpawner.cs @@ -0,0 +1,120 @@ +using System.IO; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Enemy +{ + public class HorribleHogShockwaveSpawner : ModProjectile, ILocalizedModType + { + public int OwnerIndex; + + public int ShockwaveCounter; + + public int Timer; + + public ref float SpawnInterval => ref Projectile.ai[0]; + + public ref float MaxShockwaves => ref Projectile.ai[1]; + + public ref float Direction => ref Projectile.ai[2]; + + public ref float MinHeightMultiplier => ref Projectile.localAI[0]; + + public ref float MaxHeightMultiplier => ref Projectile.localAI[1]; + + public new string LocalizationCategory => "Projectiles.Enemy"; + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetDefaults() + { + Projectile.width = 4; + Projectile.height = 4; + Projectile.penetrate = -1; + Projectile.hide = true; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + } + + 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; + + public override bool? CanHitNPC(NPC target) => false; + + public override bool CanHitPlayer(Player target) => false; + + public override void AI() + { + if (ShockwaveCounter >= MaxShockwaves) + { + Projectile.Kill(); + return; + } + + Direction = MathHelper.Clamp(Direction, -1, 1); + if (Direction == 0) + { + Direction = Main.rand.NextBool().ToDirectionInt(); + Projectile.netUpdate = true; + } + + if (Timer % SpawnInterval == 0f) + { + Vector2 shockwaveSpawnPosition = new(); + + int spawnAttempts = 20; + int shockwaveSpawnDistance = 32 * (int)ShockwaveCounter * (int)Direction; + Point bottomInTileCoords = (Projectile.Bottom + Vector2.UnitX * shockwaveSpawnDistance).ToTileCoordinates(); + for (int i = 0; i < spawnAttempts; i++) + { + int posX = bottomInTileCoords.X; + int posY = bottomInTileCoords.Y - i; + Tile tileAbove = CalamityUtils.ParanoidTileRetrieval(posX, posY - 1); + if (WorldGen.ActiveAndWalkableTile(posX, posY) && !tileAbove.HasTile) + { + shockwaveSpawnPosition = new Point(posX, posY).ToWorldCoordinates(); + break; + } + } + + for (int i = 0; i < spawnAttempts; i++) + { + int posX = bottomInTileCoords.X; + int posY = bottomInTileCoords.Y + i; + if (WorldGen.ActiveAndWalkableTile(posX, posY)) + { + shockwaveSpawnPosition = new Point(posX, posY).ToWorldCoordinates(); + break; + } + } + + if (Main.netMode != NetmodeID.MultiplayerClient) + { + 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++; + } + + Timer++; + } + } +} diff --git a/Projectiles/Enemy/HorribleHogVomitBomb.cs b/Projectiles/Enemy/HorribleHogVomitBomb.cs new file mode 100644 index 0000000000..8df3367964 --- /dev/null +++ b/Projectiles/Enemy/HorribleHogVomitBomb.cs @@ -0,0 +1,196 @@ +using CalamityMod.Effects; +using CalamityMod.Particles; +using CalamityMod.Utilities.Daybreak; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Enemy +{ + public class HorribleHogVomitBomb : ModProjectile, ILocalizedModType + { + public bool HasExplodedYet + { + get => Projectile.ai[0] == 1f; + set => Projectile.ai[0] = value.ToInt(); + } + + public ref float HogIndex => ref Projectile.ai[1]; + + public new string LocalizationCategory => "Projectiles.Enemy"; + + public override string Texture => "Terraria/Images/Projectile_" + ProjectileID.Bomb; + + public override void SetStaticDefaults() + { + ProjectileID.Sets.TrailCacheLength[Type] = 12; + ProjectileID.Sets.TrailingMode[Type] = 0; + } + + public override void SetDefaults() + { + Projectile.width = 22; + Projectile.height = 22; + Projectile.penetrate = 1; + Projectile.timeLeft = 300; + Projectile.scale = 0f; + Projectile.hostile = true; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 15; + } + + public override bool? CanHitNPC(NPC target) => target.whoAmI != (int)HogIndex; + + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) => modifiers.FinalDamage *= 5f; + + public override void AI() + { + if (!HasExplodedYet && Projectile.timeLeft <= 1) + { + Explode(); + return; + } + + Projectile.scale = MathHelper.Lerp(Projectile.scale, 1f, 0.25f); + Projectile.ExpandHitboxBy(Projectile.scale); + Projectile.spriteDirection = Projectile.direction; + + Projectile.rotation += Projectile.velocity.X * 0.035f; + if (Projectile.velocity.Y < 8f) + Projectile.velocity.Y += 0.125f; + + Vector2 dustPosition = Projectile.Center + new Vector2(4f, -14f).RotatedBy(Projectile.rotation); + Dust.NewDustPerfect(dustPosition, DustID.Torch, Vector2.UnitY * -2f, Scale: 0.8f); + + int vomitAmt = Main.rand.Next(1, 3); + for (int i = 0; i < vomitAmt; i++) + { + Vector2 velocity = Projectile.oldVelocity * Main.rand.NextFloat(-0.8f, -0.6f); + int dustType = Utils.SelectRandom(Main.rand, DustID.ToxicBubble, DustID.GreenBlood, DustID.Blood); + int dust = Dust.NewDust(Projectile.Center + Main.rand.NextVector2Circular(Projectile.width, Projectile.height), 1, 1, dustType, velocity.X, velocity.Y, Scale: Main.rand.NextFloat(1f, 1.4f)); + Main.dust[dust].noGravity = true; + } + + if (Main.rand.NextBool(6)) + { + Vector2 velocity = Projectile.oldVelocity.RotatedByRandom(MathHelper.ToRadians(20f)) * Main.rand.NextFloat(-1.8f, -0.6f) * Projectile.direction; + Color color = Color.Lerp(Color.DarkOliveGreen, Color.Green, Main.rand.NextFloat()); + float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); + + TimedSmokeParticle vomit = new(Projectile.Center + Main.rand.NextVector2Circular(Projectile.width, Projectile.height), velocity, color, color, Main.rand.NextFloat(0.4f, 0.6f), Main.rand.NextFloat(0.8f, 1f), Main.rand.Next(25, 35), rotationSpeed); + GeneralParticleHandler.SpawnParticle(vomit, false, Enums.GeneralDrawLayer.BeforeProjectiles); + } + } + + private void Explode() + { + Projectile.knockBack = 8f; + Projectile.tileCollide = false; + Projectile.hostile = true; + Projectile.penetrate = -1; + Projectile.timeLeft = 6; + Projectile.velocity *= 0f; + Projectile.ExpandHitboxBy(80, 80); + + int dustCloudAmt = Main.rand.Next(12, 17); + for (int i = 0; i < dustCloudAmt; i++) + { + Vector2 spawnPosition = Projectile.Center; + Vector2 velocity = Main.rand.NextVector2Circular(8f, 8f); + Color color = Color.Lerp(Color.OrangeRed, Color.Orange, Main.rand.NextFloat()); + float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); + + TimedSmokeParticle explosionCloud = new(spawnPosition, velocity, new Color(10, 10, 10), color, Main.rand.NextFloat(1.2f, 1.4f), 1f, Main.rand.Next(20, 30), rotationSpeed); + GeneralParticleHandler.SpawnParticle(explosionCloud, true); + } + + int sparkAmt = Main.rand.Next(7, 13); + for (int i = 0; i < sparkAmt; i++) + { + Vector2 spawnPosition = Projectile.Center; + Vector2 velocity = Main.rand.NextVector2Circular(8f, 8f); + Color color = Color.Lerp(Color.Yellow, Color.Orange, Main.rand.NextFloat()); + + SparkParticle explosionSpark = new(spawnPosition, velocity, false, Main.rand.Next(20, 30), Main.rand.NextFloat(1f, 1.2f), color); + GeneralParticleHandler.SpawnParticle(explosionSpark, true); + } + + int dustAmt = Main.rand.Next(6, 9); + for (int i = 0; i < dustAmt; i++) + { + Vector2 spawnPosition = Projectile.Center + Main.rand.NextVector2Circular(8f, 8f); + Vector2 velocity = Main.rand.NextVector2Circular(8f, 8f); + Dust.NewDust(spawnPosition, 0, 0, DustID.Torch, velocity.X, velocity.Y, Scale: Main.rand.NextFloat(1.2f, 1.6f)); + } + + CalamityUtils.AddScreenshakeAt(Projectile.Center, 3f); + SoundEngine.PlaySound(SoundID.DD2_ExplosiveTrapExplode, Projectile.Center); + Projectile.ai[0] = 1f; + Projectile.netUpdate = true; + } + + public override bool PreKill(int timeLeft) + { + if (!HasExplodedYet) + { + Explode(); + return false; + } + + return true; + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + Explode(); + return false; + } + + public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac) + { + int targetIndex = Player.FindClosest(Projectile.Center, 1, 1); + Player target = Main.player[targetIndex]; + if (Projectile.Center.Y > target.Center.Y - 48f) + fallThrough = false; + + return true; + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Vector2 origin = texture.Size() * 0.5f; + SpriteEffects spriteEffects = Projectile.spriteDirection < 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + float timeLeftInterpolant = Utils.Remap(Projectile.timeLeft, 75, 0, 1f, 0f, true); + + if (CalamityClientConfig.Instance.Afterimages) + { + for (int i = 0; i < Projectile.oldPos.Length; ++i) + { + Vector2 afterimageDrawPosition = Projectile.oldPos[i] + Projectile.Size * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); + float trailLengthInterpolant = ((float)(Projectile.oldPos.Length - i) / (float)Projectile.oldPos.Length); + Color afterimageColor = Projectile.GetAlpha(Color.Orange) * 0.5f * trailLengthInterpolant * (1f - timeLeftInterpolant); + + Main.spriteBatch.Draw(texture, afterimageDrawPosition, null, afterimageColor, Projectile.rotation, origin, Projectile.scale * trailLengthInterpolant, spriteEffects, 0f); + } + } + + using (Main.spriteBatch.Scope()) + { + Effect tintShader = CalamityShaders.BasicTintShader.Value; + tintShader.Parameters["uColor"].SetValue(Color.White.ToVector3()); + tintShader.Parameters["uOpacity"].SetValue(1f - timeLeftInterpolant); + + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, tintShader, Main.GameViewMatrix.TransformationMatrix); + Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, spriteEffects, 0f); + Main.spriteBatch.End(); + } + + return false; + } + } +} diff --git a/Projectiles/Enemy/HorribleHogVomitChunk.cs b/Projectiles/Enemy/HorribleHogVomitChunk.cs new file mode 100644 index 0000000000..640d3da251 --- /dev/null +++ b/Projectiles/Enemy/HorribleHogVomitChunk.cs @@ -0,0 +1,145 @@ +using CalamityMod.Particles; +using Microsoft.CodeAnalysis; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Enemy +{ + public class HorribleHogVomitChunk : ModProjectile, ILocalizedModType + { + private static Asset[] VomitChunkTextures; + + private string[] VomitChunkTexturePaths = new string[] + { + "Terraria/Images/Gore_3", + "Terraria/Images/Gore_154", + "Terraria/Images/Gore_241", + "Terraria/Images/Gore_243", + "Terraria/Images/Gore_246", + "Terraria/Images/Gore_262", + "Terraria/Images/Gore_722", + "Terraria/Images/Gore_1214" + }; + + public ref float TextureVariant => ref Projectile.ai[0]; + + public new string LocalizationCategory => "Projectiles.Enemy"; + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void Load() + { + if (!Main.dedServ) + { + VomitChunkTextures = new Asset[VomitChunkTexturePaths.Length]; + for (int i = 0; i < VomitChunkTexturePaths.Length; i++) + VomitChunkTextures[i] = ModContent.Request(VomitChunkTexturePaths[i]); + } + } + + public override void SetStaticDefaults() + { + ProjectileID.Sets.TrailCacheLength[Type] = 8; + ProjectileID.Sets.TrailingMode[Type] = 0; + } + + public override void SetDefaults() + { + Projectile.width = 16; + Projectile.height = 16; + Projectile.penetrate = 1; + Projectile.timeLeft = 300; + Projectile.scale = 0f; + Projectile.hostile = true; + } + + public override void OnSpawn(IEntitySource source) + { + TextureVariant = Main.rand.Next(VomitChunkTexturePaths.Length); + Projectile.netUpdate = true; + } + + public override void AI() + { + Projectile.scale = MathHelper.Lerp(Projectile.scale, 1f, 0.25f); + Projectile.ExpandHitboxBy(Projectile.scale); + + Projectile.spriteDirection = Projectile.direction; + Projectile.rotation += Projectile.velocity.X * 0.035f; + if (Projectile.velocity.Y < 8f) + Projectile.velocity.Y += 0.125f; + + int vomitAmt = Main.rand.Next(1, 3); + for (int i = 0; i < vomitAmt; i++) + { + Vector2 velocity = Projectile.oldVelocity * Main.rand.NextFloat(-0.8f, -0.6f); + int dustType = Utils.SelectRandom(Main.rand, DustID.ToxicBubble, DustID.GreenBlood, DustID.Blood); + int dust = Dust.NewDust(Projectile.Center + Main.rand.NextVector2Circular(Projectile.width, Projectile.height), 1, 1, dustType, velocity.X, velocity.Y, Scale: Main.rand.NextFloat(1f, 1.4f)); + Main.dust[dust].noGravity = true; + } + + if (Main.rand.NextBool(6)) + { + Vector2 velocity = Projectile.oldVelocity.RotatedByRandom(MathHelper.ToRadians(20f)) * Main.rand.NextFloat(-1.8f, -0.6f) * Projectile.direction; + Color color = Color.Lerp(Color.DarkOliveGreen, Color.Green, Main.rand.NextFloat()); + float rotationSpeed = Main.rand.NextFloat(0.01f, 0.03f) * Main.rand.NextBool().ToDirectionInt(); + + TimedSmokeParticle vomit = new(Projectile.Center + Main.rand.NextVector2Circular(Projectile.width, Projectile.height), velocity, color, color, Main.rand.NextFloat(0.4f, 0.6f), Main.rand.NextFloat(0.8f, 1f), Main.rand.Next(25, 35), rotationSpeed); + GeneralParticleHandler.SpawnParticle(vomit, false, Enums.GeneralDrawLayer.BeforeProjectiles); + } + } + + public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac) + { + int targetIndex = Player.FindClosest(Projectile.Center, 1, 1); + Player target = Main.player[targetIndex]; + if (Projectile.Center.Y > target.Center.Y - 48f) + fallThrough = false; + + return true; + } + + public override void OnKill(int timeLeft) + { + int dustAmt = Main.rand.Next(15, 21); + for (int i = 0; i < dustAmt; i++) + { + Vector2 spawnPosition = Projectile.Center + Main.rand.NextVector2Circular(8f, 8f); + Vector2 velocity = Main.rand.NextVector2Circular(3f, 3f); + int dustType = Utils.SelectRandom(Main.rand, DustID.ToxicBubble, DustID.GreenBlood, DustID.Blood); + Dust.NewDust(spawnPosition, 0, 0, dustType, velocity.X, velocity.Y, Scale: Main.rand.NextFloat(1.2f, 1.8f)); + } + + SoundEngine.PlaySound(SoundID.NPCDeath21, Projectile.Center); + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = VomitChunkTextures[(int)TextureVariant].Value; + Vector2 origin = texture.Size() * 0.5f; + SpriteEffects spriteEffects = Projectile.spriteDirection < 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + + if (CalamityClientConfig.Instance.Afterimages) + { + for (int i = 0; i < Projectile.oldPos.Length; ++i) + { + Vector2 drawPos = Projectile.oldPos[i] + Projectile.Size * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); + float interpolant = ((float)(Projectile.oldPos.Length - i) / (float)Projectile.oldPos.Length); + Color color = Color.GreenYellow * interpolant; + + Main.spriteBatch.Draw(texture, drawPos, null, Projectile.GetAlpha(color) * 0.6f, Projectile.rotation, origin, Projectile.scale * interpolant * 1.25f, spriteEffects, 0f); + } + } + + Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, spriteEffects, 0f); + return false; + } + } +} diff --git a/Projectiles/Enemy/HorribleHogVomitEye.cs b/Projectiles/Enemy/HorribleHogVomitEye.cs new file mode 100644 index 0000000000..da33f6207c --- /dev/null +++ b/Projectiles/Enemy/HorribleHogVomitEye.cs @@ -0,0 +1,143 @@ +using CalamityMod.Graphics.Metaballs; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Enemy +{ + public class HorribleHogVomitEye : ModProjectile, ILocalizedModType + { + public static int PlayerSearchArea => 128; + + public ref float LockOnTime => ref Projectile.ai[0]; + + public ref float Timer => ref Projectile.ai[1]; + + public new string LocalizationCategory => "Projectiles.Enemy"; + + public override string Texture => "Terraria/Images/NPC_" + NPCID.DemonEye; + + public override void SetStaticDefaults() + { + Main.projFrames[Type] = 2; + ProjectileID.Sets.TrailCacheLength[Type] = 6; + ProjectileID.Sets.TrailingMode[Type] = 2; + } + + public override void SetDefaults() + { + Projectile.width = 16; + Projectile.height = 16; + Projectile.penetrate = -1; + Projectile.timeLeft = 480; + Projectile.scale = 0f; + Projectile.hostile = true; + Projectile.tileCollide = false; + } + + public override bool CanHitPlayer(Player target) => Projectile.scale > 0.15f; + + public override void AI() + { + Projectile.scale = MathHelper.Lerp(Projectile.scale, 0.75f, 0.125f); + Projectile.ExpandHitboxBy(Projectile.scale); + + int targetIndex = Player.FindClosest(Projectile.Center, 1, 1); + if (Main.player[targetIndex].dead || !Main.player.IndexInRange(targetIndex)) + { + Projectile.velocity *= 1.12f; + Projectile.tileCollide = true; + Projectile.rotation = Projectile.rotation.AngleLerp(Projectile.velocity.ToRotation() + MathHelper.Pi, 0.15f); + return; + } + + Player target = Main.player[targetIndex]; + if (Timer >= LockOnTime) + { + if (Timer <= LockOnTime + 45) + { + Projectile.velocity *= 0.94f; + Projectile.rotation = Projectile.rotation.AngleLerp(Projectile.AngleTo(target.Center) + MathHelper.Pi, 0.15f); + } + else + { + float turnResistance = 30f; + Vector2 directionToPoint = target.Center - Projectile.Center; + directionToPoint *= 30f / directionToPoint.Length(); + Vector2 idealVelocity = (Projectile.velocity * turnResistance + directionToPoint) / (turnResistance + 1f); + Projectile.velocity = Vector2.Lerp(Projectile.velocity, idealVelocity, 0.35f); + + Projectile.rotation = Projectile.rotation.AngleLerp(Projectile.velocity.ToRotation() + MathHelper.Pi, 0.15f); + Projectile.tileCollide = true; + } + } + else + { + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.Pi; + } + + Projectile.frameCounter++; + if (Projectile.frameCounter >= 4) + { + Projectile.frame++; + Projectile.frame %= 2; + Projectile.frameCounter = 0; + } + + Timer++; + } + + public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac) + { + int targetIndex = Player.FindClosest(Projectile.Center, 1, 1); + Player target = Main.player[targetIndex]; + if (Projectile.Center.Y > target.Center.Y - 48f) + fallThrough = false; + + return true; + } + + public override void OnKill(int timeLeft) + { + SoundEngine.PlaySound(SoundID.NPCDeath1, Projectile.Center); + int bloodAmt = Main.rand.Next(14, 19); + for (int i = 0; i < bloodAmt; i++) + { + Vector2 velocity = Main.rand.NextVector2Circular(8f, 8f); + Dust.NewDust(Projectile.Center, 1, 1, DustID.Blood, velocity.X, velocity.Y, Scale: Main.rand.NextFloat(1.2f, 1.4f)); + } + + if (!Main.dedServ) + { + Gore.NewGore(Projectile.Center, Projectile.oldVelocity * -0.8f, 1, 0.75f); + Gore.NewGore(Projectile.Center, Projectile.oldVelocity * -0.8f, 2, 0.75f); + } + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Rectangle frame = texture.Frame(1, Main.projFrames[Type], 0, Projectile.frame); + Vector2 origin = frame.Size() * 0.5f; + + if (CalamityClientConfig.Instance.Afterimages) + { + for (int i = 0; i < Projectile.oldPos.Length; ++i) + { + Vector2 afterimageDrawPosition = Projectile.oldPos[i] + Projectile.Size * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); + float trailLengthInterpolant = ((float)(Projectile.oldPos.Length - i) / (float)Projectile.oldPos.Length); + Color afterimgeColor = Color.Red * trailLengthInterpolant; + + Main.spriteBatch.Draw(texture, afterimageDrawPosition, frame, Projectile.GetAlpha(afterimgeColor) * 0.6f, Projectile.oldRot[i], origin, Projectile.scale * trailLengthInterpolant * 1.25f, 0, 0f); + } + } + + Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition, frame, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, 0, 0f); + return false; + } + } +} diff --git a/Projectiles/Enemy/HorribleHogZombieSpawner.cs b/Projectiles/Enemy/HorribleHogZombieSpawner.cs new file mode 100644 index 0000000000..aafb9a330b --- /dev/null +++ b/Projectiles/Enemy/HorribleHogZombieSpawner.cs @@ -0,0 +1,196 @@ +using System.Collections.Generic; +using CalamityMod.NPCs.NormalNPCs; +using CalamityMod.Particles; +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Enemy +{ + public class HorribleHogZombieSpawner : ModProjectile, ILocalizedModType + { + private static Asset ZombieArmTexture; + private static Asset BackglowTexture; + + private static SoundStyle ZombieEmergeSound = new("CalamityMod/Sounds/Custom/HorribleHog/HorribleHogZombieEmerge"); + + public List Zombies = new() + { + NPCID.Zombie, + NPCID.FemaleZombie, + NPCID.BaldZombie, + NPCID.PincushionZombie, + NPCID.SlimedZombie, + NPCID.SwampZombie, + NPCID.TwiggyZombie, + NPCID.TorchZombie, + NPCID.BloodZombie, + NPCID.MaggotZombie, + ModContent.NPCType(), + }; + + public static CalamityUtils.CurveSegment Rise => new(CalamityUtils.EasingType.ExpOut, 0f, 0f, 1.08f); + + public static CalamityUtils.CurveSegment Fallback => new(CalamityUtils.EasingType.SineOut, 0.08f, Rise.EndingHeight, -0.08f); + + public static CalamityUtils.CurveSegment Linger => new(CalamityUtils.EasingType.Linear, 0.20f, Fallback.EndingHeight, 0f); + + public static CalamityUtils.CurveSegment BounceUp => new(CalamityUtils.EasingType.PolyInOut, 0.82f, Linger.EndingHeight, 0.14f, 4); + + public static CalamityUtils.CurveSegment Descend => new(CalamityUtils.EasingType.PolyOut, 0.92f, BounceUp.EndingHeight, -1.48f, 3); + + public float ZombieArmRiseAnimation => CalamityUtils.PiecewiseAnimation(Timer / MaxTime, Rise, Fallback, Linger, BounceUp, Descend); + + public ref float Timer => ref Projectile.ai[0]; + + public ref float MaxTime => ref Projectile.ai[1]; + + public new string LocalizationCategory => "Projectiles.Enemy"; + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void Load() + { + if (!Main.dedServ) + { + ZombieArmTexture = ModContent.Request("Terraria/Images/Item_" + ItemID.ZombieArm); + BackglowTexture = ModContent.Request("Terraria/Images/Extra_60"); + } + } + + public override void SetDefaults() + { + Projectile.width = 4; + Projectile.height = 4; + Projectile.penetrate = -1; + Projectile.hostile = true; + Projectile.hide = true; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + } + + public override void OnSpawn(IEntitySource source) + { + Projectile.spriteDirection = Main.rand.NextBool().ToDirectionInt(); + Projectile.rotation = MathHelper.ToRadians(Main.rand.NextFloat(-8f, 8f)); + } + + public override bool ShouldUpdatePosition() => false; + + public override bool? CanDamage() => false; + + public override void AI() + { + if (Timer >= MaxTime) + { + Projectile.Kill(); + return; + } + + if (Main.rand.NextBool(6)) + { + int dustAmt = Main.rand.Next(1, 2); + for (int i = 0; i < dustAmt; i++) + { + Vector2 dustPosition = Projectile.Bottom + Main.rand.NextVector2Circular(12f, 0f); + Vector2 dustVelocity = new Vector2(Main.rand.NextFloat(-2f, 2f), Main.rand.NextFloat(-3f, -2f)); + int dustType = Main.rand.Next(2); + Dust.NewDustPerfect(dustPosition, dustType, dustVelocity); + } + } + + int dustCloudAmt = Main.rand.Next(1, 2); + for (int i = 0; i < dustCloudAmt; i++) + { + Vector2 dustCloudPosition = Projectile.Bottom + Main.rand.NextVector2Circular(12f, 0f); + float dustCloudScale = Main.rand.NextFloat(0.2f, 0.3f); + Color dustCloudColor = Color.Lerp(Color.SandyBrown, Color.SaddleBrown, Main.rand.NextFloat()); + TimedSmokeParticle dustCloud = new(dustCloudPosition, Vector2.Zero, dustCloudColor, dustCloudColor, dustCloudScale, 1f, Main.rand.Next(15, 30)); + GeneralParticleHandler.SpawnParticle(dustCloud, true); + } + + Timer++; + } + + public override void OnKill(int timeLeft) + { + if (Main.netMode != NetmodeID.MultiplayerClient) + { + // Raincoat Zombies get added when its raining. + if (Main.raining) + Zombies.Add(NPCID.ZombieRaincoat); + + // Multiple Bucket Zombies and Blood Zombies get added in Revengeance and Death Mode to increase the chances of them spawning. + if (CalamityWorld.revenge) + { + for (int i = 0; i < 3; i++) + Zombies.Add(NPCID.BloodZombie); + } + + if (CalamityWorld.death) + { + for (int i = 0; i < 4; i++) + { + Zombies.Add(ModContent.NPCType()); + Zombies.Add(NPCID.BloodZombie); + } + } + + int zombieType = Utils.SelectRandom(Main.rand, [.. Zombies]); + int zombie = NPC.NewNPC(Projectile.GetItemSource_FromThis(), (int)Projectile.Center.X, (int)Projectile.Center.Y, zombieType); + Main.npc[zombie].velocity = Vector2.UnitY * -4f; + } + + int dustAmt = Main.rand.Next(12, 19); + for (int i = 0; i < dustAmt; i++) + { + Vector2 dustPosition = Projectile.Bottom + Main.rand.NextVector2Circular(12f, 0f); + Vector2 dustVelocity = Vector2.UnitY * Main.rand.NextFloat(-6f, -4f); + int dustType = Main.rand.Next(2); + Dust.NewDust(dustPosition, 0, 0, dustType, dustVelocity.X, dustVelocity.Y); + } + + int dustCloudAmt = Main.rand.Next(9, 13); + for (int i = 0; i < dustCloudAmt; i++) + { + Vector2 dustCloudPosition = Projectile.Bottom + Main.rand.NextVector2Circular(12f, 0f); + Vector2 dustCloudVelocity = new Vector2(Main.rand.NextFloat(-4f, 4f), Main.rand.NextFloat(-6f, -4f)); + float dustCloudScale = Main.rand.NextFloat(1.2f, 1.6f); + Color dustCloudColor = Color.Lerp(Color.SandyBrown, Color.SaddleBrown, Main.rand.NextFloat()); + SmallSmokeParticle dustCloud = new(dustCloudPosition, dustCloudVelocity, dustCloudColor, dustCloudColor, dustCloudScale, Main.rand.Next(120, 150)); + GeneralParticleHandler.SpawnParticle(dustCloud, true); + } + + SoundEngine.PlaySound(ZombieEmergeSound, Projectile.Center); + } + + public override void DrawBehind(int index, List behindNPCsAndTiles, List behindNPCs, List behindProjectiles, List overPlayers, List overWiresUI) + { + behindNPCsAndTiles.Add(index); + } + + public override bool PreDraw(ref Color lightColor) + { + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + float scaleX = MathHelper.Lerp(0f, 1f, ZombieArmRiseAnimation); + Vector2 backglowScale = new(scaleX, 1f); + for (int i = 0; i < 2; i++) + Main.spriteBatch.Draw(BackglowTexture.Value, drawPosition, null, Color.Red with { A = 0 } * ZombieArmRiseAnimation, 0f, BackglowTexture.Size() * 0.5f, backglowScale, 0, 0f); + + float armScale = MathHelper.Lerp(0.2f, 1f, ZombieArmRiseAnimation); + float armRotation = Projectile.rotation - MathHelper.PiOver4 + MathHelper.ToRadians(Main.rand.NextFloat(-2f, 2f)); + + float height = MathHelper.Lerp(68f, 12f, ZombieArmRiseAnimation); + Vector2 armDrawPostion = drawPosition + Vector2.UnitY * height; + + Main.spriteBatch.Draw(ZombieArmTexture.Value, armDrawPostion, null, lightColor, armRotation, ZombieArmTexture.Size() * new Vector2(0f, 1f), armScale, 0, 0f); + return false; + } + } +} diff --git a/Projectiles/Pets/Beldum.cs b/Projectiles/Pets/Beldum.cs new file mode 100644 index 0000000000..14de75451f --- /dev/null +++ b/Projectiles/Pets/Beldum.cs @@ -0,0 +1,173 @@ +using System; +using CalamityMod.Buffs.Pets; +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.DataStructures; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Pets +{ + public class Beldum : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Pets"; + public override void SetStaticDefaults() + { + Main.projPet[Type] = true; + Main.projFrames[Type] = 4; + ProjectileID.Sets.CharacterPreviewAnimations[Type] = ProjectileID.Sets.SimpleLoop(0, 0, 1) + .WithOffset(-8f, -20f).WithSpriteDirection(-1).WhenNotSelected(0, 0); + } + + public override void SetDefaults() + { + Projectile.netImportant = true; + Projectile.width = 32; + Projectile.height = 32; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.timeLeft *= 5; + Projectile.tileCollide = false; + } + + public override void AI() + { + Player player = Main.player[Projectile.owner]; + Vector2 beldumcenter = Projectile.Center; + Vector2 vectorbeldum = player.Center - beldumcenter; + float playerdistance = vectorbeldum.Length(); + if (!player.active) + { + Projectile.active = false; + return; + } + + //Delete the projectile if the player doesnt have the buff or is very far away (dunno if this needs to be deleted) + if (!player.HasBuff(ModContent.BuffType()) || playerdistance >= 4000f) + { + Projectile.Kill(); + } + + CalamityPlayer modPlayer = player.Calamity(); + if (player.dead) + { + modPlayer.beldum = false; + } + if (modPlayer.beldum) + { + Projectile.timeLeft = 2; + } + + if (player.InInteractionRange((int)Projectile.Center.X / 16, (int)Projectile.Center.Y / 16, TileReachCheckSettings.Simple)) + { + if (Projectile.Hitbox.Contains(player.ClampedMouseWorld().ToPoint())) + { + if (player.controlUseItem && player.velocity == Vector2.Zero) + { + Projectile.ai[1] = Projectile.ai[1] == 1 ? 0 : 1; + } + else if (player.controlUseTile) + { + Projectile.ai[1] = Projectile.ai[1] == 2 ? 0 : 2; + } + } + } + + // Normal behaviour + if (Projectile.ai[1] == 0) + { + Projectile.FloatingPetAI(false, 0); + } + // Being pet + else if (Projectile.ai[1] == 1) + { + if (player.velocity != Vector2.Zero || player.HasIFrames()) + { + Projectile.ai[1] = 0; + } + else + { + Projectile.Center = player.Center + new Vector2(40 * player.direction, 0); + Projectile.velocity = Vector2.Zero; + PlayerPetting(); + } + } + // Shoulder + else + { + Projectile.Center = player.Center + new Vector2(0, -20 * player.gravDir) + Vector2.UnitY * player.gfxOffY; + } + + if (Projectile.ai[1] != 2) + { + Projectile.ai[0]++; + if (Projectile.ai[1] == 0) + { + Projectile.spriteDirection = -Projectile.velocity.X.DirectionalSign(); + Projectile.rotation = MathF.Sin(Projectile.ai[0] * 0.05f) * MathHelper.ToRadians(20); + } + else + { + Projectile.spriteDirection = -Projectile.DirectionTo(player.Center).X.DirectionalSign(); + Projectile.rotation = MathF.Sin(Projectile.ai[0] * 0.05f) * MathHelper.ToRadians(5); + } + } + else + { + Projectile.ai[0] = 0; + Projectile.rotation = 0; + Projectile.spriteDirection = -player.direction; + } + + if (Main.rand.NextBool(600) && Projectile.ai[2] == 0) + { + Projectile.ai[2] = 1; + } + + if (Projectile.ai[2] == 1) + { + Projectile.frameCounter++; + if (Projectile.frameCounter > 3) + { + Projectile.frameCounter = 0; + Projectile.frame++; + } + + if (Projectile.frame > 3) + { + Projectile.frame = 0; + Projectile.ai[2] = 0; + } + } + } + + public void PlayerPetting() + { + Player player = Main.player[Projectile.owner]; + int targetDirection = (Projectile.Center.X > player.Center.X) ? 1 : (-1); + player.StopVanityActions(); + player.ChangeDir(targetDirection); + player.gravDir = 1f; + int completion = player.miscCounter % 14 / 7; + Player.CompositeArmStretchAmount stretch = Player.CompositeArmStretchAmount.ThreeQuarters; + if (completion == 1) + { + stretch = Player.CompositeArmStretchAmount.Full; + } + player.SetCompositeArmBack(enabled: true, stretch, player.DirectionTo(Projectile.Center).ToRotation() - MathHelper.PiOver2); + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D tex = TextureAssets.Projectile[Type].Value; + SpriteEffects fx = Projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + if (Main.player[Projectile.owner].gravDir == -1) + fx |= SpriteEffects.FlipVertically; + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition + Vector2.UnitY * MathF.Cos(Projectile.ai[0] * 0.05f) * (Projectile.ai[1] == 0 ? 10 : 2), tex.Frame(1, 4, 0, Projectile.frame), Projectile.GetAlpha(lightColor), Projectile.rotation, new Vector2(tex.Width / 2, tex.Height / Main.projFrames[Type] / 2), Projectile.scale, fx); + return false; + } + } +} diff --git a/Projectiles/Pets/Beldum.png b/Projectiles/Pets/Beldum.png new file mode 100644 index 0000000000..ff86674959 Binary files /dev/null and b/Projectiles/Pets/Beldum.png differ diff --git a/Projectiles/PowderTransformationsProjectile.cs b/Projectiles/PowderTransformationsProjectile.cs new file mode 100644 index 0000000000..65e26c45d6 --- /dev/null +++ b/Projectiles/PowderTransformationsProjectile.cs @@ -0,0 +1,52 @@ +using CalamityMod.NPCs.NormalNPCs; +using CalamityMod.NPCs.NormalNPCs.HorribleHog; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles +{ + public class PowderTransformationsProjectile : GlobalProjectile + { + public override bool AppliesToEntity(Projectile entity, bool lateInstantiation) + { + return entity.type == ProjectileID.VilePowder || entity.type == ProjectileID.ViciousPowder || entity.type == ProjectileID.PurificationPowder; + } + + public override void AI(Projectile projectile) + { + // Transform certain NPCs into different variants when contact is made with Vile/Vicious Powder or Purification Powder. + // Currently only used for Piggy, Divine Swine and Horrible Hog. + + bool isPurePowder = projectile.type == ProjectileID.PurificationPowder; + bool isEvilPowder = projectile.type == ProjectileID.VilePowder || projectile.type == ProjectileID.ViciousPowder; + + foreach (NPC npc in Main.ActiveNPCs) + { + bool targetIsPiggy = npc.type == ModContent.NPCType() || npc.type == ModContent.NPCType(); + bool targetIsDivineSwine = npc.type == ModContent.NPCType(); + bool targetIsHorribleHog = npc.type == ModContent.NPCType(); + + if (!targetIsPiggy && !targetIsDivineSwine && !targetIsHorribleHog) + continue; + + if (projectile.Hitbox.Intersects(npc.Hitbox)) + { + if (targetIsPiggy && npc.ModNPC().TryTransformingIntoVariant()) + { + if (isEvilPowder) + npc.ModNPC().TransformIntoVariant(ModContent.NPCType()); + else if (isPurePowder) + npc.ModNPC().TransformIntoVariant(ModContent.NPCType()); + } + + if (targetIsDivineSwine && isEvilPowder && npc.ModNPC().TryTransformingIntoPiggy()) + npc.ModNPC().TransformIntoPiggy(); + + if (targetIsHorribleHog && isPurePowder && npc.ModNPC().TryTransformingIntoPiggy()) + npc.ModNPC().TransformIntoPiggy(); + } + } + } + } +} diff --git a/Projectiles/Rogue/FrostyFlareStealth.cs b/Projectiles/Rogue/FrostyFlareStealth.cs index a9abc5f43b..9577a5e22e 100644 --- a/Projectiles/Rogue/FrostyFlareStealth.cs +++ b/Projectiles/Rogue/FrostyFlareStealth.cs @@ -18,7 +18,7 @@ namespace CalamityMod.Projectiles.Rogue Projectile.coldDamage = true; Projectile.friendly = true; Projectile.penetrate = -1; - Projectile.timeLeft = 300; + Projectile.timeLeft = 600; Projectile.DamageType = RogueDamageClass.Instance; Projectile.usesIDStaticNPCImmunity = true; Projectile.idStaticNPCHitCooldown = 10; diff --git a/Sounds/Custom/DivineSwine/DivineSwineCoinFail1.ogg b/Sounds/Custom/DivineSwine/DivineSwineCoinFail1.ogg new file mode 100644 index 0000000000..5f3d4ce420 Binary files /dev/null and b/Sounds/Custom/DivineSwine/DivineSwineCoinFail1.ogg differ diff --git a/Sounds/Custom/DivineSwine/DivineSwineCoinFail2.ogg b/Sounds/Custom/DivineSwine/DivineSwineCoinFail2.ogg new file mode 100644 index 0000000000..5af604670c Binary files /dev/null and b/Sounds/Custom/DivineSwine/DivineSwineCoinFail2.ogg differ diff --git a/Sounds/Custom/DivineSwine/DivineSwineCoinFail3.ogg b/Sounds/Custom/DivineSwine/DivineSwineCoinFail3.ogg new file mode 100644 index 0000000000..5080c3b101 Binary files /dev/null and b/Sounds/Custom/DivineSwine/DivineSwineCoinFail3.ogg differ diff --git a/Sounds/Custom/DivineSwine/DivineSwineCoinPass1.ogg b/Sounds/Custom/DivineSwine/DivineSwineCoinPass1.ogg new file mode 100644 index 0000000000..2e7fb5a471 Binary files /dev/null and b/Sounds/Custom/DivineSwine/DivineSwineCoinPass1.ogg differ diff --git a/Sounds/Custom/DivineSwine/DivineSwineCoinPass2.ogg b/Sounds/Custom/DivineSwine/DivineSwineCoinPass2.ogg new file mode 100644 index 0000000000..a195c3cc36 Binary files /dev/null and b/Sounds/Custom/DivineSwine/DivineSwineCoinPass2.ogg differ diff --git a/Sounds/Custom/DivineSwine/DivineSwineIdle1.ogg b/Sounds/Custom/DivineSwine/DivineSwineIdle1.ogg new file mode 100644 index 0000000000..6c0ad78480 Binary files /dev/null and b/Sounds/Custom/DivineSwine/DivineSwineIdle1.ogg differ diff --git a/Sounds/Custom/DivineSwine/DivineSwineIdle2.ogg b/Sounds/Custom/DivineSwine/DivineSwineIdle2.ogg new file mode 100644 index 0000000000..13b5108c9e Binary files /dev/null and b/Sounds/Custom/DivineSwine/DivineSwineIdle2.ogg differ diff --git a/Sounds/Custom/DivineSwine/DivineSwineIdle3.ogg b/Sounds/Custom/DivineSwine/DivineSwineIdle3.ogg new file mode 100644 index 0000000000..d8ed0521be Binary files /dev/null and b/Sounds/Custom/DivineSwine/DivineSwineIdle3.ogg differ diff --git a/Sounds/Custom/DivineSwine/DivineSwineIdle4.ogg b/Sounds/Custom/DivineSwine/DivineSwineIdle4.ogg new file mode 100644 index 0000000000..1425ea5cc8 Binary files /dev/null and b/Sounds/Custom/DivineSwine/DivineSwineIdle4.ogg differ diff --git a/Sounds/Custom/DivineSwine/DivineSwineNearbyLoop.ogg b/Sounds/Custom/DivineSwine/DivineSwineNearbyLoop.ogg new file mode 100644 index 0000000000..3f139a4bac Binary files /dev/null and b/Sounds/Custom/DivineSwine/DivineSwineNearbyLoop.ogg differ 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/HorribleHogDiggingFast.ogg b/Sounds/Custom/HorribleHog/HorribleHogDiggingFast.ogg new file mode 100644 index 0000000000..25b91a680e Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogDiggingFast.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogDiggingSlow.ogg b/Sounds/Custom/HorribleHog/HorribleHogDiggingSlow.ogg new file mode 100644 index 0000000000..22ade083c5 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogDiggingSlow.ogg 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/HorribleHogHiccup1.ogg b/Sounds/Custom/HorribleHog/HorribleHogHiccup1.ogg new file mode 100644 index 0000000000..e222b6edb4 Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogHiccup1.ogg differ diff --git a/Sounds/Custom/HorribleHog/HorribleHogHiccup2.ogg b/Sounds/Custom/HorribleHog/HorribleHogHiccup2.ogg new file mode 100644 index 0000000000..f2cf0ec66e Binary files /dev/null and b/Sounds/Custom/HorribleHog/HorribleHogHiccup2.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/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/Custom/Piggy/PiggyIdle_Grunt1.ogg b/Sounds/Custom/Piggy/PiggyIdle_Grunt1.ogg new file mode 100644 index 0000000000..079759cdad Binary files /dev/null and b/Sounds/Custom/Piggy/PiggyIdle_Grunt1.ogg differ diff --git a/Sounds/Custom/Piggy/PiggyIdle_Grunt2.ogg b/Sounds/Custom/Piggy/PiggyIdle_Grunt2.ogg new file mode 100644 index 0000000000..b1c5986a90 Binary files /dev/null and b/Sounds/Custom/Piggy/PiggyIdle_Grunt2.ogg differ diff --git a/Sounds/Custom/Piggy/PiggyIdle_Grunt3.ogg b/Sounds/Custom/Piggy/PiggyIdle_Grunt3.ogg new file mode 100644 index 0000000000..9948305206 Binary files /dev/null and b/Sounds/Custom/Piggy/PiggyIdle_Grunt3.ogg differ diff --git a/Sounds/Custom/Piggy/PiggyIdle_SnortYip1.ogg b/Sounds/Custom/Piggy/PiggyIdle_SnortYip1.ogg new file mode 100644 index 0000000000..65bf10904e Binary files /dev/null and b/Sounds/Custom/Piggy/PiggyIdle_SnortYip1.ogg differ diff --git a/Sounds/Custom/Piggy/PiggyIdle_SnortYip2.ogg b/Sounds/Custom/Piggy/PiggyIdle_SnortYip2.ogg new file mode 100644 index 0000000000..ef78b4e388 Binary files /dev/null and b/Sounds/Custom/Piggy/PiggyIdle_SnortYip2.ogg differ diff --git a/Sounds/Custom/Piggy/PiggyIdle_SnortYip3.ogg b/Sounds/Custom/Piggy/PiggyIdle_SnortYip3.ogg new file mode 100644 index 0000000000..9019c3c009 Binary files /dev/null and b/Sounds/Custom/Piggy/PiggyIdle_SnortYip3.ogg differ diff --git a/Sounds/Custom/Piggy/PiggyIdle_Yip1.ogg b/Sounds/Custom/Piggy/PiggyIdle_Yip1.ogg new file mode 100644 index 0000000000..4f6cbb0608 Binary files /dev/null and b/Sounds/Custom/Piggy/PiggyIdle_Yip1.ogg differ diff --git a/Sounds/Custom/Piggy/PiggyIdle_Yip2.ogg b/Sounds/Custom/Piggy/PiggyIdle_Yip2.ogg new file mode 100644 index 0000000000..35354c6527 Binary files /dev/null and b/Sounds/Custom/Piggy/PiggyIdle_Yip2.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 new file mode 100644 index 0000000000..20989e8a83 Binary files /dev/null and b/Sounds/NPCKilled/HorribleHogDeath.ogg differ diff --git a/Sounds/NPCKilled/PiggyDeath1.ogg b/Sounds/NPCKilled/PiggyDeath1.ogg new file mode 100644 index 0000000000..bf433830bf Binary files /dev/null and b/Sounds/NPCKilled/PiggyDeath1.ogg differ diff --git a/Sounds/NPCKilled/PiggyDeath2.ogg b/Sounds/NPCKilled/PiggyDeath2.ogg new file mode 100644 index 0000000000..e3431f86b8 Binary files /dev/null and b/Sounds/NPCKilled/PiggyDeath2.ogg differ diff --git a/Systems/World/WorldgenManagementSystem.cs b/Systems/World/WorldgenManagementSystem.cs index b89ef802cf..7cd974f5e0 100644 --- a/Systems/World/WorldgenManagementSystem.cs +++ b/Systems/World/WorldgenManagementSystem.cs @@ -373,6 +373,12 @@ namespace CalamityMod.Systems SulphurousSea.SulphurSeaGenerationAfterAbyss(); })); + tasks.Insert(++currentFinalIndex, new PassLegacy("Iron Ball", (progress, config) => + { + progress.Message = Language.GetOrRegister("Mods.CalamityMod.UI.IronBall").Value; + MiscWorldgenRoutines.GenerateIronBall(); + })); + // No Traps/GFB Auric Land Mines if (Main.noTrapsWorld) { diff --git a/Tiles/Furniture/PiggyCageTile.cs b/Tiles/Furniture/PiggyCageTile.cs index 8eba891699..007e934bd7 100644 --- a/Tiles/Furniture/PiggyCageTile.cs +++ b/Tiles/Furniture/PiggyCageTile.cs @@ -38,16 +38,12 @@ namespace CalamityMod.Tiles.Furniture public override void AnimateTile(ref int frame, ref int frameCounter) { - int frameAmt = 34; + int frameAmt = 18; int timeNeeded = 6; - if (frame == 0) + if (frame == 0 || frame == 9) { timeNeeded = 90; } - if (frame == 25) - { - timeNeeded = 30; - } frameCounter++; if (frameCounter >= timeNeeded) { diff --git a/Tiles/Furniture/PiggyCageTile.png b/Tiles/Furniture/PiggyCageTile.png index dd667ca4c3..53138e3e51 100644 Binary files a/Tiles/Furniture/PiggyCageTile.png and b/Tiles/Furniture/PiggyCageTile.png differ diff --git a/Tiles/IronBallPlaced.cs b/Tiles/IronBallPlaced.cs new file mode 100644 index 0000000000..be04d56908 --- /dev/null +++ b/Tiles/IronBallPlaced.cs @@ -0,0 +1,53 @@ +using System; +using CalamityMod.Items.Materials; +using CalamityMod.Items.Pets; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ObjectData; + +namespace CalamityMod.Tiles +{ + public class IronBallPlaced : ModTile + { + public static Asset GlowTexture = null; + + public override void Load() + { + GlowTexture = ModContent.Request("CalamityMod/Tiles/IronBallPlaced_Glow"); + } + + public override void SetStaticDefaults() + { + Main.tileFrameImportant[Type] = true; + Main.tileLighted[Type] = true; + + TileObjectData.newTile.CopyFrom(TileObjectData.Style1x1); + TileObjectData.newTile.StyleHorizontal = true; + TileObjectData.newTile.LavaDeath = false; + TileObjectData.newTile.DrawYOffset = 2; + TileObjectData.addTile(Type); + + DustType = DustID.Silver; + + AddMapEntry(new Color(108, 118, 134)); + RegisterItemDrop(ModContent.ItemType()); + FlexibleTileWand.RubblePlacementSmall.AddVariations(ModContent.ItemType(), Type, 0); + } + + public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + { + // Dim flickering red light + r = MathF.Sin(Main.GlobalTimeWrappedHourly * 20) * 0.05f + 0.3f; + } + + public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + { + spriteBatch.Draw(GlowTexture.Value, new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + CalamityUtils.TileDrawOffset, new Rectangle(Main.tile[i, j].TileFrameX, Main.tile[i, j].TileFrameY, 16, 16), Color.White); + } + } +} diff --git a/Tiles/IronBallPlaced.png b/Tiles/IronBallPlaced.png new file mode 100644 index 0000000000..232ca8d88f Binary files /dev/null and b/Tiles/IronBallPlaced.png differ diff --git a/Tiles/IronBallPlaced_Glow.png b/Tiles/IronBallPlaced_Glow.png new file mode 100644 index 0000000000..ae2214656d Binary files /dev/null and b/Tiles/IronBallPlaced_Glow.png differ diff --git a/Tiles/MonsterBanner.cs b/Tiles/MonsterBanner.cs index 9048bd8966..a7522beb4f 100644 --- a/Tiles/MonsterBanner.cs +++ b/Tiles/MonsterBanner.cs @@ -5,6 +5,7 @@ using CalamityMod.NPCs.Crags; using CalamityMod.NPCs.Deconstructors; using CalamityMod.NPCs.DraedonLabThings; using CalamityMod.NPCs.NormalNPCs; +using CalamityMod.NPCs.NormalNPCs.HorribleHog; using CalamityMod.NPCs.PlagueEnemies; using CalamityMod.NPCs.SulphurousSea; using CalamityMod.NPCs.SunkenSea; @@ -529,6 +530,9 @@ namespace CalamityMod.Tiles /* case 151: npc = NPCType(); break; */ + case 152: + npc = NPCType(); + break; default: break; } diff --git a/Tiles/MonsterBanner.png b/Tiles/MonsterBanner.png index 006fcf29de..218f14301a 100644 Binary files a/Tiles/MonsterBanner.png and b/Tiles/MonsterBanner.png differ diff --git a/Utilities/CollisionUtils.cs b/Utilities/CollisionUtils.cs index 5788363cb0..ca6fb43d4b 100644 --- a/Utilities/CollisionUtils.cs +++ b/Utilities/CollisionUtils.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using System; +using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; @@ -54,12 +55,46 @@ namespace CalamityMod return (dx * dx + dy * dy) <= (radius * radius); } + /// + /// Creates an arc around an entity and returns true if a specific collision check is reached for a specific point along the arc. + ///
+ /// By default, this will check if any individual point along the arc is stuck inside of a solid tile. + ///
+ ///
+ /// The minimum angle of the arc in radians. + /// The maximum angle of the arc in radians. + /// By how many radians should the loop increment by when looping between the two angles. This will affect how many points the arc has. + /// The base position the arc should be scribed from. Defaults to the entity's center. + /// The direction of the arc. Defaults to the entity's velocity. + /// The radius of the arc from the base position in pixels. Defaults to 32. + /// An optional delegate parameter of two Vector2 inputs, the base position and the individual arc point, which can be used to + /// override the default collision check logic. + public static bool ArcCollisionCheck(this Entity entity, float minRadians, float maxRadians, float radiansIncrement, Vector2? basePosition = null, Vector2? arcDirection = null, float arcRadius = 32f, Func optionalCollisionCheckOverride = null) + { + for (float i = minRadians; i < maxRadians; i += radiansIncrement) + { + Vector2 arcPointBase = basePosition ?? entity.Center; + Vector2 checkDirection = arcDirection ?? entity.velocity; + Vector2 arcPoint = arcPointBase + checkDirection.SafeNormalize(Vector2.Zero).RotatedBy(i) * arcRadius; + + bool collisionCheck = !Collision.CanHitLine(arcPointBase, 1, 1, arcPoint, 1, 1); + if (optionalCollisionCheckOverride is not null) + collisionCheck = optionalCollisionCheckOverride.Invoke(arcPointBase, arcPoint); + + if (collisionCheck) + return true; + } + + return false; + } + /// /// Determines the distance required before a ray in a given direction from a given starting position hits solid tiles. Gives up after a certain quantity of tiles, or when a world border is reached. /// /// The point to check from. /// The direction in which tiles are checked. Will always be a unit vector. - public static float? DistanceToTileCollisionHit(Vector2 startingPoint, Vector2 checkDirection, int giveUpLimit = 500) + /// An optional delegate function for overriding the base tile check logic with your own custom logic. + public static float? DistanceToTileCollisionHit(Vector2 startingPoint, Vector2 checkDirection, int giveUpLimit = 500, Func optionalTileCheckOverride = null) { // Ensure that the check direction is normalized. checkDirection = checkDirection.SafeNormalize(Vector2.Zero); @@ -78,12 +113,17 @@ namespace CalamityMod // Since Terraria's tile coordinate system is discrete and does not care for more advanced concepts, // the amount of tiles searched such far is a sufficient answer. Tile tile = ParanoidTileRetrieval(checkPosition.X, checkPosition.Y); - if (WorldGen.SolidTile(tile) || (checkDirection.Y >= 0f && tile.HasTile && Main.tileSolidTop[tile.TileType])) + bool validTileHasBeenHit = WorldGen.SolidTile(tile) || (checkDirection.Y >= 0f && tile.HasTile && Main.tileSolidTop[tile.TileType]); + if (optionalTileCheckOverride is not null) + validTileHasBeenHit = optionalTileCheckOverride.Invoke(tile); + + if (validTileHasBeenHit) return i; } return null; } + /// /// Determines the distance required before a ray in a given direction from a given starting position hits solid tiles, taking slopes into account. /// diff --git a/Utilities/DrawingUtils.cs b/Utilities/DrawingUtils.cs index 0fc90e184c..c7659c381d 100644 --- a/Utilities/DrawingUtils.cs +++ b/Utilities/DrawingUtils.cs @@ -39,6 +39,20 @@ namespace CalamityMod new Color(199, 62, 62), }; + /// + /// A custom which subtracts overlapping colors instead of adding them.

+ /// This uses the same settings as the blending used for the Light's Bane projectile. + ///
+ public static readonly BlendState SubtractiveBlending = new() + { + ColorBlendFunction = BlendFunction.ReverseSubtract, + ColorDestinationBlend = Blend.One, + ColorSourceBlend = Blend.SourceAlpha, + AlphaBlendFunction = BlendFunction.ReverseSubtract, + AlphaDestinationBlend = Blend.One, + AlphaSourceBlend = Blend.SourceAlpha + }; + /// /// The transformation matrix used for drawing backgrounds in Vanilla Terraria. Should be used for any custom background drawing or CustomSky /// drawing, such as independent sky entities or background shader effects. diff --git a/Utilities/DropHelper.cs b/Utilities/DropHelper.cs index 7dae35e350..7cdf498d1f 100644 --- a/Utilities/DropHelper.cs +++ b/Utilities/DropHelper.cs @@ -275,7 +275,7 @@ namespace CalamityMod public static void AddRevBagAccessories(this ILoot loot) { var lcr = new LeadingConditionRule(If(() => CalamityWorld.revenge)); - lcr.Add(new OneFromOptionsDropRule(20, 1, ModContent.ItemType(), ModContent.ItemType(), ModContent.ItemType())); + lcr.Add(new OneFromOptionsDropRule(20, 1, ModContent.ItemType(), ModContent.ItemType())); loot.Add(lcr); } diff --git a/World/DraedonStructures.cs b/World/DraedonStructures.cs index b4441f1453..cd940120f8 100644 --- a/World/DraedonStructures.cs +++ b/World/DraedonStructures.cs @@ -307,7 +307,7 @@ namespace CalamityMod.World #region Sunken Sea Lab - public static void FillSunkenSeaLaboratoryChest(Chest chest, int type, bool hasPlacedLogAndSchematic) + public static void FillSunkenSeaLaboratoryChest(Chest chest, int type, bool notFirstChest) { int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.EndurancePotion, ItemID.GravitationPotion, ItemID.HeartreachPotion, ItemID.LifeforcePotion); List contents = new List() @@ -324,7 +324,7 @@ namespace CalamityMod.World //Adds the Planetoid Seeking Mechanism contents.Insert(0, new ChestItem(ModContent.ItemType(), 1)); - if (!hasPlacedLogAndSchematic) + if (notFirstChest) { contents.Insert(0, new ChestItem(ModContent.ItemType(), 1)); contents.Insert(1, new ChestItem(ModContent.ItemType(), 1)); @@ -396,7 +396,7 @@ namespace CalamityMod.World #endregion #region Ice Lab - public static void FillIceLaboratoryChest(Chest chest, int type, bool hasPlacedLogAndSchematic) + public static void FillIceLaboratoryChest(Chest chest, int type, bool notFirstChest) { int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.EndurancePotion, ItemID.GravitationPotion, ItemID.HeartreachPotion, ItemID.LifeforcePotion); List contents = new List() @@ -413,7 +413,7 @@ namespace CalamityMod.World //Adds the Base Seeking Mechanism contents.Insert(0, new ChestItem(ModContent.ItemType(), 1)); - if (!hasPlacedLogAndSchematic) + if (notFirstChest) { contents.Insert(0, new ChestItem(ModContent.ItemType(), 1)); contents.Insert(1, new ChestItem(ModContent.ItemType(), 1)); diff --git a/World/MiscWorldgenRoutines.cs b/World/MiscWorldgenRoutines.cs index 1f37a9c1d9..0850262d29 100644 --- a/World/MiscWorldgenRoutines.cs +++ b/World/MiscWorldgenRoutines.cs @@ -2,6 +2,7 @@ using CalamityMod.Items.Materials; using CalamityMod.Items.Potions; using CalamityMod.Items.Potions.Food; +using CalamityMod.Tiles; using CalamityMod.Tiles.Abyss; using CalamityMod.Tiles.Astral; using CalamityMod.Tiles.FurnitureAuric; @@ -564,5 +565,29 @@ namespace CalamityMod.World } } #endregion + + #region Iron Ball + public static void GenerateIronBall() + { + int ballID = ModContent.TileType(); + int attempts = 0; + int ballsPlaced = 0; + int maxBalls = 8; + while (attempts < 10000) + { + Point location = new Point(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)Main.rockLayer, Main.UnderworldLayer)); + Tile t = CalamityUtils.ParanoidTileRetrieval(location.X, location.Y); + Tile above = CalamityUtils.ParanoidTileRetrieval(location.X, location.Y - 1); + if (t.TileType == TileID.Stone && t.HasTile && !above.HasTile) + { + WorldGen.SlopeTile(location.X, location.Y); + WorldGen.PlaceTile(location.X, location.Y - 1, ballID); + ballsPlaced++; + } + if (ballsPlaced >= maxBalls) + break; + } + } + #endregion } }