2017-03-03 10:15:07 +08:00
|
|
|
|
using System;
|
2017-08-06 03:51:44 +08:00
|
|
|
|
using Omegasis.TimeFreeze.Framework;
|
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
|
|
|
|
|
*********/
|
2017-08-06 03:51:44 +08:00
|
|
|
|
/// <summary>The mod configuration.</summary>
|
|
|
|
|
private ModConfig Config;
|
2017-07-30 10:55:10 +08:00
|
|
|
|
|
2018-08-08 16:39:13 +08:00
|
|
|
|
public int oldInterval;
|
|
|
|
|
|
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-08-06 03:51:44 +08:00
|
|
|
|
this.Config = helper.ReadConfig<ModConfig>();
|
|
|
|
|
|
2017-07-30 10:55:10 +08:00
|
|
|
|
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
|
2018-08-09 00:18:05 +08:00
|
|
|
|
//oldInterval = 7;
|
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
|
|
|
|
|
2018-08-09 00:18:05 +08:00
|
|
|
|
/*
|
2018-08-08 16:39:13 +08:00
|
|
|
|
if (Game1.gameTimeInterval != 0)
|
|
|
|
|
{
|
|
|
|
|
oldInterval = Game1.gameTimeInterval;
|
2018-08-09 00:18:05 +08:00
|
|
|
|
if (oldInterval < 3)
|
|
|
|
|
{
|
|
|
|
|
oldInterval = 7;
|
|
|
|
|
}
|
2018-08-08 16:39:13 +08:00
|
|
|
|
}
|
2018-08-09 00:18:05 +08:00
|
|
|
|
*/
|
2018-08-08 16:39:13 +08:00
|
|
|
|
if (Game1.IsMultiplayer)
|
|
|
|
|
{
|
|
|
|
|
if (Config.freezeIfEvenOnePlayerMeetsTimeFreezeConditions)
|
|
|
|
|
{
|
|
|
|
|
bool isAnyFarmerSuitable = false;
|
2018-08-09 00:18:05 +08:00
|
|
|
|
foreach (Farmer farmer in Game1.getOnlineFarmers())
|
2018-08-08 16:39:13 +08:00
|
|
|
|
{
|
|
|
|
|
if (this.ShouldFreezeTime(farmer, farmer.currentLocation))
|
|
|
|
|
{
|
|
|
|
|
Game1.gameTimeInterval = 0;
|
|
|
|
|
isAnyFarmerSuitable = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isAnyFarmerSuitable == false)
|
|
|
|
|
{
|
2018-08-09 00:18:05 +08:00
|
|
|
|
// Game1.gameTimeInterval += Game1.currentGameTime.ElapsedGameTime.Milliseconds;
|
2018-08-08 16:39:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (Config.freezeIfMajorityPlayersMeetsTimeFreezeConditions)
|
|
|
|
|
{
|
|
|
|
|
int freezeCount = 0;
|
|
|
|
|
int playerCount = 0;
|
2018-08-09 00:18:05 +08:00
|
|
|
|
foreach (Farmer farmer in Game1.getOnlineFarmers())
|
2018-08-08 16:39:13 +08:00
|
|
|
|
{
|
|
|
|
|
playerCount++;
|
|
|
|
|
if (this.ShouldFreezeTime(farmer, farmer.currentLocation))
|
|
|
|
|
{
|
|
|
|
|
//Game1.gameTimeInterval = 0;
|
|
|
|
|
freezeCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (freezeCount >= (playerCount / 2))
|
|
|
|
|
{
|
|
|
|
|
Game1.gameTimeInterval = 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-08-09 00:18:05 +08:00
|
|
|
|
// Game1.gameTimeInterval += Game1.currentGameTime.ElapsedGameTime.Milliseconds;
|
2018-08-08 16:39:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (Config.freezeIfAllPlayersMeetTimeFreezeConditions)
|
|
|
|
|
{
|
|
|
|
|
int freezeCount = 0;
|
|
|
|
|
int playerCount = 0;
|
2018-08-09 00:18:05 +08:00
|
|
|
|
foreach (Farmer farmer in Game1.getOnlineFarmers())
|
2018-08-08 16:39:13 +08:00
|
|
|
|
{
|
|
|
|
|
playerCount++;
|
|
|
|
|
if (this.ShouldFreezeTime(farmer, farmer.currentLocation))
|
|
|
|
|
{
|
|
|
|
|
//Game1.gameTimeInterval = 0;
|
|
|
|
|
freezeCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (freezeCount >= playerCount)
|
|
|
|
|
{
|
|
|
|
|
Game1.gameTimeInterval = 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-08-09 00:18:05 +08:00
|
|
|
|
// Game1.gameTimeInterval = oldInterval;
|
2018-08-08 16:39:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Farmer player = Game1.player;
|
|
|
|
|
if (this.ShouldFreezeTime(player, player.currentLocation))
|
|
|
|
|
{
|
|
|
|
|
Game1.gameTimeInterval = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-08-09 00:18:05 +08:00
|
|
|
|
// Game1.gameTimeInterval = oldInterval;
|
2018-08-08 16:39:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-30 10:55:10 +08:00
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
2018-08-08 16:39:13 +08:00
|
|
|
|
|
2018-08-14 03:41:11 +08:00
|
|
|
|
if (Config.PassTimeWhileInsideMine==true)
|
2018-08-08 16:39:13 +08:00
|
|
|
|
{
|
|
|
|
|
if(location.Name == "Mine" || location.Name.StartsWith("UndergroundMine"))
|
|
|
|
|
{
|
2018-08-14 03:41:11 +08:00
|
|
|
|
return false;
|
2018-08-08 16:39:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-14 03:41:11 +08:00
|
|
|
|
if (Config.PassTimeWhileInsideSkullCave==true)
|
2018-08-08 16:39:13 +08:00
|
|
|
|
{
|
|
|
|
|
if (location.Name == "SkullCave" || location.Name.StartsWith("SkullCave"))
|
|
|
|
|
{
|
2018-08-14 03:41:11 +08:00
|
|
|
|
return false;
|
2018-08-08 16:39:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-14 03:41:11 +08:00
|
|
|
|
if (location.IsOutdoors == true)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-08 16:39:13 +08:00
|
|
|
|
|
2018-05-01 09:21:31 +08:00
|
|
|
|
if (player.swimming.Value)
|
2017-03-03 10:15:07 +08:00
|
|
|
|
{
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (this.Config.PassTimeWhileSwimmingInBathhouse && location is BathHousePool)
|
2017-07-30 10:55:10 +08:00
|
|
|
|
return false;
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (this.Config.PassTimeWhileSwimming)
|
2017-07-30 10:55:10 +08:00
|
|
|
|
return false;
|
2017-03-03 10:15:07 +08:00
|
|
|
|
}
|
2018-08-14 03:41:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
2017-03-03 10:15:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|