2017-03-03 10:15:07 +08:00
|
|
|
|
using System;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
using System.IO;
|
2017-03-03 10:15:07 +08:00
|
|
|
|
using StardewModdingAPI;
|
2017-07-30 10:55:10 +08:00
|
|
|
|
using StardewModdingAPI.Events;
|
2017-03-03 10:15:07 +08:00
|
|
|
|
using StardewValley;
|
2017-07-30 10:55:10 +08:00
|
|
|
|
using StardewValley.Locations;
|
2017-03-03 10:15:07 +08:00
|
|
|
|
|
2017-07-28 08:28:39 +08:00
|
|
|
|
namespace Omegasis.TimeFreeze
|
2017-03-03 10:15:07 +08:00
|
|
|
|
{
|
2017-07-30 10:55:10 +08:00
|
|
|
|
/// <summary>The mod entry point.</summary>
|
|
|
|
|
public class TimeFreeze : Mod
|
2017-03-03 10:15:07 +08:00
|
|
|
|
{
|
2017-07-30 10:55:10 +08:00
|
|
|
|
/*********
|
|
|
|
|
** Properties
|
|
|
|
|
*********/
|
|
|
|
|
/// <summary>Whether time should be unfrozen while the player is swimming.</summary>
|
|
|
|
|
private bool PassTimeWhileSwimming = true;
|
|
|
|
|
|
|
|
|
|
/// <summary>Whether time should be unfrozen while the player is swimming in the vanilla bathhouse.</summary>
|
|
|
|
|
private bool PassTimeWhileSwimmingInBathhouse = true;
|
|
|
|
|
|
2017-03-03 10:15:07 +08:00
|
|
|
|
|
2017-07-30 10:55:10 +08:00
|
|
|
|
/*********
|
|
|
|
|
** Public methods
|
|
|
|
|
*********/
|
|
|
|
|
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
|
|
|
|
|
/// <param name="helper">Provides simplified APIs for writing mods.</param>
|
|
|
|
|
public override void Entry(IModHelper helper)
|
2017-05-14 06:27:24 +08:00
|
|
|
|
{
|
2017-07-30 10:55:10 +08:00
|
|
|
|
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
|
|
|
|
|
this.LoadConfig();
|
2017-05-14 06:27:24 +08:00
|
|
|
|
}
|
2017-03-03 10:15:07 +08:00
|
|
|
|
|
2017-07-30 10:55:10 +08:00
|
|
|
|
/*********
|
|
|
|
|
** Private methods
|
|
|
|
|
*********/
|
|
|
|
|
/// <summary>The method invoked when the game updates (roughly 60 times per second).</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
2017-03-03 10:15:07 +08:00
|
|
|
|
private void GameEvents_UpdateTick(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-08-06 03:23:10 +08:00
|
|
|
|
if (!Context.IsWorldReady)
|
2017-07-30 10:55:10 +08:00
|
|
|
|
return;
|
2017-03-03 10:15:07 +08:00
|
|
|
|
|
2017-07-30 10:55:10 +08:00
|
|
|
|
if (this.ShouldFreezeTime(Game1.player, Game1.player.currentLocation))
|
|
|
|
|
Game1.gameTimeInterval = 0;
|
|
|
|
|
}
|
2017-03-03 10:15:07 +08:00
|
|
|
|
|
2017-07-30 10:55:10 +08:00
|
|
|
|
/// <summary>Get whether time should be frozen for the player at the given location.</summary>
|
|
|
|
|
/// <param name="player">The player to check.</param>
|
|
|
|
|
/// <param name="location">The location to check.</param>
|
|
|
|
|
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)
|
2017-03-03 10:15:07 +08:00
|
|
|
|
{
|
2017-07-30 10:55:10 +08:00
|
|
|
|
if (this.PassTimeWhileSwimmingInBathhouse && location is BathHousePool)
|
|
|
|
|
return false;
|
|
|
|
|
if (this.PassTimeWhileSwimming)
|
|
|
|
|
return false;
|
2017-03-03 10:15:07 +08:00
|
|
|
|
}
|
2017-07-30 10:55:10 +08:00
|
|
|
|
return true;
|
2017-03-03 10:15:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 10:55:10 +08:00
|
|
|
|
/// <summary>Save the configuration settings.</summary>
|
|
|
|
|
private void WriteConfig()
|
2017-05-14 06:27:24 +08:00
|
|
|
|
{
|
2017-07-30 10:55:10 +08:00
|
|
|
|
string path = Path.Combine(Helper.DirectoryPath, "ModConfig.txt");
|
|
|
|
|
string[] text = new string[6];
|
|
|
|
|
text[0] = "Player: TimeFreeze Config";
|
|
|
|
|
text[1] = "====================================================================================";
|
|
|
|
|
text[2] = "Whether to unfreeze time while swimming in the vanilla bathhouse.";
|
|
|
|
|
text[3] = this.PassTimeWhileSwimmingInBathhouse.ToString();
|
|
|
|
|
text[4] = "Whether to unfreeze time while swimming anywhere.";
|
|
|
|
|
text[5] = this.PassTimeWhileSwimming.ToString();
|
|
|
|
|
File.WriteAllLines(path, text);
|
2017-05-14 06:27:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 10:55:10 +08:00
|
|
|
|
/// <summary>Load the configuration settings.</summary>
|
|
|
|
|
private void LoadConfig()
|
2017-03-03 10:15:07 +08:00
|
|
|
|
{
|
2017-07-30 10:55:10 +08:00
|
|
|
|
string path = Path.Combine(Helper.DirectoryPath, "ModConfig.txt");
|
|
|
|
|
if (!File.Exists(path))
|
2017-03-03 10:15:07 +08:00
|
|
|
|
{
|
2017-07-30 10:55:10 +08:00
|
|
|
|
this.PassTimeWhileSwimming = true;
|
|
|
|
|
this.PassTimeWhileSwimmingInBathhouse = true;
|
|
|
|
|
this.WriteConfig();
|
2017-03-03 10:15:07 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-30 10:55:10 +08:00
|
|
|
|
string[] text = File.ReadAllLines(path);
|
|
|
|
|
this.PassTimeWhileSwimming = Convert.ToBoolean(text[3]);
|
|
|
|
|
this.PassTimeWhileSwimmingInBathhouse = Convert.ToBoolean(text[5]);
|
2017-03-03 10:15:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|