/// <summary>Raised after the game begins a new day (including when the player loads a save).</summary> private static void OnDayStarted(object sender, DayStartedEventArgs e) { // reload NPC schedules ShouldResetSchedules = true; // update NPC schedules NpcSchedules.Clear(); foreach (NPC npc in Utility.getAllCharacters()) { if (!NpcSchedules.ContainsKey(npc.Name)) { NpcSchedules.Add(npc.Name, ParseSchedule(npc)); } } }
/// <summary>Apply the NPC schedules to each NPC.</summary> private static void ApplySchedules() { if (Game1.weatherIcon == Game1.weather_festival || Game1.isFestival() || Game1.eventUp) { return; } // apply for each NPC foreach (NPC npc in Utility.getAllCharacters()) { if (npc.DirectionsToNewLocation != null || npc.isMoving() || npc.Schedule == null || npc.controller != null || npc is Horse) { continue; } // get raw schedule from XNBs IDictionary <string, string> rawSchedule = GetRawSchedule(npc.Name); if (rawSchedule == null) { continue; } // get schedule data if (!NpcSchedules.TryGetValue(npc.Name, out string scheduleData) || string.IsNullOrEmpty(scheduleData)) { //this.Monitor.Log("THIS IS AWKWARD"); continue; } // get schedule script if (!rawSchedule.TryGetValue(scheduleData, out string script)) { continue; } // parse entries string[] entries = script.Split('/'); int index = 0; foreach (string _ in entries) { string[] fields = entries[index].Split(' '); // handle GOTO command if (fields.Contains("GOTO")) { for (int i = 0; i < fields.Length; i++) { string s = fields[i]; if (s == "GOTO") { rawSchedule.TryGetValue(fields[i + 1], out script); string[] newEntries = script.Split('/'); fields = newEntries[0].Split(' '); } } } // parse schedule script SchedulePathDescription schedulePathDescription; try { if (Convert.ToInt32(fields[0]) > Game1.timeOfDay) { break; } string endMap = Convert.ToString(fields[1]); int x = Convert.ToInt32(fields[2]); int y = Convert.ToInt32(fields[3]); int endFacingDir = Convert.ToInt32(fields[4]); schedulePathDescription = Reflection .GetMethod(npc, "pathfindToNextScheduleLocation") .Invoke <SchedulePathDescription>(npc.currentLocation.Name, npc.getTileX(), npc.getTileY(), endMap, x, y, endFacingDir, null, null); index++; } catch { continue; } npc.DirectionsToNewLocation = schedulePathDescription; npc.controller = new PathFindController(npc.DirectionsToNewLocation.route, npc, Utility.getGameLocationOfCharacter(npc)) { finalFacingDirection = npc.DirectionsToNewLocation.facingDirection, endBehaviorFunction = null }; } } }