2016-10-21 15:52:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2017-07-30 07:59:16 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.Xna.Framework;
|
2017-08-06 03:51:44 +08:00
|
|
|
|
using Omegasis.NightOwl.Framework;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
using StardewModdingAPI;
|
2017-07-30 07:59:16 +08:00
|
|
|
|
using StardewModdingAPI.Events;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
using StardewValley;
|
|
|
|
|
|
2016-10-21 15:52:22 +08:00
|
|
|
|
/*TODO:
|
|
|
|
|
Issues:
|
|
|
|
|
-Mail can't be wiped without destroying all mail.
|
|
|
|
|
-Lighting transition does not work if it is raining.
|
2017-05-14 06:27:24 +08:00
|
|
|
|
-set the weather to clear if you are stayig up late.
|
2016-10-21 15:52:22 +08:00
|
|
|
|
-transition still doesnt work. However atleast it is dark now.
|
|
|
|
|
|
|
|
|
|
-Known glitched
|
|
|
|
|
*/
|
2017-07-28 08:28:39 +08:00
|
|
|
|
namespace Omegasis.NightOwl
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
/// <summary>The mod entry point.</summary>
|
2017-07-31 11:07:07 +08:00
|
|
|
|
public class NightOwl : Mod
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
/*********
|
|
|
|
|
** Properties
|
|
|
|
|
*********/
|
2017-08-06 03:51:44 +08:00
|
|
|
|
/// <summary>The mod configuration.</summary>
|
|
|
|
|
private ModConfig Config;
|
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
/****
|
|
|
|
|
** Context
|
|
|
|
|
****/
|
|
|
|
|
/// <summary>Whether the player stayed up all night.</summary>
|
|
|
|
|
private bool IsUpLate;
|
|
|
|
|
|
|
|
|
|
/// <summary>Whether the player should be reset to their pre-collapse details for the morning transition on the next update.</summary>
|
|
|
|
|
private bool ShouldResetPlayerAfterCollapseNow;
|
|
|
|
|
|
|
|
|
|
/// <summary>Whether the player just started a new day.</summary>
|
|
|
|
|
private bool JustStartedNewDay;
|
|
|
|
|
|
|
|
|
|
/// <summary>Whether the player just collapsed for the morning transition.</summary>
|
|
|
|
|
private bool JustCollapsed;
|
|
|
|
|
|
|
|
|
|
/****
|
|
|
|
|
** Pre-collapse state
|
|
|
|
|
****/
|
|
|
|
|
/// <summary>The player's location name before they collapsed.</summary>
|
|
|
|
|
private string PreCollapseMap;
|
|
|
|
|
|
|
|
|
|
/// <summary>The player's tile position before they collapsed.</summary>
|
|
|
|
|
private Point PreCollapseTile;
|
2016-10-21 15:52:22 +08:00
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
/// <summary>The player's money before they collapsed.</summary>
|
|
|
|
|
private int PreCollapseMoney;
|
2016-10-21 15:52:22 +08:00
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
/// <summary>The player's stamina before they collapsed.</summary>
|
|
|
|
|
private float PreCollapseStamina;
|
2016-10-21 15:52:22 +08:00
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
/// <summary>The player's health before they collapsed.</summary>
|
|
|
|
|
private int PreCollapseHealth;
|
2016-10-21 15:52:22 +08:00
|
|
|
|
|
2017-07-30 07:59:16 +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>
|
2016-12-09 08:34:28 +08:00
|
|
|
|
public override void Entry(IModHelper helper)
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-08-06 03:51:44 +08:00
|
|
|
|
this.Config = helper.ReadConfig<ModConfig>();
|
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
TimeEvents.TimeOfDayChanged += this.TimeEvents_TimeOfDayChanged;
|
2017-08-06 03:20:46 +08:00
|
|
|
|
TimeEvents.AfterDayStarted += this.TimeEvents_AfterDayStarted;
|
2017-07-30 07:59:16 +08:00
|
|
|
|
SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
|
|
|
|
|
GameEvents.FourthUpdateTick += this.GameEvents_FourthUpdateTick;
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-14 06:27:24 +08:00
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
/*********
|
|
|
|
|
** Private methods
|
|
|
|
|
*********/
|
|
|
|
|
/// <summary>The method invoked every fourth game update (roughly 15 times per second).</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
2016-10-21 15:52:22 +08:00
|
|
|
|
public void GameEvents_FourthUpdateTick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
// reset position after collapse
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (Context.IsWorldReady && this.JustStartedNewDay && this.Config.KeepPositionAfterCollapse)
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
if (this.PreCollapseMap != null)
|
|
|
|
|
Game1.warpFarmer(this.PreCollapseMap, this.PreCollapseTile.X, this.PreCollapseTile.Y, false);
|
2016-10-21 15:52:22 +08:00
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
this.PreCollapseMap = null;
|
|
|
|
|
this.JustStartedNewDay = false;
|
|
|
|
|
this.JustCollapsed = false;
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
this.Monitor.Log(ex.ToString(), LogLevel.Error);
|
|
|
|
|
this.WriteErrorLog();
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
/// <summary>The method invoked after the player loads a save.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
|
|
|
|
public void SaveEvents_AfterLoad(object sender, EventArgs e)
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
this.IsUpLate = false;
|
|
|
|
|
this.JustStartedNewDay = false;
|
|
|
|
|
this.JustCollapsed = false;
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-06 03:20:46 +08:00
|
|
|
|
/// <summary>The method invoked when a new day starts.</summary>
|
2017-07-30 07:59:16 +08:00
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
2017-08-06 03:20:46 +08:00
|
|
|
|
public void TimeEvents_AfterDayStarted(object sender, EventArgs e)
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
try
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
// reset data
|
|
|
|
|
this.IsUpLate = false;
|
|
|
|
|
Game1.farmerShouldPassOut = false;
|
|
|
|
|
|
|
|
|
|
// transition to the next day
|
|
|
|
|
if (this.ShouldResetPlayerAfterCollapseNow)
|
|
|
|
|
{
|
|
|
|
|
this.ShouldResetPlayerAfterCollapseNow = false;
|
|
|
|
|
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (this.Config.KeepStaminaAfterCollapse)
|
2017-07-30 07:59:16 +08:00
|
|
|
|
Game1.player.stamina = this.PreCollapseStamina;
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (this.Config.KeepHealthAfterCollapse)
|
2017-07-30 07:59:16 +08:00
|
|
|
|
Game1.player.health = this.PreCollapseHealth;
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (this.Config.KeepMoneyAfterCollapse)
|
2017-07-30 07:59:16 +08:00
|
|
|
|
Game1.player.money = this.PreCollapseMoney;
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (this.Config.KeepPositionAfterCollapse)
|
2017-07-30 07:59:16 +08:00
|
|
|
|
Game1.warpFarmer(this.PreCollapseMap, this.PreCollapseTile.X, this.PreCollapseTile.Y, false);
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
2017-07-30 07:59:16 +08:00
|
|
|
|
|
|
|
|
|
// delete annoying charge messages (if only I could do this with mail IRL)
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (this.Config.SkipCollapseMail)
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
string[] validMail = Game1.mailbox
|
|
|
|
|
.Where(p => !p.Contains("passedOut"))
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
Game1.mailbox.Clear();
|
|
|
|
|
foreach (string mail in validMail)
|
|
|
|
|
Game1.mailbox.Enqueue(mail);
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
2017-07-30 07:59:16 +08:00
|
|
|
|
|
|
|
|
|
this.JustStartedNewDay = true;
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
this.Monitor.Log(ex.ToString(), LogLevel.Error);
|
|
|
|
|
this.WriteErrorLog();
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
/// <summary>The method invoked when <see cref="Game1.timeOfDay"/> changes.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
|
|
|
|
private void TimeEvents_TimeOfDayChanged(object sender, EventArgsIntChanged e)
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-08-06 03:23:10 +08:00
|
|
|
|
if (!Context.IsWorldReady)
|
2017-07-30 07:59:16 +08:00
|
|
|
|
return;
|
2016-10-21 15:52:22 +08:00
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
try
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
// transition morning light more realistically
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (this.Config.MorningLightTransition && Game1.timeOfDay > 400 && Game1.timeOfDay < 600)
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
float colorMod = (1300 - Game1.timeOfDay) / 1000f;
|
|
|
|
|
Game1.outdoorLight = Game1.ambientLight * colorMod;
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
// transition to next morning
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (this.Config.StayUp && Game1.timeOfDay == 2550)
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
Game1.isRaining = false; // remove rain, otherwise lighting gets screwy
|
|
|
|
|
Game1.updateWeatherIcon();
|
|
|
|
|
Game1.timeOfDay = 150; //change it from 1:50 am late, to 1:50 am early
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
// collapse player at 6am to save & reset
|
|
|
|
|
if (Game1.timeOfDay == 550)
|
|
|
|
|
this.IsUpLate = true;
|
|
|
|
|
if (this.IsUpLate && Game1.timeOfDay == 600 && !this.JustCollapsed)
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
this.JustCollapsed = true;
|
|
|
|
|
|
|
|
|
|
this.ShouldResetPlayerAfterCollapseNow = true;
|
|
|
|
|
this.PreCollapseTile = new Point(Game1.player.getTileX(), Game1.player.getTileY());
|
|
|
|
|
this.PreCollapseMap = Game1.player.currentLocation.name;
|
|
|
|
|
this.PreCollapseStamina = Game1.player.stamina;
|
|
|
|
|
this.PreCollapseHealth = Game1.player.health;
|
|
|
|
|
this.PreCollapseMoney = Game1.player.money;
|
|
|
|
|
|
|
|
|
|
if (Game1.currentMinigame != null)
|
|
|
|
|
Game1.currentMinigame = null;
|
|
|
|
|
Game1.farmerShouldPassOut = true;
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2017-07-30 07:59:16 +08:00
|
|
|
|
this.Monitor.Log(ex.ToString(), LogLevel.Error);
|
|
|
|
|
this.WriteErrorLog();
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 07:59:16 +08:00
|
|
|
|
/// <summary>Write the current mod state to the error log file.</summary>
|
|
|
|
|
private void WriteErrorLog()
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-08-06 03:51:44 +08:00
|
|
|
|
var state = new
|
2016-10-21 15:52:22 +08:00
|
|
|
|
{
|
2017-08-06 03:51:44 +08:00
|
|
|
|
this.Config,
|
|
|
|
|
this.IsUpLate,
|
|
|
|
|
this.ShouldResetPlayerAfterCollapseNow,
|
|
|
|
|
this.JustStartedNewDay,
|
|
|
|
|
this.JustCollapsed,
|
|
|
|
|
this.PreCollapseMap,
|
|
|
|
|
this.PreCollapseTile,
|
|
|
|
|
this.PreCollapseMoney,
|
|
|
|
|
this.PreCollapseStamina,
|
|
|
|
|
this.PreCollapseHealth
|
|
|
|
|
};
|
|
|
|
|
string path = Path.Combine(this.Helper.DirectoryPath, "Error_Logs", "Mod_State.json");
|
|
|
|
|
this.Helper.WriteJsonFile(path, state);
|
2016-10-21 15:52:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|