small cleanup pr

This commit is contained in:
Dreitone committed 2025-12-22 21:36:02 -06:00
1 parent aa40112059
commit 08bddf36c3
5 files changed
+19 -63

No files matched your search

@@ -59,7 +59,7 @@ CosmicTentacle.DisplayName: Dark Tentacle
CryoBlast.DisplayName: Cryo Blast
DarkSparkBeam.DisplayName: Dark Spark Beam
DarkSparkPrism.DisplayName: Dark Crystal
HyperdeathRiftScepterBeam.DisplayName: Hypderdeath Rift Ripper
HyperdeathRiftScepterBeam.DisplayName: Hyperdeath Rift Ripper
DeathValleyDusterProjectile.DisplayName: Death Valley Duster
DeathhailBeam.DisplayName: Deathhail Beam
EelDrop.DisplayName: Acid Eel Drop
@@ -101,7 +101,6 @@ HellfireExplosionFriendly.DisplayName: Explosion
HellwingBat.DisplayName: Ashen Hellwing
HolyFlame.DisplayName: Holy Flame
HolyLaser.DisplayName: Holy Laser
HyperdeathRiftScepterBeam.DisplayName: Hyperdeath Rift Scepter Beam
IceBarrageMain.DisplayName: Ice Barrage
IceBlock.DisplayName: Ice Barrage Block
IceBlockIcicle.DisplayName: Ice Barrage Icicle
+8 -16
View File
@@ -41,25 +41,17 @@ namespace CalamityMod
/// <param name="targetHitbox">The hitbox of the target to check.</param>
public static bool CircularHitboxCollision(Vector2 centerCheckPosition, float radius, Rectangle targetHitbox)
{
// If the center intersects the hitbox, return true immediately
Rectangle center = new Rectangle((int)centerCheckPosition.X, (int)centerCheckPosition.Y, 1, 1);
if (center.Intersects(targetHitbox))
return true;
float topLeftDistance = Vector2.Distance(centerCheckPosition, targetHitbox.TopLeft());
float topRightDistance = Vector2.Distance(centerCheckPosition, targetHitbox.TopRight());
float bottomLeftDistance = Vector2.Distance(centerCheckPosition, targetHitbox.BottomLeft());
float bottomRightDistance = Vector2.Distance(centerCheckPosition, targetHitbox.BottomRight());
if (radius <= 0f)
return false;
float distanceToClosestPoint = topLeftDistance;
if (topRightDistance < distanceToClosestPoint)
distanceToClosestPoint = topRightDistance;
if (bottomLeftDistance < distanceToClosestPoint)
distanceToClosestPoint = bottomLeftDistance;
if (bottomRightDistance < distanceToClosestPoint)
distanceToClosestPoint = bottomRightDistance;
float closestX = MathHelper.Clamp(centerCheckPosition.X, targetHitbox.Left, targetHitbox.Right);
float closestY = MathHelper.Clamp(centerCheckPosition.Y, targetHitbox.Top, targetHitbox.Bottom);
return distanceToClosestPoint <= radius;
float dx = centerCheckPosition.X - closestX;
float dy = centerCheckPosition.Y - closestY;
return (dx * dx + dy * dy) <= (radius * radius);
}
/// <summary>
+5 -30
View File
@@ -69,60 +69,35 @@ namespace CalamityMod
/// </summary>
/// <param name="index">whoAmI index to check</param>
/// <returns>true if index is in valid range [0 <= index < Main.maxNPCs]</returns>
public static bool IndexInRange(this NPC[] _, int index)
{
if (index >= 0)
return index < Main.maxNPCs;
return false;
}
public static bool IndexInRange(this NPC[] _, int index) => (uint)index < Main.maxNPCs;
/// <summary>
/// Fallback method for Main.player.IndexInRange which provide accurate range check (0 <= index < Main.maxPlayers)
/// </summary>
/// <param name="index">whoAmI index to check</param>
/// <returns>true if index is in valid range [0 <= index < Main.maxPlayers]</returns>
public static bool IndexInRange(this Player[] _, int index)
{
if (index >= 0)
return index < Main.maxPlayers;
return false;
}
public static bool IndexInRange(this Player[] _, int index) => (uint)index < Main.maxPlayers;
/// <summary>
/// Fallback method for Main.projectile.IndexInRange which provide accurate range check (0 <= index < Main.maxProjectiles)
/// </summary>
/// <param name="index">whoAmI index to check</param>
/// <returns>true if index is in valid range [0 <= index < Main.maxProjectiles]</returns>
public static bool IndexInRange(this Projectile[] _, int index)
{
if (index >= 0)
return index < Main.maxProjectiles;
return false;
}
public static bool IndexInRange(this Projectile[] _, int index) => (uint)index < Main.maxProjectiles;
/// <summary>
/// Fallback method for Main.gore.IndexInRange which provide accurate range check (0 <= index < Main.maxGore)
/// </summary>
/// <param name="index">whoAmI index to check</param>
/// <returns>true if index is in valid range [0 <= index < Main.maxGore]</returns>
public static bool IndexInRange(this Gore[] _, int index)
{
if (index >= 0)
return index < Main.maxGore;
return false;
}
public static bool IndexInRange(this Gore[] _, int index) => (uint)index < Main.maxGore;
/// <summary>
/// Fallback method for Main.npc.IndexInRange which provide accurate range check (0 <= index < Main.maxDust)
/// </summary>
/// <param name="index">whoAmI index to check</param>
/// <returns>true if index is in valid range [0 <= index < Main.maxDust]</returns>
public static bool IndexInRange(this Dust[] _, int index)
{
if (index >= 0)
return index < Main.maxDust;
return false;
}
public static bool IndexInRange(this Dust[] _, int index) => (uint)index < Main.maxDust;
#endregion
}
}
+1 -11
View File
@@ -90,17 +90,7 @@ namespace CalamityMod
public static void FindAndReplaceAll(this List<TooltipLine> tooltips, string replacedKey, string newKey)
{
foreach (TooltipLine line in tooltips)
{
if (!line.Text.Contains(replacedKey))
continue;
//loops only 100 times at max per tooltip line to prevent any infinite loops
for (var i = 0; i < 100; i++)
{
line.Text = line.Text.Replace(replacedKey, newKey);
if (!line.Text.Contains(replacedKey))
break;
}
}
line.Text = line.Text.Replace(replacedKey, newKey);
}
/// <summary>
+4 -4
View File
@@ -140,7 +140,7 @@ namespace CalamityMod
/// <typeparam name="T">The base type of the collection.</typeparam>
/// <param name="collection">The collection.</param>
/// <param name="type">The type to search for.</param>
public static bool ContainsType<T>(this IEnumerable<T> collection, Type type) => collection.Any(entry => entry.GetType() == type.GetType());
public static bool ContainsType<T>(this IEnumerable<T> collection, Type type) => collection.Any(entry => entry.GetType() == type);
/// <summary>
/// Calculates the sound volume and panning for a sound which is played at the specified location in the game world.<br/>
@@ -156,7 +156,7 @@ namespace CalamityMod
if (soundPos.X == -1f || soundPos.Y == -1f)
volume = 1f;
else if (WorldGen.gen || Main.dedServ || Main.dedServ)
else if (WorldGen.gen || Main.dedServ)
volume = 0f;
else
{
@@ -273,12 +273,12 @@ namespace CalamityMod
for (int i = 0; i < originalText.Length; i++)
{
for (int j = 0; j < 37; j++)
{
{
if (TextKeys[j] == originalText[i])
{
morseText += MorseKeys[j];
break;
}
}
}
}