diff --git a/Events/AcidRainEvent.cs b/Events/AcidRainEvent.cs index 3d33fe7eed..dc05c4d9f5 100644 --- a/Events/AcidRainEvent.cs +++ b/Events/AcidRainEvent.cs @@ -91,7 +91,8 @@ namespace CalamityMod.Events public static Dictionary PossibleMinibossesPolter = new Dictionary() { { ModContent.NPCType(), new AcidRainSpawnData(4, 0.08f, AcidRainSpawnRequirement.Water) }, - { ModContent.NPCType(), new AcidRainSpawnData(8, 0.05f, AcidRainSpawnRequirement.Anywhere) } + { ModContent.NPCType(), new AcidRainSpawnData(4, 0.07f, AcidRainSpawnRequirement.Water) }, + { ModContent.NPCType(), new AcidRainSpawnData(8, 0.045f, AcidRainSpawnRequirement.Anywhere) } }; public static readonly List AllMinibosses = PossibleMinibossesAS.Select(miniboss => miniboss.Key).ToList().Concat(PossibleMinibossesPolter.Select(miniboss => miniboss.Key)).Distinct().ToList(); diff --git a/ExtraTextures/Line.png b/ExtraTextures/Line.png new file mode 100644 index 0000000000..2408d29233 Binary files /dev/null and b/ExtraTextures/Line.png differ diff --git a/NPCs/AcidRain/CragmawMire.cs b/NPCs/AcidRain/CragmawMire.cs index 14dcea5b11..14faa021ed 100644 --- a/NPCs/AcidRain/CragmawMire.cs +++ b/NPCs/AcidRain/CragmawMire.cs @@ -1,19 +1,15 @@ using CalamityMod.Dusts; using CalamityMod.Items.Accessories; using CalamityMod.Projectiles.Enemy; -using CalamityMod.Projectiles.Environment; using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using System; -using System.Collections.Generic; using Terraria; using Terraria.ID; using Terraria.ModLoader; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Items.Weapons.Rogue; using Terraria.Utilities; -using CalamityMod.Projectiles.Rogue; using Terraria.World.Generation; namespace CalamityMod.NPCs.AcidRain @@ -82,11 +78,11 @@ namespace CalamityMod.NPCs.AcidRain npc.noTileCollide = false; npc.HitSound = SoundID.NPCHit1; npc.DeathSound = SoundID.NPCDeath1; - npc.Calamity().VulnerableToHeat = false; - npc.Calamity().VulnerableToSickness = false; - npc.Calamity().VulnerableToElectricity = true; - npc.Calamity().VulnerableToWater = false; - } + npc.Calamity().VulnerableToHeat = false; + npc.Calamity().VulnerableToSickness = false; + npc.Calamity().VulnerableToElectricity = true; + npc.Calamity().VulnerableToWater = false; + } public override void AI() { diff --git a/NPCs/AcidRain/Mauler.cs b/NPCs/AcidRain/Mauler.cs new file mode 100644 index 0000000000..88fe6296a9 --- /dev/null +++ b/NPCs/AcidRain/Mauler.cs @@ -0,0 +1,449 @@ +using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.Items.Placeables.Banners; +using CalamityMod.Items.Weapons.Ranged; +using CalamityMod.Projectiles.Enemy; +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Utilities; +using Terraria.World.Generation; + +namespace CalamityMod.NPCs.AcidRain +{ + public class Mauler : ModNPC + { + public enum MaulerAttackState + { + BubbleBursts, + HorizontalAcidCharge, + BigChargeupDash + } + + public bool InWater => Collision.DrownCollision(npc.Center, 1, 1); + public Player Target => Main.player[npc.target]; + public MaulerAttackState CurrentAttack + { + get => (MaulerAttackState)(int)npc.ai[0]; + set => npc.ai[0] = (int)value; + } + public ref float AttackTimer => ref npc.ai[1]; + public int CurrentFrame + { + get => (int)npc.localAI[0]; + set => npc.localAI[0] = value; + } + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Mauler"); + Main.npcFrameCount[npc.type] = 8; + } + + public override void SetDefaults() + { + npc.noGravity = true; + npc.damage = 135; + npc.width = 180; + npc.height = 90; + npc.defense = 50; + npc.DR_NERD(0.05f); + npc.lifeMax = 88500; + npc.aiStyle = -1; + aiType = -1; + npc.value = Item.buyPrice(0, 25, 0, 0); + npc.HitSound = SoundID.NPCHit1; + npc.DeathSound = SoundID.NPCDeath60; + npc.knockBackResist = 0f; + npc.rarity = 2; + banner = npc.type; + bannerItem = ModContent.ItemType(); + npc.RemoveWaterSlowness(); + npc.Calamity().canBreakPlayerDefense = true; + npc.Calamity().VulnerableToHeat = false; + npc.Calamity().VulnerableToSickness = false; + npc.Calamity().VulnerableToElectricity = true; + npc.Calamity().VulnerableToWater = false; + } + + public override void AI() + { + npc.TargetClosest(false); + + // Reset things every frame. They may be changed in the attack states below. + npc.noTileCollide = false; + npc.noGravity = InWater; + TelegraphCompletionInterpolant = 0f; + + switch (CurrentAttack) + { + case MaulerAttackState.BubbleBursts: + DoBehavior_BubbleBursts(); + break; + case MaulerAttackState.HorizontalAcidCharge: + DoBehavior_HorizontalAcidCharge(); + break; + case MaulerAttackState.BigChargeupDash: + DoBehavior_BigChargeupDash(); + break; + } + + // Emit radioactive light. + Vector2 left = npc.Center - Vector2.UnitX * 15f; + Vector2 right = npc.Center + Vector2.UnitX * 15f; + DelegateMethods.v3_1 = Color.Lime.ToVector3(); + Utils.PlotTileLine(left, right, 10f, DelegateMethods.CastLightOpen); + + // Drift away from the world border. + if (npc.Center.X < (Main.offLimitBorderTiles + 6f) * 16f || npc.Center.X >= (Main.maxTilesX - Main.offLimitBorderTiles - 6f) * 16f) + { + npc.velocity *= 0.9f; + npc.Center = npc.Center.MoveTowards(Target.Center, 12f); + } + + AttackTimer++; + } + + public void DoBehavior_BubbleBursts() + { + int roarDelay = 32; + int shootDelay = 24; + int bubblesPerBurst = 7; + int burstShootRate = 45; + int burstCount = 3; + float wrappedAttackTimer = (AttackTimer - roarDelay - shootDelay) % burstShootRate; + + // Slow down. If necessary, fall. + npc.velocity *= 0.94f; + if (!InWater) + { + npc.noTileCollide = true; + npc.position.Y += 6f; + } + + // Roar prior to releasing bubbles. + if (AttackTimer <= roarDelay) + CurrentFrame = (int)Math.Round(Utils.InverseLerp(0f, roarDelay, AttackTimer, true) * 5f); + + // Animate as usual a bit after roaring. + else if (AttackTimer >= roarDelay + shootDelay) + { + npc.frameCounter++; + if (npc.frameCounter >= 5) + { + CurrentFrame = (CurrentFrame + 1) % Main.npcFrameCount[npc.type]; + npc.frameCounter = 0; + } + + // Open the mouth prior to creating bubbles. + if (wrappedAttackTimer >= burstShootRate * 0.7f) + CurrentFrame = 4; + } + if (AttackTimer == roarDelay) + Main.PlaySound(SoundID.Zombie, Target.Center, 97); + + // Rotate towards the target. + int previousSpriteDirection = npc.spriteDirection; + float idealRotation = npc.AngleTo(Target.Center); + if (previousSpriteDirection == 1) + idealRotation += MathHelper.Pi; + npc.spriteDirection = (Target.Center.X < npc.Center.X).ToDirectionInt(); + if (previousSpriteDirection != npc.spriteDirection) + npc.rotation += MathHelper.Pi; + + npc.rotation = npc.rotation.AngleTowards(idealRotation, 0.125f).AngleLerp(idealRotation, 0.075f); + + // Fire the bubble bursts. + bool shouldShootBubbles = AttackTimer >= roarDelay + shootDelay && wrappedAttackTimer == burstShootRate - 1f; + if (shouldShootBubbles) + { + Vector2 mouthPosition = npc.Center + new Vector2(npc.spriteDirection * -56f, 22f).RotatedBy(npc.rotation); + Main.PlaySound(SoundID.Item96, mouthPosition); + if (Main.netMode != NetmodeID.MultiplayerClient) + { + int bubbleShootType = ModContent.ProjectileType(); + int bubbleDamage = npc.GetProjectileDamage(bubbleShootType); + Vector2 baseBubbleShootVelocity = npc.SafeDirectionTo(mouthPosition) * 13.5f; + for (int i = 0; i < bubblesPerBurst; i++) + { + Vector2 bubbleShootVelocity = baseBubbleShootVelocity + Main.rand.NextVector2Circular(4f, 4f); + Projectile.NewProjectile(mouthPosition, bubbleShootVelocity, bubbleShootType, bubbleDamage, 0f); + } + + // Get launched back after firing. This only happens if in water and there's no obstacles behind. + if (InWater && Collision.CanHit(npc.Center, 1, 1, npc.Center - baseBubbleShootVelocity.SafeNormalize(Vector2.Zero) * 100f, 1, 1)) + npc.velocity -= baseBubbleShootVelocity * 0.62f; + npc.netUpdate = true; + } + } + + if (AttackTimer >= roarDelay + shootDelay + burstShootRate * burstCount) + SelectNextAttack(); + } + + public void DoBehavior_HorizontalAcidCharge() + { + int stuckGiveupTime = 360; + int chargeDelay = 45; + int chargePreparationTime = 15; + int chargeTime = 72; + int acidShootRate = 4; + float chargeSpeed = 24.5f; + ref float stuckTimer = ref npc.ai[2]; + ref float chargeDirection = ref npc.ai[3]; + + // Select frames. + npc.frameCounter++; + if (npc.frameCounter >= 5) + { + CurrentFrame = (CurrentFrame + 1) % Main.npcFrameCount[npc.type]; + npc.frameCounter = 0; + } + + // Decide the rotation and direction. + npc.rotation = npc.velocity.X * 0.0125f; + if (Math.Abs(npc.velocity.X) > 0.1f) + npc.spriteDirection = (npc.velocity.X < 0f).ToDirectionInt(); + if (AttackTimer < chargeDelay + chargePreparationTime) + npc.spriteDirection = (Target.Center.X < npc.Center.X).ToDirectionInt(); + + // Move through tiles and attempt to reach water if stuck on land. + Vector2 idealPosition = Target.Center + Vector2.UnitX * (Target.Center.X < npc.Center.X).ToDirectionInt() * 480f; + if (!InWater && AttackTimer < chargeDelay) + { + npc.noTileCollide = true; + npc.noGravity = true; + AttackTimer = 0f; + + if (WorldUtils.Find(idealPosition.ToTileCoordinates(), Searches.Chain(new Searches.Down(1500), new CustomConditions.IsWater()), out Point hitPoint)) + idealPosition = hitPoint.ToWorldCoordinates(); + Vector2 idealVelocity = npc.SafeDirectionTo(idealPosition) * 20f; + + // Move towards the ideal position. + if (!npc.WithinRange(idealPosition, 120f)) + npc.velocity = Vector2.Lerp(npc.velocity, idealVelocity, 0.05f); + + // Give up and do another attack if unable to find water. + stuckTimer++; + if (stuckTimer >= stuckGiveupTime) + { + npc.Opacity = 1f; + SelectNextAttack(); + } + } + else + stuckTimer = 0f; + + // Handle opacity. When not in water, become almost completely transparent. + npc.Opacity = MathHelper.Clamp(npc.Opacity + InWater.ToDirectionInt() * 0.04f, 0.33f, 1f); + + // Charge and release homing acid upward. + if (AttackTimer >= chargeDelay && AttackTimer < chargeDelay + chargePreparationTime) + { + // Define the charge direction. + if (chargeDirection == 0f) + { + chargeDirection = (Target.Center.X > npc.Center.X).ToDirectionInt(); + npc.netUpdate = true; + } + npc.position.Y += npc.SafeDirectionTo(Target.Center).Y * 8f; + npc.velocity = Vector2.Lerp(npc.velocity, Vector2.UnitX * chargeDirection * chargeSpeed, 0.075f); + } + + bool isCharging = AttackTimer >= chargeDelay + chargePreparationTime && AttackTimer < chargeDelay + chargePreparationTime + chargeTime; + bool shouldShootAcid = isCharging && AttackTimer % acidShootRate == acidShootRate - 1f; + if (shouldShootAcid) + { + Main.PlaySound(SoundID.Item95, npc.Center); + if (Main.netMode != NetmodeID.MultiplayerClient) + { + int acidShootType = ModContent.ProjectileType(); + int acidDamage = npc.GetProjectileDamage(acidShootType); + Vector2 acidSpawnPosition = npc.Center + Main.rand.NextVector2Circular(30f, 10f).RotatedBy(npc.rotation); + Vector2 acidShootVelocity = -Vector2.UnitY.RotatedByRandom(0.33f) * Main.rand.NextFloat(8f, 10.5f); + Projectile.NewProjectile(acidSpawnPosition, acidShootVelocity, acidShootType, acidDamage, 0f); + npc.netUpdate = true; + } + } + + if (npc.velocity.Length() < 0.4f) + npc.velocity = Vector2.Zero; + + Vector2 aheadPosition = npc.position + npc.velocity.SafeNormalize(Vector2.UnitX * -npc.spriteDirection) * 150f; + bool stuckWhileCharging = !Collision.CanHit(npc.position, npc.width, npc.height, aheadPosition, npc.width, npc.height) || + Collision.SolidCollision(npc.position, npc.width, npc.height); + stuckWhileCharging &= isCharging; + if (AttackTimer >= chargeDelay + chargePreparationTime + chargeTime || stuckWhileCharging) + { + npc.velocity *= 0.5f; + SelectNextAttack(); + } + } + + public void DoBehavior_BigChargeupDash() + { + int chargeDelay = 105; + int telegraphTime = 60; + int chargeTime = 50; + float chargeSpeed = MathHelper.Clamp(npc.Distance(Target.Center) / chargeTime * 1.35f, 29f, 45f); + bool hasCharged = AttackTimer >= chargeDelay; + + // Slow down at first. If necessary, fall. + if (!hasCharged) + { + npc.velocity *= 0.94f; + npc.noGravity = true; + } + + // Select frames. + npc.frameCounter++; + if (npc.frameCounter >= (hasCharged ? 4 : 7)) + { + CurrentFrame = (CurrentFrame + 1) % Main.npcFrameCount[npc.type]; + npc.frameCounter = 0; + } + + // Open the mouth if close to the target after charging. + if (CurrentFrame < 4 && npc.WithinRange(Target.Center, 200f) && AttackTimer > chargeDelay) + CurrentFrame = 4; + + // Create the telegraph. + TelegraphCompletionInterpolant = Utils.InverseLerp(chargeDelay - telegraphTime, chargeDelay, AttackTimer, true); + TelegraphCompletionInterpolant *= Utils.InverseLerp(chargeDelay + 16f, chargeDelay, AttackTimer, true); + + // Rotate towards the target at first. + int previousSpriteDirection = npc.spriteDirection; + float idealRotation = npc.AngleTo(Target.Center); + if (previousSpriteDirection == 1) + idealRotation += MathHelper.Pi; + + // Roar as a telegraph. The placement of the sound is offset such that the player and ideally determine the determine where the charge will come from. + if (AttackTimer == chargeDelay - telegraphTime) + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/MaulerRoar"), Target.Center + Target.SafeDirectionTo(npc.Center) * 300f); + + // Charge. + if (AttackTimer == chargeDelay) + { + Main.PlaySound(SoundID.DD2_FlameburstTowerShot, Target.Center); + npc.velocity = npc.SafeDirectionTo(Target.Center) * chargeSpeed; + npc.netUpdate = true; + } + if (!hasCharged) + { + npc.spriteDirection = (Target.Center.X < npc.Center.X).ToDirectionInt(); + if (previousSpriteDirection != npc.spriteDirection) + npc.rotation += MathHelper.Pi; + + npc.rotation = npc.rotation.AngleTowards(idealRotation, 0.18f).AngleLerp(idealRotation, 0.08f); + } + else + { + TelegraphCompletionInterpolant = 0f; + npc.noGravity = npc.noTileCollide = true; + npc.rotation = npc.velocity.ToRotation(); + if (previousSpriteDirection == 1) + npc.rotation += MathHelper.Pi; + } + + if (AttackTimer >= chargeDelay + chargeTime) + SelectNextAttack(); + } + + public void SelectNextAttack() + { + // Reset the attack timer and optional attack variables. + AttackTimer = 0f; + npc.ai[2] = 0f; + npc.ai[3] = 0f; + + MaulerAttackState oldAttack = CurrentAttack; + + bool targetDefinitelyNotNearWater = false; + bool isInCrampedPosition = Collision.SolidCollision(npc.Center - Vector2.One * 150f, 300, 300) && InWater; + if (Collision.SolidCollision(npc.position, npc.width, npc.height)) + isInCrampedPosition = true; + + // Register the target as not near water if they have left the ocean. + if (Target.position.X > 8000f && Target.position.X < Main.maxTilesX * 16f - 8000f) + targetDefinitelyNotNearWater = true; + + // Register the target as not near water if there's no water below the target's position or it's very far away. + if (WorldUtils.Find(Target.Center.ToTileCoordinates(), Searches.Chain(new Searches.Down(750), new CustomConditions.IsWater()), out Point hitPoint)) + { + if (Target.Distance(hitPoint.ToWorldCoordinates()) > 6400f) + targetDefinitelyNotNearWater = true; + } + else + targetDefinitelyNotNearWater = true; + + WeightedRandom attackSelector = new WeightedRandom(Main.rand); + attackSelector.Add(MaulerAttackState.BubbleBursts); + attackSelector.Add(MaulerAttackState.HorizontalAcidCharge); + attackSelector.Add(MaulerAttackState.BigChargeupDash); + + // Select the new attack. + // It is random, but will never perform the same attack twice in succession. + do + CurrentAttack = attackSelector.Get(); + while (oldAttack == CurrentAttack); + + // Bypass the above check and use an attack that doesn't require water if there's none nearby. + if (targetDefinitelyNotNearWater || isInCrampedPosition) + CurrentAttack = MaulerAttackState.BigChargeupDash; + + npc.netUpdate = true; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor) + { + Texture2D texture = Main.npcTexture[npc.type]; + Texture2D glowmask = ModContent.GetTexture("CalamityMod/NPCs/AcidRain/MaulerGlowmask"); + Vector2 drawPosition = npc.Center - Main.screenPosition + Vector2.UnitY * npc.gfxOffY; + Vector2 origin = npc.frame.Size() * 0.5f; + SpriteEffects direction = npc.spriteDirection == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + + spriteBatch.Draw(texture, drawPosition, npc.frame, npc.GetAlpha(drawColor), npc.rotation, origin, npc.scale, direction, 0f); + spriteBatch.Draw(glowmask, drawPosition, npc.frame, npc.GetAlpha(Color.White), npc.rotation, origin, npc.scale, direction, 0f); + return false; + } + + public override void FindFrame(int frameHeight) + { + npc.frame.Y = CurrentFrame * frameHeight; + } + + public override void OnHitPlayer(Player player, int damage, bool crit) + { + player.AddBuff(ModContent.BuffType(), 420); + } + + public override void NPCLoot() + { + DropHelper.DropItemChance(npc, ModContent.ItemType(), 3); + + // Drop shark fins. They are specially colored to match the color of maulers. + int item = Item.NewItem(npc.Center, npc.Size, ItemID.SharkFin, Main.rand.Next(2, 5), false, 0, false, false); + Main.item[item].color = new Color(151, 115, 57, 255); + NetMessage.SendData(MessageID.ItemTweaker, -1, -1, null, item, 1f, 0f, 0f, 0, 0, 0); + } + + public override void HitEffect(int hitDirection, double damage) + { + for (int k = 0; k < 5; k++) + Dust.NewDust(npc.position, npc.width, npc.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); + + if (npc.life <= 0) + { + for (int k = 0; k < 30; k++) + Dust.NewDust(npc.position, npc.width, npc.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); + + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Mauler"), npc.scale); + for (int i = 2; i <= 5; i++) + Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot($"Gores/Mauler{i}"), npc.scale); + } + } + } +} diff --git a/NPCs/AcidRain/Mauler.png b/NPCs/AcidRain/Mauler.png new file mode 100644 index 0000000000..97e48d86f0 Binary files /dev/null and b/NPCs/AcidRain/Mauler.png differ diff --git a/NPCs/AcidRain/MaulerGlowmask.png b/NPCs/AcidRain/MaulerGlowmask.png new file mode 100644 index 0000000000..1402c965a0 Binary files /dev/null and b/NPCs/AcidRain/MaulerGlowmask.png differ diff --git a/NPCs/AcidRain/NuclearTerror.cs b/NPCs/AcidRain/NuclearTerror.cs index df6be2ec85..5af0cd2527 100644 --- a/NPCs/AcidRain/NuclearTerror.cs +++ b/NPCs/AcidRain/NuclearTerror.cs @@ -86,7 +86,7 @@ namespace CalamityMod.NPCs.AcidRain npc.lifeMax = 198230; npc.defense = 50; - npc.damage = 175; + npc.damage = 135; npc.knockBackResist = 0f; npc.value = Item.buyPrice(0, 20, 0, 0); npc.DR_NERD(0.3f); diff --git a/NPCs/SulphurousSea/Mauler.cs b/NPCs/SulphurousSea/Mauler.cs deleted file mode 100644 index 7c60fd681c..0000000000 --- a/NPCs/SulphurousSea/Mauler.cs +++ /dev/null @@ -1,395 +0,0 @@ -using CalamityMod.Buffs.StatDebuffs; -using CalamityMod.Items.Placeables.Banners; -using CalamityMod.Items.Weapons.Ranged; -using CalamityMod.NPCs.AquaticScourge; -using CalamityMod.Projectiles.Enemy; -using CalamityMod.World; -using Microsoft.Xna.Framework; -using System; -using System.IO; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.NPCs.SulphurousSea -{ - public class Mauler : ModNPC - { - private bool hasBeenHit = false; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Mauler"); - Main.npcFrameCount[npc.type] = 8; - } - - public override void SetDefaults() - { - npc.Calamity().canBreakPlayerDefense = true; - npc.noGravity = true; - npc.damage = 135; - npc.width = 180; - npc.height = 90; - npc.defense = 50; - npc.DR_NERD(0.05f); - npc.lifeMax = 165000; - npc.aiStyle = -1; - aiType = -1; - npc.value = Item.buyPrice(0, 25, 0, 0); - npc.HitSound = SoundID.NPCHit1; - npc.DeathSound = SoundID.NPCDeath60; - npc.knockBackResist = 0f; - npc.rarity = 2; - banner = npc.type; - bannerItem = ModContent.ItemType(); - npc.Calamity().VulnerableToHeat = false; - npc.Calamity().VulnerableToSickness = false; - npc.Calamity().VulnerableToElectricity = true; - npc.Calamity().VulnerableToWater = false; - } - - public override void SendExtraAI(BinaryWriter writer) - { - writer.Write(hasBeenHit); - writer.Write(npc.chaseable); - } - - public override void ReceiveExtraAI(BinaryReader reader) - { - hasBeenHit = reader.ReadBoolean(); - npc.chaseable = reader.ReadBoolean(); - } - - public override void AI() - { - npc.spriteDirection = (npc.direction > 0) ? 1 : -1; - npc.noGravity = true; - if (npc.direction == 0) - { - npc.TargetClosest(true); - } - if (npc.justHit) - { - hasBeenHit = true; - } - npc.chaseable = hasBeenHit; - if (npc.wet) - { - bool flag14 = hasBeenHit; - npc.TargetClosest(false); - if (Main.player[npc.target].wet && !Main.player[npc.target].dead && - Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height) && - (Main.player[npc.target].Center - npc.Center).Length() < 300f) - { - flag14 = true; - } - if (Main.player[npc.target].dead && flag14) - { - flag14 = false; - } - if (!flag14) - { - if (npc.collideX) - { - npc.velocity.X = npc.velocity.X * -1f; - npc.direction *= -1; - npc.netUpdate = true; - } - if (npc.collideY) - { - npc.netUpdate = true; - if (npc.velocity.Y > 0f) - { - npc.velocity.Y = Math.Abs(npc.velocity.Y) * -1f; - npc.directionY = -1; - npc.ai[0] = -1f; - } - else if (npc.velocity.Y < 0f) - { - npc.velocity.Y = Math.Abs(npc.velocity.Y); - npc.directionY = 1; - npc.ai[0] = 1f; - } - } - } - if (flag14) - { - if (!Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) - { - npc.localAI[1] += 1f; - } - else - { - if (npc.localAI[1] > 0f) - { - npc.localAI[1] -= 1f; - } - } - npc.localAI[2] += 1f; - npc.TargetClosest(true); - npc.velocity.X = npc.velocity.X + (float)npc.direction * 0.5f; - npc.velocity.Y = npc.velocity.Y + (float)npc.directionY * 0.25f; - if (npc.velocity.X > 22f) - { - npc.velocity.X = 22f; - } - if (npc.velocity.X < -22f) - { - npc.velocity.X = -22f; - } - if (npc.velocity.Y > 13f) - { - npc.velocity.Y = 13f; - } - if (npc.velocity.Y < -13f) - { - npc.velocity.Y = -13f; - } - } - else - { - npc.velocity.X += (float)npc.direction * 0.2f; - if (npc.velocity.X < -4f || npc.velocity.X > 4f) - { - npc.velocity.X *= 0.95f; - } - if (npc.ai[0] == -1f) - { - npc.velocity.Y -= 0.01f; - if (npc.velocity.Y < -0.3f) - { - npc.ai[0] = 1f; - } - } - else - { - npc.velocity.Y += 0.01f; - if (npc.velocity.Y > 0.3f) - { - npc.ai[0] = -1f; - } - } - } - int num258 = (int)(npc.position.X + (float)(npc.width / 2)) / 16; - int num259 = (int)(npc.position.Y + (float)(npc.height / 2)) / 16; - if (Main.tile[num258, num259 - 1] == null) - { - Main.tile[num258, num259 - 1] = new Tile(); - } - if (Main.tile[num258, num259 + 1] == null) - { - Main.tile[num258, num259 + 1] = new Tile(); - } - if (Main.tile[num258, num259 + 2] == null) - { - Main.tile[num258, num259 + 2] = new Tile(); - } - if (Main.tile[num258, num259 - 1].liquid > 128) - { - if (Main.tile[num258, num259 + 1].active()) - { - npc.ai[0] = -1f; - } - else if (Main.tile[num258, num259 + 2].active()) - { - npc.ai[0] = -1f; - } - } - if (npc.velocity.Y > 0.4f || npc.velocity.Y < -0.4f) - { - npc.velocity.Y *= 0.95f; - } - } - else - { - npc.localAI[1] += 1f; - npc.localAI[0] += 1f; - if (Main.netMode != NetmodeID.MultiplayerClient && npc.localAI[0] >= 30f) - { - npc.localAI[0] = 0f; - if (Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) - { - float speed = 12f; - Vector2 vector = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)(npc.height / 2)); - float num6 = Main.player[npc.target].position.X + (float)Main.player[npc.target].width * 0.5f - vector.X + (float)Main.rand.Next(-20, 21); - float num7 = Main.player[npc.target].position.Y + (float)Main.player[npc.target].height * 0.5f - vector.Y + (float)Main.rand.Next(-20, 21); - float num8 = (float)Math.Sqrt((double)(num6 * num6 + num7 * num7)); - num8 = speed / num8; - num6 *= num8; - num7 *= num8; - int damage = 50; - if (Main.expertMode) - { - damage = 45; - } - int beam = Projectile.NewProjectile(npc.Center.X + (npc.spriteDirection == 1 ? 60f : -60f), npc.Center.Y, num6, num7, ModContent.ProjectileType(), damage, 0f, Main.myPlayer, 0f, 0f); - } - } - if (npc.velocity.Y == 0f) - { - if (Main.netMode != NetmodeID.MultiplayerClient) - { - npc.velocity.Y = (float)Main.rand.Next(-200, -150) * 0.1f; //50 20 - npc.velocity.X = (float)Main.rand.Next(-20, 20) * 0.1f; //20 20 - npc.netUpdate = true; - } - } - npc.velocity.Y = npc.velocity.Y + 0.4f; //0.4 - if (npc.velocity.Y > 16f) - { - npc.velocity.Y = 16f; - } - npc.ai[0] = 1f; - } - if (hasBeenHit) - { - if (Main.rand.NextBool(300)) - { - Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/MaulerRoar"), (int)npc.position.X, (int)npc.position.Y); - } - } - if (npc.localAI[1] >= 255f || npc.localAI[2] >= 600f) - { - npc.localAI[2] = 0f; - BlowUp(); - return; - } - else if (npc.localAI[1] > 0f) - { - for (int k = 0; k < (int)((double)npc.localAI[1] * 0.05); k++) - { - Dust.NewDust(npc.position, npc.width, npc.height, 5, 0f, 0f, 0, default, 1f); - } - } - npc.rotation = npc.velocity.Y * (float)npc.direction * 0.1f; - if (npc.rotation < -0.2f) - { - npc.rotation = -0.2f; - } - if (npc.rotation > 0.2f) - { - npc.rotation = 0.2f; - return; - } - } - - public override bool? CanBeHitByProjectile(Projectile projectile) - { - if (projectile.minion && !projectile.Calamity().overridesMinionDamagePrevention) - { - return hasBeenHit; - } - return null; - } - - public void BlowUp() - { - Main.PlaySound(SoundID.NPCDeath60, npc.Center); - if (Main.netMode != NetmodeID.MultiplayerClient) - { - Vector2 valueBoom = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); - float spreadBoom = 15f * 0.0174f; - double startAngleBoom = Math.Atan2(npc.velocity.X, npc.velocity.Y) - spreadBoom / 2; - double deltaAngleBoom = spreadBoom / 8f; - double offsetAngleBoom; - int iBoom; - int damageBoom = npc.localAI[1] >= 255f ? 200 : 50; - for (iBoom = 0; iBoom < 25; iBoom++) - { - int projectileType = Main.rand.NextBool(2) ? ModContent.ProjectileType() : ModContent.ProjectileType(); - offsetAngleBoom = startAngleBoom + deltaAngleBoom * (iBoom + iBoom * iBoom) / 2f + 32f * iBoom; - int boom1 = Projectile.NewProjectile(valueBoom.X, valueBoom.Y, (float)(Math.Sin(offsetAngleBoom) * 6f), (float)(Math.Cos(offsetAngleBoom) * 6f), projectileType, damageBoom, 0f, Main.myPlayer, 0f, 0f); - int boom2 = Projectile.NewProjectile(valueBoom.X, valueBoom.Y, (float)(-Math.Sin(offsetAngleBoom) * 6f), (float)(-Math.Cos(offsetAngleBoom) * 6f), projectileType, damageBoom, 0f, Main.myPlayer, 0f, 0f); - } - } - for (int num621 = 0; num621 < 25; num621++) - { - int num622 = Dust.NewDust(npc.position, npc.width, npc.height, 31, 0f, 0f, 100, default, 2f); - Main.dust[num622].velocity *= 3f; - if (Main.rand.NextBool(2)) - { - Main.dust[num622].scale = 0.5f; - Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; - } - Main.dust[num622].noGravity = true; - } - for (int num623 = 0; num623 < 50; num623++) - { - int num624 = Dust.NewDust(npc.position, npc.width, npc.height, DustID.Blood, 0f, 0f, 100, default, 3f); - Main.dust[num624].noGravity = true; - Main.dust[num624].velocity *= 5f; - num624 = Dust.NewDust(npc.position, npc.width, npc.height, DustID.Blood, 0f, 0f, 100, default, 2f); - Main.dust[num624].velocity *= 2f; - Main.dust[num624].noGravity = true; - } - if (npc.localAI[1] >= 255f) - { - npc.active = false; - } - npc.netUpdate = true; - } - - public override void FindFrame(int frameHeight) - { - npc.frameCounter += hasBeenHit ? 0.15f : 0.075f; - npc.frameCounter %= Main.npcFrameCount[npc.type]; - int frame = (int)npc.frameCounter; - npc.frame.Y = frame * frameHeight; - } - - public override void OnHitPlayer(Player player, int damage, bool crit) - { - player.AddBuff(ModContent.BuffType(), 420); - } - - public override void NPCLoot() - { - DropHelper.DropItemCondition(npc, ModContent.ItemType(), CalamityWorld.downedPolterghast, 3, 1, 1); - int item = Item.NewItem(npc.Center, npc.Size, ItemID.SharkFin, Main.rand.Next(2, 5), false, 0, false, false); - Main.item[item].color = new Color(151, 115, 57, 255); - NetMessage.SendData(MessageID.ItemTweaker, -1, -1, null, item, 1f, 0f, 0f, 0, 0, 0); - } - - public override float SpawnChance(NPCSpawnInfo spawnInfo) - { - if (spawnInfo.playerSafe) - { - return 0f; - } - if (spawnInfo.player.Calamity().ZoneSulphur && spawnInfo.water && !NPC.AnyNPCs(ModContent.NPCType()) && - !NPC.AnyNPCs(ModContent.NPCType())) - { - if (!Main.hardMode) - { - return 0.001f; - } - if (!NPC.downedMoonlord) - { - return 0.01f; - } - return 0.1f; - } - return 0f; - } - - public override void HitEffect(int hitDirection, double damage) - { - for (int k = 0; k < 5; k++) - { - Dust.NewDust(npc.position, npc.width, npc.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); - } - if (npc.life <= 0) - { - for (int k = 0; k < 30; k++) - { - Dust.NewDust(npc.position, npc.width, npc.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); - } - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Mauler"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Mauler2"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Mauler3"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Mauler4"), 1f); - Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/Mauler5"), 1f); - } - } - } -} diff --git a/NPCs/SulphurousSea/Mauler.png b/NPCs/SulphurousSea/Mauler.png deleted file mode 100644 index ac13375124..0000000000 Binary files a/NPCs/SulphurousSea/Mauler.png and /dev/null differ diff --git a/Projectiles/Enemy/MaulerAcidBubble.cs b/Projectiles/Enemy/MaulerAcidBubble.cs new file mode 100644 index 0000000000..b29d82dc28 --- /dev/null +++ b/Projectiles/Enemy/MaulerAcidBubble.cs @@ -0,0 +1,79 @@ +using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.Dusts; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Enemy +{ + public class MaulerAcidBubble : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public override string Texture => "CalamityMod/Projectiles/Enemy/SulphuricAcidBubble"; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Acid Bubble"); + Main.projFrames[projectile.type] = 7; + } + + public override void SetDefaults() + { + projectile.width = 30; + projectile.height = 30; + projectile.hostile = true; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.timeLeft = 150; + projectile.penetrate = -1; + } + + public override void AI() + { + // Handle frames. + projectile.frameCounter++; + projectile.frame = projectile.frameCounter / 4 % Main.projFrames[projectile.type]; + + // Home in on players after a sufficient amount of time has passed. + if (Time > 60f) + { + float flySpeed = Main.expertMode ? 17.5f : 14.5f; + Player target = Main.player[Player.FindClosest(projectile.Center, 1, 1)]; + if (!projectile.WithinRange(target.Center, 50f)) + projectile.velocity = (projectile.velocity * 49f + projectile.SafeDirectionTo(target.Center) * flySpeed) / 50f; + projectile.tileCollide = true; + } + + // Emit light. + Lighting.AddLight(projectile.Center, 0.2f, 0.6f, 0.2f); + + // Rotate. + projectile.rotation += projectile.direction * 0.04f; + Time++; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D texture = Main.projectileTexture[projectile.type]; + Rectangle frame = texture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame); + Vector2 origin = frame.Size() * 0.5f; + spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, frame, projectile.GetAlpha(lightColor), projectile.rotation, origin, projectile.scale, SpriteEffects.None, 0f); + return false; + } + + public override void OnHitPlayer(Player target, int damage, bool crit) + { + if (projectile.localAI[1] < 1f) + { + return; + } + target.AddBuff(ModContent.BuffType(), 120); + } + + public override void Kill(int timeLeft) + { + Main.PlaySound(SoundID.Item54, projectile.position); + } + } +} diff --git a/Projectiles/Enemy/MaulerAcidDrop.cs b/Projectiles/Enemy/MaulerAcidDrop.cs new file mode 100644 index 0000000000..0653f3e90c --- /dev/null +++ b/Projectiles/Enemy/MaulerAcidDrop.cs @@ -0,0 +1,48 @@ +using CalamityMod.Buffs.StatDebuffs; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Enemy +{ + public class MaulerAcidDrop : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Environment/AcidDrop"; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Acid"); + } + + public override void SetDefaults() + { + projectile.width = 16; + projectile.height = 16; + projectile.penetrate = -1; + projectile.hostile = true; + projectile.timeLeft = 240; + projectile.tileCollide = false; + projectile.ignoreWater = false; + } + public override void AI() + { + float homingSpeed = 16f; + Player target = Main.player[Player.FindClosest(projectile.Center, 1, 1)]; + if (projectile.WithinRange(target.Center, 1200f) && projectile.timeLeft < 210) + projectile.velocity = (projectile.velocity * 59f + projectile.SafeDirectionTo(target.Center) * homingSpeed) / 60f; + projectile.Opacity = Utils.InverseLerp(0f, 25f, projectile.timeLeft, true); + projectile.rotation = projectile.velocity.ToRotation() - MathHelper.PiOver2; + } + + public override void OnHitPlayer(Player target, int damage, bool crit) + { + target.AddBuff(ModContent.BuffType(), 60); + } + + public override Color? GetAlpha(Color lightColor) + { + lightColor = Color.White; + lightColor.A = 64; + return lightColor * projectile.Opacity; + } + } +} diff --git a/Utilities/DrawingUtils.cs b/Utilities/DrawingUtils.cs index 25e9bd1d51..8e53532801 100644 --- a/Utilities/DrawingUtils.cs +++ b/Utilities/DrawingUtils.cs @@ -12,9 +12,9 @@ using Terraria.ModLoader; namespace CalamityMod { - public static partial class CalamityUtils - { - public static readonly Color[] ExoPalette = new Color[] + public static partial class CalamityUtils + { + public static readonly Color[] ExoPalette = new Color[] { new Color(250, 255, 112), new Color(211, 235, 108), @@ -26,542 +26,566 @@ namespace CalamityMod new Color(199, 62, 62), }; - #region Projectile Afterimages - /// - /// Draws a projectile as a series of afterimages. The first of these afterimages is centered on the center of the projectile's hitbox.
- /// This function is guaranteed to draw the projectile itself, even if it has no afterimages and/or the Afterimages config option is turned off. - ///
- /// The projectile to be drawn. - /// The type of afterimage drawing code to use. Vanilla Terraria has three options: 0, 1, and 2. - /// The light color to use for the afterimages. - /// If mode 1 is used, this controls the loop increment. Set it to more than 1 to skip afterimages. - /// The texture to draw. Set to null to draw the projectile's own loaded texture. - /// If false, the afterimages will be centered on the projectile's position instead of its own center. - public static void DrawAfterimagesCentered(Projectile proj, int mode, Color lightColor, int typeOneIncrement = 1, Texture2D texture = null, bool drawCentered = true) - { - if (texture is null) - texture = Main.projectileTexture[proj.type]; + #region Projectile Afterimages + /// + /// Draws a projectile as a series of afterimages. The first of these afterimages is centered on the center of the projectile's hitbox.
+ /// This function is guaranteed to draw the projectile itself, even if it has no afterimages and/or the Afterimages config option is turned off. + ///
+ /// The projectile to be drawn. + /// The type of afterimage drawing code to use. Vanilla Terraria has three options: 0, 1, and 2. + /// The light color to use for the afterimages. + /// If mode 1 is used, this controls the loop increment. Set it to more than 1 to skip afterimages. + /// The texture to draw. Set to null to draw the projectile's own loaded texture. + /// If false, the afterimages will be centered on the projectile's position instead of its own center. + public static void DrawAfterimagesCentered(Projectile proj, int mode, Color lightColor, int typeOneIncrement = 1, Texture2D texture = null, bool drawCentered = true) + { + if (texture is null) + texture = Main.projectileTexture[proj.type]; - int frameHeight = texture.Height / Main.projFrames[proj.type]; - int frameY = frameHeight * proj.frame; - float scale = proj.scale; - float rotation = proj.rotation; + int frameHeight = texture.Height / Main.projFrames[proj.type]; + int frameY = frameHeight * proj.frame; + float scale = proj.scale; + float rotation = proj.rotation; - Rectangle rectangle = new Rectangle(0, frameY, texture.Width, frameHeight); - Vector2 origin = rectangle.Size() / 2f; + Rectangle rectangle = new Rectangle(0, frameY, texture.Width, frameHeight); + Vector2 origin = rectangle.Size() / 2f; - SpriteEffects spriteEffects = SpriteEffects.None; - if (proj.spriteDirection == -1) - spriteEffects = SpriteEffects.FlipHorizontally; + SpriteEffects spriteEffects = SpriteEffects.None; + if (proj.spriteDirection == -1) + spriteEffects = SpriteEffects.FlipHorizontally; - // If no afterimages are drawn due to an invalid mode being specified, ensure the projectile itself is drawn anyway. - bool failedToDrawAfterimages = false; + // If no afterimages are drawn due to an invalid mode being specified, ensure the projectile itself is drawn anyway. + bool failedToDrawAfterimages = false; - if (CalamityConfig.Instance.Afterimages) - { - Vector2 centerOffset = drawCentered ? proj.Size / 2f : Vector2.Zero; - switch (mode) - { - // Standard afterimages. No customizable features other than total afterimage count. - // Type 0 afterimages linearly scale down from 100% to 0% opacity. Their color and lighting is equal to the main projectile's. - case 0: - for (int i = 0; i < proj.oldPos.Length; ++i) - { - Vector2 drawPos = proj.oldPos[i] + centerOffset - Main.screenPosition + new Vector2(0f, proj.gfxOffY); - // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS. THIS WILL BREAK THE AFTERIMAGES. - Color color = proj.GetAlpha(lightColor) * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); - Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), color, rotation, origin, scale, spriteEffects, 0f); - } - break; + if (CalamityConfig.Instance.Afterimages) + { + Vector2 centerOffset = drawCentered ? proj.Size / 2f : Vector2.Zero; + switch (mode) + { + // Standard afterimages. No customizable features other than total afterimage count. + // Type 0 afterimages linearly scale down from 100% to 0% opacity. Their color and lighting is equal to the main projectile's. + case 0: + for (int i = 0; i < proj.oldPos.Length; ++i) + { + Vector2 drawPos = proj.oldPos[i] + centerOffset - Main.screenPosition + new Vector2(0f, proj.gfxOffY); + // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS. THIS WILL BREAK THE AFTERIMAGES. + Color color = proj.GetAlpha(lightColor) * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), color, rotation, origin, scale, spriteEffects, 0f); + } + break; - // Paladin's Hammer style afterimages. Can be optionally spaced out further by using the typeOneDistanceMultiplier variable. - // Type 1 afterimages linearly scale down from 66% to 0% opacity. They otherwise do not differ from type 0. - case 1: - // Safety check: the loop must increment - int increment = Math.Max(1, typeOneIncrement); - Color drawColor = proj.GetAlpha(lightColor); - int afterimageCount = ProjectileID.Sets.TrailCacheLength[proj.type]; - int k = 0; - while (k < afterimageCount) - { - Vector2 drawPos = proj.oldPos[k] + centerOffset - Main.screenPosition + new Vector2(0f, proj.gfxOffY); - // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS EITHER. - if (k > 0) - { - float colorMult = (float)(afterimageCount - k); - drawColor *= colorMult / ((float)afterimageCount * 1.5f); - } - Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), drawColor, rotation, origin, scale, spriteEffects, 0f); - k += increment; - } - break; + // Paladin's Hammer style afterimages. Can be optionally spaced out further by using the typeOneDistanceMultiplier variable. + // Type 1 afterimages linearly scale down from 66% to 0% opacity. They otherwise do not differ from type 0. + case 1: + // Safety check: the loop must increment + int increment = Math.Max(1, typeOneIncrement); + Color drawColor = proj.GetAlpha(lightColor); + int afterimageCount = ProjectileID.Sets.TrailCacheLength[proj.type]; + int k = 0; + while (k < afterimageCount) + { + Vector2 drawPos = proj.oldPos[k] + centerOffset - Main.screenPosition + new Vector2(0f, proj.gfxOffY); + // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS EITHER. + if (k > 0) + { + float colorMult = (float)(afterimageCount - k); + drawColor *= colorMult / ((float)afterimageCount * 1.5f); + } + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), drawColor, rotation, origin, scale, spriteEffects, 0f); + k += increment; + } + break; - // Standard afterimages with rotation. No customizable features other than total afterimage count. - // Type 2 afterimages linearly scale down from 100% to 0% opacity. Their color and lighting is equal to the main projectile's. - case 2: - for (int i = 0; i < proj.oldPos.Length; ++i) - { - float afterimageRot = proj.oldRot[i]; - SpriteEffects sfxForThisAfterimage = proj.oldSpriteDirection[i] == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + // Standard afterimages with rotation. No customizable features other than total afterimage count. + // Type 2 afterimages linearly scale down from 100% to 0% opacity. Their color and lighting is equal to the main projectile's. + case 2: + for (int i = 0; i < proj.oldPos.Length; ++i) + { + float afterimageRot = proj.oldRot[i]; + SpriteEffects sfxForThisAfterimage = proj.oldSpriteDirection[i] == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; - Vector2 drawPos = proj.oldPos[i] + centerOffset - Main.screenPosition + new Vector2(0f, proj.gfxOffY); - // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS. THIS WILL BREAK THE AFTERIMAGES. - Color color = proj.GetAlpha(lightColor) * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); - Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), color, afterimageRot, origin, scale, sfxForThisAfterimage, 0f); - } - break; + Vector2 drawPos = proj.oldPos[i] + centerOffset - Main.screenPosition + new Vector2(0f, proj.gfxOffY); + // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS. THIS WILL BREAK THE AFTERIMAGES. + Color color = proj.GetAlpha(lightColor) * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), color, afterimageRot, origin, scale, sfxForThisAfterimage, 0f); + } + break; - default: - failedToDrawAfterimages = true; - break; - } - } + default: + failedToDrawAfterimages = true; + break; + } + } - // Draw the projectile itself. Only do this if no afterimages are drawn because afterimage 0 is the projectile itself. - if (!CalamityConfig.Instance.Afterimages || ProjectileID.Sets.TrailCacheLength[proj.type] <= 0 || failedToDrawAfterimages) - { - Vector2 startPos = drawCentered ? proj.Center : proj.position; - Main.spriteBatch.Draw(texture, startPos - Main.screenPosition + new Vector2(0f, proj.gfxOffY), rectangle, proj.GetAlpha(lightColor), rotation, origin, scale, spriteEffects, 0f); - } - } + // Draw the projectile itself. Only do this if no afterimages are drawn because afterimage 0 is the projectile itself. + if (!CalamityConfig.Instance.Afterimages || ProjectileID.Sets.TrailCacheLength[proj.type] <= 0 || failedToDrawAfterimages) + { + Vector2 startPos = drawCentered ? proj.Center : proj.position; + Main.spriteBatch.Draw(texture, startPos - Main.screenPosition + new Vector2(0f, proj.gfxOffY), rectangle, proj.GetAlpha(lightColor), rotation, origin, scale, spriteEffects, 0f); + } + } - // Used for bullets. This lets you draw afterimages while keeping the hitbox at the front of the projectile. - // This supports type 0 and type 2 afterimages. Vanilla bullets never have type 2 afterimages. - public static void DrawAfterimagesFromEdge(Projectile proj, int mode, Color lightColor, Texture2D texture = null) - { - if (texture is null) - texture = Main.projectileTexture[proj.type]; + // Used for bullets. This lets you draw afterimages while keeping the hitbox at the front of the projectile. + // This supports type 0 and type 2 afterimages. Vanilla bullets never have type 2 afterimages. + public static void DrawAfterimagesFromEdge(Projectile proj, int mode, Color lightColor, Texture2D texture = null) + { + if (texture is null) + texture = Main.projectileTexture[proj.type]; - int frameHeight = texture.Height / Main.projFrames[proj.type]; - int frameY = frameHeight * proj.frame; - float scale = proj.scale; - float rotation = proj.rotation; + int frameHeight = texture.Height / Main.projFrames[proj.type]; + int frameY = frameHeight * proj.frame; + float scale = proj.scale; + float rotation = proj.rotation; - Rectangle rectangle = new Rectangle(0, frameY, texture.Width, frameHeight); + Rectangle rectangle = new Rectangle(0, frameY, texture.Width, frameHeight); - SpriteEffects spriteEffects = SpriteEffects.None; - if (proj.spriteDirection == -1) - spriteEffects = SpriteEffects.FlipHorizontally; + SpriteEffects spriteEffects = SpriteEffects.None; + if (proj.spriteDirection == -1) + spriteEffects = SpriteEffects.FlipHorizontally; - Vector2 drawOrigin = new Vector2(texture.Width * 0.5f, proj.height * 0.5f); + Vector2 drawOrigin = new Vector2(texture.Width * 0.5f, proj.height * 0.5f); - switch (mode) - { - default: // If you specify an afterimage mode other than 0 or 2, you get nothing. - return; + switch (mode) + { + default: // If you specify an afterimage mode other than 0 or 2, you get nothing. + return; - // Standard afterimages. No customizable features other than total afterimage count. - // Type 0 afterimages linearly scale down from 100% to 0% opacity. Their color and lighting is equal to the main projectile's. - case 0: - for (int i = 0; i < proj.oldPos.Length; ++i) - { - Vector2 drawPos = proj.oldPos[i] + drawOrigin - Main.screenPosition + new Vector2(0f, proj.gfxOffY); - // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS. THIS WILL BREAK THE AFTERIMAGES. - Color color = proj.GetAlpha(lightColor) * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); - Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), color, rotation, drawOrigin, scale, spriteEffects, 0f); - } - return; + // Standard afterimages. No customizable features other than total afterimage count. + // Type 0 afterimages linearly scale down from 100% to 0% opacity. Their color and lighting is equal to the main projectile's. + case 0: + for (int i = 0; i < proj.oldPos.Length; ++i) + { + Vector2 drawPos = proj.oldPos[i] + drawOrigin - Main.screenPosition + new Vector2(0f, proj.gfxOffY); + // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS. THIS WILL BREAK THE AFTERIMAGES. + Color color = proj.GetAlpha(lightColor) * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), color, rotation, drawOrigin, scale, spriteEffects, 0f); + } + return; - // Standard afterimages with rotation. No customizable features other than total afterimage count. - // Type 2 afterimages linearly scale down from 100% to 0% opacity. Their color and lighting is equal to the main projectile's. - case 2: - for (int i = 0; i < proj.oldPos.Length; ++i) - { - float afterimageRot = proj.oldRot[i]; - SpriteEffects sfxForThisAfterimage = proj.oldSpriteDirection[i] == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + // Standard afterimages with rotation. No customizable features other than total afterimage count. + // Type 2 afterimages linearly scale down from 100% to 0% opacity. Their color and lighting is equal to the main projectile's. + case 2: + for (int i = 0; i < proj.oldPos.Length; ++i) + { + float afterimageRot = proj.oldRot[i]; + SpriteEffects sfxForThisAfterimage = proj.oldSpriteDirection[i] == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; - Vector2 drawPos = proj.oldPos[i] + drawOrigin - Main.screenPosition + new Vector2(0f, proj.gfxOffY); - // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS. THIS WILL BREAK THE AFTERIMAGES. - Color color = proj.GetAlpha(lightColor) * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); - Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), color, afterimageRot, drawOrigin, scale, sfxForThisAfterimage, 0f); - } - return; - } - } - #endregion + Vector2 drawPos = proj.oldPos[i] + drawOrigin - Main.screenPosition + new Vector2(0f, proj.gfxOffY); + // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS. THIS WILL BREAK THE AFTERIMAGES. + Color color = proj.GetAlpha(lightColor) * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), color, afterimageRot, drawOrigin, scale, sfxForThisAfterimage, 0f); + } + return; + } + } + #endregion - /// - /// Calculates perspective matrices for usage by vertex shaders. - /// - /// The view matrix. - /// The projection matrix. - public static void CalculatePerspectiveMatricies(out Matrix viewMatrix, out Matrix projectionMatrix) - { - Vector2 zoom = Main.GameViewMatrix.Zoom; - Matrix zoomScaleMatrix = Matrix.CreateScale(zoom.X, zoom.Y, 1f); + /// + /// Calculates perspective matrices for usage by vertex shaders. + /// + /// The view matrix. + /// The projection matrix. + public static void CalculatePerspectiveMatricies(out Matrix viewMatrix, out Matrix projectionMatrix) + { + Vector2 zoom = Main.GameViewMatrix.Zoom; + Matrix zoomScaleMatrix = Matrix.CreateScale(zoom.X, zoom.Y, 1f); - // Screen bounds. - int height = Main.instance.GraphicsDevice.Viewport.Height; + // Screen bounds. + int height = Main.instance.GraphicsDevice.Viewport.Height; - // Get a matrix that aims towards the Z axis (these calculations are relative to a 2D world). - viewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.UnitZ, Vector3.Up); + // Get a matrix that aims towards the Z axis (these calculations are relative to a 2D world). + viewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.UnitZ, Vector3.Up); - // Offset the matrix to the appropriate position. - viewMatrix *= Matrix.CreateTranslation(0f, -height, 0f); + // Offset the matrix to the appropriate position. + viewMatrix *= Matrix.CreateTranslation(0f, -height, 0f); - // Flip the matrix around 180 degrees. - viewMatrix *= Matrix.CreateRotationZ(MathHelper.Pi); + // Flip the matrix around 180 degrees. + viewMatrix *= Matrix.CreateRotationZ(MathHelper.Pi); - // Account for the inverted gravity effect. - if (Main.LocalPlayer.gravDir == -1f) - viewMatrix *= Matrix.CreateScale(1f, -1f, 1f) * Matrix.CreateTranslation(0f, height, 0f); + // Account for the inverted gravity effect. + if (Main.LocalPlayer.gravDir == -1f) + viewMatrix *= Matrix.CreateScale(1f, -1f, 1f) * Matrix.CreateTranslation(0f, height, 0f); - // And account for the current zoom. - viewMatrix *= zoomScaleMatrix; + // And account for the current zoom. + viewMatrix *= zoomScaleMatrix; - projectionMatrix = Matrix.CreateOrthographicOffCenter(0f, Main.screenWidth * zoom.X, 0f, Main.screenHeight * zoom.Y, 0f, 1f) * zoomScaleMatrix; - } + projectionMatrix = Matrix.CreateOrthographicOffCenter(0f, Main.screenWidth * zoom.X, 0f, Main.screenHeight * zoom.Y, 0f, 1f) * zoomScaleMatrix; + } - /// - /// Sets a 's arbitrarily. - /// - /// The sprite batch. - /// The blend state to use. - public static void SetBlendState(this SpriteBatch spriteBatch, BlendState blendState) - { - spriteBatch.End(); - spriteBatch.Begin(SpriteSortMode.Immediate, blendState, Main.DefaultSamplerState, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Main.GameViewMatrix.TransformationMatrix); - } + /// + /// Sets a 's arbitrarily. + /// + /// The sprite batch. + /// The blend state to use. + public static void SetBlendState(this SpriteBatch spriteBatch, BlendState blendState) + { + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, blendState, Main.DefaultSamplerState, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Main.GameViewMatrix.TransformationMatrix); + } - // Cached for efficiency purposes. - internal static readonly FieldInfo BeginEndPairField = typeof(SpriteBatch).GetField("inBeginEndPair", BindingFlags.NonPublic | BindingFlags.Instance); + // Cached for efficiency purposes. + internal static readonly FieldInfo BeginEndPairField = typeof(SpriteBatch).GetField("inBeginEndPair", BindingFlags.NonPublic | BindingFlags.Instance); - /// - /// Determines if a is in a lock due to a call. - /// - /// The sprite batch to check. - public static bool HasBeginBeenCalled(this SpriteBatch spriteBatch) - { - return (bool)BeginEndPairField.GetValue(spriteBatch); - } + /// + /// Determines if a is in a lock due to a call. + /// + /// The sprite batch to check. + public static bool HasBeginBeenCalled(this SpriteBatch spriteBatch) + { + return (bool)BeginEndPairField.GetValue(spriteBatch); + } - /// - /// Draws text with an eight-way one-pixel offset border. - /// - /// - /// - /// - /// - /// - /// - /// - public static void DrawBorderStringEightWay(SpriteBatch sb, DynamicSpriteFont font, string text, Vector2 baseDrawPosition, Color main, Color border, float scale = 1f) - { - for (int x = -1; x <= 1; x++) - { - for (int y = -1; y <= 1; y++) - { - Vector2 drawPosition = baseDrawPosition + new Vector2(x, y); - if (x == 0 && y == 0) - continue; + /// + /// Draws a line significantly more efficiently than using just one scaled line texture. Positions are automatically converted to screen coordinates. + /// + /// The sprite batch by which the line should be drawn. + /// The starting point of the line in world coordinates. + /// The ending point of the line in world coordinates. + /// The color of the line. + /// The width of the line. + public static void DrawLineBetter(this SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color, float width) + { + // Draw nothing if the start and end are equal, to prevent division by 0 problems. + if (start == end) + return; - DynamicSpriteFontExtensionMethods.DrawString(sb, font, text, drawPosition, border, 0f, default, scale, SpriteEffects.None, 0f); - } - } - DynamicSpriteFontExtensionMethods.DrawString(sb, font, text, baseDrawPosition, main, 0f, default, scale, SpriteEffects.None, 0f); - } + start -= Main.screenPosition; + end -= Main.screenPosition; - public static void DrawItemGlowmaskSingleFrame(this Item item, SpriteBatch spriteBatch, float rotation, Texture2D glowmaskTexture) - { - Vector2 origin = new Vector2(glowmaskTexture.Width / 2f, glowmaskTexture.Height / 2f - 2f); - spriteBatch.Draw(glowmaskTexture, item.Center - Main.screenPosition, null, Color.White, rotation, origin, 1f, SpriteEffects.None, 0f); - } + Texture2D line = ModContent.GetTexture("InfernumMode/ExtraTextures/Line"); + float rotation = (end - start).ToRotation(); + Vector2 scale = new Vector2(Vector2.Distance(start, end) / line.Width, width); - public static Rectangle GetCurrentFrame(this Item item, ref int frame, ref int frameCounter, int frameDelay, int frameAmt, bool frameCounterUp = true) - { - if (frameCounter >= frameDelay) - { - frameCounter = -1; - frame = frame == frameAmt - 1 ? 0 : frame + 1; - } - if (frameCounterUp) - frameCounter++; - return new Rectangle(0, item.height * frame, item.width, item.height); - } + spriteBatch.Draw(line, start, null, color, rotation, line.Size() * Vector2.UnitY * 0.5f, scale, SpriteEffects.None, 0f); + } - public static bool DrawFishingLine(this Projectile projectile, int fishingRodType, Color poleColor, int xPositionAdditive = 45, float yPositionAdditive = 35f) - { - Player player = Main.player[projectile.owner]; - Item item = player.HeldItem; - if (!projectile.bobber || item.holdStyle <= 0) - return false; + /// + /// Draws text with an eight-way one-pixel offset border. + /// + /// + /// + /// + /// + /// + /// + /// + public static void DrawBorderStringEightWay(SpriteBatch sb, DynamicSpriteFont font, string text, Vector2 baseDrawPosition, Color main, Color border, float scale = 1f) + { + for (int x = -1; x <= 1; x++) + { + for (int y = -1; y <= 1; y++) + { + Vector2 drawPosition = baseDrawPosition + new Vector2(x, y); + if (x == 0 && y == 0) + continue; - float originX = player.MountedCenter.X; - float originY = player.MountedCenter.Y; - originY += player.gfxOffY; - //This variable is used to account for Gravitation Potions - float gravity = player.gravDir; + DynamicSpriteFontExtensionMethods.DrawString(sb, font, text, drawPosition, border, 0f, default, scale, SpriteEffects.None, 0f); + } + } + DynamicSpriteFontExtensionMethods.DrawString(sb, font, text, baseDrawPosition, main, 0f, default, scale, SpriteEffects.None, 0f); + } - if (item.type == fishingRodType) - { - originX += (float)(xPositionAdditive * player.direction); - if (player.direction < 0) - { - originX -= 13f; - } - originY -= yPositionAdditive * gravity; - } + public static void DrawItemGlowmaskSingleFrame(this Item item, SpriteBatch spriteBatch, float rotation, Texture2D glowmaskTexture) + { + Vector2 origin = new Vector2(glowmaskTexture.Width / 2f, glowmaskTexture.Height / 2f - 2f); + spriteBatch.Draw(glowmaskTexture, item.Center - Main.screenPosition, null, Color.White, rotation, origin, 1f, SpriteEffects.None, 0f); + } - if (gravity == -1f) - { - originY -= 12f; - } - Vector2 mountedCenter = new Vector2(originX, originY); - mountedCenter = player.RotatedRelativePoint(mountedCenter + new Vector2(8f), true) - new Vector2(8f); - Vector2 lineOrigin = projectile.Center - mountedCenter; - bool canDraw = true; - if (lineOrigin.X == 0f && lineOrigin.Y == 0f) - return false; + public static Rectangle GetCurrentFrame(this Item item, ref int frame, ref int frameCounter, int frameDelay, int frameAmt, bool frameCounterUp = true) + { + if (frameCounter >= frameDelay) + { + frameCounter = -1; + frame = frame == frameAmt - 1 ? 0 : frame + 1; + } + if (frameCounterUp) + frameCounter++; + return new Rectangle(0, item.height * frame, item.width, item.height); + } - float projPosMagnitude = lineOrigin.Length(); - projPosMagnitude = 12f / projPosMagnitude; - lineOrigin.X *= projPosMagnitude; - lineOrigin.Y *= projPosMagnitude; - mountedCenter -= lineOrigin; - lineOrigin = projectile.Center - mountedCenter; + public static bool DrawFishingLine(this Projectile projectile, int fishingRodType, Color poleColor, int xPositionAdditive = 45, float yPositionAdditive = 35f) + { + Player player = Main.player[projectile.owner]; + Item item = player.HeldItem; + if (!projectile.bobber || item.holdStyle <= 0) + return false; - while (canDraw) - { - float height = 12f; - float positionMagnitude = lineOrigin.Length(); - if (float.IsNaN(positionMagnitude) || float.IsNaN(positionMagnitude)) - break; + float originX = player.MountedCenter.X; + float originY = player.MountedCenter.Y; + originY += player.gfxOffY; + //This variable is used to account for Gravitation Potions + float gravity = player.gravDir; - if (positionMagnitude < 20f) - { - height = positionMagnitude - 8f; - canDraw = false; - } - positionMagnitude = 12f / positionMagnitude; - lineOrigin.X *= positionMagnitude; - lineOrigin.Y *= positionMagnitude; - mountedCenter += lineOrigin; - lineOrigin = projectile.Center - mountedCenter; - if (positionMagnitude > 12f) - { - float positionInverseMultiplier = 0.3f; - float absVelocitySum = Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y); - if (absVelocitySum > 16f) - { - absVelocitySum = 16f; - } - absVelocitySum = 1f - absVelocitySum / 16f; - positionInverseMultiplier *= absVelocitySum; - absVelocitySum = positionMagnitude / 80f; - if (absVelocitySum > 1f) - { - absVelocitySum = 1f; - } - positionInverseMultiplier *= absVelocitySum; - if (positionInverseMultiplier < 0f) - { - positionInverseMultiplier = 0f; - } - absVelocitySum = 1f - projectile.localAI[0] / 100f; - positionInverseMultiplier *= absVelocitySum; - if (lineOrigin.Y > 0f) - { - lineOrigin.Y *= 1f + positionInverseMultiplier; - lineOrigin.X *= 1f - positionInverseMultiplier; - } - else - { - absVelocitySum = Math.Abs(projectile.velocity.X) / 3f; - if (absVelocitySum > 1f) - { - absVelocitySum = 1f; - } - absVelocitySum -= 0.5f; - positionInverseMultiplier *= absVelocitySum; - if (positionInverseMultiplier > 0f) - { - positionInverseMultiplier *= 2f; - } - lineOrigin.Y *= 1f + positionInverseMultiplier; - lineOrigin.X *= 1f - positionInverseMultiplier; - } - } - //This color decides the color of the fishing line. - Color lineColor = Lighting.GetColor((int)mountedCenter.X / 16, (int)mountedCenter.Y / 16, poleColor); - float rotation = lineOrigin.ToRotation() - MathHelper.PiOver2; + if (item.type == fishingRodType) + { + originX += (float)(xPositionAdditive * player.direction); + if (player.direction < 0) + { + originX -= 13f; + } + originY -= yPositionAdditive * gravity; + } - Main.spriteBatch.Draw(Main.fishingLineTexture, new Vector2(mountedCenter.X - Main.screenPosition.X + Main.fishingLineTexture.Width * 0.5f, mountedCenter.Y - Main.screenPosition.Y + Main.fishingLineTexture.Height * 0.5f), new Rectangle?(new Rectangle(0, 0, Main.fishingLineTexture.Width, (int)height)), lineColor, rotation, new Vector2(Main.fishingLineTexture.Width * 0.5f, 0f), 1f, SpriteEffects.None, 0f); - } - return false; - } + if (gravity == -1f) + { + originY -= 12f; + } + Vector2 mountedCenter = new Vector2(originX, originY); + mountedCenter = player.RotatedRelativePoint(mountedCenter + new Vector2(8f), true) - new Vector2(8f); + Vector2 lineOrigin = projectile.Center - mountedCenter; + bool canDraw = true; + if (lineOrigin.X == 0f && lineOrigin.Y == 0f) + return false; - public static void DrawHook(this Projectile projectile, Texture2D hookTexture, float angleAdditive = 0f) - { - Player player = Main.player[projectile.owner]; - Vector2 center = projectile.Center; - float angleToMountedCenter = projectile.AngleTo(player.MountedCenter) - MathHelper.PiOver2; - bool canShowHook = true; - while (canShowHook) - { - float distanceMagnitude = (player.MountedCenter - center).Length(); //Exact same as using a Sqrt - if (distanceMagnitude < hookTexture.Height + 1f) - { - canShowHook = false; - } - else if (float.IsNaN(distanceMagnitude)) - { - canShowHook = false; - } - else - { - center += projectile.SafeDirectionTo(player.MountedCenter) * hookTexture.Height; - Color tileAtCenterColor = Lighting.GetColor((int)center.X / 16, (int)(center.Y / 16f)); - Main.spriteBatch.Draw(hookTexture, center - Main.screenPosition, - new Rectangle?(new Rectangle(0, 0, hookTexture.Width, hookTexture.Height)), - tileAtCenterColor, angleToMountedCenter + angleAdditive, - hookTexture.Size() / 2, 1f, SpriteEffects.None, 0f); - } - } - } + float projPosMagnitude = lineOrigin.Length(); + projPosMagnitude = 12f / projPosMagnitude; + lineOrigin.X *= projPosMagnitude; + lineOrigin.Y *= projPosMagnitude; + mountedCenter -= lineOrigin; + lineOrigin = projectile.Center - mountedCenter; - internal static void IterateDisco(ref Color c, ref float aiParam, in byte discoIter = 7) - { - switch (aiParam) - { - case 0f: - c.G += discoIter; - if (c.G >= 255) - { - c.G = 255; - aiParam = 1f; - } - break; - case 1f: - c.R -= discoIter; - if (c.R <= 0) - { - c.R = 0; - aiParam = 2f; - } - break; - case 2f: - c.B += discoIter; - if (c.B >= 255) - { - c.B = 255; - aiParam = 3f; - } - break; - case 3f: - c.G -= discoIter; - if (c.G <= 0) - { - c.G = 0; - aiParam = 4f; - } - break; - case 4f: - c.R += discoIter; - if (c.R >= 255) - { - c.R = 255; - aiParam = 5f; - } - break; - case 5f: - c.B -= discoIter; - if (c.B <= 0) - { - c.B = 0; - aiParam = 0f; - } - break; - default: - aiParam = 0f; - c = Color.Red; - break; - } - } + while (canDraw) + { + float height = 12f; + float positionMagnitude = lineOrigin.Length(); + if (float.IsNaN(positionMagnitude) || float.IsNaN(positionMagnitude)) + break; - public static string ColorMessage(string msg, Color color) - { - StringBuilder sb; - if (!msg.Contains("\n")) - { - sb = new StringBuilder(msg.Length + 12); - sb.Append("[c/").Append(color.Hex3()).Append(':').Append(msg).Append(']'); - } - else - { - sb = new StringBuilder(); - foreach (string newlineSlice in msg.Split('\n')) - sb.Append("[c/").Append(color.Hex3()).Append(':').Append(newlineSlice).Append(']').Append('\n'); - } - return sb.ToString(); - } + if (positionMagnitude < 20f) + { + height = positionMagnitude - 8f; + canDraw = false; + } + positionMagnitude = 12f / positionMagnitude; + lineOrigin.X *= positionMagnitude; + lineOrigin.Y *= positionMagnitude; + mountedCenter += lineOrigin; + lineOrigin = projectile.Center - mountedCenter; + if (positionMagnitude > 12f) + { + float positionInverseMultiplier = 0.3f; + float absVelocitySum = Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y); + if (absVelocitySum > 16f) + { + absVelocitySum = 16f; + } + absVelocitySum = 1f - absVelocitySum / 16f; + positionInverseMultiplier *= absVelocitySum; + absVelocitySum = positionMagnitude / 80f; + if (absVelocitySum > 1f) + { + absVelocitySum = 1f; + } + positionInverseMultiplier *= absVelocitySum; + if (positionInverseMultiplier < 0f) + { + positionInverseMultiplier = 0f; + } + absVelocitySum = 1f - projectile.localAI[0] / 100f; + positionInverseMultiplier *= absVelocitySum; + if (lineOrigin.Y > 0f) + { + lineOrigin.Y *= 1f + positionInverseMultiplier; + lineOrigin.X *= 1f - positionInverseMultiplier; + } + else + { + absVelocitySum = Math.Abs(projectile.velocity.X) / 3f; + if (absVelocitySum > 1f) + { + absVelocitySum = 1f; + } + absVelocitySum -= 0.5f; + positionInverseMultiplier *= absVelocitySum; + if (positionInverseMultiplier > 0f) + { + positionInverseMultiplier *= 2f; + } + lineOrigin.Y *= 1f + positionInverseMultiplier; + lineOrigin.X *= 1f - positionInverseMultiplier; + } + } + //This color decides the color of the fishing line. + Color lineColor = Lighting.GetColor((int)mountedCenter.X / 16, (int)mountedCenter.Y / 16, poleColor); + float rotation = lineOrigin.ToRotation() - MathHelper.PiOver2; - /// - /// Returns a color lerp that allows for smooth transitioning between two given colors - /// - /// The first color you want it to switch between - /// The second color you want it to switch between - /// How long you want it to take to swap between colors - public static Color ColorSwap(Color firstColor, Color secondColor, float seconds) - { - double timeMult = (double)(MathHelper.TwoPi / seconds); - float colorMePurple = (float)((Math.Sin(timeMult * Main.GlobalTime) + 1) * 0.5f); - return Color.Lerp(firstColor, secondColor, colorMePurple); - } - /// - /// Returns a color lerp that supports multiple colors. - /// - /// The 0-1 incremental value used when interpolating. - /// The various colors to interpolate across. - /// - public static Color MulticolorLerp(float increment, params Color[] colors) - { - increment %= 0.999f; - int currentColorIndex = (int)(increment * colors.Length); - Color currentColor = colors[currentColorIndex]; - Color nextColor = colors[(currentColorIndex + 1) % colors.Length]; - return Color.Lerp(currentColor, nextColor, increment * colors.Length % 1f); - } + Main.spriteBatch.Draw(Main.fishingLineTexture, new Vector2(mountedCenter.X - Main.screenPosition.X + Main.fishingLineTexture.Width * 0.5f, mountedCenter.Y - Main.screenPosition.Y + Main.fishingLineTexture.Height * 0.5f), new Rectangle?(new Rectangle(0, 0, Main.fishingLineTexture.Width, (int)height)), lineColor, rotation, new Vector2(Main.fishingLineTexture.Width * 0.5f, 0f), 1f, SpriteEffects.None, 0f); + } + return false; + } - // Cached for efficiency purposes. - internal static readonly FieldInfo UImageFieldMisc = typeof(MiscShaderData).GetField("_uImage", BindingFlags.NonPublic | BindingFlags.Instance); - internal static readonly FieldInfo UImageFieldArmor = typeof(ArmorShaderData).GetField("_uImage", BindingFlags.NonPublic | BindingFlags.Instance); + public static void DrawHook(this Projectile projectile, Texture2D hookTexture, float angleAdditive = 0f) + { + Player player = Main.player[projectile.owner]; + Vector2 center = projectile.Center; + float angleToMountedCenter = projectile.AngleTo(player.MountedCenter) - MathHelper.PiOver2; + bool canShowHook = true; + while (canShowHook) + { + float distanceMagnitude = (player.MountedCenter - center).Length(); //Exact same as using a Sqrt + if (distanceMagnitude < hookTexture.Height + 1f) + { + canShowHook = false; + } + else if (float.IsNaN(distanceMagnitude)) + { + canShowHook = false; + } + else + { + center += projectile.SafeDirectionTo(player.MountedCenter) * hookTexture.Height; + Color tileAtCenterColor = Lighting.GetColor((int)center.X / 16, (int)(center.Y / 16f)); + Main.spriteBatch.Draw(hookTexture, center - Main.screenPosition, + new Rectangle?(new Rectangle(0, 0, hookTexture.Width, hookTexture.Height)), + tileAtCenterColor, angleToMountedCenter + angleAdditive, + hookTexture.Size() / 2, 1f, SpriteEffects.None, 0f); + } + } + } - /// - /// Manually sets the texture of a instance, since vanilla's implementation only supports strings that access vanilla textures. - /// - /// The shader to bind the texture to. - /// The texture to bind. - public static MiscShaderData SetShaderTexture(this MiscShaderData shader, Texture2D texture) - { - UImageFieldMisc.SetValue(shader, new Ref(texture)); - return shader; - } + internal static void IterateDisco(ref Color c, ref float aiParam, in byte discoIter = 7) + { + switch (aiParam) + { + case 0f: + c.G += discoIter; + if (c.G >= 255) + { + c.G = 255; + aiParam = 1f; + } + break; + case 1f: + c.R -= discoIter; + if (c.R <= 0) + { + c.R = 0; + aiParam = 2f; + } + break; + case 2f: + c.B += discoIter; + if (c.B >= 255) + { + c.B = 255; + aiParam = 3f; + } + break; + case 3f: + c.G -= discoIter; + if (c.G <= 0) + { + c.G = 0; + aiParam = 4f; + } + break; + case 4f: + c.R += discoIter; + if (c.R >= 255) + { + c.R = 255; + aiParam = 5f; + } + break; + case 5f: + c.B -= discoIter; + if (c.B <= 0) + { + c.B = 0; + aiParam = 0f; + } + break; + default: + aiParam = 0f; + c = Color.Red; + break; + } + } - /// - /// Manually sets the texture of a instance, since vanilla's implementation only supports strings that access vanilla textures. - /// - /// The shader to bind the texture to. - /// The texture to bind. - public static ArmorShaderData SetShaderTexture(this ArmorShaderData shader, Texture2D texture) - { - UImageFieldArmor.SetValue(shader, new Ref(texture)); - return shader; - } + public static string ColorMessage(string msg, Color color) + { + StringBuilder sb; + if (!msg.Contains("\n")) + { + sb = new StringBuilder(msg.Length + 12); + sb.Append("[c/").Append(color.Hex3()).Append(':').Append(msg).Append(']'); + } + else + { + sb = new StringBuilder(); + foreach (string newlineSlice in msg.Split('\n')) + sb.Append("[c/").Append(color.Hex3()).Append(':').Append(newlineSlice).Append(']').Append('\n'); + } + return sb.ToString(); + } - public static void EnterShaderRegion(this SpriteBatch spriteBatch) - { - spriteBatch.End(); - spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); - } + /// + /// Returns a color lerp that allows for smooth transitioning between two given colors + /// + /// The first color you want it to switch between + /// The second color you want it to switch between + /// How long you want it to take to swap between colors + public static Color ColorSwap(Color firstColor, Color secondColor, float seconds) + { + double timeMult = (double)(MathHelper.TwoPi / seconds); + float colorMePurple = (float)((Math.Sin(timeMult * Main.GlobalTime) + 1) * 0.5f); + return Color.Lerp(firstColor, secondColor, colorMePurple); + } + /// + /// Returns a color lerp that supports multiple colors. + /// + /// The 0-1 incremental value used when interpolating. + /// The various colors to interpolate across. + /// + public static Color MulticolorLerp(float increment, params Color[] colors) + { + increment %= 0.999f; + int currentColorIndex = (int)(increment * colors.Length); + Color currentColor = colors[currentColorIndex]; + Color nextColor = colors[(currentColorIndex + 1) % colors.Length]; + return Color.Lerp(currentColor, nextColor, increment * colors.Length % 1f); + } - public static void ExitShaderRegion(this SpriteBatch spriteBatch) - { - spriteBatch.End(); - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); - } + // Cached for efficiency purposes. + internal static readonly FieldInfo UImageFieldMisc = typeof(MiscShaderData).GetField("_uImage", BindingFlags.NonPublic | BindingFlags.Instance); + internal static readonly FieldInfo UImageFieldArmor = typeof(ArmorShaderData).GetField("_uImage", BindingFlags.NonPublic | BindingFlags.Instance); - public static void DrawAuroras(Player player, float auroraCount, float opacity, Color color) - { + /// + /// Manually sets the texture of a instance, since vanilla's implementation only supports strings that access vanilla textures. + /// + /// The shader to bind the texture to. + /// The texture to bind. + public static MiscShaderData SetShaderTexture(this MiscShaderData shader, Texture2D texture) + { + UImageFieldMisc.SetValue(shader, new Ref(texture)); + return shader; + } + + /// + /// Manually sets the texture of a instance, since vanilla's implementation only supports strings that access vanilla textures. + /// + /// The shader to bind the texture to. + /// The texture to bind. + public static ArmorShaderData SetShaderTexture(this ArmorShaderData shader, Texture2D texture) + { + UImageFieldArmor.SetValue(shader, new Ref(texture)); + return shader; + } + + public static void EnterShaderRegion(this SpriteBatch spriteBatch) + { + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + } + + public static void ExitShaderRegion(this SpriteBatch spriteBatch) + { + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + } + + public static void DrawAuroras(Player player, float auroraCount, float opacity, Color color) + { float time = Main.GlobalTime % 3f / 3f; Texture2D auroraTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/AuroraTexture"); for (int i = 0; i < auroraCount; i++) @@ -582,6 +606,6 @@ namespace CalamityMod 1); Main.playerDrawData.Add(drawData); } - } - } + } + } } diff --git a/Utilities/NPCStats.cs b/Utilities/NPCStats.cs index 942dea6426..7a6cabd163 100644 --- a/Utilities/NPCStats.cs +++ b/Utilities/NPCStats.cs @@ -38,6 +38,7 @@ using System.Collections.Generic; using Terraria; using Terraria.ID; using Terraria.ModLoader; +using CalamityMod.NPCs.AcidRain; namespace CalamityMod { @@ -739,6 +740,9 @@ namespace CalamityMod { new Tuple(ModContent.NPCType(), ModContent.ProjectileType()), new int[] { 160, 276, 304, 320, 456 } }, { new Tuple(ModContent.NPCType(), ModContent.ProjectileType()), new int[] { 130, 212, 236, 248, 354 } }, + { new Tuple(ModContent.NPCType(), ModContent.ProjectileType()), new int[] { 140, 220, 220, 220, 220 } }, + { new Tuple(ModContent.NPCType(), ModContent.ProjectileType()), new int[] { 140, 220, 220, 220, 220 } }, + { new Tuple(ModContent.NPCType(), ModContent.ProjectileType()), new int[] { 150, 240, 264, 276, 390 } }, { new Tuple(ModContent.NPCType(), ModContent.ProjectileType()), new int[] { 280, 400, 440, 464, 660 } }, { new Tuple(ModContent.NPCType(), ModContent.ProjectileType()), new int[] { 150, 240, 264, 276, 390 } },