summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-04-14 00:24:24 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-04-14 00:24:24 -0400
commit6616c87c1806159ce6e751d4ccd54b5500d8b903 (patch)
treefb9f1aecf95c438db67a7774d969f3fddc65b827
parent6d269621b28240a0da6de5fd5faa4c35553c15bb (diff)
downloadSMAPI-6616c87c1806159ce6e751d4ccd54b5500d8b903.tar.gz
SMAPI-6616c87c1806159ce6e751d4ccd54b5500d8b903.tar.bz2
SMAPI-6616c87c1806159ce6e751d4ccd54b5500d8b903.zip
fix world_settime command sometimes breaking NPC schedules
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs34
2 files changed, 33 insertions, 2 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index f3e9af6f..e524ea65 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -6,6 +6,7 @@
* Added `Context.IsMultiplayer` and `Context.IsMainPlayer` flags.
* Fixed SMAPI update checks not showing newer beta versions when using a beta version.
* Fixed console color scheme on Mac or PowerShell, and added override option to `StardewModdingAPI.config.json`.
+ * Fixed `world_settime` console command sometimes breaking NPC schedules (e.g. so they stay in bed).
* For modders:
* Added code analysis to mod build config package to flag common issues as warnings.
diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs
index d6c71387..7644ee46 100644
--- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs
+++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs
@@ -1,4 +1,5 @@
-using System.Linq;
+using System;
+using System.Linq;
using StardewValley;
namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World
@@ -31,9 +32,38 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World
return;
// handle
- Game1.timeOfDay = time;
+ this.SafelySetTime(time);
FreezeTimeCommand.FrozenTime = Game1.timeOfDay;
monitor.Log($"OK, the time is now {Game1.timeOfDay.ToString().PadLeft(4, '0')}.", LogLevel.Info);
}
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>Safely transition to the given time, allowing NPCs to update their schedule.</summary>
+ /// <param name="time">The time of day.</param>
+ private void SafelySetTime(int time)
+ {
+ // define conversion between game time and TimeSpan
+ TimeSpan ToTimeSpan(int value) => new TimeSpan(0, value / 100, value % 100, 0);
+ int FromTimeSpan(TimeSpan span) => (int)((span.Hours * 100) + span.Minutes);
+
+ // transition to new time
+ int intervals = (int)((ToTimeSpan(time) - ToTimeSpan(Game1.timeOfDay)).TotalMinutes / 10);
+ if (intervals > 0)
+ {
+ for (int i = 0; i < intervals; i++)
+ Game1.performTenMinuteClockUpdate();
+ }
+ else if (intervals < 0)
+ {
+ for (int i = 0; i > intervals; i--)
+ {
+ Game1.timeOfDay = FromTimeSpan(ToTimeSpan(Game1.timeOfDay).Subtract(TimeSpan.FromMinutes(20))); // offset 20 mins so game updates to next interval
+ Game1.performTenMinuteClockUpdate();
+ }
+ }
+ }
}
}