From 021d1f26d89c1997ed02fe1e9d036615874a02a5 Mon Sep 17 00:00:00 2001 From: GinYuH Date: Fri, 31 Mar 2023 01:38:39 -0700 Subject: [PATCH] Calamity new AI calls --- ModSupport/ModCalls.cs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ModSupport/ModCalls.cs b/ModSupport/ModCalls.cs index 5037e5baa5..f9eb9d7b20 100644 --- a/ModSupport/ModCalls.cs +++ b/ModSupport/ModCalls.cs @@ -1551,6 +1551,16 @@ namespace CalamityMod } #endregion + public static float[] GetCalamityAI(NPC npc) => npc?.Calamity()?.newAI ?? new float[0]; + + public static void SetCalamityAI(NPC npc, int aiSlot, float value) + { + if (npc != null) + { + npc.Calamity().newAI[aiSlot] = value; + } + } + #region Boss Health Bars public static bool BossHealthBarVisible() => Main.LocalPlayer.Calamity().drawBossHPBar; @@ -2150,6 +2160,35 @@ namespace CalamityMod return null; } + case "GetCalamityAI": + case "GetNewAI": + { + if (args.Length < 2) + return new ArgumentNullException("ERROR: Must specify an NPC."); + if (!isValidNPCArg(args[1])) + return new ArgumentException("ERROR: The first argument to \"GetCalamityAI\" must be an NPC."); + return GetCalamityAI(castNPC(args[1])); + } + + case "SetCalamityAI": + case "SetNewAI": + { + if (args.Length < 2) + return new ArgumentNullException("ERROR: Must specify an NPC, an AI slot as an int, and a value for it as a float or a double."); + if (args.Length < 3) + return new ArgumentNullException("ERROR: Must specify an AI slot as an int, and a value for it as a float or a double."); + if (args.Length < 4) + return new ArgumentNullException("ERROR: Must specify a value for the AI slot as a float or a double."); + if (!(args[3] is float) && !(args[3] is double)) + return new ArgumentException("ERROR: The third argument to \"SetCalamityAI\" must be a float or a double."); + if (!(args[2] is int newValue)) + return new ArgumentException("ERROR: The second argument to \"SetCalamityAI\" must be an int."); + if (!isValidNPCArg(args[1])) + return new ArgumentException("ERROR: The first argument to \"SetCalamityAI\" must be an NPC."); + SetCalamityAI(castNPC(args[1]), newValue, (float)args[3]); + return null; + } + case "BossHealthBarVisible": case "BossHealthBarsVisible": case "GetBossHealthBarVisible":