From f26ea60600d4bb5f9264ac9468f2de2f742b7fed Mon Sep 17 00:00:00 2001 From: Andrew Marheine Date: Mon, 8 Nov 2021 21:09:53 -0600 Subject: [PATCH] 1 - Hive Mind circular hitbox. --- NPCs/HiveMind/HiveMind.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/NPCs/HiveMind/HiveMind.cs b/NPCs/HiveMind/HiveMind.cs index c4029f99da..98d5008a5e 100644 --- a/NPCs/HiveMind/HiveMind.cs +++ b/NPCs/HiveMind/HiveMind.cs @@ -982,7 +982,26 @@ namespace CalamityMod.NPCs.HiveMind public override bool? CanHitNPC(NPC target) => npc.alpha == 0; // Can only be hit while fully visible - public override bool CanHitPlayer(Player target, ref int cooldownSlot) => npc.alpha == 0 && npc.scale == 1f; // No damage while not fully visible or shrunk + // Can only hit the target if within certain distance + public override bool CanHitPlayer(Player target, ref int cooldownSlot) + { + Rectangle targetHitbox = target.Hitbox; + + float dist1 = Vector2.Distance(npc.Center, targetHitbox.TopLeft()); + float dist2 = Vector2.Distance(npc.Center, targetHitbox.TopRight()); + float dist3 = Vector2.Distance(npc.Center, targetHitbox.BottomLeft()); + float dist4 = Vector2.Distance(npc.Center, targetHitbox.BottomRight()); + + float minDist = dist1; + if (dist2 < minDist) + minDist = dist2; + if (dist3 < minDist) + minDist = dist3; + if (dist4 < minDist) + minDist = dist4; + + return minDist <= 60f && npc.alpha == 0 && npc.scale == 1f; // No damage while not fully visible or shrunk + } public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position) => npc.scale == 1f; // Only draw HP bar while at full size