using System; using Omegasis.TimeFreeze.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; using StardewValley.Locations; namespace Omegasis.TimeFreeze { /// The mod entry point. public class TimeFreeze : Mod { /********* ** Properties *********/ /// The mod configuration. private ModConfig Config; /********* ** Public methods *********/ /// The mod entry point, called after the mod is first loaded. /// Provides simplified APIs for writing mods. public override void Entry(IModHelper helper) { this.Config = helper.ReadConfig(); GameEvents.UpdateTick += this.GameEvents_UpdateTick; } /********* ** Private methods *********/ /// The method invoked when the game updates (roughly 60 times per second). /// The event sender. /// The event data. private void GameEvents_UpdateTick(object sender, EventArgs e) { if (!Context.IsWorldReady) return; if (this.ShouldFreezeTime(Game1.player, Game1.player.currentLocation)) Game1.gameTimeInterval = 0; } /// Get whether time should be frozen for the player at the given location. /// The player to check. /// The location to check. private bool ShouldFreezeTime(StardewValley.Farmer player, GameLocation location) { if (location.name == "Mine" || location.name == "SkullCave" || location.name == "UndergroundMine" || location.isOutdoors) return false; if (player.swimming) { if (this.Config.PassTimeWhileSwimmingInBathhouse && location is BathHousePool) return false; if (this.Config.PassTimeWhileSwimming) return false; } return true; } } }