diff --git a/NPCs/Abyss/ColossalSquid.cs b/NPCs/Abyss/ColossalSquid.cs index 3ebfabf130..818727d813 100644 --- a/NPCs/Abyss/ColossalSquid.cs +++ b/NPCs/Abyss/ColossalSquid.cs @@ -116,6 +116,9 @@ namespace CalamityMod.NPCs.Abyss NPC.noTileCollide = false; if (NPC.ai[0] == 0f) { + // Avoid cheap bullshit + NPC.damage = 0; + NPC.TargetClosest(true); if (Collision.CanHit(NPC.Center, 1, 1, Main.player[NPC.target].Center, 1, 1)) { @@ -174,6 +177,9 @@ namespace CalamityMod.NPCs.Abyss } else if (NPC.ai[0] == 1f) { + // Avoid cheap bullshit + NPC.damage = 0; + NPC.rotation += (float)NPC.direction * 0.1f; Vector2 latchPosition = Main.player[NPC.target].Top - NPC.Center; float latchDistance = latchPosition.Length(); @@ -199,6 +205,9 @@ namespace CalamityMod.NPCs.Abyss } else if (NPC.ai[0] == 2f) { + // Avoid cheap bullshit + NPC.damage = 0; + NPC.rotation = NPC.velocity.X * 0.05f; NPC.noTileCollide = true; Vector2 lungeDirection = Main.player[NPC.target].Center - NPC.Center; @@ -215,6 +224,9 @@ namespace CalamityMod.NPCs.Abyss } else if (NPC.ai[0] == 3f) { + // Avoid cheap bullshit + NPC.damage = 0; + NPC.rotation = NPC.velocity.X * 0.05f; Vector2 otherLungePos = new Vector2(NPC.ai[1], NPC.ai[2]); Vector2 otherLungeDirection = otherLungePos - NPC.Center; @@ -236,6 +248,9 @@ namespace CalamityMod.NPCs.Abyss } else if (NPC.ai[0] == 4f) { + // Avoid cheap bullshit + NPC.damage = 0; + NPC.rotation = NPC.velocity.X * 0.05f; if (NPC.collideX) { @@ -295,6 +310,9 @@ namespace CalamityMod.NPCs.Abyss } else if (NPC.ai[0] == 5f) { + // Set damage + NPC.damage = NPC.defDamage; + Player latchedTarget = Main.player[NPC.target]; if (!latchedTarget.active || latchedTarget.dead || clone) { @@ -437,9 +455,23 @@ namespace CalamityMod.NPCs.Abyss if (Main.netMode != NetmodeID.MultiplayerClient) Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center.X, NPC.Center.Y + 60, 0f, 2f, ModContent.ProjectileType(), damage, 0f, Main.myPlayer); } + NPC.rotation = NPC.velocity.X * 0.05f; NPC.velocity *= 0.975f; + float hitLungeThreshold = 2.5f; + float lungeVelocity = 20f; + if (NPC.velocity.Length() > lungeVelocity * 0.4f) + { + // Set damage + NPC.damage = NPC.defDamage; + } + else + { + // Avoid cheap bullshit + NPC.damage = 0; + } + if (NPC.velocity.X > -hitLungeThreshold && NPC.velocity.X < hitLungeThreshold && NPC.velocity.Y > -hitLungeThreshold && NPC.velocity.Y < hitLungeThreshold) { NPC.TargetClosest(true); @@ -447,7 +479,7 @@ namespace CalamityMod.NPCs.Abyss float hitLungeTargetX = Main.player[NPC.target].position.X + (float)(Main.player[NPC.target].width / 2) - hitLungePos.X; float hitLungeTargetY = Main.player[NPC.target].position.Y + (float)(Main.player[NPC.target].height / 2) - hitLungePos.Y; float hitLungeTargetDist = (float)Math.Sqrt((double)(hitLungeTargetX * hitLungeTargetX + hitLungeTargetY * hitLungeTargetY)); - hitLungeTargetDist = 20f / hitLungeTargetDist; + hitLungeTargetDist = lungeVelocity / hitLungeTargetDist; hitLungeTargetX *= hitLungeTargetDist; hitLungeTargetY *= hitLungeTargetDist; NPC.velocity.X = hitLungeTargetX; @@ -457,6 +489,9 @@ namespace CalamityMod.NPCs.Abyss } else { + // Avoid cheap bullshit + NPC.damage = 0; + if (Main.rand.NextBool(300)) { SoundEngine.PlaySound(SoundID.Zombie35, NPC.Center); @@ -508,6 +543,7 @@ namespace CalamityMod.NPCs.Abyss } } } + float pushVelocity = 0.05f; for (int i = 0; i < Main.maxNPCs; i++) { @@ -530,10 +566,9 @@ namespace CalamityMod.NPCs.Abyss } } } + if (Vector2.Distance(Main.player[NPC.target].Center, NPC.Center) > 6400f) - { NPC.active = false; - } } public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) diff --git a/NPCs/Astral/HiveEnemy.cs b/NPCs/Astral/HiveEnemy.cs index fec00f84d9..664ef0c51f 100644 --- a/NPCs/Astral/HiveEnemy.cs +++ b/NPCs/Astral/HiveEnemy.cs @@ -71,6 +71,9 @@ namespace CalamityMod.NPCs.Astral public override void AI() { + // Setting this in SetDefaults will disable expert mode scaling, so put it here instead + NPC.damage = 0; + NPC.ai[0]++; if (NPC.ai[0] > (CalamityWorld.death ? 60f : CalamityWorld.revenge ? 120f : 180f)) { diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index ea7c92c5d3..0ff25a29a8 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -7734,12 +7734,13 @@ namespace CalamityMod.NPCs if (!Main.expertMode) return; - if (npc.knockBackResist <= 0f || npc.knockBackResist >= 1f) + if (npc.knockBackResist <= 0f) return; + // Knockback resist is backasswards in this fucking game so we need to add to the knockBackResist variable here :^) float knockBackResistMult = Main.masterMode ? MasterModeEnemyKnockbackMultiplier : ExpertModeEnemyKnockbackMultiplier; - float knockBackResistReduction = MathHelper.Clamp((1f - npc.knockBackResist) * knockBackResistMult, 0f, npc.knockBackResist - 0.01f); - npc.knockBackResist -= knockBackResistReduction; + float knockBackResistReduction = npc.knockBackResist * knockBackResistMult; + npc.knockBackResist += knockBackResistReduction; } #endregion } diff --git a/NPCs/Crags/SoulSlurper.cs b/NPCs/Crags/SoulSlurper.cs index b0b66cabb8..59bd6b5d5e 100644 --- a/NPCs/Crags/SoulSlurper.cs +++ b/NPCs/Crags/SoulSlurper.cs @@ -29,7 +29,7 @@ namespace CalamityMod.NPCs.Crags AIType = -1; NPC.npcSlots = 1f; NPC.damage = 30; - NPC.width = 60; + NPC.width = 40; NPC.height = 40; NPC.defense = 30; NPC.DR_NERD(0.15f); @@ -73,6 +73,9 @@ namespace CalamityMod.NPCs.Crags public override void AI() { + // Setting this in SetDefaults will disable expert mode scaling, so put it here instead + NPC.damage = 0; + bool provy = DownedBossSystem.downedProvidence; Player target = Main.player[NPC.target]; if (NPC.target < 0 || NPC.target == Main.maxPlayers || target.dead) @@ -163,13 +166,10 @@ namespace CalamityMod.NPCs.Crags NPC.localAI[0] = 0f; if (Collision.CanHit(NPC.position, NPC.width, NPC.height, target.position, target.width, target.height)) { - int dmg = 30; - if (Main.expertMode) - { - dmg = 22; - } + int dmg = Main.expertMode ? 22 : 30; int projType = ModContent.ProjectileType(); - Projectile.NewProjectile(NPC.GetSource_FromAI(), npcCenter.X, npcCenter.Y, targetX, targetY, projType, dmg + (provy ? 30 : 0), 0f, Main.myPlayer, 1f, 0f); + Vector2 projectileVelocity = new Vector2(targetX, targetY); + Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center + projectileVelocity.SafeNormalize(Vector2.UnitY) * 16f, projectileVelocity, projType, dmg + (provy ? 30 : 0), 0f, Main.myPlayer, 1f, 0f); } } int npcTileX = (int)NPC.Center.X; diff --git a/NPCs/DesertScourge/DesertScourgeBody.cs b/NPCs/DesertScourge/DesertScourgeBody.cs index eead0992e7..23693f3e39 100644 --- a/NPCs/DesertScourge/DesertScourgeBody.cs +++ b/NPCs/DesertScourge/DesertScourgeBody.cs @@ -67,12 +67,19 @@ namespace CalamityMod.NPCs.DesertScourge public override void AI() { + bool bossRush = BossRushEvent.BossRushActive; + bool expertMode = Main.expertMode || bossRush; + bool masterMode = Main.masterMode || bossRush; + if (NPC.ai[2] > 0f) NPC.realLife = (int)NPC.ai[2]; if (NPC.life > Main.npc[(int)NPC.ai[1]].life) NPC.life = Main.npc[(int)NPC.ai[1]].life; + // Percent life remaining + float lifeRatio = NPC.life / (float)NPC.lifeMax; + if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(); @@ -147,7 +154,10 @@ namespace CalamityMod.NPCs.DesertScourge } // Calculate contact damage based on velocity - float maxChaseSpeed = 16f; + float maxChaseSpeed = masterMode ? DesertScourgeHead.SegmentVelocity_Master : expertMode ? DesertScourgeHead.SegmentVelocity_Expert : DesertScourgeHead.SegmentVelocity_Normal; + if (expertMode) + maxChaseSpeed += 5f * (1f - lifeRatio); + float minimalContactDamageVelocity = maxChaseSpeed * 0.25f; float minimalDamageVelocity = maxChaseSpeed * 0.5f; float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); diff --git a/NPCs/DesertScourge/DesertScourgeHead.cs b/NPCs/DesertScourge/DesertScourgeHead.cs index 50894191b5..01c314de5f 100644 --- a/NPCs/DesertScourge/DesertScourgeHead.cs +++ b/NPCs/DesertScourge/DesertScourgeHead.cs @@ -37,6 +37,10 @@ namespace CalamityMod.NPCs.DesertScourge private bool TailSpawned = false; public bool playRoarSound = false; + public const float SegmentVelocity_Normal = 8f; + public const float SegmentVelocity_Expert = 10f; + public const float SegmentVelocity_Master = 12f; + public static readonly SoundStyle RoarSound = new("CalamityMod/Sounds/Custom/DesertScourgeRoar"); public override void SetStaticDefaults() @@ -134,6 +138,7 @@ namespace CalamityMod.NPCs.DesertScourge { bool bossRush = BossRushEvent.BossRushActive; bool expertMode = Main.expertMode || bossRush; + bool masterMode = Main.masterMode || bossRush; bool revenge = CalamityWorld.revenge || bossRush; bool death = CalamityWorld.death || bossRush; @@ -177,19 +182,19 @@ namespace CalamityMod.NPCs.DesertScourge bool lungeUpward = burrow && NPC.Calamity().newAI[1] == 1f; bool quickFall = NPC.Calamity().newAI[1] == 2f; - float speed = 0.09f; - float turnSpeed = 0.06f; + float speed = death ? 0.15f : 0.12f; + float turnSpeed = death ? 0.1f : 0.08f; - if (expertMode) + if (revenge) { - float velocityScale = death ? 0.12f : 0.06f; + float velocityScale = death ? 0.08f : 0.06f; speed += velocityScale * (1f - lifeRatio); - float accelerationScale = death ? 0.075f : 0.05f; + float accelerationScale = death ? 0.05f : 0.04f; turnSpeed += accelerationScale * (1f - lifeRatio); } - speed += 0.12f * enrageScale; - turnSpeed += 0.06f * enrageScale; + speed += 0.1f * enrageScale; + turnSpeed += 0.05f * enrageScale; if (Main.getGoodWorld) { @@ -371,7 +376,10 @@ namespace CalamityMod.NPCs.DesertScourge else NPC.localAI[1] = 0f; - float maxChaseSpeed = 16f; + float maxChaseSpeed = masterMode ? SegmentVelocity_Master : expertMode ? SegmentVelocity_Expert : SegmentVelocity_Normal; + if (expertMode) + maxChaseSpeed += 5f * (1f - lifeRatio); + if (player.dead) { shouldFly = false; diff --git a/NPCs/DesertScourge/DesertScourgeTail.cs b/NPCs/DesertScourge/DesertScourgeTail.cs index f71f79fe64..ea0d38c87f 100644 --- a/NPCs/DesertScourge/DesertScourgeTail.cs +++ b/NPCs/DesertScourge/DesertScourgeTail.cs @@ -65,12 +65,19 @@ namespace CalamityMod.NPCs.DesertScourge public override void AI() { + bool bossRush = BossRushEvent.BossRushActive; + bool expertMode = Main.expertMode || bossRush; + bool masterMode = Main.masterMode || bossRush; + if (NPC.ai[2] > 0f) NPC.realLife = (int)NPC.ai[2]; if (NPC.life > Main.npc[(int)NPC.ai[1]].life) NPC.life = Main.npc[(int)NPC.ai[1]].life; + // Percent life remaining + float lifeRatio = NPC.life / (float)NPC.lifeMax; + if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(); @@ -145,7 +152,10 @@ namespace CalamityMod.NPCs.DesertScourge } // Calculate contact damage based on velocity - float maxChaseSpeed = 16f; + float maxChaseSpeed = masterMode ? DesertScourgeHead.SegmentVelocity_Master : expertMode ? DesertScourgeHead.SegmentVelocity_Expert : DesertScourgeHead.SegmentVelocity_Normal; + if (expertMode) + maxChaseSpeed += 5f * (1f - lifeRatio); + float minimalContactDamageVelocity = maxChaseSpeed * 0.25f; float minimalDamageVelocity = maxChaseSpeed * 0.5f; float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); diff --git a/NPCs/DevourerofGods/DevourerofGodsHead.cs b/NPCs/DevourerofGods/DevourerofGodsHead.cs index f75b9a66d6..df7d5fcc58 100644 --- a/NPCs/DevourerofGods/DevourerofGodsHead.cs +++ b/NPCs/DevourerofGods/DevourerofGodsHead.cs @@ -1372,6 +1372,8 @@ namespace CalamityMod.NPCs.DevourerofGods if (NPC.velocity.Y > segmentVelocity) NPC.velocity.Y = segmentVelocity; + // This bool exists to stop the strange wiggle behavior when worms are falling down + bool slowXVelocity = Math.Abs(NPC.velocity.X) > segmentVelocity; if ((Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < segmentVelocity * 2.2) { if (NPC.velocity.X < 0f) @@ -1381,17 +1383,27 @@ namespace CalamityMod.NPCs.DevourerofGods } else if (NPC.velocity.Y == segmentVelocity) { - if (NPC.velocity.X < targetX) - NPC.velocity.X += turnSpeedCopy; - else if (NPC.velocity.X > targetX) - NPC.velocity.X -= turnSpeedCopy; + if (slowXVelocity) + { + if (NPC.velocity.X < targetX) + NPC.velocity.X += turnSpeedCopy; + else if (NPC.velocity.X > targetX) + NPC.velocity.X -= turnSpeedCopy; + } + else + NPC.velocity.X = 0f; } else if (NPC.velocity.Y > 4f) { - if (NPC.velocity.X < 0f) - NPC.velocity.X += turnSpeedCopy * 0.9f; + if (slowXVelocity) + { + if (NPC.velocity.X < 0f) + NPC.velocity.X += turnSpeedCopy * 0.9f; + else + NPC.velocity.X -= turnSpeedCopy * 0.9f; + } else - NPC.velocity.X -= turnSpeedCopy * 0.9f; + NPC.velocity.X = 0f; } } else @@ -2136,6 +2148,8 @@ namespace CalamityMod.NPCs.DevourerofGods if (NPC.velocity.Y > segmentVelocity) NPC.velocity.Y = segmentVelocity; + // This bool exists to stop the strange wiggle behavior when worms are falling down + bool slowXVelocity = Math.Abs(NPC.velocity.X) > segmentVelocity; if ((Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < segmentVelocity * 2.2) { if (NPC.velocity.X < 0f) @@ -2145,17 +2159,27 @@ namespace CalamityMod.NPCs.DevourerofGods } else if (NPC.velocity.Y == segmentVelocity) { - if (NPC.velocity.X < targetX) - NPC.velocity.X += turnSpeedCopy; - else if (NPC.velocity.X > targetX) - NPC.velocity.X -= turnSpeedCopy; + if (slowXVelocity) + { + if (NPC.velocity.X < targetX) + NPC.velocity.X += turnSpeedCopy; + else if (NPC.velocity.X > targetX) + NPC.velocity.X -= turnSpeedCopy; + } + else + NPC.velocity.X = 0f; } else if (NPC.velocity.Y > 4f) { - if (NPC.velocity.X < 0f) - NPC.velocity.X += turnSpeedCopy * 0.9f; + if (slowXVelocity) + { + if (NPC.velocity.X < 0f) + NPC.velocity.X += turnSpeedCopy * 0.9f; + else + NPC.velocity.X -= turnSpeedCopy * 0.9f; + } else - NPC.velocity.X -= turnSpeedCopy * 0.9f; + NPC.velocity.X = 0f; } } else diff --git a/NPCs/NormalNPCs/Cnidrion.cs b/NPCs/NormalNPCs/Cnidrion.cs index 216a4edcde..58a51c18da 100644 --- a/NPCs/NormalNPCs/Cnidrion.cs +++ b/NPCs/NormalNPCs/Cnidrion.cs @@ -83,7 +83,7 @@ namespace CalamityMod.NPCs.NormalNPCs if (NPC.AnyNPCs(NPC.type)) return 0f; - return 0.05f; + return 0.1f; } public override void FindFrame(int frameHeight) @@ -96,6 +96,9 @@ namespace CalamityMod.NPCs.NormalNPCs public override void AI() { + // Setting this in SetDefaults will disable expert mode scaling, so put it here instead + NPC.damage = 0; + Player player = Main.player[NPC.target]; bool expertMode = Main.expertMode; NPC.spriteDirection = (NPC.direction > 0) ? 1 : -1; diff --git a/NPCs/NormalNPCs/Horse.cs b/NPCs/NormalNPCs/Horse.cs index 6490d7d371..4c3273b908 100644 --- a/NPCs/NormalNPCs/Horse.cs +++ b/NPCs/NormalNPCs/Horse.cs @@ -275,21 +275,35 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.direction = playerLocation < 0 ? 1 : -1; NPC.spriteDirection = NPC.direction; - Vector2 direction = Main.player[NPC.target].Center - NPC.Center; - direction.Normalize(); - NPC.ai[1] += Main.expertMode ? 2f : 1f; - if (NPC.ai[1] >= 600f) + Vector2 direction = (Main.player[NPC.target].Center - NPC.Center).SafeNormalize(Vector2.UnitY); + float chargeGateValue = Main.expertMode ? 300f : 600f; + NPC.ai[1] += 1f; + if (NPC.ai[1] >= chargeGateValue) { - direction *= 6f; + // Set damage + NPC.damage = NPC.defDamage; + + float chargeVelocity = Main.expertMode ? 9f : 6f; + direction *= chargeVelocity; NPC.velocity = direction; - NPC.ai[1] = 0f; + NPC.ai[1] = -30f; } - if (Math.Sqrt((NPC.velocity.X * NPC.velocity.X) + (NPC.velocity.Y * NPC.velocity.Y)) > 1) - NPC.velocity *= 0.985f; + if (Math.Sqrt((NPC.velocity.X * NPC.velocity.X) + (NPC.velocity.Y * NPC.velocity.Y)) > 1D && NPC.ai[1] >= 0f) + { + // Avoid cheap bullshit + NPC.damage = 0; - if (Math.Sqrt((NPC.velocity.X * NPC.velocity.X) + (NPC.velocity.Y * NPC.velocity.Y)) <= 1 * 1.15) - NPC.velocity = direction * 1; + NPC.velocity *= 0.97f; + } + + if (Math.Sqrt((NPC.velocity.X * NPC.velocity.X) + (NPC.velocity.Y * NPC.velocity.Y)) <= 1.15) + { + // Avoid cheap bullshit + NPC.damage = 0; + + NPC.velocity = direction; + } return false; } diff --git a/NPCs/NormalNPCs/ScornEater.cs b/NPCs/NormalNPCs/ScornEater.cs index 4a79296582..21f01352fc 100644 --- a/NPCs/NormalNPCs/ScornEater.cs +++ b/NPCs/NormalNPCs/ScornEater.cs @@ -79,37 +79,37 @@ namespace CalamityMod.NPCs.NormalNPCs if (NPC.velocity.Y == 0f) { + // Avoid cheap bullshit + NPC.damage = 0; + NPC.ai[2] += 1f; - int decelerationDelay = 20; + + int decelerationDelay = CalamityWorld.death ? 6 : CalamityWorld.revenge ? 12 : 20; if (NPC.ai[1] == 0f) - { - decelerationDelay = 12; - } - if (CalamityWorld.revenge) - { - decelerationDelay /= 2; - } - if (CalamityWorld.death) - { - decelerationDelay /= 2; - } + decelerationDelay = CalamityWorld.death ? 3 : CalamityWorld.revenge ? 6 : 12; + if (NPC.ai[2] < (float)decelerationDelay) { NPC.velocity.X = NPC.velocity.X * 0.9f; return; } + NPC.ai[2] = 0f; if (NPC.direction == 0) - { NPC.direction = -1; - } + NPC.spriteDirection = NPC.direction; + NPC.ai[1] += 1f; NPC.ai[3] += 1f; if (NPC.ai[3] >= 4f) { + // Set damage + NPC.damage = NPC.defDamage; + NPC.ai[3] = 0f; NPC.noTileCollide = true; + if (NPC.ai[1] == 2f) { NPC.velocity.X = (float)NPC.direction * 15f; @@ -130,9 +130,11 @@ namespace CalamityMod.NPCs.NormalNPCs else NPC.velocity.Y = 12f; } + if (!Main.zenithWorld) SoundEngine.PlaySound(JumpSound, NPC.Center); } + NPC.netUpdate = true; } else @@ -142,10 +144,9 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.velocity.X = NPC.velocity.X + 0.1f; return; } + if (NPC.direction == -1 && NPC.velocity.X > -1f) - { NPC.velocity.X = NPC.velocity.X - 0.1f; - } } } diff --git a/NPCs/NormalNPCs/ShockstormShuttle.cs b/NPCs/NormalNPCs/ShockstormShuttle.cs index b9b4d33249..3e715a42dd 100644 --- a/NPCs/NormalNPCs/ShockstormShuttle.cs +++ b/NPCs/NormalNPCs/ShockstormShuttle.cs @@ -58,6 +58,9 @@ namespace CalamityMod.NPCs.NormalNPCs public override void AI() { + // Setting this in SetDefaults will disable expert mode scaling, so put it here instead + NPC.damage = 0; + if (NPC.justHit) NPC.localAI[0] = 0f; diff --git a/NPCs/NormalNPCs/ThiccWaifu.cs b/NPCs/NormalNPCs/ThiccWaifu.cs index 32613e2226..beeca7e806 100644 --- a/NPCs/NormalNPCs/ThiccWaifu.cs +++ b/NPCs/NormalNPCs/ThiccWaifu.cs @@ -133,6 +133,9 @@ namespace CalamityMod.NPCs.NormalNPCs public void DoBehavior_Hover() { + // Avoid cheap bullshit + NPC.damage = 0; + float lifeRatio = NPC.life / (float)NPC.lifeMax; int hoverTime = (int)MathHelper.Lerp(330f, 180f, 1f - lifeRatio); float hoverAcceleration = MathHelper.Lerp(0.2f, 0.425f, 1f - lifeRatio); @@ -194,6 +197,9 @@ namespace CalamityMod.NPCs.NormalNPCs public void DoBehavior_CloudTeleport() { + // Avoid cheap bullshit + NPC.damage = 0; + int teleportFadeoutTime = 75; int teleportFadeinTime = 60; @@ -246,6 +252,9 @@ namespace CalamityMod.NPCs.NormalNPCs public void DoBehavior_LightningSummon() { + // Avoid cheap bullshit + NPC.damage = 0; + int cloudSummonDelay = 60; int cloudSummonRate = 30; int totalCloudWavesToSummon = 5; @@ -285,6 +294,9 @@ namespace CalamityMod.NPCs.NormalNPCs public void DoBehavior_TornadoSummon() { + // Avoid cheap bullshit + NPC.damage = 0; + int tornadoSpawnDelay = 60; int totalTornadosToSummon = Phase2 ? 8 : 5; @@ -313,6 +325,9 @@ namespace CalamityMod.NPCs.NormalNPCs public void DoBehavior_NimbusSummon() { + // Avoid cheap bullshit + NPC.damage = 0; + int nimbusSummonDelay = 45; int totalNimbiToSummon = 5; int nimbusSummonRate = 50; @@ -380,7 +395,9 @@ namespace CalamityMod.NPCs.NormalNPCs if (AttackTimer >= (sliceChargeTime + sliceChargeDelay) * totalSlices) { - NPC.damage = NPC.defDamage; + // Avoid cheap bullshit + NPC.damage = 0; + CurrentAttackState = AttackState.Hover; AttackTimer = 0f; NPC.netUpdate = true; diff --git a/NPCs/Perforator/PerforatorBodyLarge.cs b/NPCs/Perforator/PerforatorBodyLarge.cs index 1ceb9b39c9..34bc115a9b 100644 --- a/NPCs/Perforator/PerforatorBodyLarge.cs +++ b/NPCs/Perforator/PerforatorBodyLarge.cs @@ -29,7 +29,11 @@ namespace CalamityMod.NPCs.Perforator NPC.width = 60; NPC.height = 60; NPC.defense = 8; + NPC.LifeMaxNERB(2700, 3240, 80000); + if (Main.zenithWorld) + NPC.lifeMax *= 4; + double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01; NPC.lifeMax += (int)(NPC.lifeMax * HPBoost); NPC.aiStyle = -1; @@ -70,20 +74,6 @@ namespace CalamityMod.NPCs.Perforator public override void AI() { - // Calculate contact damage based on velocity - float minimalContactDamageVelocity = 4f; - float minimalDamageVelocity = 8f; - float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); - if (bodyAndTailVelocity <= minimalContactDamageVelocity) - { - NPC.damage = 0; - } - else - { - float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); - NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); - } - if (NPC.ai[2] > 0f) NPC.realLife = (int)NPC.ai[2]; @@ -124,9 +114,9 @@ namespace CalamityMod.NPCs.Perforator if (Main.player[NPC.target].dead) NPC.TargetClosest(false); - Vector2 segmentPosition = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f); - float targetX = Main.player[NPC.target].position.X + (float)(Main.player[NPC.target].width / 2); - float targetY = Main.player[NPC.target].position.Y + (float)(Main.player[NPC.target].height / 2); + Vector2 segmentPosition = NPC.Center; + float targetX = Main.player[NPC.target].Center.X; + float targetY = Main.player[NPC.target].Center.Y; targetX = (float)((int)(targetX / 16f) * 16); targetY = (float)((int)(targetY / 16f) * 16); segmentPosition.X = (float)((int)(segmentPosition.X / 16f) * 16); @@ -138,28 +128,43 @@ namespace CalamityMod.NPCs.Perforator { try { - segmentPosition = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f); - targetX = Main.npc[(int)NPC.ai[1]].position.X + (float)(Main.npc[(int)NPC.ai[1]].width / 2) - segmentPosition.X; - targetY = Main.npc[(int)NPC.ai[1]].position.Y + (float)(Main.npc[(int)NPC.ai[1]].height / 2) - segmentPosition.Y; + segmentPosition = NPC.Center; + targetX = Main.npc[(int)NPC.ai[1]].Center.X - segmentPosition.X; + targetY = Main.npc[(int)NPC.ai[1]].Center.Y - segmentPosition.Y; } catch { } - NPC.rotation = (float)System.Math.Atan2((double)targetY, (double)targetX) + 1.57f; + NPC.rotation = (float)System.Math.Atan2((double)targetY, (double)targetX) + MathHelper.PiOver2; targetDistance = (float)System.Math.Sqrt((double)(targetX * targetX + targetY * targetY)); int npcWidth = NPC.width; targetDistance = (targetDistance - (float)npcWidth) / targetDistance; targetX *= targetDistance; targetY *= targetDistance; NPC.velocity = Vector2.Zero; - NPC.position.X = NPC.position.X + targetX; - NPC.position.Y = NPC.position.Y + targetY; + NPC.position.X += targetX; + NPC.position.Y += targetY; if (targetX < 0f) NPC.spriteDirection = 1; else if (targetX > 0f) NPC.spriteDirection = -1; } + + // Calculate contact damage based on velocity + float maxChaseSpeed = 16f; + float minimalContactDamageVelocity = maxChaseSpeed * 0.25f; + float minimalDamageVelocity = maxChaseSpeed * 0.5f; + float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); + if (bodyAndTailVelocity <= minimalContactDamageVelocity) + { + NPC.damage = 0; + } + else + { + float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); + } } public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) diff --git a/NPCs/Perforator/PerforatorBodyMedium.cs b/NPCs/Perforator/PerforatorBodyMedium.cs index 54d6e836e1..f08082c394 100644 --- a/NPCs/Perforator/PerforatorBodyMedium.cs +++ b/NPCs/Perforator/PerforatorBodyMedium.cs @@ -32,7 +32,11 @@ namespace CalamityMod.NPCs.Perforator NPC.width = 40; NPC.height = 40; NPC.defense = 6; + NPC.LifeMaxNERB(180, 216, 7000); + if (Main.zenithWorld) + NPC.lifeMax *= 4; + double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01; NPC.lifeMax += (int)(NPC.lifeMax * HPBoost); NPC.aiStyle = -1; @@ -70,20 +74,6 @@ namespace CalamityMod.NPCs.Perforator public override void AI() { - // Calculate contact damage based on velocity - float minimalContactDamageVelocity = 4f; - float minimalDamageVelocity = 8f; - float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); - if (bodyAndTailVelocity <= minimalContactDamageVelocity) - { - NPC.damage = 0; - } - else - { - float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); - NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); - } - NPC.realLife = -1; // Target @@ -105,9 +95,9 @@ namespace CalamityMod.NPCs.Perforator if (NPC.ai[0] == 0f) { if (NPC.ai[2] > 0f) - NPC.ai[0] = NPC.NewNPC(NPC.GetSource_FromAI(), (int)(NPC.position.X + (NPC.width / 2)), (int)(NPC.position.Y + NPC.height), NPC.type, NPC.whoAmI, 0f, 0f, 0f, 0f, 255); + NPC.ai[0] = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.Center.X, (int)(NPC.position.Y + NPC.height), NPC.type, NPC.whoAmI); else - NPC.ai[0] = NPC.NewNPC(NPC.GetSource_FromAI(), (int)(NPC.position.X + (NPC.width / 2)), (int)(NPC.position.Y + NPC.height), ModContent.NPCType(), NPC.whoAmI, 0f, 0f, 0f, 0f, 255); + NPC.ai[0] = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.Center.X, (int)(NPC.position.Y + NPC.height), ModContent.NPCType(), NPC.whoAmI); Main.npc[(int)NPC.ai[0]].ai[1] = NPC.whoAmI; Main.npc[(int)NPC.ai[0]].ai[2] = NPC.ai[2] - 1f; @@ -153,9 +143,9 @@ namespace CalamityMod.NPCs.Perforator NetMessage.SendData(MessageID.DamageNPC, -1, -1, null, NPC.whoAmI, -1f, 0f, 0f, 0, 0, 0); } - Vector2 segmentDirection = new Vector2(NPC.position.X + NPC.width * 0.5f, NPC.position.Y + NPC.height * 0.5f); - float targetX = Main.player[NPC.target].position.X + (Main.player[NPC.target].width / 2); - float targetY = Main.player[NPC.target].position.Y + (Main.player[NPC.target].height / 2); + Vector2 segmentDirection = NPC.Center; + float targetX = Main.player[NPC.target].Center.X; + float targetY = Main.player[NPC.target].Center.Y; targetX = (int)(targetX / 16f) * 16; targetY = (int)(targetY / 16f) * 16; @@ -169,9 +159,9 @@ namespace CalamityMod.NPCs.Perforator { try { - segmentDirection = new Vector2(NPC.position.X + NPC.width * 0.5f, NPC.position.Y + NPC.height * 0.5f); - targetX = Main.npc[(int)NPC.ai[1]].position.X + (Main.npc[(int)NPC.ai[1]].width / 2) - segmentDirection.X; - targetY = Main.npc[(int)NPC.ai[1]].position.Y + (Main.npc[(int)NPC.ai[1]].height / 2) - segmentDirection.Y; + segmentDirection = NPC.Center; + targetX = Main.npc[(int)NPC.ai[1]].Center.X - segmentDirection.X; + targetY = Main.npc[(int)NPC.ai[1]].Center.Y - segmentDirection.Y; } catch { @@ -188,6 +178,21 @@ namespace CalamityMod.NPCs.Perforator NPC.position.X += targetX; NPC.position.Y += targetY; } + + // Calculate contact damage based on velocity + float maxChaseSpeed = 16f; + float minimalContactDamageVelocity = maxChaseSpeed * 0.25f; + float minimalDamageVelocity = maxChaseSpeed * 0.5f; + float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); + if (bodyAndTailVelocity <= minimalContactDamageVelocity) + { + NPC.damage = 0; + } + else + { + float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); + } } public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) diff --git a/NPCs/Perforator/PerforatorBodySmall.cs b/NPCs/Perforator/PerforatorBodySmall.cs index e71b43f432..d17ea9ba89 100644 --- a/NPCs/Perforator/PerforatorBodySmall.cs +++ b/NPCs/Perforator/PerforatorBodySmall.cs @@ -29,7 +29,11 @@ namespace CalamityMod.NPCs.Perforator NPC.width = 42; NPC.height = 42; NPC.defense = 4; + NPC.LifeMaxNERB(1200, 1440, 50000); + if (Main.zenithWorld) + NPC.lifeMax *= 4; + double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01; NPC.lifeMax += (int)(NPC.lifeMax * HPBoost); NPC.aiStyle = -1; @@ -70,20 +74,6 @@ namespace CalamityMod.NPCs.Perforator public override void AI() { - // Calculate contact damage based on velocity - float minimalContactDamageVelocity = 4f; - float minimalDamageVelocity = 8f; - float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); - if (bodyAndTailVelocity <= minimalContactDamageVelocity) - { - NPC.damage = 0; - } - else - { - float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); - NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); - } - if (NPC.ai[2] > 0f) NPC.realLife = (int)NPC.ai[2]; @@ -124,9 +114,9 @@ namespace CalamityMod.NPCs.Perforator if (Main.player[NPC.target].dead) NPC.TargetClosest(false); - Vector2 segmentPosition = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f); - float targetX = Main.player[NPC.target].position.X + (float)(Main.player[NPC.target].width / 2); - float targetY = Main.player[NPC.target].position.Y + (float)(Main.player[NPC.target].height / 2); + Vector2 segmentPosition = NPC.Center; + float targetX = Main.player[NPC.target].Center.X; + float targetY = Main.player[NPC.target].Center.Y; targetX = (float)((int)(targetX / 16f) * 16); targetY = (float)((int)(targetY / 16f) * 16); segmentPosition.X = (float)((int)(segmentPosition.X / 16f) * 16); @@ -138,28 +128,43 @@ namespace CalamityMod.NPCs.Perforator { try { - segmentPosition = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f); - targetX = Main.npc[(int)NPC.ai[1]].position.X + (float)(Main.npc[(int)NPC.ai[1]].width / 2) - segmentPosition.X; - targetY = Main.npc[(int)NPC.ai[1]].position.Y + (float)(Main.npc[(int)NPC.ai[1]].height / 2) - segmentPosition.Y; + segmentPosition = NPC.Center; + targetX = Main.npc[(int)NPC.ai[1]].Center.X - segmentPosition.X; + targetY = Main.npc[(int)NPC.ai[1]].Center.Y - segmentPosition.Y; } catch { } - NPC.rotation = (float)System.Math.Atan2((double)targetY, (double)targetX) + 1.57f; + NPC.rotation = (float)System.Math.Atan2((double)targetY, (double)targetX) + MathHelper.PiOver2; targetDistance = (float)System.Math.Sqrt((double)(targetX * targetX + targetY * targetY)); int npcWidth = NPC.width; targetDistance = (targetDistance - (float)npcWidth) / targetDistance; targetX *= targetDistance; targetY *= targetDistance; NPC.velocity = Vector2.Zero; - NPC.position.X = NPC.position.X + targetX; - NPC.position.Y = NPC.position.Y + targetY; + NPC.position.X += targetX; + NPC.position.Y += targetY; if (targetX < 0f) NPC.spriteDirection = 1; else if (targetX > 0f) NPC.spriteDirection = -1; } + + // Calculate contact damage based on velocity + float maxChaseSpeed = 16f; + float minimalContactDamageVelocity = maxChaseSpeed * 0.25f; + float minimalDamageVelocity = maxChaseSpeed * 0.5f; + float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); + if (bodyAndTailVelocity <= minimalContactDamageVelocity) + { + NPC.damage = 0; + } + else + { + float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); + } } public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) diff --git a/NPCs/Perforator/PerforatorHeadLarge.cs b/NPCs/Perforator/PerforatorHeadLarge.cs index 4ba795dcf7..e9f0b1dade 100644 --- a/NPCs/Perforator/PerforatorHeadLarge.cs +++ b/NPCs/Perforator/PerforatorHeadLarge.cs @@ -49,7 +49,11 @@ namespace CalamityMod.NPCs.Perforator NPC.width = 70; NPC.height = 84; NPC.defense = 4; + NPC.LifeMaxNERB(2700, 3240, 80000); + if (Main.zenithWorld) + NPC.lifeMax *= 4; + double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01; NPC.lifeMax += (int)(NPC.lifeMax * HPBoost); NPC.aiStyle = -1; @@ -115,19 +119,6 @@ namespace CalamityMod.NPCs.Perforator bool revenge = CalamityWorld.revenge || bossRush; bool death = CalamityWorld.death || bossRush; - // Calculate contact damage based on velocity - float minimalContactDamageVelocity = 4f; - float minimalDamageVelocity = 8f; - if (NPC.velocity.Length() <= minimalContactDamageVelocity) - { - NPC.damage = (int)(NPC.defDamage * 0.5f); - } - else - { - float velocityDamageScalar = MathHelper.Clamp((NPC.velocity.Length() - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); - NPC.damage = (int)MathHelper.Lerp(NPC.defDamage * 0.5f, NPC.defDamage, velocityDamageScalar); - } - // Get a target if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(); @@ -158,15 +149,6 @@ namespace CalamityMod.NPCs.Perforator // Percent life remaining float lifeRatio = NPC.life / (float)NPC.lifeMax; - if (revenge || lifeRatio < (expertMode ? 0.75f : 0.5f)) - NPC.Calamity().newAI[0] += 1f; - - float burrowTimeGateValue = death ? 480f : 600f; - bool burrow = NPC.Calamity().newAI[0] >= burrowTimeGateValue; - bool resetTime = NPC.Calamity().newAI[0] >= burrowTimeGateValue + 600f; - bool lungeUpward = burrow && NPC.Calamity().newAI[1] == 1f; - bool quickFall = NPC.Calamity().newAI[1] == 2f; - float speed = 0.09f; float turnSpeed = 0.06f; @@ -178,15 +160,6 @@ namespace CalamityMod.NPCs.Perforator turnSpeed += accelerationScale * (1f - lifeRatio); } - if (lungeUpward) - { - speed *= 1.25f; - turnSpeed *= 1.5f; - - if (NPC.Calamity().newAI[2] == 0f) - NPC.Calamity().newAI[2] = player.Center.Y - 600f; - } - if (NPC.ai[2] > 0f) NPC.realLife = (int)NPC.ai[2]; @@ -204,17 +177,13 @@ namespace CalamityMod.NPCs.Perforator { int lol; if (segments >= 0 && segments < maxLength - 1) - { - lol = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.position.X + (NPC.width / 2), (int)NPC.position.Y + (NPC.height / 2), ModContent.NPCType(), NPC.whoAmI); - } + lol = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.Center.X, (int)NPC.Center.Y, ModContent.NPCType(), NPC.whoAmI); else - { - lol = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.position.X + (NPC.width / 2), (int)NPC.position.Y + (NPC.height / 2), ModContent.NPCType(), NPC.whoAmI); - } + lol = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.Center.X, (int)NPC.Center.Y, ModContent.NPCType(), NPC.whoAmI); + if (segments % 2 == 0) - { Main.npc[lol].localAI[3] = 1f; - } + Main.npc[lol].realLife = NPC.whoAmI; Main.npc[lol].ai[2] = NPC.whoAmI; Main.npc[lol].ai[1] = Previous; @@ -222,6 +191,7 @@ namespace CalamityMod.NPCs.Perforator NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, lol, 0f, 0f, 0f, 0); Previous = lol; } + TailSpawned = true; } } @@ -231,22 +201,15 @@ namespace CalamityMod.NPCs.Perforator int tilePositionY = (int)(NPC.position.Y / 16f) - 1; int tileWidthPosY = (int)((NPC.position.Y + (float)NPC.height) / 16f) + 2; if (tilePositionX < 0) - { tilePositionX = 0; - } if (tileWidthPosX > Main.maxTilesX) - { tileWidthPosX = Main.maxTilesX; - } if (tilePositionY < 0) - { tilePositionY = 0; - } if (tileWidthPosY > Main.maxTilesY) - { tileWidthPosY = Main.maxTilesY; - } - bool shouldFly = lungeUpward; + + bool shouldFly = false; if (!shouldFly) { for (int k = tilePositionX; k < tileWidthPosX; k++) @@ -267,6 +230,7 @@ namespace CalamityMod.NPCs.Perforator } } } + if (!shouldFly) { NPC.localAI[1] = 1f; @@ -275,7 +239,7 @@ namespace CalamityMod.NPCs.Perforator bool outsideFlyingRadius = true; if (NPC.position.Y > player.position.Y) { - for (int m = 0; m < 255; m++) + for (int m = 0; m < Main.maxPlayers; m++) { if (Main.player[m].active) { @@ -287,41 +251,36 @@ namespace CalamityMod.NPCs.Perforator } } } + if (outsideFlyingRadius) - { shouldFly = true; - } } } else - { NPC.localAI[1] = 0f; - } - float fallSpeed = 16f; + float maxChargeSpeed = 16f; if (player.dead || CalamityGlobalNPC.perfHive < 0 || !Main.npc[CalamityGlobalNPC.perfHive].active) { shouldFly = false; NPC.velocity.Y += 1f; - if ((double)NPC.position.Y > Main.worldSurface * 16.0) + if ((double)NPC.position.Y > Main.worldSurface * 16D) { NPC.velocity.Y += 1f; - fallSpeed = 32f; + maxChargeSpeed *= 2f; } - if ((double)NPC.position.Y > Main.rockLayer * 16.0) + + if ((double)NPC.position.Y > Main.rockLayer * 16D) { for (int a = 0; a < Main.maxNPCs; a++) { - if (Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || - Main.npc[a].type == ModContent.NPCType()) - { + if (Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType()) Main.npc[a].active = false; - } } } } - //This is possibly the best or worst idea ever conceived + // This is possibly the best or worst idea ever conceived float laserOffset = 1500f; float laserVelocity = 4f; int type = ModContent.ProjectileType(); @@ -330,12 +289,12 @@ namespace CalamityMod.NPCs.Perforator if (Main.zenithWorld) NPC.Calamity().newAI[3]++; - if (NPC.Calamity().newAI[3] > 180f) //Effectively 10 seconds but give a little headstart in case players kill it too fast + if (NPC.Calamity().newAI[3] > 180f) // Effectively 10 seconds but give a little headstart in case players kill it too fast { if (NPC.Calamity().newAI[3] % 60 == 59) { SoundEngine.PlaySound(SoundID.Item12, player.Center); - for (int i = -7; i < 8; i++) //15 lasers + for (int i = -7; i < 8; i++) // 15 lasers { float laserGap = (i * 128f); Projectile.NewProjectile(NPC.GetSource_FromAI(), player.Center.X + laserOffset, player.Center.Y + laserGap, -laserVelocity, 0f, type, damage, 0f, Main.myPlayer); @@ -351,12 +310,9 @@ namespace CalamityMod.NPCs.Perforator float speedCopy = speed; float turnSpeedCopy = turnSpeed; - float burrowDistance = bossRush ? 500f : 800f; - float burrowTarget = player.Center.Y + burrowDistance; - float lungeTarget = NPC.Calamity().newAI[2]; Vector2 npcCenter = NPC.Center; float playerX = player.Center.X; - float targettingPosition = lungeUpward ? lungeTarget : burrow ? burrowTarget : player.Center.Y; + float targettingPosition = player.Center.Y; playerX = (float)((int)(playerX / 16f) * 16); targettingPosition = (float)((int)(targettingPosition / 16f) * 16); npcCenter.X = (float)((int)(npcCenter.X / 16f) * 16); @@ -365,76 +321,45 @@ namespace CalamityMod.NPCs.Perforator targettingPosition -= npcCenter.Y; float targetDistance = (float)Math.Sqrt((double)(playerX * playerX + targettingPosition * targettingPosition)); - // Lunge up towards target - if (burrow && NPC.Center.Y >= burrowTarget - 16f) - NPC.Calamity().newAI[1] = 1f; - - // Quickly fall back down once above target - if (lungeUpward && NPC.Center.Y <= NPC.Calamity().newAI[2] + 600f - 420f) - { - NPC.TargetClosest(); - NPC.Calamity().newAI[1] = 2f; - } - - // Quickly fall and reset variables once at target's Y position - if (quickFall) - { - NPC.velocity.Y += 0.5f; - if (NPC.Center.Y >= NPC.Calamity().newAI[2] + 600f) - { - NPC.Calamity().newAI[0] = 0f; - NPC.Calamity().newAI[1] = 0f; - NPC.Calamity().newAI[2] = 0f; - } - } - - // Reset variables if the burrow and lunge attack is taking too long - if (resetTime) - { - NPC.Calamity().newAI[0] = 0f; - NPC.Calamity().newAI[1] = 0f; - } - if (!shouldFly) { NPC.TargetClosest(true); - NPC.velocity.Y = NPC.velocity.Y + 0.15f; - if (NPC.velocity.Y > fallSpeed) - { - NPC.velocity.Y = fallSpeed; - } - if ((double)(Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < (double)fallSpeed * 0.4) + NPC.velocity.Y += 0.15f; + if (NPC.velocity.Y > maxChargeSpeed) + NPC.velocity.Y = maxChargeSpeed; + + // This bool exists to stop the strange wiggle behavior when worms are falling down + bool slowXVelocity = Math.Abs(NPC.velocity.X) > maxChargeSpeed; + if ((double)(Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < (double)maxChargeSpeed * 0.4) { if (NPC.velocity.X < 0f) + NPC.velocity.X -= speedCopy * 1.1f; + else + NPC.velocity.X += speedCopy * 1.1f; + } + else if (NPC.velocity.Y == maxChargeSpeed) + { + if (slowXVelocity) { - NPC.velocity.X = NPC.velocity.X - speedCopy * 1.1f; + if (NPC.velocity.X < playerX) + NPC.velocity.X += speedCopy; + else if (NPC.velocity.X > playerX) + NPC.velocity.X -= speedCopy; } else - { - NPC.velocity.X = NPC.velocity.X + speedCopy * 1.1f; - } - } - else if (NPC.velocity.Y == fallSpeed) - { - if (NPC.velocity.X < playerX) - { - NPC.velocity.X = NPC.velocity.X + speedCopy; - } - else if (NPC.velocity.X > playerX) - { - NPC.velocity.X = NPC.velocity.X - speedCopy; - } + NPC.velocity.X = 0f; } else if (NPC.velocity.Y > 4f) { - if (NPC.velocity.X < 0f) + if (slowXVelocity) { - NPC.velocity.X = NPC.velocity.X + speedCopy * 0.9f; + if (NPC.velocity.X < 0f) + NPC.velocity.X += speedCopy * 0.9f; + else + NPC.velocity.X -= speedCopy * 0.9f; } else - { - NPC.velocity.X = NPC.velocity.X - speedCopy * 0.9f; - } + NPC.velocity.X = 0f; } } else @@ -443,20 +368,18 @@ namespace CalamityMod.NPCs.Perforator { float soundDelay = targetDistance / 40f; if (soundDelay < 10f) - { soundDelay = 10f; - } if (soundDelay > 20f) - { soundDelay = 20f; - } + NPC.soundDelay = (int)soundDelay; SoundEngine.PlaySound(SoundID.WormDig, NPC.Center); } + targetDistance = (float)Math.Sqrt((double)(playerX * playerX + targettingPosition * targettingPosition)); float absoluteTargetX = Math.Abs(playerX); float absoluteTargetPos = Math.Abs(targettingPosition); - float timeToReachTarget = fallSpeed / targetDistance; + float timeToReachTarget = maxChargeSpeed / targetDistance; playerX *= timeToReachTarget; targettingPosition *= timeToReachTarget; if (((NPC.velocity.X > 0f && playerX > 0f) || (NPC.velocity.X < 0f && playerX < 0f)) && ((NPC.velocity.Y > 0f && targettingPosition > 0f) || (NPC.velocity.Y < 0f && targettingPosition < 0f))) @@ -469,6 +392,7 @@ namespace CalamityMod.NPCs.Perforator { NPC.velocity.X = NPC.velocity.X - turnSpeedCopy; } + if (NPC.velocity.Y < targettingPosition) { NPC.velocity.Y = NPC.velocity.Y + turnSpeedCopy; @@ -488,6 +412,7 @@ namespace CalamityMod.NPCs.Perforator { NPC.velocity.X = NPC.velocity.X - speedCopy; } + if (NPC.velocity.Y < targettingPosition) { NPC.velocity.Y = NPC.velocity.Y + speedCopy; @@ -496,7 +421,8 @@ namespace CalamityMod.NPCs.Perforator { NPC.velocity.Y = NPC.velocity.Y - speedCopy; } - if ((double)Math.Abs(targettingPosition) < (double)fallSpeed * 0.2 && ((NPC.velocity.X > 0f && playerX < 0f) || (NPC.velocity.X < 0f && playerX > 0f))) + + if ((double)Math.Abs(targettingPosition) < (double)maxChargeSpeed * 0.2 && ((NPC.velocity.X > 0f && playerX < 0f) || (NPC.velocity.X < 0f && playerX > 0f))) { if (NPC.velocity.Y > 0f) { @@ -507,7 +433,8 @@ namespace CalamityMod.NPCs.Perforator NPC.velocity.Y = NPC.velocity.Y - speedCopy * 2f; } } - if ((double)Math.Abs(playerX) < (double)fallSpeed * 0.2 && ((NPC.velocity.Y > 0f && targettingPosition < 0f) || (NPC.velocity.Y < 0f && targettingPosition > 0f))) + + if ((double)Math.Abs(playerX) < (double)maxChargeSpeed * 0.2 && ((NPC.velocity.Y > 0f && targettingPosition < 0f) || (NPC.velocity.Y < 0f && targettingPosition > 0f))) { if (NPC.velocity.X > 0f) { @@ -529,7 +456,8 @@ namespace CalamityMod.NPCs.Perforator { NPC.velocity.X = NPC.velocity.X - speedCopy * 1.1f; } - if ((double)(Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < (double)fallSpeed * 0.5) + + if ((double)(Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < (double)maxChargeSpeed * 0.5) { if (NPC.velocity.Y > 0f) { @@ -551,7 +479,8 @@ namespace CalamityMod.NPCs.Perforator { NPC.velocity.Y = NPC.velocity.Y - speedCopy * 1.1f; } - if ((double)(Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < (double)fallSpeed * 0.5) + + if ((double)(Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < (double)maxChargeSpeed * 0.5) { if (NPC.velocity.X > 0f) { @@ -564,27 +493,39 @@ namespace CalamityMod.NPCs.Perforator } } } - NPC.rotation = (float)Math.Atan2((double)NPC.velocity.Y, (double)NPC.velocity.X) + 1.57f; + + // Calculate contact damage based on velocity + float minimalContactDamageVelocity = maxChargeSpeed * 0.25f; + float minimalDamageVelocity = maxChargeSpeed * 0.5f; + if (NPC.velocity.Length() <= minimalContactDamageVelocity) + { + NPC.damage = (int)(NPC.defDamage * 0.5f); + } + else + { + float velocityDamageScalar = MathHelper.Clamp((NPC.velocity.Length() - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + NPC.damage = (int)MathHelper.Lerp(NPC.defDamage * 0.5f, NPC.defDamage, velocityDamageScalar); + } + + NPC.rotation = (float)Math.Atan2((double)NPC.velocity.Y, (double)NPC.velocity.X) + MathHelper.PiOver2; + if (shouldFly) { if (NPC.localAI[0] != 1f) - { NPC.netUpdate = true; - } + NPC.localAI[0] = 1f; } else { if (NPC.localAI[0] != 0f) - { NPC.netUpdate = true; - } + NPC.localAI[0] = 0f; } + if (((NPC.velocity.X > 0f && NPC.oldVelocity.X < 0f) || (NPC.velocity.X < 0f && NPC.oldVelocity.X > 0f) || (NPC.velocity.Y > 0f && NPC.oldVelocity.Y < 0f) || (NPC.velocity.Y < 0f && NPC.oldVelocity.Y > 0f)) && !NPC.justHit) - { NPC.netUpdate = true; - } } public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) diff --git a/NPCs/Perforator/PerforatorHeadMedium.cs b/NPCs/Perforator/PerforatorHeadMedium.cs index 79827c6771..21ed01fac6 100644 --- a/NPCs/Perforator/PerforatorHeadMedium.cs +++ b/NPCs/Perforator/PerforatorHeadMedium.cs @@ -45,7 +45,11 @@ namespace CalamityMod.NPCs.Perforator NPC.width = 58; NPC.height = 68; NPC.defense = 2; + NPC.LifeMaxNERB(180, 216, 7000); + if (Main.zenithWorld) + NPC.lifeMax *= 4; + double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01; NPC.lifeMax += (int)(NPC.lifeMax * HPBoost); NPC.aiStyle = -1; @@ -99,19 +103,6 @@ namespace CalamityMod.NPCs.Perforator bool revenge = CalamityWorld.revenge || bossRush; bool death = CalamityWorld.death || bossRush; - // Calculate contact damage based on velocity - float minimalContactDamageVelocity = 4f; - float minimalDamageVelocity = 8f; - if (NPC.velocity.Length() <= minimalContactDamageVelocity) - { - NPC.damage = (int)(NPC.defDamage * 0.5f); - } - else - { - float velocityDamageScalar = MathHelper.Clamp((NPC.velocity.Length() - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); - NPC.damage = (int)MathHelper.Lerp(NPC.defDamage * 0.5f, NPC.defDamage, velocityDamageScalar); - } - float enrageScale = bossRush ? 1f : 0f; if ((NPC.position.Y / 16f) < Main.worldSurface || bossRush) enrageScale += 1f; @@ -154,7 +145,7 @@ namespace CalamityMod.NPCs.Perforator { int totalSegments = death ? 14 : revenge ? 13 : expertMode ? 12 : 10; NPC.ai[2] = totalSegments; - NPC.ai[0] = NPC.NewNPC(NPC.GetSource_FromAI(), (int)(NPC.position.X + (NPC.width / 2)), (int)(NPC.position.Y + NPC.height), ModContent.NPCType(), NPC.whoAmI, 0f, 0f, 0f, 0f, 255); + NPC.ai[0] = NPC.NewNPC(NPC.GetSource_FromAI(), (int)(NPC.position.X + (NPC.width / 2)), (int)(NPC.position.Y + NPC.height), ModContent.NPCType(), NPC.whoAmI); Main.npc[(int)NPC.ai[0]].ai[1] = NPC.whoAmI; Main.npc[(int)NPC.ai[0]].ai[2] = NPC.ai[2] - 1f; NPC.netUpdate = true; @@ -213,18 +204,17 @@ namespace CalamityMod.NPCs.Perforator { shouldFly = true; if (Main.rand.NextBool(100) && Main.tile[i, j].HasUnactuatedTile) - { WorldGen.KillTile(i, j, true, true, false); - } } } } } } + if (!shouldFly) { Rectangle rectangle = new Rectangle((int)NPC.position.X, (int)NPC.position.Y, NPC.width, NPC.height); - int stopFlyingRadius = death ? 160 : revenge ? 200 : expertMode ? 240 : 300; + int stopFlyingRadius = death ? 320 : revenge ? 400 : expertMode ? 480 : 600; bool outsideFlyRadius = true; for (int k = 0; k < Main.maxPlayers; k++) { @@ -238,29 +228,29 @@ namespace CalamityMod.NPCs.Perforator } } } + if (outsideFlyRadius) shouldFly = true; } - float fallSpeed = 16f; + float maxChargeSpeed = 16f; if (player.dead || CalamityGlobalNPC.perfHive < 0 || !Main.npc[CalamityGlobalNPC.perfHive].active) { NPC.TargetClosest(false); shouldFly = false; NPC.velocity.Y += 1f; - if (NPC.position.Y > Main.worldSurface * 16.0) + if (NPC.position.Y > Main.worldSurface * 16D) { NPC.velocity.Y += 1f; - fallSpeed = 32f; + maxChargeSpeed *= 2f; } - if (NPC.position.Y > Main.rockLayer * 16.0) + + if (NPC.position.Y > Main.rockLayer * 16D) { for (int p = 0; p < Main.maxNPCs; p++) { if (Main.npc[p].type == NPC.type || Main.npc[p].type == ModContent.NPCType() || Main.npc[p].type == ModContent.NPCType()) - { Main.npc[p].active = false; - } } } } @@ -293,29 +283,41 @@ namespace CalamityMod.NPCs.Perforator if (!shouldFly) { NPC.velocity.Y += 0.15f; - if (NPC.velocity.Y > fallSpeed) - NPC.velocity.Y = fallSpeed; + if (NPC.velocity.Y > maxChargeSpeed) + NPC.velocity.Y = maxChargeSpeed; - if ((Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < fallSpeed * 0.4) + // This bool exists to stop the strange wiggle behavior when worms are falling down + bool slowXVelocity = Math.Abs(NPC.velocity.X) > maxChargeSpeed; + if ((Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < maxChargeSpeed * 0.4) { if (NPC.velocity.X < 0f) NPC.velocity.X -= turnSpeedCopy * 1.1f; else NPC.velocity.X += turnSpeedCopy * 1.1f; } - else if (NPC.velocity.Y == fallSpeed) + else if (NPC.velocity.Y == maxChargeSpeed) { - if (NPC.velocity.X < targetX) - NPC.velocity.X += turnSpeedCopy; - else if (NPC.velocity.X > targetX) - NPC.velocity.X -= turnSpeedCopy; + if (slowXVelocity) + { + if (NPC.velocity.X < targetX) + NPC.velocity.X += turnSpeedCopy; + else if (NPC.velocity.X > targetX) + NPC.velocity.X -= turnSpeedCopy; + } + else + NPC.velocity.X = 0f; } else if (NPC.velocity.Y > 4f) { - if (NPC.velocity.X < 0f) - NPC.velocity.X += turnSpeedCopy * 0.9f; + if (slowXVelocity) + { + if (NPC.velocity.X < 0f) + NPC.velocity.X += turnSpeedCopy * 0.9f; + else + NPC.velocity.X -= turnSpeedCopy * 0.9f; + } else - NPC.velocity.X -= turnSpeedCopy * 0.9f; + NPC.velocity.X = 0f; } } else @@ -336,7 +338,7 @@ namespace CalamityMod.NPCs.Perforator targetDistance = (float)Math.Sqrt(targetX * targetX + targetY * targetY); float absoluteTargetX = Math.Abs(targetX); float absoluteTargetY = Math.Abs(targetY); - float timeToReachTarget = fallSpeed / targetDistance; + float timeToReachTarget = maxChargeSpeed / targetDistance; targetX *= timeToReachTarget; targetY *= timeToReachTarget; @@ -365,7 +367,7 @@ namespace CalamityMod.NPCs.Perforator else if (NPC.velocity.Y > targetY) NPC.velocity.Y -= speedCopy; - if (Math.Abs(targetY) < fallSpeed * 0.2 && ((NPC.velocity.X > 0f && targetX < 0f) || (NPC.velocity.X < 0f && targetX > 0f))) + if (Math.Abs(targetY) < maxChargeSpeed * 0.2 && ((NPC.velocity.X > 0f && targetX < 0f) || (NPC.velocity.X < 0f && targetX > 0f))) { if (NPC.velocity.Y > 0f) NPC.velocity.Y += speedCopy * 2f; @@ -373,7 +375,7 @@ namespace CalamityMod.NPCs.Perforator NPC.velocity.Y -= speedCopy * 2f; } - if (Math.Abs(targetX) < fallSpeed * 0.2 && ((NPC.velocity.Y > 0f && targetY < 0f) || (NPC.velocity.Y < 0f && targetY > 0f))) + if (Math.Abs(targetX) < maxChargeSpeed * 0.2 && ((NPC.velocity.Y > 0f && targetY < 0f) || (NPC.velocity.Y < 0f && targetY > 0f))) { if (NPC.velocity.X > 0f) NPC.velocity.X += speedCopy * 2f; @@ -388,7 +390,7 @@ namespace CalamityMod.NPCs.Perforator else if (NPC.velocity.X > targetX) NPC.velocity.X -= speedCopy * 1.1f; - if ((Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < fallSpeed * 0.5) + if ((Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < maxChargeSpeed * 0.5) { if (NPC.velocity.Y > 0f) NPC.velocity.Y += speedCopy; @@ -403,7 +405,7 @@ namespace CalamityMod.NPCs.Perforator else if (NPC.velocity.Y > targetY) NPC.velocity.Y -= speedCopy * 1.1f; - if ((Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < fallSpeed * 0.5) + if ((Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < maxChargeSpeed * 0.5) { if (NPC.velocity.X > 0f) NPC.velocity.X += speedCopy; @@ -413,6 +415,19 @@ namespace CalamityMod.NPCs.Perforator } } + // Calculate contact damage based on velocity + float minimalContactDamageVelocity = maxChargeSpeed * 0.25f; + float minimalDamageVelocity = maxChargeSpeed * 0.5f; + if (NPC.velocity.Length() <= minimalContactDamageVelocity) + { + NPC.damage = (int)(NPC.defDamage * 0.5f); + } + else + { + float velocityDamageScalar = MathHelper.Clamp((NPC.velocity.Length() - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + NPC.damage = (int)MathHelper.Lerp(NPC.defDamage * 0.5f, NPC.defDamage, velocityDamageScalar); + } + NPC.rotation = (float)Math.Atan2(NPC.velocity.Y, NPC.velocity.X) + MathHelper.PiOver2; if (shouldFly) @@ -429,6 +444,7 @@ namespace CalamityMod.NPCs.Perforator NPC.localAI[0] = 0f; } + if (((NPC.velocity.X > 0f && NPC.oldVelocity.X < 0f) || (NPC.velocity.X < 0f && NPC.oldVelocity.X > 0f) || (NPC.velocity.Y > 0f && NPC.oldVelocity.Y < 0f) || (NPC.velocity.Y < 0f && NPC.oldVelocity.Y > 0f)) && !NPC.justHit) NPC.netUpdate = true; } diff --git a/NPCs/Perforator/PerforatorHeadSmall.cs b/NPCs/Perforator/PerforatorHeadSmall.cs index 1f6bb5cc30..0077cd773d 100644 --- a/NPCs/Perforator/PerforatorHeadSmall.cs +++ b/NPCs/Perforator/PerforatorHeadSmall.cs @@ -48,7 +48,11 @@ namespace CalamityMod.NPCs.Perforator NPC.npcSlots = 5f; NPC.width = 42; NPC.height = 62; + NPC.LifeMaxNERB(1200, 1440, 50000); + if (Main.zenithWorld) + NPC.lifeMax *= 4; + double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01; NPC.lifeMax += (int)(NPC.lifeMax * HPBoost); NPC.aiStyle = -1; @@ -110,19 +114,6 @@ namespace CalamityMod.NPCs.Perforator bool revenge = CalamityWorld.revenge || bossRush; bool death = CalamityWorld.death || bossRush; - // Calculate contact damage based on velocity - float minimalContactDamageVelocity = 4f; - float minimalDamageVelocity = 8f; - if (NPC.velocity.Length() <= minimalContactDamageVelocity) - { - NPC.damage = (int)(NPC.defDamage * 0.5f); - } - else - { - float velocityDamageScalar = MathHelper.Clamp((NPC.velocity.Length() - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); - NPC.damage = (int)MathHelper.Lerp(NPC.defDamage * 0.5f, NPC.defDamage, velocityDamageScalar); - } - // Enrage if ((!Main.player[NPC.target].ZoneCrimson || (NPC.position.Y / 16f) < Main.worldSurface) && !bossRush) { @@ -181,13 +172,10 @@ namespace CalamityMod.NPCs.Perforator { int lol; if (segments >= 0 && segments < maxLength - 1) - { - lol = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.position.X + (NPC.width / 2), (int)NPC.position.Y + (NPC.height / 2), ModContent.NPCType(), NPC.whoAmI); - } + lol = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.Center.X, (int)NPC.Center.Y, ModContent.NPCType(), NPC.whoAmI); else - { - lol = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.position.X + (NPC.width / 2), (int)NPC.position.Y + (NPC.height / 2), ModContent.NPCType(), NPC.whoAmI); - } + lol = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.Center.X, (int)NPC.Center.Y, ModContent.NPCType(), NPC.whoAmI); + Main.npc[lol].realLife = NPC.whoAmI; Main.npc[lol].ai[2] = NPC.whoAmI; Main.npc[lol].ai[1] = Previous; @@ -195,6 +183,7 @@ namespace CalamityMod.NPCs.Perforator NetMessage.SendData(MsgType, -1, -1, null, lol, 0f, 0f, 0f, 0); Previous = lol; } + TailSpawned = true; } } @@ -204,21 +193,14 @@ namespace CalamityMod.NPCs.Perforator int tilePositionY = (int)(NPC.position.Y / 16f) - 1; int tileWidthPosY = (int)((NPC.position.Y + (float)NPC.height) / 16f) + 2; if (tilePositionX < 0) - { tilePositionX = 0; - } if (tileWidthPosX > Main.maxTilesX) - { tileWidthPosX = Main.maxTilesX; - } if (tilePositionY < 0) - { tilePositionY = 0; - } if (tileWidthPosY > Main.maxTilesY) - { tileWidthPosY = Main.maxTilesY; - } + bool shouldFly = false; if (!shouldFly) { @@ -240,15 +222,16 @@ namespace CalamityMod.NPCs.Perforator } } } + if (!shouldFly) { NPC.localAI[1] = 1f; Rectangle rectangle = new Rectangle((int)NPC.position.X, (int)NPC.position.Y, NPC.width, NPC.height); - int stopFlyingRadius = death ? 160 : revenge ? 200 : expertMode ? 240 : 300; + int stopFlyingRadius = death ? 320 : revenge ? 400 : expertMode ? 480 : 600; bool outsideFlyRadius = true; if (NPC.position.Y > player.position.Y) { - for (int m = 0; m < 255; m++) + for (int m = 0; m < Main.maxPlayers; m++) { if (Main.player[m].active) { @@ -260,35 +243,31 @@ namespace CalamityMod.NPCs.Perforator } } } + if (outsideFlyRadius) - { shouldFly = true; - } } } else - { NPC.localAI[1] = 0f; - } + float maxChargeSpeed = 16f; if (player.dead || CalamityGlobalNPC.perfHive < 0 || !Main.npc[CalamityGlobalNPC.perfHive].active) { shouldFly = false; NPC.velocity.Y += 1f; - if ((double)NPC.position.Y > Main.worldSurface * 16.0) + if ((double)NPC.position.Y > Main.worldSurface * 16D) { NPC.velocity.Y += 1f; - maxChargeSpeed = 32f; + maxChargeSpeed *= 2f; } - if ((double)NPC.position.Y > Main.rockLayer * 16.0) + + if ((double)NPC.position.Y > Main.rockLayer * 16D) { for (int a = 0; a < Main.maxNPCs; a++) { - if (Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || - Main.npc[a].type == ModContent.NPCType()) - { + if (Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType() || Main.npc[a].type == ModContent.NPCType()) Main.npc[a].active = false; - } } } } @@ -296,7 +275,7 @@ namespace CalamityMod.NPCs.Perforator if (Main.zenithWorld && CalamityGlobalNPC.perfHive >= 0) NPC.ai[0]++; - //GFB movement + // GFB movement if (NPC.ai[0] >= 300f && CalamityGlobalNPC.perfHive >= 0) { shouldFly = false; @@ -305,14 +284,17 @@ namespace CalamityMod.NPCs.Perforator Vector2 targetDistance = Hive.Center - NPC.Center; float velocity = 16f; float acceleration = 0.15f; - //Move towards the hive really quickly + + // Move towards the hive really quickly if (targetDistance.Length() > 32f) + { CalamityUtils.SmoothMovement(NPC, 0f, targetDistance, velocity, acceleration, true); + } else { - //Go and succ it + // Go and succ it NPC.Center = Hive.Center + (Vector2.UnitY * 4f).RotatedBy(NPC.rotation); - Hive.localAI[1]++; + Hive.localAI[1] += 1f; } if (NPC.ai[0] >= 600f) @@ -321,14 +303,14 @@ namespace CalamityMod.NPCs.Perforator Hive.localAI[1] = 0f; } } - //Normal movement + // Normal movement else { float speedCopy = speed; float turnSpeedCopy = turnSpeed; - Vector2 npcCenter = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f); - float targetX = player.position.X + (float)(player.width / 2); - float targetY = player.position.Y + (float)(player.height / 2); + Vector2 npcCenter = NPC.Center; + float targetX = player.Center.X; + float targetY = player.Center.Y; targetX = (float)((int)(targetX / 16f) * 16); targetY = (float)((int)(targetY / 16f) * 16); npcCenter.X = (float)((int)(npcCenter.X / 16f) * 16); @@ -339,43 +321,42 @@ namespace CalamityMod.NPCs.Perforator if (!shouldFly) { NPC.TargetClosest(true); - NPC.velocity.Y = NPC.velocity.Y + 0.15f; + NPC.velocity.Y += 0.15f; if (NPC.velocity.Y > maxChargeSpeed) - { NPC.velocity.Y = maxChargeSpeed; - } + + // This bool exists to stop the strange wiggle behavior when worms are falling down + bool slowXVelocity = Math.Abs(NPC.velocity.X) > maxChargeSpeed; if ((double)(Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < (double)maxChargeSpeed * 0.4) { if (NPC.velocity.X < 0f) - { - NPC.velocity.X = NPC.velocity.X - speedCopy * 1.1f; - } + NPC.velocity.X -= speedCopy * 1.1f; else - { - NPC.velocity.X = NPC.velocity.X + speedCopy * 1.1f; - } + NPC.velocity.X += speedCopy * 1.1f; } else if (NPC.velocity.Y == maxChargeSpeed) { - if (NPC.velocity.X < targetX) + if (slowXVelocity) { - NPC.velocity.X = NPC.velocity.X + speedCopy; - } - else if (NPC.velocity.X > targetX) - { - NPC.velocity.X = NPC.velocity.X - speedCopy; + if (NPC.velocity.X < targetX) + NPC.velocity.X += speedCopy; + else if (NPC.velocity.X > targetX) + NPC.velocity.X -= speedCopy; } + else + NPC.velocity.X = 0f; } else if (NPC.velocity.Y > 4f) { - if (NPC.velocity.X < 0f) + if (slowXVelocity) { - NPC.velocity.X = NPC.velocity.X + speedCopy * 0.9f; + if (NPC.velocity.X < 0f) + NPC.velocity.X += speedCopy * 0.9f; + else + NPC.velocity.X -= speedCopy * 0.9f; } else - { - NPC.velocity.X = NPC.velocity.X - speedCopy * 0.9f; - } + NPC.velocity.X = 0f; } } else @@ -384,16 +365,14 @@ namespace CalamityMod.NPCs.Perforator { float soundDelay = targetDistance / 40f; if (soundDelay < 10f) - { soundDelay = 10f; - } if (soundDelay > 20f) - { soundDelay = 20f; - } + NPC.soundDelay = (int)soundDelay; SoundEngine.PlaySound(SoundID.WormDig, NPC.Center); } + targetDistance = (float)Math.Sqrt((double)(targetX * targetX + targetY * targetY)); float absoluteTargetX = Math.Abs(targetX); float absoluteTargetY = Math.Abs(targetY); @@ -403,130 +382,108 @@ namespace CalamityMod.NPCs.Perforator if (((NPC.velocity.X > 0f && targetX > 0f) || (NPC.velocity.X < 0f && targetX < 0f)) && ((NPC.velocity.Y > 0f && targetY > 0f) || (NPC.velocity.Y < 0f && targetY < 0f))) { if (NPC.velocity.X < targetX) - { - NPC.velocity.X = NPC.velocity.X + turnSpeedCopy; - } + NPC.velocity.X += turnSpeedCopy; else if (NPC.velocity.X > targetX) - { - NPC.velocity.X = NPC.velocity.X - turnSpeedCopy; - } + NPC.velocity.X -= turnSpeedCopy; + if (NPC.velocity.Y < targetY) - { - NPC.velocity.Y = NPC.velocity.Y + turnSpeedCopy; - } + NPC.velocity.Y += turnSpeedCopy; else if (NPC.velocity.Y > targetY) - { - NPC.velocity.Y = NPC.velocity.Y - turnSpeedCopy; - } + NPC.velocity.Y -= turnSpeedCopy; } if ((NPC.velocity.X > 0f && targetX > 0f) || (NPC.velocity.X < 0f && targetX < 0f) || (NPC.velocity.Y > 0f && targetY > 0f) || (NPC.velocity.Y < 0f && targetY < 0f)) { if (NPC.velocity.X < targetX) - { - NPC.velocity.X = NPC.velocity.X + speedCopy; - } + NPC.velocity.X += speedCopy; else if (NPC.velocity.X > targetX) - { - NPC.velocity.X = NPC.velocity.X - speedCopy; - } + NPC.velocity.X -= speedCopy; + if (NPC.velocity.Y < targetY) - { - NPC.velocity.Y = NPC.velocity.Y + speedCopy; - } + NPC.velocity.Y += speedCopy; else if (NPC.velocity.Y > targetY) - { - NPC.velocity.Y = NPC.velocity.Y - speedCopy; - } + NPC.velocity.Y -= speedCopy; + if ((double)Math.Abs(targetY) < (double)maxChargeSpeed * 0.2 && ((NPC.velocity.X > 0f && targetX < 0f) || (NPC.velocity.X < 0f && targetX > 0f))) { if (NPC.velocity.Y > 0f) - { - NPC.velocity.Y = NPC.velocity.Y + speedCopy * 2f; - } + NPC.velocity.Y += speedCopy * 2f; else - { - NPC.velocity.Y = NPC.velocity.Y - speedCopy * 2f; - } + NPC.velocity.Y -= speedCopy * 2f; } + if ((double)Math.Abs(targetX) < (double)maxChargeSpeed * 0.2 && ((NPC.velocity.Y > 0f && targetY < 0f) || (NPC.velocity.Y < 0f && targetY > 0f))) { if (NPC.velocity.X > 0f) - { - NPC.velocity.X = NPC.velocity.X + speedCopy * 2f; - } + NPC.velocity.X += speedCopy * 2f; else - { - NPC.velocity.X = NPC.velocity.X - speedCopy * 2f; - } + NPC.velocity.X -= speedCopy * 2f; } } else if (absoluteTargetX > absoluteTargetY) { if (NPC.velocity.X < targetX) - { - NPC.velocity.X = NPC.velocity.X + speedCopy * 1.1f; - } + NPC.velocity.X += speedCopy * 1.1f; else if (NPC.velocity.X > targetX) - { - NPC.velocity.X = NPC.velocity.X - speedCopy * 1.1f; - } + NPC.velocity.X -= speedCopy * 1.1f; + if ((double)(Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < (double)maxChargeSpeed * 0.5) { if (NPC.velocity.Y > 0f) - { - NPC.velocity.Y = NPC.velocity.Y + speedCopy; - } + NPC.velocity.Y += speedCopy; else - { - NPC.velocity.Y = NPC.velocity.Y - speedCopy; - } + NPC.velocity.Y -= speedCopy; } } else { if (NPC.velocity.Y < targetY) - { - NPC.velocity.Y = NPC.velocity.Y + speedCopy * 1.1f; - } + NPC.velocity.Y += speedCopy * 1.1f; else if (NPC.velocity.Y > targetY) - { - NPC.velocity.Y = NPC.velocity.Y - speedCopy * 1.1f; - } + NPC.velocity.Y -= speedCopy * 1.1f; + if ((double)(Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < (double)maxChargeSpeed * 0.5) { if (NPC.velocity.X > 0f) - { - NPC.velocity.X = NPC.velocity.X + speedCopy; - } + NPC.velocity.X += speedCopy; else - { - NPC.velocity.X = NPC.velocity.X - speedCopy; - } + NPC.velocity.X -= speedCopy; } } } } - NPC.rotation = (float)Math.Atan2((double)NPC.velocity.Y, (double)NPC.velocity.X) + 1.57f; + + // Calculate contact damage based on velocity + float minimalContactDamageVelocity = maxChargeSpeed * 0.25f; + float minimalDamageVelocity = maxChargeSpeed * 0.5f; + if (NPC.velocity.Length() <= minimalContactDamageVelocity) + { + NPC.damage = (int)(NPC.defDamage * 0.5f); + } + else + { + float velocityDamageScalar = MathHelper.Clamp((NPC.velocity.Length() - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + NPC.damage = (int)MathHelper.Lerp(NPC.defDamage * 0.5f, NPC.defDamage, velocityDamageScalar); + } + + NPC.rotation = (float)Math.Atan2((double)NPC.velocity.Y, (double)NPC.velocity.X) + MathHelper.PiOver2; + if (shouldFly) { if (NPC.localAI[0] != 1f) - { NPC.netUpdate = true; - } + NPC.localAI[0] = 1f; } else { if (NPC.localAI[0] != 0f) - { NPC.netUpdate = true; - } + NPC.localAI[0] = 0f; } + if (((NPC.velocity.X > 0f && NPC.oldVelocity.X < 0f) || (NPC.velocity.X < 0f && NPC.oldVelocity.X > 0f) || (NPC.velocity.Y > 0f && NPC.oldVelocity.Y < 0f) || (NPC.velocity.Y < 0f && NPC.oldVelocity.Y > 0f)) && !NPC.justHit) - { NPC.netUpdate = true; - } } public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) diff --git a/NPCs/Perforator/PerforatorTailLarge.cs b/NPCs/Perforator/PerforatorTailLarge.cs index fc9e8bd7bb..b5e9ce7611 100644 --- a/NPCs/Perforator/PerforatorTailLarge.cs +++ b/NPCs/Perforator/PerforatorTailLarge.cs @@ -29,7 +29,11 @@ namespace CalamityMod.NPCs.Perforator NPC.width = 60; NPC.height = 78; NPC.defense = 12; + NPC.LifeMaxNERB(2700, 3240, 80000); + if (Main.zenithWorld) + NPC.lifeMax *= 4; + double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01; NPC.lifeMax += (int)(NPC.lifeMax * HPBoost); NPC.aiStyle = -1; @@ -70,20 +74,6 @@ namespace CalamityMod.NPCs.Perforator public override void AI() { - // Calculate contact damage based on velocity - float minimalContactDamageVelocity = 4f; - float minimalDamageVelocity = 8f; - float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); - if (bodyAndTailVelocity <= minimalContactDamageVelocity) - { - NPC.damage = 0; - } - else - { - float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); - NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); - } - if (NPC.ai[2] > 0f) NPC.realLife = (int)NPC.ai[2]; @@ -124,9 +114,9 @@ namespace CalamityMod.NPCs.Perforator if (Main.player[NPC.target].dead) NPC.TargetClosest(false); - Vector2 segmentPosition = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f); - float targetX = Main.player[NPC.target].position.X + (float)(Main.player[NPC.target].width / 2); - float targetY = Main.player[NPC.target].position.Y + (float)(Main.player[NPC.target].height / 2); + Vector2 segmentPosition = NPC.Center; + float targetX = Main.player[NPC.target].Center.X; + float targetY = Main.player[NPC.target].Center.Y; targetX = (float)((int)(targetX / 16f) * 16); targetY = (float)((int)(targetY / 16f) * 16); segmentPosition.X = (float)((int)(segmentPosition.X / 16f) * 16); @@ -138,28 +128,44 @@ namespace CalamityMod.NPCs.Perforator { try { - segmentPosition = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f); - targetX = Main.npc[(int)NPC.ai[1]].position.X + (float)(Main.npc[(int)NPC.ai[1]].width / 2) - segmentPosition.X; - targetY = Main.npc[(int)NPC.ai[1]].position.Y + (float)(Main.npc[(int)NPC.ai[1]].height / 2) - segmentPosition.Y; + segmentPosition = NPC.Center; + targetX = Main.npc[(int)NPC.ai[1]].Center.X - segmentPosition.X; + targetY = Main.npc[(int)NPC.ai[1]].Center.Y - segmentPosition.Y; } catch { } - NPC.rotation = (float)System.Math.Atan2((double)targetY, (double)targetX) + 1.57f; + + NPC.rotation = (float)System.Math.Atan2((double)targetY, (double)targetX) + MathHelper.PiOver2; targetDistance = (float)System.Math.Sqrt((double)(targetX * targetX + targetY * targetY)); int npcWidth = NPC.width; targetDistance = (targetDistance - (float)npcWidth) / targetDistance; targetX *= targetDistance; targetY *= targetDistance; NPC.velocity = Vector2.Zero; - NPC.position.X = NPC.position.X + targetX; - NPC.position.Y = NPC.position.Y + targetY; + NPC.position.X += targetX; + NPC.position.Y += targetY; if (targetX < 0f) NPC.spriteDirection = 1; else if (targetX > 0f) NPC.spriteDirection = -1; } + + // Calculate contact damage based on velocity + float maxChaseSpeed = 16f; + float minimalContactDamageVelocity = maxChaseSpeed * 0.25f; + float minimalDamageVelocity = maxChaseSpeed * 0.5f; + float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); + if (bodyAndTailVelocity <= minimalContactDamageVelocity) + { + NPC.damage = 0; + } + else + { + float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); + } } public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) diff --git a/NPCs/Perforator/PerforatorTailMedium.cs b/NPCs/Perforator/PerforatorTailMedium.cs index bc0407001e..57f55dfdc0 100644 --- a/NPCs/Perforator/PerforatorTailMedium.cs +++ b/NPCs/Perforator/PerforatorTailMedium.cs @@ -32,7 +32,11 @@ namespace CalamityMod.NPCs.Perforator NPC.width = 40; NPC.height = 50; NPC.defense = 10; + NPC.LifeMaxNERB(180, 216, 7000); + if (Main.zenithWorld) + NPC.lifeMax *= 4; + double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01; NPC.lifeMax += (int)(NPC.lifeMax * HPBoost); NPC.aiStyle = -1; @@ -70,20 +74,6 @@ namespace CalamityMod.NPCs.Perforator public override void AI() { - // Calculate contact damage based on velocity - float minimalContactDamageVelocity = 4f; - float minimalDamageVelocity = 8f; - float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); - if (bodyAndTailVelocity <= minimalContactDamageVelocity) - { - NPC.damage = 0; - } - else - { - float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); - NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); - } - NPC.realLife = -1; // Target @@ -124,9 +114,9 @@ namespace CalamityMod.NPCs.Perforator NetMessage.SendData(MessageID.DamageNPC, -1, -1, null, NPC.whoAmI, -1f, 0f, 0f, 0, 0, 0); } - Vector2 segmentDirection = new Vector2(NPC.position.X + NPC.width * 0.5f, NPC.position.Y + NPC.height * 0.5f); - float targetX = Main.player[NPC.target].position.X + (Main.player[NPC.target].width / 2); - float targetY = Main.player[NPC.target].position.Y + (Main.player[NPC.target].height / 2); + Vector2 segmentDirection = NPC.Center; + float targetX = Main.player[NPC.target].Center.X; + float targetY = Main.player[NPC.target].Center.Y; targetX = (int)(targetX / 16f) * 16; targetY = (int)(targetY / 16f) * 16; @@ -140,9 +130,9 @@ namespace CalamityMod.NPCs.Perforator { try { - segmentDirection = new Vector2(NPC.position.X + NPC.width * 0.5f, NPC.position.Y + NPC.height * 0.5f); - targetX = Main.npc[(int)NPC.ai[1]].position.X + (Main.npc[(int)NPC.ai[1]].width / 2) - segmentDirection.X; - targetY = Main.npc[(int)NPC.ai[1]].position.Y + (Main.npc[(int)NPC.ai[1]].height / 2) - segmentDirection.Y; + segmentDirection = NPC.Center; + targetX = Main.npc[(int)NPC.ai[1]].Center.X - segmentDirection.X; + targetY = Main.npc[(int)NPC.ai[1]].Center.Y - segmentDirection.Y; } catch { @@ -159,6 +149,21 @@ namespace CalamityMod.NPCs.Perforator NPC.position.X += targetX; NPC.position.Y += targetY; } + + // Calculate contact damage based on velocity + float maxChaseSpeed = 16f; + float minimalContactDamageVelocity = maxChaseSpeed * 0.25f; + float minimalDamageVelocity = maxChaseSpeed * 0.5f; + float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); + if (bodyAndTailVelocity <= minimalContactDamageVelocity) + { + NPC.damage = 0; + } + else + { + float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); + } } public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) diff --git a/NPCs/Perforator/PerforatorTailSmall.cs b/NPCs/Perforator/PerforatorTailSmall.cs index 8743d2d114..1b184b4bbd 100644 --- a/NPCs/Perforator/PerforatorTailSmall.cs +++ b/NPCs/Perforator/PerforatorTailSmall.cs @@ -29,7 +29,11 @@ namespace CalamityMod.NPCs.Perforator NPC.width = 40; NPC.height = 34; NPC.defense = 8; + NPC.LifeMaxNERB(1200, 1440, 50000); + if (Main.zenithWorld) + NPC.lifeMax *= 4; + double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01; NPC.lifeMax += (int)(NPC.lifeMax * HPBoost); NPC.aiStyle = -1; @@ -70,20 +74,6 @@ namespace CalamityMod.NPCs.Perforator public override void AI() { - // Calculate contact damage based on velocity - float minimalContactDamageVelocity = 4f; - float minimalDamageVelocity = 8f; - float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); - if (bodyAndTailVelocity <= minimalContactDamageVelocity) - { - NPC.damage = 0; - } - else - { - float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); - NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); - } - if (NPC.ai[2] > 0f) NPC.realLife = (int)NPC.ai[2]; @@ -124,9 +114,9 @@ namespace CalamityMod.NPCs.Perforator if (Main.player[NPC.target].dead) NPC.TargetClosest(false); - Vector2 segmentPosition = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f); - float targetX = Main.player[NPC.target].position.X + (float)(Main.player[NPC.target].width / 2); - float targetY = Main.player[NPC.target].position.Y + (float)(Main.player[NPC.target].height / 2); + Vector2 segmentPosition = NPC.Center; + float targetX = Main.player[NPC.target].Center.X; + float targetY = Main.player[NPC.target].Center.Y; targetX = (float)((int)(targetX / 16f) * 16); targetY = (float)((int)(targetY / 16f) * 16); segmentPosition.X = (float)((int)(segmentPosition.X / 16f) * 16); @@ -138,28 +128,44 @@ namespace CalamityMod.NPCs.Perforator { try { - segmentPosition = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f); - targetX = Main.npc[(int)NPC.ai[1]].position.X + (float)(Main.npc[(int)NPC.ai[1]].width / 2) - segmentPosition.X; - targetY = Main.npc[(int)NPC.ai[1]].position.Y + (float)(Main.npc[(int)NPC.ai[1]].height / 2) - segmentPosition.Y; + segmentPosition = NPC.Center; + targetX = Main.npc[(int)NPC.ai[1]].Center.X - segmentPosition.X; + targetY = Main.npc[(int)NPC.ai[1]].Center.Y - segmentPosition.Y; } catch { } - NPC.rotation = (float)System.Math.Atan2((double)targetY, (double)targetX) + 1.57f; + + NPC.rotation = (float)System.Math.Atan2((double)targetY, (double)targetX) + MathHelper.PiOver2; targetDistance = (float)System.Math.Sqrt((double)(targetX * targetX + targetY * targetY)); int npcWidth = NPC.width; targetDistance = (targetDistance - (float)npcWidth) / targetDistance; targetX *= targetDistance; targetY *= targetDistance; NPC.velocity = Vector2.Zero; - NPC.position.X = NPC.position.X + targetX; - NPC.position.Y = NPC.position.Y + targetY; + NPC.position.X += targetX; + NPC.position.Y += targetY; if (targetX < 0f) NPC.spriteDirection = 1; else if (targetX > 0f) NPC.spriteDirection = -1; } + + // Calculate contact damage based on velocity + float maxChaseSpeed = 16f; + float minimalContactDamageVelocity = maxChaseSpeed * 0.25f; + float minimalDamageVelocity = maxChaseSpeed * 0.5f; + float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length(); + if (bodyAndTailVelocity <= minimalContactDamageVelocity) + { + NPC.damage = 0; + } + else + { + float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar); + } } public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) diff --git a/NPCs/SulphurousSea/AnthozoanCrab.cs b/NPCs/SulphurousSea/AnthozoanCrab.cs index bfbfad4f9f..61e56a7537 100644 --- a/NPCs/SulphurousSea/AnthozoanCrab.cs +++ b/NPCs/SulphurousSea/AnthozoanCrab.cs @@ -17,6 +17,7 @@ namespace CalamityMod.NPCs.SulphurousSea public class AnthozoanCrab : ModNPC { public int boulderIndex; + public override void SetStaticDefaults() { Main.npcFrameCount[NPC.type] = 16; @@ -67,12 +68,17 @@ namespace CalamityMod.NPCs.SulphurousSea { writer.Write(boulderIndex); } + public override void ReceiveExtraAI(BinaryReader reader) { boulderIndex = reader.ReadInt32(); } + public override void AI() { + // Setting this in SetDefaults will disable expert mode scaling, so put it here instead + NPC.damage = 0; + if (NPC.ai[1]++ % 360f < 280f) { if (NPC.ai[2] > 1f) diff --git a/NPCs/SulphurousSea/BelchingCoral.cs b/NPCs/SulphurousSea/BelchingCoral.cs index 4997ec5000..bb897824ea 100644 --- a/NPCs/SulphurousSea/BelchingCoral.cs +++ b/NPCs/SulphurousSea/BelchingCoral.cs @@ -64,6 +64,9 @@ namespace CalamityMod.NPCs.SulphurousSea public override void AI() { + // Setting this in SetDefaults will disable expert mode scaling, so put it here instead + NPC.damage = 0; + NPC.velocity.Y += 0.25f; NPC.TargetClosest(false); Player player = Main.player[NPC.target]; diff --git a/NPCs/SulphurousSea/Sulflounder.cs b/NPCs/SulphurousSea/Sulflounder.cs index b34c98bd2c..edfa82d133 100644 --- a/NPCs/SulphurousSea/Sulflounder.cs +++ b/NPCs/SulphurousSea/Sulflounder.cs @@ -60,6 +60,9 @@ namespace CalamityMod.NPCs.SulphurousSea public override void AI() { + // Setting this in SetDefaults will disable expert mode scaling, so put it here instead + NPC.damage = 0; + NPC.spriteDirection = (NPC.direction > 0) ? 1 : -1; int alphaControl = 200; if (NPC.ai[2] == 0f) diff --git a/NPCs/SunkenSea/GiantClam.cs b/NPCs/SunkenSea/GiantClam.cs index 9fb9fba030..059e9bb7cd 100644 --- a/NPCs/SunkenSea/GiantClam.cs +++ b/NPCs/SunkenSea/GiantClam.cs @@ -35,7 +35,6 @@ namespace CalamityMod.NPCs.SunkenSea private int attack = -1; //-1 doing nothing, 0 = shell hiding, 1 = telestomp, 2 = pearl burst, 3 = pearl rain private bool attackAnim = false; private bool hasBeenHit = false; - private bool statChange = false; private bool hide = false; public override void SetStaticDefaults() @@ -56,6 +55,7 @@ namespace CalamityMod.NPCs.SunkenSea NPC.lavaImmune = true; NPC.npcSlots = 5f; NPC.damage = Main.hardMode ? 100 : 50; + NPC.defense = Main.hardMode ? 35 : 10; NPC.width = 160; NPC.height = 120; NPC.defense = 9999; @@ -94,7 +94,6 @@ namespace CalamityMod.NPCs.SunkenSea writer.Write(NPC.dontTakeDamage); writer.Write(NPC.chaseable); writer.Write(hasBeenHit); - writer.Write(statChange); writer.Write(hide); for (int i = 0; i < 2; i++) writer.Write(NPC.Calamity().newAI[i]); @@ -108,7 +107,6 @@ namespace CalamityMod.NPCs.SunkenSea NPC.dontTakeDamage = reader.ReadBoolean(); NPC.chaseable = reader.ReadBoolean(); hasBeenHit = reader.ReadBoolean(); - statChange = reader.ReadBoolean(); hide = reader.ReadBoolean(); for (int i = 0; i < 2; i++) NPC.Calamity().newAI[i] = reader.ReadSingle(); @@ -117,36 +115,34 @@ namespace CalamityMod.NPCs.SunkenSea public override void AI() { NPC.TargetClosest(true); + Player player = Main.player[NPC.target]; CalamityGlobalNPC calamityGlobalNPC = NPC.Calamity(); + if (NPC.justHit && hitAmount < 5) { ++hitAmount; hasBeenHit = true; } + NPC.chaseable = hasBeenHit; + if (hitAmount == 5) { if (Main.netMode != NetmodeID.Server) { if (!Main.player[NPC.target].dead && Main.player[NPC.target].active) - { player.AddBuff(ModContent.BuffType(), 2); //CLAM INVASION - } } if (!hide) Lighting.AddLight(NPC.Center, 0f, (255 - NPC.alpha) * 2.5f / 255f, (255 - NPC.alpha) * 2.5f / 255f); - if (!statChange) - { - NPC.defense = Main.hardMode ? 35 : 10; - NPC.damage = NPC.defDamage; - statChange = true; - } - if (NPC.ai[0] < 240f) { + // Avoid cheap bullshit + NPC.damage = 0; + NPC.ai[0] += 1f; hide = false; } @@ -154,14 +150,18 @@ namespace CalamityMod.NPCs.SunkenSea { if (attack == -1) { + // Avoid cheap bullshit + NPC.damage = 0; + attack = Main.rand.Next(2); if (attack == 0) - { attack = Main.rand.Next(2); //rarer chance of doing the hiding clam - } } else if (attack == 0) { + // Avoid cheap bullshit + NPC.damage = 0; + hide = true; NPC.defense = 9999; NPC.ai[1] += 1f; @@ -190,11 +190,14 @@ namespace CalamityMod.NPCs.SunkenSea } else if (NPC.ai[2] == 1f) { + // Avoid cheap bullshit NPC.damage = 0; + NPC.chaseable = false; NPC.dontTakeDamage = true; NPC.noGravity = true; NPC.noTileCollide = true; + NPC.alpha += Main.hardMode ? 8 : 5; if (NPC.alpha >= 255) { @@ -223,10 +226,13 @@ namespace CalamityMod.NPCs.SunkenSea vector *= 34f; Main.dust[attackDust].position = NPC.Center - vector; } + NPC.alpha -= Main.hardMode ? 7 : 4; if (NPC.alpha <= 0) { + // Set damage NPC.damage = NPC.defDamage; + NPC.chaseable = true; NPC.dontTakeDamage = false; NPC.alpha = 0; @@ -236,6 +242,9 @@ namespace CalamityMod.NPCs.SunkenSea } else if (NPC.ai[2] == 3f) { + // Set damage + NPC.damage = NPC.defDamage; + NPC.velocity.Y += 0.8f; attackAnim = true; if (NPC.Center.Y > (player.Center.Y - (float)(NPC.height / 2) + player.gfxOffY - 15f)) @@ -249,6 +258,9 @@ namespace CalamityMod.NPCs.SunkenSea { if (NPC.velocity.Y == 0f) { + // Avoid cheap bullshit + NPC.damage = 0; + NPC.ai[2] = 0f; NPC.ai[0] = 0f; NPC.netUpdate = true; @@ -269,6 +281,7 @@ namespace CalamityMod.NPCs.SunkenSea } } } + NPC.velocity.Y += 0.8f; } }