2016-11-04 02:25:53 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2018-06-23 15:31:40 +08:00
|
|
|
|
using Omegasis.SaveAnywhere.API;
|
2017-07-31 11:07:07 +08:00
|
|
|
|
using Omegasis.SaveAnywhere.Framework;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
using StardewModdingAPI;
|
|
|
|
|
using StardewModdingAPI.Events;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
using StardewValley;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
using StardewValley.Characters;
|
2018-06-09 02:40:23 +08:00
|
|
|
|
using StardewValley.Monsters;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
|
2017-07-28 08:28:39 +08:00
|
|
|
|
namespace Omegasis.SaveAnywhere
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
/// <summary>The mod entry point.</summary>
|
2017-07-31 05:42:15 +08:00
|
|
|
|
public class SaveAnywhere : Mod
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
/*********
|
|
|
|
|
** Properties
|
|
|
|
|
*********/
|
2017-08-06 11:20:48 +08:00
|
|
|
|
/// <summary>The mod configuration.</summary>
|
|
|
|
|
private ModConfig Config;
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
/// <summary>Provides methods for saving and loading game data.</summary>
|
2017-07-31 05:57:00 +08:00
|
|
|
|
private SaveManager SaveManager;
|
2017-07-31 10:55:58 +08:00
|
|
|
|
|
2017-08-06 11:00:37 +08:00
|
|
|
|
/// <summary>The parsed schedules by NPC name.</summary>
|
|
|
|
|
private readonly IDictionary<string, string> NpcSchedules = new Dictionary<string, string>();
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
/// <summary>Whether villager schedules should be reset now.</summary>
|
|
|
|
|
private bool ShouldResetSchedules;
|
|
|
|
|
|
2017-08-06 11:17:51 +08:00
|
|
|
|
/// <summary>Whether we're performing a non-vanilla save (i.e. not by sleeping in bed).</summary>
|
|
|
|
|
private bool IsCustomSaving;
|
2017-05-14 06:27:24 +08:00
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
|
2018-01-11 05:14:19 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to access the Mod's helper from other files associated with the mod.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static IModHelper ModHelper;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to access the Mod's monitor to allow for debug logging in other files associated with the mod.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static IMonitor ModMonitor;
|
|
|
|
|
|
2018-06-09 02:40:23 +08:00
|
|
|
|
private List<Monster> monsters;
|
|
|
|
|
|
|
|
|
|
private bool customMenuOpen;
|
|
|
|
|
|
2017-07-31 10:55:58 +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-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-08-06 11:20:48 +08:00
|
|
|
|
this.Config = helper.ReadConfig<ModConfig>();
|
2017-07-31 05:57:00 +08:00
|
|
|
|
|
2018-06-23 15:31:40 +08:00
|
|
|
|
this.SaveManager = new SaveManager(this.Helper, this.Helper.Reflection, onLoaded: () => this.ShouldResetSchedules = true);
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
|
2017-08-06 11:17:51 +08:00
|
|
|
|
SaveEvents.AfterSave += this.SaveEvents_AfterSave;
|
|
|
|
|
MenuEvents.MenuChanged += this.MenuEvents_MenuChanged;
|
2017-07-31 10:55:58 +08:00
|
|
|
|
ControlEvents.KeyPressed += this.ControlEvents_KeyPressed;
|
2017-07-31 09:58:48 +08:00
|
|
|
|
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
|
2017-08-06 03:20:46 +08:00
|
|
|
|
TimeEvents.AfterDayStarted += this.TimeEvents_AfterDayStarted;
|
2018-06-09 02:40:23 +08:00
|
|
|
|
|
2018-01-11 05:14:19 +08:00
|
|
|
|
ModHelper = helper;
|
|
|
|
|
ModMonitor = Monitor;
|
2018-06-09 02:40:23 +08:00
|
|
|
|
customMenuOpen = false;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
2017-05-14 06:27:24 +08:00
|
|
|
|
|
2018-06-23 15:31:40 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Exposes the SaveAnywhere API to other SMAPI mods
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override object GetApi()
|
|
|
|
|
{
|
|
|
|
|
SaveAnywhereAPI api = new SaveAnywhereAPI(SaveManager);
|
|
|
|
|
return api;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-07 05:01:44 +08:00
|
|
|
|
/*Notes. Mods that want to support save anywhere will get the api for Save anywhere and then add their clean up code to the events that happen for Before/After Save and Loading.
|
|
|
|
|
Example with pseudo code.
|
|
|
|
|
SaveAnywhere.api.BeforeSave+=StardustCore.Objects.CleanUpBeforeSave;
|
|
|
|
|
We then can use function wrapping (is that what it's called?) to just handle calling the actual function that deals with clean-up code.
|
2017-07-31 10:55:58 +08:00
|
|
|
|
|
2018-08-07 05:01:44 +08:00
|
|
|
|
*/
|
2017-07-31 10:55:58 +08:00
|
|
|
|
/*********
|
|
|
|
|
** Private methods
|
|
|
|
|
*********/
|
|
|
|
|
/// <summary>The method invoked after the player loads a save.</summary>
|
2017-07-31 09:58:48 +08:00
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
2017-07-31 10:55:58 +08:00
|
|
|
|
private void SaveEvents_AfterLoad(object sender, EventArgs e)
|
2017-05-14 06:27:24 +08:00
|
|
|
|
{
|
2017-08-06 11:00:37 +08:00
|
|
|
|
// reset state
|
2017-08-06 11:17:51 +08:00
|
|
|
|
this.IsCustomSaving = false;
|
2017-08-06 11:00:37 +08:00
|
|
|
|
this.ShouldResetSchedules = false;
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// load positions
|
2017-08-06 11:19:38 +08:00
|
|
|
|
this.SaveManager.LoadData();
|
2017-05-14 06:27:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-06 11:17:51 +08:00
|
|
|
|
/// <summary>The method invoked after the player finishes saving.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
|
|
|
|
private void SaveEvents_AfterSave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// clear custom data after a normal save (to avoid restoring old state)
|
2018-06-09 02:40:23 +08:00
|
|
|
|
if (!this.IsCustomSaving)
|
2017-08-06 11:17:51 +08:00
|
|
|
|
this.SaveManager.ClearData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>The method invoked after a menu is opened or changed.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
|
|
|
|
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e)
|
|
|
|
|
{
|
2017-08-06 11:38:07 +08:00
|
|
|
|
this.IsCustomSaving = e.NewMenu != null && (e.NewMenu is NewSaveGameMenu || e.NewMenu is NewShippingMenu);
|
2017-08-06 11:17:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
/// <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>
|
|
|
|
|
private void GameEvents_UpdateTick(object sender, EventArgs e)
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2018-05-19 05:24:59 +08:00
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// let save manager run background logic
|
|
|
|
|
if (Context.IsWorldReady)
|
2018-05-19 05:24:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (Game1.player.IsMainPlayer == false) return;
|
2017-07-31 10:55:58 +08:00
|
|
|
|
this.SaveManager.Update();
|
2018-05-19 05:24:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
|
|
|
|
|
// reset NPC schedules
|
|
|
|
|
if (Context.IsWorldReady && this.ShouldResetSchedules)
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
this.ShouldResetSchedules = false;
|
|
|
|
|
this.ApplySchedules();
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
2018-06-09 02:40:23 +08:00
|
|
|
|
|
|
|
|
|
if (Game1.activeClickableMenu == null && this.customMenuOpen == false) return;
|
|
|
|
|
if(Game1.activeClickableMenu==null && this.customMenuOpen == true)
|
|
|
|
|
{
|
|
|
|
|
restoreMonsters();
|
|
|
|
|
this.customMenuOpen = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (Game1.activeClickableMenu != null)
|
|
|
|
|
{
|
|
|
|
|
if (Game1.activeClickableMenu.GetType() == typeof(NewSaveGameMenu))
|
|
|
|
|
{
|
|
|
|
|
this.customMenuOpen = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves all monsters from the game world.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void cleanMonsters()
|
|
|
|
|
{
|
|
|
|
|
monsters = new List<Monster>();
|
|
|
|
|
|
|
|
|
|
foreach (var monster in Game1.player.currentLocation.characters)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (monster is Monster)
|
|
|
|
|
{
|
|
|
|
|
monsters.Add(monster as Monster);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception err)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var monster in this.monsters)
|
|
|
|
|
{
|
|
|
|
|
Game1.player.currentLocation.characters.Remove(monster);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds all saved monster back into the game world.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void restoreMonsters()
|
|
|
|
|
{
|
|
|
|
|
foreach (var monster in this.monsters)
|
|
|
|
|
{
|
|
|
|
|
Game1.player.currentLocation.characters.Add(monster);
|
|
|
|
|
}
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-06 03:20:46 +08:00
|
|
|
|
/// <summary>The method invoked after a new day starts.</summary>
|
2017-07-31 10:55:58 +08:00
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
2017-08-06 03:20:46 +08:00
|
|
|
|
private void TimeEvents_AfterDayStarted(object sender, EventArgs e)
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// reload NPC schedules
|
|
|
|
|
this.ShouldResetSchedules = true;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// update NPC schedules
|
|
|
|
|
this.NpcSchedules.Clear();
|
|
|
|
|
foreach (NPC npc in Utility.getAllCharacters())
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2018-05-01 09:21:31 +08:00
|
|
|
|
if (!this.NpcSchedules.ContainsKey(npc.Name))
|
|
|
|
|
this.NpcSchedules.Add(npc.Name, this.ParseSchedule(npc));
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
/// <summary>The method invoked when the presses a keyboard button.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
|
|
|
|
private void ControlEvents_KeyPressed(object sender, EventArgsKeyPressed e)
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-08-06 03:23:10 +08:00
|
|
|
|
if (!Context.IsPlayerFree)
|
2016-12-09 08:34:28 +08:00
|
|
|
|
return;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
|
2018-05-19 05:24:59 +08:00
|
|
|
|
|
|
|
|
|
|
2017-08-06 11:22:15 +08:00
|
|
|
|
// initiate save (if valid context)
|
2017-08-06 11:20:48 +08:00
|
|
|
|
if (e.KeyPressed.ToString() == this.Config.SaveKey)
|
2017-08-06 11:22:15 +08:00
|
|
|
|
{
|
2018-05-19 05:24:59 +08:00
|
|
|
|
if (Game1.client==null)
|
2017-08-06 11:22:15 +08:00
|
|
|
|
{
|
2018-06-09 02:40:23 +08:00
|
|
|
|
cleanMonsters();
|
2018-05-19 05:24:59 +08:00
|
|
|
|
// validate: community center Junimos can't be saved
|
|
|
|
|
|
|
|
|
|
if (Game1.player.currentLocation.getCharacters().OfType<Junimo>().Any())
|
|
|
|
|
{
|
|
|
|
|
Game1.addHUDMessage(new HUDMessage("The spirits don't want you to save here.", HUDMessage.error_type));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-08-06 11:22:15 +08:00
|
|
|
|
|
2018-05-19 05:24:59 +08:00
|
|
|
|
// save
|
|
|
|
|
this.SaveManager.BeginSaveData();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Game1.addHUDMessage(new HUDMessage("Only server hosts can save anywhere.",HUDMessage.error_type));
|
|
|
|
|
}
|
2017-08-06 11:22:15 +08:00
|
|
|
|
}
|
2017-07-31 10:55:58 +08:00
|
|
|
|
}
|
2017-07-31 05:42:15 +08:00
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
/// <summary>Apply the NPC schedules to each NPC.</summary>
|
|
|
|
|
private void ApplySchedules()
|
|
|
|
|
{
|
|
|
|
|
if (Game1.weatherIcon == Game1.weather_festival || Game1.isFestival() || Game1.eventUp)
|
|
|
|
|
return;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// apply for each NPC
|
|
|
|
|
foreach (NPC npc in Utility.getAllCharacters())
|
|
|
|
|
{
|
|
|
|
|
if (npc.DirectionsToNewLocation != null || npc.isMoving() || npc.Schedule == null || npc.controller != null || npc is Horse)
|
|
|
|
|
continue;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// get raw schedule from XNBs
|
2018-05-01 09:21:31 +08:00
|
|
|
|
IDictionary<string, string> rawSchedule = this.GetRawSchedule(npc.Name);
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (rawSchedule == null)
|
|
|
|
|
continue;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// get schedule data
|
|
|
|
|
string scheduleData;
|
2018-05-01 09:21:31 +08:00
|
|
|
|
if (!this.NpcSchedules.TryGetValue(npc.Name, out scheduleData) || string.IsNullOrEmpty(scheduleData))
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2018-06-09 02:40:23 +08:00
|
|
|
|
//this.Monitor.Log("THIS IS AWKWARD");
|
2017-07-31 10:55:58 +08:00
|
|
|
|
continue;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// get schedule script
|
|
|
|
|
string script;
|
|
|
|
|
if (!rawSchedule.TryGetValue(scheduleData, out script))
|
|
|
|
|
continue;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// parse entries
|
|
|
|
|
string[] entries = script.Split('/');
|
|
|
|
|
int index = 0;
|
|
|
|
|
foreach (string _ in entries)
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
string[] fields = entries[index].Split(' ');
|
|
|
|
|
|
|
|
|
|
// handle GOTO command
|
|
|
|
|
if (fields.Contains("GOTO"))
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
for (int i = 0; i < fields.Length; i++)
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
string s = fields[i];
|
|
|
|
|
if (s == "GOTO")
|
|
|
|
|
{
|
|
|
|
|
rawSchedule.TryGetValue(fields[i + 1], out script);
|
|
|
|
|
string[] newEntries = script.Split('/');
|
|
|
|
|
fields = newEntries[0].Split(' ');
|
|
|
|
|
}
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// parse schedule script
|
2016-11-04 02:25:53 +08:00
|
|
|
|
SchedulePathDescription schedulePathDescription;
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (Convert.ToInt32(fields[0]) > Game1.timeOfDay) break;
|
|
|
|
|
string endMap = Convert.ToString(fields[1]);
|
|
|
|
|
int x = Convert.ToInt32(fields[2]);
|
|
|
|
|
int y = Convert.ToInt32(fields[3]);
|
|
|
|
|
int endFacingDir = Convert.ToInt32(fields[4]);
|
2017-08-06 03:24:01 +08:00
|
|
|
|
|
|
|
|
|
schedulePathDescription = this.Helper.Reflection
|
2018-01-11 13:50:16 +08:00
|
|
|
|
.GetMethod(npc, "pathfindToNextScheduleLocation")
|
2018-05-01 09:21:31 +08:00
|
|
|
|
.Invoke<SchedulePathDescription>(npc.currentLocation.Name, npc.getTileX(), npc.getTileY(), endMap, x, y, endFacingDir, null, null);
|
2017-07-31 10:55:58 +08:00
|
|
|
|
index++;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2018-05-01 09:21:31 +08:00
|
|
|
|
ex.ToString();
|
2017-08-04 09:05:48 +08:00
|
|
|
|
//this.Monitor.Log($"Error pathfinding NPC {npc.name}: {ex}", LogLevel.Error);
|
2016-11-04 02:25:53 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
npc.DirectionsToNewLocation = schedulePathDescription;
|
|
|
|
|
npc.controller = new PathFindController(npc.DirectionsToNewLocation.route, npc, Utility.getGameLocationOfCharacter(npc))
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
finalFacingDirection = npc.DirectionsToNewLocation.facingDirection,
|
|
|
|
|
endBehaviorFunction = null
|
|
|
|
|
};
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
2017-07-31 10:55:58 +08:00
|
|
|
|
}
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
/// <summary>Get an NPC's raw schedule data from the XNB files.</summary>
|
|
|
|
|
/// <param name="npcName">The NPC name whose schedules to read.</param>
|
|
|
|
|
/// <returns>Returns the NPC schedule if found, else <c>null</c>.</returns>
|
|
|
|
|
private IDictionary<string, string> GetRawSchedule(string npcName)
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
return Game1.content.Load<Dictionary<string, string>>($"Characters\\schedules\\{npcName}");
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
2017-07-31 10:55:58 +08:00
|
|
|
|
catch (Exception)
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
/// <summary>Load the raw schedule data for an NPC.</summary>
|
|
|
|
|
/// <param name="npc">The NPC whose schedule to read.</param>
|
|
|
|
|
private string ParseSchedule(NPC npc)
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// set flags
|
2018-05-01 09:21:31 +08:00
|
|
|
|
if (npc.Name.Equals("Robin") || Game1.player.currentUpgrade != null)
|
|
|
|
|
npc.IsInvisible = false;
|
|
|
|
|
if (npc.Name.Equals("Willy") && Game1.stats.DaysPlayed < 2u)
|
|
|
|
|
npc.IsInvisible = true;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
else if (npc.Schedule != null)
|
|
|
|
|
npc.followSchedule = true;
|
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// read schedule data
|
2018-05-01 09:21:31 +08:00
|
|
|
|
IDictionary<string, string> schedule = this.GetRawSchedule(npc.Name);
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (schedule == null)
|
2016-11-04 02:25:53 +08:00
|
|
|
|
return "";
|
2017-07-31 05:42:15 +08:00
|
|
|
|
|
2017-07-31 10:55:58 +08:00
|
|
|
|
// do stuff
|
2016-11-04 02:25:53 +08:00
|
|
|
|
if (npc.isMarried())
|
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
string dayName = Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth);
|
2018-05-01 09:21:31 +08:00
|
|
|
|
if ((npc.Name.Equals("Penny") && (dayName.Equals("Tue") || dayName.Equals("Wed") || dayName.Equals("Fri"))) || (npc.Name.Equals("Maru") && (dayName.Equals("Tue") || dayName.Equals("Thu"))) || (npc.Name.Equals("Harvey") && (dayName.Equals("Tue") || dayName.Equals("Thu"))))
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-08-06 03:24:01 +08:00
|
|
|
|
this.Helper.Reflection
|
2018-01-11 13:50:16 +08:00
|
|
|
|
.GetField<string>(npc, "nameofTodaysSchedule")
|
2017-08-06 03:24:01 +08:00
|
|
|
|
.SetValue("marriageJob");
|
2017-07-31 10:55:58 +08:00
|
|
|
|
return "marriageJob";
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (!Game1.isRaining && schedule.ContainsKey("marriage_" + Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth)))
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-08-06 03:24:01 +08:00
|
|
|
|
this.Helper.Reflection
|
2018-01-11 13:50:16 +08:00
|
|
|
|
.GetField<string>(npc, "nameofTodaysSchedule")
|
2017-08-06 03:24:01 +08:00
|
|
|
|
.SetValue("marriage_" + Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth));
|
2017-07-31 10:55:58 +08:00
|
|
|
|
return "marriage_" + Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth);
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
|
|
|
|
npc.followSchedule = false;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (schedule.ContainsKey(Game1.currentSeason + "_" + Game1.dayOfMonth))
|
|
|
|
|
return Game1.currentSeason + "_" + Game1.dayOfMonth;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
int i;
|
2018-05-01 09:21:31 +08:00
|
|
|
|
Friendship f;
|
|
|
|
|
Game1.player.friendshipData.TryGetValue(npc.Name, out f);
|
|
|
|
|
for (i = (Game1.player.friendshipData.ContainsKey(npc.Name) ? (f.Points/ 250) : -1); i > 0; i--)
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (schedule.ContainsKey(Game1.dayOfMonth + "_" + i))
|
|
|
|
|
return Game1.dayOfMonth + "_" + i;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (schedule.ContainsKey(string.Empty + Game1.dayOfMonth))
|
|
|
|
|
return string.Empty + Game1.dayOfMonth;
|
2018-05-01 09:21:31 +08:00
|
|
|
|
if (npc.Name.Equals("Pam") && Game1.player.mailReceived.Contains("ccVault"))
|
2017-07-31 10:55:58 +08:00
|
|
|
|
return "bus";
|
2016-11-04 02:25:53 +08:00
|
|
|
|
if (Game1.isRaining)
|
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (Game1.random.NextDouble() < 0.5 && schedule.ContainsKey("rain2"))
|
|
|
|
|
return "rain2";
|
|
|
|
|
if (schedule.ContainsKey("rain"))
|
|
|
|
|
return "rain";
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
2017-07-31 10:55:58 +08:00
|
|
|
|
List<string> list = new List<string> { Game1.currentSeason, Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth) };
|
2018-05-01 09:21:31 +08:00
|
|
|
|
Friendship friendship;
|
|
|
|
|
Game1.player.friendshipData.TryGetValue(npc.Name, out friendship);
|
|
|
|
|
i = (Game1.player.friendshipData.ContainsKey(npc.Name) ? (friendship.Points / 250) : -1);
|
2016-11-04 02:25:53 +08:00
|
|
|
|
while (i > 0)
|
|
|
|
|
{
|
|
|
|
|
list.Add(string.Empty + i);
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (schedule.ContainsKey(string.Join("_", list)))
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
return string.Join("_", list);
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
|
|
|
|
i--;
|
|
|
|
|
list.RemoveAt(list.Count - 1);
|
|
|
|
|
}
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (schedule.ContainsKey(string.Join("_", list)))
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
return string.Join("_", list);
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (schedule.ContainsKey(Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth)))
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
return Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth);
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (schedule.ContainsKey(Game1.currentSeason))
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
return Game1.currentSeason;
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (schedule.ContainsKey("spring_" + Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth)))
|
2016-11-04 02:25:53 +08:00
|
|
|
|
{
|
2017-07-31 10:55:58 +08:00
|
|
|
|
return "spring_" + Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth);
|
2016-11-04 02:25:53 +08:00
|
|
|
|
}
|
|
|
|
|
list.RemoveAt(list.Count - 1);
|
|
|
|
|
list.Add("spring");
|
2018-05-01 09:21:31 +08:00
|
|
|
|
Friendship friendship2;
|
|
|
|
|
Game1.player.friendshipData.TryGetValue(npc.Name, out friendship2);
|
|
|
|
|
i = (Game1.player.friendshipData.ContainsKey(npc.Name) ? (friendship2.Points / 250) : -1);
|
2016-11-04 02:25:53 +08:00
|
|
|
|
while (i > 0)
|
|
|
|
|
{
|
|
|
|
|
list.Add(string.Empty + i);
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (schedule.ContainsKey(string.Join("_", list)))
|
|
|
|
|
return string.Join("_", list);
|
2016-11-04 02:25:53 +08:00
|
|
|
|
i--;
|
|
|
|
|
list.RemoveAt(list.Count - 1);
|
|
|
|
|
}
|
2017-07-31 10:55:58 +08:00
|
|
|
|
if (schedule.ContainsKey("spring"))
|
|
|
|
|
return "spring";
|
2016-11-04 02:25:53 +08:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|