From 424cbc3f4f25cccc3970fb6f005d05518fcc29f7 Mon Sep 17 00:00:00 2001 From: thojmr <72571672+thojmr@users.noreply.github.com> Date: Wed, 3 Mar 2021 12:47:16 -0500 Subject: [PATCH] Ai main game day change fix (#25) --- src/AIAPI/MainGame/GameAPI.Hooks.cs | 21 ++++++++------------- src/AIAPI/MainGame/GameExtensions.cs | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/AIAPI/MainGame/GameAPI.Hooks.cs b/src/AIAPI/MainGame/GameAPI.Hooks.cs index 49ff4f9..8399fb9 100644 --- a/src/AIAPI/MainGame/GameAPI.Hooks.cs +++ b/src/AIAPI/MainGame/GameAPI.Hooks.cs @@ -13,8 +13,8 @@ public static partial class GameAPI { private class Hooks { - public static int lastCurrentDay = 1;//Always starts at 1 public static bool isNewGame = false; + public static int day = 0; public static void SetupHooks() { @@ -66,21 +66,16 @@ public static void HScene_EndProc(HScene __instance) [HarmonyPostfix] [HarmonyPatch(typeof(EnvironmentSimulator), nameof(EnvironmentSimulator.SetTimeZone), typeof(AIProject.TimeZone))] public static void EnvironmentChangeTypeHook(AIProject.TimeZone zone) - { + { + if (zone == AIProject.TimeZone.Morning) + { + OnDayChange(day); + day++; + } + OnPeriodChange(zone);//morning, day, evening } - [HarmonyPostfix] - [HarmonyPatch(typeof(EnviroSky), "SetGameTime")] - public static void EnvironmentChangeDayHook(EnviroSky __instance) - { - var currentDay = (int)__instance.currentDay; - if (lastCurrentDay < currentDay) - { - lastCurrentDay = currentDay; - OnDayChange(currentDay); - } - } } } } diff --git a/src/AIAPI/MainGame/GameExtensions.cs b/src/AIAPI/MainGame/GameExtensions.cs index 14f4e62..c866b4b 100644 --- a/src/AIAPI/MainGame/GameExtensions.cs +++ b/src/AIAPI/MainGame/GameExtensions.cs @@ -102,6 +102,21 @@ public static IEnumerable GetRelatedChaFiles(this AgentData agen return results; } + /// + /// Get ChaFiles that are related to this AgentActor (heroine). Warning: It might not return some copies. + /// + public static IEnumerable GetRelatedChaFiles(this AgentActor agentActor) + { + if (agentActor == null) throw new ArgumentNullException(nameof(agentActor)); + + var results = new HashSet(); + + if (agentActor?.ChaControl?.chaFile != null) + results.Add(agentActor.ChaControl.chaFile); + + return results; + } + /// /// Get the persisting player object that describes this character. /// Returns null if the player could not be found. Works only in the main game.