From 63bb89c9b5c373f5e9cd8bbccb08d4344b3259d0 Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sun, 1 Sep 2024 02:28:04 +0900 Subject: [PATCH] Splitted IndexInRange Fallback method to each types --- Utilities/EntityUtils.cs | 59 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/Utilities/EntityUtils.cs b/Utilities/EntityUtils.cs index 75704529d5..13a11b4bd1 100644 --- a/Utilities/EntityUtils.cs +++ b/Utilities/EntityUtils.cs @@ -39,17 +39,66 @@ namespace CalamityMod Main.LocalPlayer.GetModPlayer().GeneralScreenShakePower += (intensity * dist); } + #region Fallback Method for IndexInRange /// - /// Fallback method for Main.[EntityType].IndexInRange which provide accurate range check (0 <= index < Main.max[EntityType]s) + /// Fallback method for Main.npc.IndexInRange which provide accurate range check (0 <= index < Main.maxNPCs) /// - /// /// whoAmI index to check - /// true if index is in valid range [0 <= index < Main.max[EntityType]s] - public static bool IndexInRange(this Entity[] entityArrayFromMainISuppose, int index) + /// true if index is in valid range [0 <= index < Main.maxNPCs] + public static bool IndexInRange(this NPC[] _, int index) { if (index >= 0) - return index < entityArrayFromMainISuppose.Length - 1; + return index < Main.maxNPCs; return false; } + + /// + /// Fallback method for Main.player.IndexInRange which provide accurate range check (0 <= index < Main.maxPlayers) + /// + /// whoAmI index to check + /// true if index is in valid range [0 <= index < Main.maxPlayers] + public static bool IndexInRange(this Player[] _, int index) + { + if (index >= 0) + return index < Main.maxPlayers; + return false; + } + + /// + /// Fallback method for Main.projectile.IndexInRange which provide accurate range check (0 <= index < Main.maxProjectiles) + /// + /// whoAmI index to check + /// true if index is in valid range [0 <= index < Main.maxProjectiles] + public static bool IndexInRange(this Projectile[] _, int index) + { + if (index >= 0) + return index < Main.maxProjectiles; + return false; + } + + /// + /// Fallback method for Main.gore.IndexInRange which provide accurate range check (0 <= index < Main.maxGore) + /// + /// whoAmI index to check + /// true if index is in valid range [0 <= index < Main.maxGore] + public static bool IndexInRange(this Gore[] _, int index) + { + if (index >= 0) + return index < Main.maxGore; + return false; + } + + /// + /// Fallback method for Main.npc.IndexInRange which provide accurate range check (0 <= index < Main.maxDust) + /// + /// whoAmI index to check + /// true if index is in valid range [0 <= index < Main.maxDust] + public static bool IndexInRange(this Dust[] _, int index) + { + if (index >= 0) + return index < Main.maxDust; + return false; + } + #endregion } }