unify SaveAnywhere's save utilities

This commit is contained in:
Jesse Plamondon-Willard 2017-07-30 17:42:15 -04:00
parent d99a45144e
commit 5a7bac7ea5
11 changed files with 894 additions and 938 deletions

View File

@ -1,33 +0,0 @@
using System.IO;
namespace Omegasis.SaveAnywhere
{
class Animal_Utilities
{
public static void save_animal_info()
{
Mod_Core.animal_path = Path.Combine(Mod_Core.player_path, "Animals");
if (!Directory.Exists(Mod_Core.animal_path))
{
Directory.CreateDirectory(Mod_Core.animal_path);
}
Horse_Utility.Save_Horse_Info();
Pet_Utilities.save_pet_info();
}
public static void load_animal_info()
{
Mod_Core.animal_path = Path.Combine(Mod_Core.player_path, "Animals");
if (!Directory.Exists(Mod_Core.animal_path))
{
Directory.CreateDirectory(Mod_Core.animal_path);
}
Horse_Utility.Load_Horse_Info();
Pet_Utilities.Load_pet_Info();
}
}
}

View File

@ -11,7 +11,7 @@ namespace Omegasis.SaveAnywhere
{
//loads the data to the variables upon loading the game.
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(Mod_Core.mod_path, "Save_Anywhere_Config");
string mylocation = Path.Combine(SaveAnywhere.mod_path, "Save_Anywhere_Config");
string mylocation2 = mylocation;
string mylocation3 = mylocation2 + ".txt";
if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
@ -33,7 +33,7 @@ namespace Omegasis.SaveAnywhere
//write all of my info to a text file.
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(Mod_Core.mod_path, "Save_Anywhere_Config");
string mylocation = Path.Combine(SaveAnywhere.mod_path, "Save_Anywhere_Config");
string mylocation2 = mylocation;
string mylocation3 = mylocation2 + ".txt";

View File

@ -1,89 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using StardewModdingAPI;
using StardewValley;
namespace Omegasis.SaveAnywhere
{
public class GameUtilities
{
public static bool passiveSave;
public static bool should_ship;
public static void save_game()
{
/*
if (Game1.player.currentLocation.name == "Sewer")
{
Log.Error("There is an issue saving in the Sewer. Blame the animals for not being saved to the player's save file.");
Log.Error("Your data has not been saved. Sorry for the issue.");
return;
}
*/
//if a player has shipped an item, run this code.
if (Enumerable.Count<Item>((IEnumerable<Item>)Game1.getFarm().shippingBin) > 0)
{
should_ship = true;
// Game1.endOfNightMenus.Push((IClickableMenu)new ShippingMenu(Game1.getFarm().shippingBin));
// Game1.showEndOfNightStuff(); //shows the nightly shipping menu.
// Game1.getFarm().shippingBin.Clear(); //clears out the shipping bin to prevent exploits
}
try
{
shipping_check();
// Game1.activeClickableMenu = new StardewValley.Menus.SaveGameMenu();
}
catch(Exception rrr)
{
Game1.showRedMessage("Can't save here. See log for error.");
Mod_Core.thisMonitor.Log(rrr.ToString(), LogLevel.Error);
}
// Game1.activeClickableMenu = new StardewValley.Menus.SaveGameMenu(); //This command is what allows the player to save anywhere as it calls the saving function.
Player_Utilities.save_player_info();
Animal_Utilities.save_animal_info();
NPC_Utilities.Save_NPC_Info();
//grab the player's info
// player_map_name = StardewValley.Game1.player.currentLocation.name;
// player_tile_x = StardewValley.Game1.player.getTileX();
// player_tile_Y = StardewValley.Game1.player.getTileY();
// player_flop = false;
// MyWritter_Player(); //write my info to a text file
// MyWritter_Horse();
// DataLoader_Settings(); //load settings. Prevents acidental overwrite.
// MyWritter_Settings(); //save settings.
//Game1.warpFarmer(player_map_name, player_tile_x, player_tile_Y, player_flop); //refresh the player's location just incase. That will prove that they character's info was valid.
//so this is essentially the basics of the code...
// Log.Error("IS THIS BREAKING?");
}
public static void shipping_check()
{
if (Game1.activeClickableMenu != null) return;
if (should_ship == true)
{
Game1.activeClickableMenu = new New_Shipping_Menu(Game1.getFarm().shippingBin);
should_ship = false;
Game1.getFarm().shippingBin.Clear();
Game1.getFarm().lastItemShipped = null;
passiveSave = true;
}
else
{
Game1.activeClickableMenu = new StardewValley.Menus.SaveGameMenu();
}
}
}
}

View File

@ -1,118 +0,0 @@
using System;
using System.IO;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Characters;
namespace Omegasis.SaveAnywhere
{
class Horse_Utility
{
public static void Save_Horse_Info()
{
Horse horse = Utility.findHorse();
if (horse == null)
{
//Game1.getFarm().characters.Add((NPC)new Horse(this.player_tile_x + 1, this.player_tile_Y + 1));
Mod_Core.thisMonitor.Log("NEIGH: No horse exists", LogLevel.Debug);
return;
}
// else
// Game1.warpCharacter((NPC)horse, Game1.player.currentLocation.name, StardewValley.Game1.player.getTileLocationPoint(), false, true);
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(Mod_Core.animal_path, "Horse_Save_Info_");
string mylocation2 = mylocation + myname;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
Mod_Core.thisMonitor.Log("The horse save info doesn't exist. It will be created when the custom saving method is run. Which is now.", LogLevel.Debug);
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Horse: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Horse Current Map Name";
mystring3[3] = horse.currentLocation.name.ToString();
mystring3[4] = "Horse X Position";
mystring3[5] = horse.getTileX().ToString();
mystring3[6] = "Horse Y Position";
mystring3[7] = horse.getTileY().ToString();
File.WriteAllLines(mylocation3, mystring3);
}
else
{
// Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now.");
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Horse: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Horse Current Map Name";
mystring3[3] = horse.currentLocation.name.ToString();
mystring3[4] = "Horse X Position";
mystring3[5] = horse.getTileX().ToString();
mystring3[6] = "Horse Y Position";
mystring3[7] = horse.getTileY().ToString();
File.WriteAllLines(mylocation3, mystring3);
}
}
public static void Load_Horse_Info()
{
Horse horse = Utility.findHorse();
if (horse == null)
{
Mod_Core.thisMonitor.Log("NEIGH: No horse exists", LogLevel.Debug);
return;
}
// DataLoader_Settings();
//loads the data to the variables upon loading the game.
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(Mod_Core.animal_path, "Horse_Save_Info_");
string mylocation2 = mylocation + myname;
string mylocation3 = mylocation2 + ".txt";
if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
{
}
else
{
string horse_map_name = "";
int horse_x;
int horse_y;
Point horse_point;
string[] readtext = File.ReadAllLines(mylocation3);
horse_map_name = Convert.ToString(readtext[3]);
horse_x = Convert.ToInt32(readtext[5]);
horse_y = Convert.ToInt32(readtext[7]);
horse_point.X = horse_x;
horse_point.Y = horse_y;
Game1.warpCharacter((NPC)horse, horse_map_name, horse_point, false, true);
}
}
}
}

View File

@ -11,7 +11,7 @@ using StardewValley.Characters;
namespace Omegasis.SaveAnywhere
{
public class Mod_Core : StardewModdingAPI.Mod
public class SaveAnywhere : Mod
{
public static string mod_path;
@ -28,17 +28,18 @@ namespace Omegasis.SaveAnywhere
public override void Entry(IModHelper helper)
{
try {
StardewModdingAPI.Events.ControlEvents.KeyPressed += KeyPressed_Save_Load_Menu;
StardewModdingAPI.Events.SaveEvents.AfterLoad += PlayerEvents_LoadedGame;
StardewModdingAPI.Events.GameEvents.UpdateTick += Warp_Check;
StardewModdingAPI.Events.GameEvents.UpdateTick += PassiveSaveChecker;
StardewModdingAPI.Events.TimeEvents.TimeOfDayChanged += NPC_scheduel_update;
StardewModdingAPI.Events.TimeEvents.DayOfMonthChanged += TimeEvents_DayOfMonthChanged;
StardewModdingAPI.Events.TimeEvents.DayOfMonthChanged += TimeEvents_OnNewDay;
mod_path = Helper.DirectoryPath;
try
{
ControlEvents.KeyPressed += KeyPressed_Save_Load_Menu;
SaveEvents.AfterLoad += PlayerEvents_LoadedGame;
GameEvents.UpdateTick += Warp_Check;
GameEvents.UpdateTick += PassiveSaveChecker;
TimeEvents.TimeOfDayChanged += NPC_scheduel_update;
TimeEvents.DayOfMonthChanged += TimeEvents_DayOfMonthChanged;
TimeEvents.DayOfMonthChanged += TimeEvents_OnNewDay;
SaveAnywhere.mod_path = Helper.DirectoryPath;
npc_key_value_pair = new Dictionary<string, string>();
thisMonitor = Monitor;
SaveAnywhere.thisMonitor = Monitor;
}
catch (Exception x)
{
@ -48,21 +49,22 @@ namespace Omegasis.SaveAnywhere
private void PassiveSaveChecker(object sender, EventArgs e)
{
if (GameUtilities.passiveSave == true && Game1.activeClickableMenu==null)
if (SaveUtilities.passiveSave == true && Game1.activeClickableMenu == null)
{
Game1.activeClickableMenu = new StardewValley.Menus.SaveGameMenu();
GameUtilities.passiveSave = false;
SaveUtilities.passiveSave = false;
}
}
//done
private void TimeEvents_OnNewDay(object sender, EventArgsIntChanged e)
{
try {
try
{
//Log.Info("Day of Month Changed");
new_day = true;
SaveAnywhere.new_day = true;
string name = Game1.player.name;
Mod_Core.player_path = Path.Combine(Mod_Core.mod_path, "Save_Data", name);
SaveAnywhere.player_path = Path.Combine(SaveAnywhere.mod_path, "Save_Data", name);
}
catch (Exception err)
@ -74,7 +76,8 @@ namespace Omegasis.SaveAnywhere
//done
private void TimeEvents_DayOfMonthChanged(object sender, EventArgsIntChanged e)
{
try {
try
{
//new_day = true;
// Log.Info("Day of Month Changed");
npc_key_value_pair.Clear();
@ -114,10 +117,10 @@ namespace Omegasis.SaveAnywhere
// MethodInfo dynMethod = typeof(NPC).GetMethod("prepareToDisembarkOnNewSchedulePath",BindingFlags.NonPublic | BindingFlags.Instance);
MethodInfo dynMethod2 = typeof(NPC).GetMethod("pathfindToNextScheduleLocation", BindingFlags.NonPublic | BindingFlags.Instance);
if (npc_warp == false) return;
if (new_day == true) return;
List<StardewValley.Characters.Child> child_list = new List<StardewValley.Characters.Child>();
child_list = StardewValley.Game1.player.getChildren();
if (SaveAnywhere.npc_warp == false) return;
if (SaveAnywhere.new_day == true) return;
List<Child> child_list = new List<Child>();
child_list = Game1.player.getChildren();
foreach (var loc in Game1.locations)
{
foreach (var npc in loc.characters)
@ -131,7 +134,7 @@ namespace Omegasis.SaveAnywhere
if (npc.name == child_name.name) continue;
}
if (npc.name == Game1.player.getPetName()) continue;
Horse horse = StardewValley.Utility.findHorse();
Horse horse = Utility.findHorse();
if (horse != null)
{
if (npc.name == horse.name) continue;
@ -220,7 +223,8 @@ namespace Omegasis.SaveAnywhere
}
}
try {
try
{
if (Convert.ToInt32(valueArray2.ElementAt(0)) > Game1.timeOfDay) break;
end_map = Convert.ToString(valueArray2.ElementAt(1));
x = Convert.ToInt32(valueArray2.ElementAt(2));
@ -260,7 +264,7 @@ namespace Omegasis.SaveAnywhere
}
}
}
once = true;
SaveAnywhere.once = true;
}
@ -673,9 +677,10 @@ namespace Omegasis.SaveAnywhere
//done
private void ShippingCheck(object sender, EventArgs e)
{
try {
try
{
if (Game1.activeClickableMenu != null) return;
GameUtilities.shipping_check();
SaveUtilities.shipping_check();
}
catch (Exception err)
{
@ -688,9 +693,9 @@ namespace Omegasis.SaveAnywhere
{
try
{
string name = StardewValley.Game1.player.name;
Mod_Core.player_path = Path.Combine(Mod_Core.mod_path, "Save_Data", name);
if (!Directory.Exists(Mod_Core.player_path))
string name = Game1.player.name;
SaveAnywhere.player_path = Path.Combine(SaveAnywhere.mod_path, "Save_Data", name);
if (!Directory.Exists(SaveAnywhere.player_path))
{
//Log.AsyncM(Save_Anywhere_V2.Mod_Core.player_path);
//Log.AsyncC("WOOPS");
@ -699,13 +704,13 @@ namespace Omegasis.SaveAnywhere
// Log.AsyncY(Player_Utilities.has_player_warped_yet);
if (Player_Utilities.has_player_warped_yet == false && Game1.player.isMoving() == true)
if (SaveUtilities.has_player_warped_yet == false && Game1.player.isMoving() == true)
{
//Log.AsyncM("Ok Good");
Player_Utilities.warp_player();
Animal_Utilities.load_animal_info();
NPC_Utilities.Load_NPC_Info();
Player_Utilities.has_player_warped_yet = true;
SaveUtilities.warp_player();
SaveUtilities.load_animal_info();
SaveUtilities.Load_NPC_Info();
SaveUtilities.has_player_warped_yet = true;
}
}
@ -719,27 +724,30 @@ namespace Omegasis.SaveAnywhere
//done
private void PlayerEvents_LoadedGame(object sender, EventArgs e)
{
try {
Player_Utilities.load_player_info();
try
{
SaveUtilities.load_player_info();
Config_Utilities.DataLoader_Settings();
Config_Utilities.MyWritter_Settings();
}
catch (Exception err) {
catch (Exception err)
{
Monitor.Log(err.ToString());
}
}
public void KeyPressed_Save_Load_Menu(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e)
public void KeyPressed_Save_Load_Menu(object sender, EventArgsKeyPressed e)
{
if (e.KeyPressed.ToString() == Config_Utilities.key_binding) //if the key is pressed, load my cusom save function
{
if (Game1.activeClickableMenu != null) return;
try {
GameUtilities.save_game();
try
{
SaveUtilities.save_game();
}
catch (Exception exe)
{
Mod_Core.thisMonitor.Log(exe.ToString(), LogLevel.Error);
SaveAnywhere.thisMonitor.Log(exe.ToString(), LogLevel.Error);
}
}

View File

@ -1,198 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewValley;
namespace Omegasis.SaveAnywhere
{
class NPC_Utilities
{
public static string npc_name;
public static int npc_tile_x;
public static int npc_tile_y;
public static string npc_current_map_name;
public static System.Collections.Generic.List<List<string>> routesFromLocationToLocation = new List<List<string>>();
public static Microsoft.Xna.Framework.Point npc_point;
public static void Save_NPC_Info()
{
Mod_Core.npc_path = Path.Combine(Mod_Core.player_path, "NPC_Save_Info");
if (!Directory.Exists(Mod_Core.npc_path))
{
Directory.CreateDirectory(Mod_Core.npc_path);
}
foreach (var location in Game1.locations)
{
foreach (var npc in location.characters)
{
if (npc.IsMonster == true) continue;
if (npc is StardewValley.Monsters.Bat || npc is StardewValley.Monsters.BigSlime || npc is StardewValley.Monsters.Bug || npc is StardewValley.Monsters.Cat || npc is StardewValley.Monsters.Crow || npc is StardewValley.Monsters.Duggy || npc is StardewValley.Monsters.DustSpirit || npc is StardewValley.Monsters.Fireball || npc is StardewValley.Monsters.Fly || npc is StardewValley.Monsters.Ghost || npc is StardewValley.Monsters.GoblinPeasant || npc is StardewValley.Monsters.GoblinWizard || npc is StardewValley.Monsters.GreenSlime || npc is StardewValley.Monsters.Grub || npc is StardewValley.Monsters.LavaCrab || npc is StardewValley.Monsters.MetalHead || npc is StardewValley.Monsters.Monster || npc is StardewValley.Monsters.Mummy || npc is StardewValley.Monsters.RockCrab || npc is StardewValley.Monsters.RockGolem || npc is StardewValley.Monsters.Serpent || npc is StardewValley.Monsters.ShadowBrute || npc is StardewValley.Monsters.ShadowGirl || npc is StardewValley.Monsters.ShadowGuy || npc is StardewValley.Monsters.ShadowShaman || npc is StardewValley.Monsters.Skeleton || npc is StardewValley.Monsters.SkeletonMage || npc is StardewValley.Monsters.SkeletonWarrior || npc is StardewValley.Monsters.Spiker || npc is StardewValley.Monsters.SquidKid) continue;
npc_name = npc.name;
npc_current_map_name = location.name;
npc_tile_x = npc.getTileX();
npc_tile_y = npc.getTileY();
string mylocation = Path.Combine(Mod_Core.npc_path, npc.name);
string mylocation2 = mylocation;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
Mod_Core.thisMonitor.Log("Save Anywhere: The NPC save info for " + npc_name + " doesn't exist. It will be created when the custom saving method is run. Which is now.");
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "NPC: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "NPC Name";
mystring3[3] = npc_name.ToString();
mystring3[4] = "NPC Current Map Name";
mystring3[5] = npc_current_map_name.ToString();
mystring3[6] = "NPC X Position";
mystring3[7] = npc_tile_x.ToString();
mystring3[8] = "NPC Y Position";
mystring3[9] = npc_tile_y.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
else
{
// Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now.");
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "NPC: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "NPC Current Map Name";
mystring3[3] = npc_name.ToString();
mystring3[4] = "NPC Current Map Name";
mystring3[5] = npc_current_map_name.ToString();
mystring3[6] = "NPC X Position";
mystring3[7] = npc_tile_x.ToString();
mystring3[8] = "NPC Y Position";
mystring3[9] = npc_tile_y.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
}
}
}
public static void Load_NPC_Info()
{
List<NPC> npc_list = new List<NPC>();
foreach (var location in Game1.locations)
{
foreach (var npc in location.characters)
{
if (npc.IsMonster == true) continue;
if (npc is StardewValley.Monsters.Bat || npc is StardewValley.Monsters.BigSlime || npc is StardewValley.Monsters.Bug || npc is StardewValley.Monsters.Cat || npc is StardewValley.Monsters.Crow || npc is StardewValley.Monsters.Duggy || npc is StardewValley.Monsters.DustSpirit || npc is StardewValley.Monsters.Fireball || npc is StardewValley.Monsters.Fly || npc is StardewValley.Monsters.Ghost || npc is StardewValley.Monsters.GoblinPeasant || npc is StardewValley.Monsters.GoblinWizard || npc is StardewValley.Monsters.GreenSlime || npc is StardewValley.Monsters.Grub || npc is StardewValley.Monsters.LavaCrab || npc is StardewValley.Monsters.MetalHead || npc is StardewValley.Monsters.Monster || npc is StardewValley.Monsters.Mummy || npc is StardewValley.Monsters.RockCrab || npc is StardewValley.Monsters.RockGolem || npc is StardewValley.Monsters.Serpent || npc is StardewValley.Monsters.ShadowBrute || npc is StardewValley.Monsters.ShadowGirl || npc is StardewValley.Monsters.ShadowGuy || npc is StardewValley.Monsters.ShadowShaman || npc is StardewValley.Monsters.Skeleton || npc is StardewValley.Monsters.SkeletonMage || npc is StardewValley.Monsters.SkeletonWarrior || npc is StardewValley.Monsters.Spiker || npc is StardewValley.Monsters.SquidKid) continue;
if (npc is StardewValley.NPC || npc is StardewValley.Characters.Cat || npc is StardewValley.Characters.Dog) npc_list.Add(npc);
}
}
foreach(var npc in npc_list) {
if (npc.IsMonster == true) continue;
if (npc is StardewValley.Monsters.Bat || npc is StardewValley.Monsters.BigSlime || npc is StardewValley.Monsters.Bug || npc is StardewValley.Monsters.Cat || npc is StardewValley.Monsters.Crow || npc is StardewValley.Monsters.Duggy || npc is StardewValley.Monsters.DustSpirit || npc is StardewValley.Monsters.Fireball || npc is StardewValley.Monsters.Fly || npc is StardewValley.Monsters.Ghost || npc is StardewValley.Monsters.GoblinPeasant || npc is StardewValley.Monsters.GoblinWizard || npc is StardewValley.Monsters.GreenSlime || npc is StardewValley.Monsters.Grub || npc is StardewValley.Monsters.LavaCrab || npc is StardewValley.Monsters.MetalHead || npc is StardewValley.Monsters.Monster || npc is StardewValley.Monsters.Mummy || npc is StardewValley.Monsters.RockCrab || npc is StardewValley.Monsters.RockGolem || npc is StardewValley.Monsters.Serpent || npc is StardewValley.Monsters.ShadowBrute || npc is StardewValley.Monsters.ShadowGirl || npc is StardewValley.Monsters.ShadowGuy || npc is StardewValley.Monsters.ShadowShaman || npc is StardewValley.Monsters.Skeleton || npc is StardewValley.Monsters.SkeletonMage || npc is StardewValley.Monsters.SkeletonWarrior || npc is StardewValley.Monsters.Spiker || npc is StardewValley.Monsters.SquidKid) continue;
Mod_Core.npc_path = Path.Combine(Mod_Core.player_path, "NPC_Save_Info");
if (!Directory.Exists(Mod_Core.npc_path))
{
Directory.CreateDirectory(Mod_Core.npc_path);
}
string mylocation = Path.Combine(Mod_Core.npc_path, npc.name);
string mylocation2 = mylocation;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
Mod_Core.thisMonitor.Log("Missing character file?!?", LogLevel.Error);
continue;
}
else
{
string[] readtext = File.ReadAllLines(mylocation3);
npc_name = Convert.ToString(readtext[3]);
npc_current_map_name = Convert.ToString(readtext[5]);
npc_tile_x = Convert.ToInt32(readtext[7]);
npc_tile_y = Convert.ToInt32(readtext[9]);
npc_point = new Microsoft.Xna.Framework.Point();
npc_point.X = npc_tile_x;
npc_point.Y = npc_tile_y;
if (npc_current_map_name == "" || npc_current_map_name == null) continue;
//Log.Info("Warped NPC" +npc_name);
Game1.warpCharacter((StardewValley.NPC)npc, npc_current_map_name, npc_point, false, true);
// npc.updateMovement(Game1.getLocationFromName(npc_current_map_name), Game1.currentGameTime);
//npc.moveCharacterOnSchedulePath();
// npc.dayUpdate(Game1.dayOfMonth);
//npc_update(npc, Game1.dayOfMonth);
// npc.DirectionsToNewLocation = pathfindToNextScheduleLocation(npc, npc.currentLocation.name, npc.getTileX(), npc.getTileY(), npc.currentLocation.name, 52, 99, 3, "", "");
// npc.updateMovement(npc.currentLocation,Game1.currentGameTime);
//npc.Schedule = npc.getSchedule(Game1.dayOfMonth);
//npc.moveCharacterOnSchedulePath();
}
}
Mod_Core.npc_warp = true;
}
private static Stack<Point> addToStackForSchedule(Stack<Point> original, Stack<Point> toAdd)
{
if (toAdd == null)
return original;
original = new Stack<Point>((IEnumerable<Point>)original);
while (original.Count > 0)
toAdd.Push(original.Pop());
return toAdd;
}
private static List<string> getLocationRoute(NPC npc, string startingLocation, string endingLocation)
{
foreach (List<string> list in routesFromLocationToLocation)
{
if (Enumerable.First<string>((IEnumerable<string>)list).Equals(startingLocation) && Enumerable.Last<string>((IEnumerable<string>)list).Equals(endingLocation) && (npc.gender == 0 || !list.Contains("BathHouse_MensLocker")) && (npc.gender != 0 || !list.Contains("BathHouse_WomensLocker")))
return list;
}
return (List<string>)null;
}
private static SchedulePathDescription pathfindToNextScheduleLocation(NPC npc,string startingLocation, int startingX, int startingY, string endingLocation, int endingX, int endingY, int finalFacingDirection, string endBehavior, string endMessage)
{
Stack<Point> stack = new Stack<Point>();
Point startPoint = new Point(startingX, startingY);
List<string> list = startingLocation.Equals(endingLocation) ? (List<string>)null : getLocationRoute(npc,startingLocation, endingLocation);
if (list != null)
{
for (int index = 0; index < Enumerable.Count<string>((IEnumerable<string>)list); ++index)
{
GameLocation locationFromName = Game1.getLocationFromName(list[index]);
if (index < Enumerable.Count<string>((IEnumerable<string>)list) - 1)
{
Point warpPointTo = locationFromName.getWarpPointTo(list[index + 1]);
if (warpPointTo.Equals(Point.Zero) || startPoint.Equals(Point.Zero))
throw new Exception("schedule pathing tried to find a warp point that doesn't exist.");
stack = addToStackForSchedule(stack, PathFindController.findPathForNPCSchedules(startPoint, warpPointTo, locationFromName, 30000));
startPoint = locationFromName.getWarpPointTarget(warpPointTo);
}
else
stack = addToStackForSchedule(stack, PathFindController.findPathForNPCSchedules(startPoint, new Point(endingX, endingY), locationFromName, 30000));
}
}
else if (startingLocation.Equals(endingLocation))
stack = PathFindController.findPathForNPCSchedules(startPoint, new Point(endingX, endingY), Game1.getLocationFromName(startingLocation), 30000);
return new SchedulePathDescription(stack, finalFacingDirection, endBehavior, endMessage);
}
}
}

View File

@ -17,7 +17,7 @@ using StardewValley.Menus;
namespace Omegasis.SaveAnywhere
{
public class New_Shipping_Menu : IClickableMenu
public class NewShippingMenu : IClickableMenu
{
public int currentPage = -1;
public int currentTab = 0;
@ -59,7 +59,7 @@ namespace Omegasis.SaveAnywhere
private bool savedYet;
private SaveGameMenu saveGameMenu;
public New_Shipping_Menu(List<Item> items)
public NewShippingMenu(List<Item> items)
: base(Game1.viewport.Width / 2 - 640, Game1.viewport.Height / 2 - 360, 1280, 720, false)
{
this.parseItems(items);
@ -273,7 +273,7 @@ namespace Omegasis.SaveAnywhere
catch (Exception rrr)
{
Game1.showRedMessage("Can't save here. See log for error.");
Mod_Core.thisMonitor.Log(rrr.ToString(), LogLevel.Error);
SaveAnywhere.thisMonitor.Log(rrr.ToString(), LogLevel.Error);
}
return;
}

View File

@ -1,138 +0,0 @@
using System;
using System.IO;
using StardewModdingAPI;
using StardewValley;
namespace Omegasis.SaveAnywhere
{
class Pet_Utilities
{
public static string pet_name;
public static StardewValley.Character my_pet;
public static string pet_map_name;
public static int pet_tile_x;
public static int pet_tile_y;
public static bool is_pet_outside;
public static Microsoft.Xna.Framework.Point pet_point;
public static void save_pet_info()
{
if (Game1.player.hasPet() == false) return;
pet_name = Game1.player.getPetName();
foreach (var location in Game1.locations)
{
foreach (var npc in location.characters)
{
if (npc is StardewValley.Characters.Dog || npc is StardewValley.Characters.Cat)
{
pet_map_name = location.name;
pet_tile_x = npc.getTileX();
pet_tile_y = npc.getTileY();
is_pet_outside = location.isOutdoors;
}
}
}
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(Mod_Core.animal_path, "Pet_Save_Info_");
string mylocation2 = mylocation + myname;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
Mod_Core.thisMonitor.Log("Save Anywhere: The pet save info doesn't exist. It will be created when the custom saving method is run. Which is now.", LogLevel.Debug);
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Pet: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Pet Current Map Name";
mystring3[3] = pet_map_name.ToString();
mystring3[4] = "Pet X Position";
mystring3[5] = pet_tile_x.ToString();
mystring3[6] = "Pet Y Position";
mystring3[7] = pet_tile_y.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
else
{
// Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now.");
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Pet: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Pet Current Map Name";
mystring3[3] = pet_map_name.ToString();
mystring3[4] = "Pet X Position";
mystring3[5] = pet_tile_x.ToString();
mystring3[6] = "Pet Y Position";
mystring3[7] = pet_tile_y.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
}
public static void Load_pet_Info()
{
if (Game1.player.hasPet() == false) return;
// DataLoader_Settings();
//loads the data to the variables upon loading the game.
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(Mod_Core.animal_path, "Pet_Save_Info_");
string mylocation2 = mylocation + myname;
string mylocation3 = mylocation2 + ".txt";
if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
{
}
else
{
string[] readtext = File.ReadAllLines(mylocation3);
pet_map_name = Convert.ToString(readtext[3]);
pet_tile_x = Convert.ToInt32(readtext[5]);
pet_tile_y = Convert.ToInt32(readtext[7]);
get_pet();
pet_point = new Microsoft.Xna.Framework.Point();
pet_point.X = pet_tile_x;
pet_point.Y = pet_tile_y;
Game1.warpCharacter((StardewValley.NPC)my_pet, pet_map_name, pet_point, false, true);
}
}
public static void get_pet()
{
if (Game1.player.hasPet() == false) return;
foreach (var location in Game1.locations)
{
foreach (var npc in location.characters)
{
if (npc is StardewValley.Characters.Dog || npc is StardewValley.Characters.Cat)
{
pet_map_name = location.name;
pet_tile_x = npc.getTileX();
pet_tile_y = npc.getTileY();
is_pet_outside = location.isOutdoors;
my_pet = npc;
}
}
}
}
}
}

View File

@ -1,165 +0,0 @@
using System;
using System.IO;
using StardewModdingAPI;
using StardewValley;
namespace Omegasis.SaveAnywhere
{
class Player_Utilities
{
public static int player_x_tile;
public static int player_y_tile;
public static string players_current_map_name;
public static int player_game_time;
public static int player_facing_direction;
public static bool has_player_warped_yet;
public static void get_player_info()
{
get_x();
get_y();
get_current_map_name();
get_facing_direction();
}
public static void get_x()
{
player_x_tile=Game1.player.getTileX();
}
public static void get_y()
{
player_y_tile = Game1.player.getTileY();
}
public static void get_current_map_name()
{
players_current_map_name = Game1.player.currentLocation.name;
}
public static void get_facing_direction()
{
player_facing_direction = Game1.player.facingDirection;
}
public static void save_player_info()
{
get_player_info();
string name = StardewValley.Game1.player.name;
Mod_Core.player_path= Path.Combine(Mod_Core.mod_path, "Save_Data", name);
if (!Directory.Exists(Mod_Core.player_path)){
Directory.CreateDirectory(Mod_Core.player_path);
}
string mylocation = Path.Combine(Mod_Core.player_path, "Player_Save_Info_");
string mylocation2 = mylocation + name;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
Mod_Core.thisMonitor.Log("Save Anywhere: The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now.", LogLevel.Info);
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Player: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Player Current Game Time";
mystring3[3] = Game1.timeOfDay.ToString();
mystring3[4] = "Player Current Map Name";
mystring3[5] = players_current_map_name.ToString();
mystring3[6] = "Player X Position";
mystring3[7] = player_x_tile.ToString();
mystring3[8] = "Player Y Position";
mystring3[9] = player_y_tile.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
else
{
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Player: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Player Current Game Time";
mystring3[3] = Game1.timeOfDay.ToString();
mystring3[4] = "Player Current Map Name";
mystring3[5] = players_current_map_name.ToString();
mystring3[6] = "Player X Position";
mystring3[7] = player_x_tile.ToString();
mystring3[8] = "Player Y Position";
mystring3[9] = player_y_tile.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
}
public static void load_player_info()
{
string name = StardewValley.Game1.player.name;
Mod_Core.player_path = Path.Combine(Mod_Core.mod_path, "Save_Data", name);
if (!Directory.Exists(Mod_Core.player_path))
{
Directory.CreateDirectory(Mod_Core.player_path);
}
string mylocation = Path.Combine(Mod_Core.player_path, "Player_Save_Info_");
string mylocation2 = mylocation + name;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
{
// Console.WriteLine("Can't load custom save info since the file doesn't exist.");
Player_Utilities.has_player_warped_yet = true;
}
else
{
// Console.WriteLine("HEY THERE IM LOADING DATA");
string[] readtext = File.ReadAllLines(mylocation3);
player_game_time = Convert.ToInt32(readtext[3]);
players_current_map_name = Convert.ToString(readtext[5]);
player_x_tile = Convert.ToInt32(readtext[7]);
player_y_tile = Convert.ToInt32(readtext[9]);
Game1.timeOfDay = player_game_time;
}
}
public static void warp_player()
{
GameLocation new_location = Game1.getLocationFromName(players_current_map_name);
Game1.player.previousLocationName = Game1.player.currentLocation.name;
Game1.locationAfterWarp = new_location;
Game1.xLocationAfterWarp = player_x_tile;
Game1.yLocationAfterWarp = player_y_tile;
Game1.facingDirectionAfterWarp = player_facing_direction;
Game1.fadeScreenToBlack();
Game1.warpFarmer(players_current_map_name, player_x_tile, player_y_tile, false);
Mod_Core.thisMonitor.Log("WARP THE PLAYER");
Game1.player.faceDirection(player_facing_direction);
if (Directory.Exists(Mod_Core.player_path))
{
// Directory.Delete(player_path, true);
}
}
}
}

View File

@ -34,15 +34,10 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Animal_Utilities.cs" />
<Compile Include="SaveUtilities.cs" />
<Compile Include="Config_Utilities.cs" />
<Compile Include="Horse_Utility.cs" />
<Compile Include="Mod_Core.cs" />
<Compile Include="GameUtilities.cs" />
<Compile Include="New_Shipping_Menu.cs" />
<Compile Include="NPC_Utilities.cs" />
<Compile Include="Pet_Utilities.cs" />
<Compile Include="Player_Utilities.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,694 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Characters;
using StardewValley.Menus;
namespace Omegasis.SaveAnywhere
{
/// <summary>Provides methods for saving and loading game data.</summary>
internal class SaveUtilities
{
public static bool passiveSave;
public static bool should_ship;
public static string npc_name;
public static int npc_tile_x;
public static int npc_tile_y;
public static string npc_current_map_name;
public static System.Collections.Generic.List<List<string>> routesFromLocationToLocation = new List<List<string>>();
public static Microsoft.Xna.Framework.Point npc_point;
public static string pet_name;
public static StardewValley.Character my_pet;
public static string pet_map_name;
public static int pet_tile_x;
public static int pet_tile_y;
public static bool is_pet_outside;
public static Microsoft.Xna.Framework.Point pet_point;
public static int player_x_tile;
public static int player_y_tile;
public static string players_current_map_name;
public static int player_game_time;
public static int player_facing_direction;
public static bool has_player_warped_yet;
public static void shipping_check()
{
if (Game1.activeClickableMenu != null) return;
if (SaveUtilities.should_ship == true)
{
Game1.activeClickableMenu = new NewShippingMenu(Game1.getFarm().shippingBin);
SaveUtilities.should_ship = false;
Game1.getFarm().shippingBin.Clear();
Game1.getFarm().lastItemShipped = null;
SaveUtilities.passiveSave = true;
}
else
{
Game1.activeClickableMenu = new StardewValley.Menus.SaveGameMenu();
}
}
public static void save_game()
{
/*
if (Game1.player.currentLocation.name == "Sewer")
{
Log.Error("There is an issue saving in the Sewer. Blame the animals for not being saved to the player's save file.");
Log.Error("Your data has not been saved. Sorry for the issue.");
return;
}
*/
//if a player has shipped an item, run this code.
if (Enumerable.Count<Item>((IEnumerable<Item>)Game1.getFarm().shippingBin) > 0)
{
should_ship = true;
// Game1.endOfNightMenus.Push((IClickableMenu)new ShippingMenu(Game1.getFarm().shippingBin));
// Game1.showEndOfNightStuff(); //shows the nightly shipping menu.
// Game1.getFarm().shippingBin.Clear(); //clears out the shipping bin to prevent exploits
}
try
{
shipping_check();
// Game1.activeClickableMenu = new StardewValley.Menus.SaveGameMenu();
}
catch (Exception rrr)
{
Game1.showRedMessage("Can't save here. See log for error.");
SaveAnywhere.thisMonitor.Log(rrr.ToString(), LogLevel.Error);
}
// Game1.activeClickableMenu = new StardewValley.Menus.SaveGameMenu(); //This command is what allows the player to save anywhere as it calls the saving function.
SaveUtilities.save_player_info();
SaveUtilities.save_animal_info();
SaveUtilities.Save_NPC_Info();
//grab the player's info
// player_map_name = StardewValley.Game1.player.currentLocation.name;
// player_tile_x = StardewValley.Game1.player.getTileX();
// player_tile_Y = StardewValley.Game1.player.getTileY();
// player_flop = false;
// MyWritter_Player(); //write my info to a text file
// MyWritter_Horse();
// DataLoader_Settings(); //load settings. Prevents acidental overwrite.
// MyWritter_Settings(); //save settings.
//Game1.warpFarmer(player_map_name, player_tile_x, player_tile_Y, player_flop); //refresh the player's location just incase. That will prove that they character's info was valid.
//so this is essentially the basics of the code...
// Log.Error("IS THIS BREAKING?");
}
public static void Save_Horse_Info()
{
Horse horse = Utility.findHorse();
if (horse == null)
{
//Game1.getFarm().characters.Add((NPC)new Horse(this.player_tile_x + 1, this.player_tile_Y + 1));
SaveAnywhere.thisMonitor.Log("NEIGH: No horse exists", LogLevel.Debug);
return;
}
// else
// Game1.warpCharacter((NPC)horse, Game1.player.currentLocation.name, StardewValley.Game1.player.getTileLocationPoint(), false, true);
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(SaveAnywhere.animal_path, "Horse_Save_Info_");
string mylocation2 = mylocation + myname;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
SaveAnywhere.thisMonitor.Log("The horse save info doesn't exist. It will be created when the custom saving method is run. Which is now.", LogLevel.Debug);
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Horse: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Horse Current Map Name";
mystring3[3] = horse.currentLocation.name.ToString();
mystring3[4] = "Horse X Position";
mystring3[5] = horse.getTileX().ToString();
mystring3[6] = "Horse Y Position";
mystring3[7] = horse.getTileY().ToString();
File.WriteAllLines(mylocation3, mystring3);
}
else
{
// Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now.");
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Horse: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Horse Current Map Name";
mystring3[3] = horse.currentLocation.name.ToString();
mystring3[4] = "Horse X Position";
mystring3[5] = horse.getTileX().ToString();
mystring3[6] = "Horse Y Position";
mystring3[7] = horse.getTileY().ToString();
File.WriteAllLines(mylocation3, mystring3);
}
}
public static void Load_Horse_Info()
{
Horse horse = Utility.findHorse();
if (horse == null)
{
SaveAnywhere.thisMonitor.Log("NEIGH: No horse exists", LogLevel.Debug);
return;
}
// DataLoader_Settings();
//loads the data to the variables upon loading the game.
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(SaveAnywhere.animal_path, "Horse_Save_Info_");
string mylocation2 = mylocation + myname;
string mylocation3 = mylocation2 + ".txt";
if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
{
}
else
{
string horse_map_name = "";
int horse_x;
int horse_y;
Point horse_point;
string[] readtext = File.ReadAllLines(mylocation3);
horse_map_name = Convert.ToString(readtext[3]);
horse_x = Convert.ToInt32(readtext[5]);
horse_y = Convert.ToInt32(readtext[7]);
horse_point.X = horse_x;
horse_point.Y = horse_y;
Game1.warpCharacter((NPC)horse, horse_map_name, horse_point, false, true);
}
}
public static void save_animal_info()
{
SaveAnywhere.animal_path = Path.Combine(SaveAnywhere.player_path, "Animals");
if (!Directory.Exists(SaveAnywhere.animal_path))
{
Directory.CreateDirectory(SaveAnywhere.animal_path);
}
SaveUtilities.Save_Horse_Info();
SaveUtilities.save_pet_info();
}
public static void load_animal_info()
{
SaveAnywhere.animal_path = Path.Combine(SaveAnywhere.player_path, "Animals");
if (!Directory.Exists(SaveAnywhere.animal_path))
{
Directory.CreateDirectory(SaveAnywhere.animal_path);
}
SaveUtilities.Load_Horse_Info();
SaveUtilities.Load_pet_Info();
}
public static void Save_NPC_Info()
{
SaveAnywhere.npc_path = Path.Combine(SaveAnywhere.player_path, "NPC_Save_Info");
if (!Directory.Exists(SaveAnywhere.npc_path))
{
Directory.CreateDirectory(SaveAnywhere.npc_path);
}
foreach (var location in Game1.locations)
{
foreach (var npc in location.characters)
{
if (npc.IsMonster == true) continue;
if (npc is StardewValley.Monsters.Bat || npc is StardewValley.Monsters.BigSlime || npc is StardewValley.Monsters.Bug || npc is StardewValley.Monsters.Cat || npc is StardewValley.Monsters.Crow || npc is StardewValley.Monsters.Duggy || npc is StardewValley.Monsters.DustSpirit || npc is StardewValley.Monsters.Fireball || npc is StardewValley.Monsters.Fly || npc is StardewValley.Monsters.Ghost || npc is StardewValley.Monsters.GoblinPeasant || npc is StardewValley.Monsters.GoblinWizard || npc is StardewValley.Monsters.GreenSlime || npc is StardewValley.Monsters.Grub || npc is StardewValley.Monsters.LavaCrab || npc is StardewValley.Monsters.MetalHead || npc is StardewValley.Monsters.Monster || npc is StardewValley.Monsters.Mummy || npc is StardewValley.Monsters.RockCrab || npc is StardewValley.Monsters.RockGolem || npc is StardewValley.Monsters.Serpent || npc is StardewValley.Monsters.ShadowBrute || npc is StardewValley.Monsters.ShadowGirl || npc is StardewValley.Monsters.ShadowGuy || npc is StardewValley.Monsters.ShadowShaman || npc is StardewValley.Monsters.Skeleton || npc is StardewValley.Monsters.SkeletonMage || npc is StardewValley.Monsters.SkeletonWarrior || npc is StardewValley.Monsters.Spiker || npc is StardewValley.Monsters.SquidKid) continue;
npc_name = npc.name;
npc_current_map_name = location.name;
npc_tile_x = npc.getTileX();
npc_tile_y = npc.getTileY();
string mylocation = Path.Combine(SaveAnywhere.npc_path, npc.name);
string mylocation2 = mylocation;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
SaveAnywhere.thisMonitor.Log("Save Anywhere: The NPC save info for " + npc_name + " doesn't exist. It will be created when the custom saving method is run. Which is now.");
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "NPC: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "NPC Name";
mystring3[3] = npc_name.ToString();
mystring3[4] = "NPC Current Map Name";
mystring3[5] = npc_current_map_name.ToString();
mystring3[6] = "NPC X Position";
mystring3[7] = npc_tile_x.ToString();
mystring3[8] = "NPC Y Position";
mystring3[9] = npc_tile_y.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
else
{
// Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now.");
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "NPC: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "NPC Current Map Name";
mystring3[3] = npc_name.ToString();
mystring3[4] = "NPC Current Map Name";
mystring3[5] = npc_current_map_name.ToString();
mystring3[6] = "NPC X Position";
mystring3[7] = npc_tile_x.ToString();
mystring3[8] = "NPC Y Position";
mystring3[9] = npc_tile_y.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
}
}
}
public static void Load_NPC_Info()
{
List<NPC> npc_list = new List<NPC>();
foreach (var location in Game1.locations)
{
foreach (var npc in location.characters)
{
if (npc.IsMonster == true) continue;
if (npc is StardewValley.Monsters.Bat || npc is StardewValley.Monsters.BigSlime || npc is StardewValley.Monsters.Bug || npc is StardewValley.Monsters.Cat || npc is StardewValley.Monsters.Crow || npc is StardewValley.Monsters.Duggy || npc is StardewValley.Monsters.DustSpirit || npc is StardewValley.Monsters.Fireball || npc is StardewValley.Monsters.Fly || npc is StardewValley.Monsters.Ghost || npc is StardewValley.Monsters.GoblinPeasant || npc is StardewValley.Monsters.GoblinWizard || npc is StardewValley.Monsters.GreenSlime || npc is StardewValley.Monsters.Grub || npc is StardewValley.Monsters.LavaCrab || npc is StardewValley.Monsters.MetalHead || npc is StardewValley.Monsters.Monster || npc is StardewValley.Monsters.Mummy || npc is StardewValley.Monsters.RockCrab || npc is StardewValley.Monsters.RockGolem || npc is StardewValley.Monsters.Serpent || npc is StardewValley.Monsters.ShadowBrute || npc is StardewValley.Monsters.ShadowGirl || npc is StardewValley.Monsters.ShadowGuy || npc is StardewValley.Monsters.ShadowShaman || npc is StardewValley.Monsters.Skeleton || npc is StardewValley.Monsters.SkeletonMage || npc is StardewValley.Monsters.SkeletonWarrior || npc is StardewValley.Monsters.Spiker || npc is StardewValley.Monsters.SquidKid) continue;
if (npc is StardewValley.NPC || npc is StardewValley.Characters.Cat || npc is StardewValley.Characters.Dog) npc_list.Add(npc);
}
}
foreach (var npc in npc_list)
{
if (npc.IsMonster == true) continue;
if (npc is StardewValley.Monsters.Bat || npc is StardewValley.Monsters.BigSlime || npc is StardewValley.Monsters.Bug || npc is StardewValley.Monsters.Cat || npc is StardewValley.Monsters.Crow || npc is StardewValley.Monsters.Duggy || npc is StardewValley.Monsters.DustSpirit || npc is StardewValley.Monsters.Fireball || npc is StardewValley.Monsters.Fly || npc is StardewValley.Monsters.Ghost || npc is StardewValley.Monsters.GoblinPeasant || npc is StardewValley.Monsters.GoblinWizard || npc is StardewValley.Monsters.GreenSlime || npc is StardewValley.Monsters.Grub || npc is StardewValley.Monsters.LavaCrab || npc is StardewValley.Monsters.MetalHead || npc is StardewValley.Monsters.Monster || npc is StardewValley.Monsters.Mummy || npc is StardewValley.Monsters.RockCrab || npc is StardewValley.Monsters.RockGolem || npc is StardewValley.Monsters.Serpent || npc is StardewValley.Monsters.ShadowBrute || npc is StardewValley.Monsters.ShadowGirl || npc is StardewValley.Monsters.ShadowGuy || npc is StardewValley.Monsters.ShadowShaman || npc is StardewValley.Monsters.Skeleton || npc is StardewValley.Monsters.SkeletonMage || npc is StardewValley.Monsters.SkeletonWarrior || npc is StardewValley.Monsters.Spiker || npc is StardewValley.Monsters.SquidKid) continue;
SaveAnywhere.npc_path = Path.Combine(SaveAnywhere.player_path, "NPC_Save_Info");
if (!Directory.Exists(SaveAnywhere.npc_path))
{
Directory.CreateDirectory(SaveAnywhere.npc_path);
}
string mylocation = Path.Combine(SaveAnywhere.npc_path, npc.name);
string mylocation2 = mylocation;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
SaveAnywhere.thisMonitor.Log("Missing character file?!?", LogLevel.Error);
continue;
}
else
{
string[] readtext = File.ReadAllLines(mylocation3);
npc_name = Convert.ToString(readtext[3]);
npc_current_map_name = Convert.ToString(readtext[5]);
npc_tile_x = Convert.ToInt32(readtext[7]);
npc_tile_y = Convert.ToInt32(readtext[9]);
npc_point = new Microsoft.Xna.Framework.Point();
npc_point.X = npc_tile_x;
npc_point.Y = npc_tile_y;
if (npc_current_map_name == "" || npc_current_map_name == null) continue;
//Log.Info("Warped NPC" +npc_name);
Game1.warpCharacter((StardewValley.NPC)npc, npc_current_map_name, npc_point, false, true);
// npc.updateMovement(Game1.getLocationFromName(npc_current_map_name), Game1.currentGameTime);
//npc.moveCharacterOnSchedulePath();
// npc.dayUpdate(Game1.dayOfMonth);
//npc_update(npc, Game1.dayOfMonth);
// npc.DirectionsToNewLocation = pathfindToNextScheduleLocation(npc, npc.currentLocation.name, npc.getTileX(), npc.getTileY(), npc.currentLocation.name, 52, 99, 3, "", "");
// npc.updateMovement(npc.currentLocation,Game1.currentGameTime);
//npc.Schedule = npc.getSchedule(Game1.dayOfMonth);
//npc.moveCharacterOnSchedulePath();
}
}
SaveAnywhere.npc_warp = true;
}
private static Stack<Point> addToStackForSchedule(Stack<Point> original, Stack<Point> toAdd)
{
if (toAdd == null)
return original;
original = new Stack<Point>((IEnumerable<Point>)original);
while (original.Count > 0)
toAdd.Push(original.Pop());
return toAdd;
}
private static List<string> getLocationRoute(NPC npc, string startingLocation, string endingLocation)
{
foreach (List<string> list in routesFromLocationToLocation)
{
if (Enumerable.First<string>((IEnumerable<string>)list).Equals(startingLocation) && Enumerable.Last<string>((IEnumerable<string>)list).Equals(endingLocation) && (npc.gender == 0 || !list.Contains("BathHouse_MensLocker")) && (npc.gender != 0 || !list.Contains("BathHouse_WomensLocker")))
return list;
}
return (List<string>)null;
}
private static SchedulePathDescription pathfindToNextScheduleLocation(NPC npc, string startingLocation, int startingX, int startingY, string endingLocation, int endingX, int endingY, int finalFacingDirection, string endBehavior, string endMessage)
{
Stack<Point> stack = new Stack<Point>();
Point startPoint = new Point(startingX, startingY);
List<string> list = startingLocation.Equals(endingLocation) ? (List<string>)null : getLocationRoute(npc, startingLocation, endingLocation);
if (list != null)
{
for (int index = 0; index < Enumerable.Count<string>((IEnumerable<string>)list); ++index)
{
GameLocation locationFromName = Game1.getLocationFromName(list[index]);
if (index < Enumerable.Count<string>((IEnumerable<string>)list) - 1)
{
Point warpPointTo = locationFromName.getWarpPointTo(list[index + 1]);
if (warpPointTo.Equals(Point.Zero) || startPoint.Equals(Point.Zero))
throw new Exception("schedule pathing tried to find a warp point that doesn't exist.");
stack = addToStackForSchedule(stack, PathFindController.findPathForNPCSchedules(startPoint, warpPointTo, locationFromName, 30000));
startPoint = locationFromName.getWarpPointTarget(warpPointTo);
}
else
stack = addToStackForSchedule(stack, PathFindController.findPathForNPCSchedules(startPoint, new Point(endingX, endingY), locationFromName, 30000));
}
}
else if (startingLocation.Equals(endingLocation))
stack = PathFindController.findPathForNPCSchedules(startPoint, new Point(endingX, endingY), Game1.getLocationFromName(startingLocation), 30000);
return new SchedulePathDescription(stack, finalFacingDirection, endBehavior, endMessage);
}
public static void save_pet_info()
{
if (Game1.player.hasPet() == false) return;
pet_name = Game1.player.getPetName();
foreach (var location in Game1.locations)
{
foreach (var npc in location.characters)
{
if (npc is StardewValley.Characters.Dog || npc is StardewValley.Characters.Cat)
{
pet_map_name = location.name;
pet_tile_x = npc.getTileX();
pet_tile_y = npc.getTileY();
is_pet_outside = location.isOutdoors;
}
}
}
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(SaveAnywhere.animal_path, "Pet_Save_Info_");
string mylocation2 = mylocation + myname;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
SaveAnywhere.thisMonitor.Log("Save Anywhere: The pet save info doesn't exist. It will be created when the custom saving method is run. Which is now.", LogLevel.Debug);
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Pet: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Pet Current Map Name";
mystring3[3] = pet_map_name.ToString();
mystring3[4] = "Pet X Position";
mystring3[5] = pet_tile_x.ToString();
mystring3[6] = "Pet Y Position";
mystring3[7] = pet_tile_y.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
else
{
// Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now.");
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Pet: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Pet Current Map Name";
mystring3[3] = pet_map_name.ToString();
mystring3[4] = "Pet X Position";
mystring3[5] = pet_tile_x.ToString();
mystring3[6] = "Pet Y Position";
mystring3[7] = pet_tile_y.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
}
public static void Load_pet_Info()
{
if (Game1.player.hasPet() == false) return;
// DataLoader_Settings();
//loads the data to the variables upon loading the game.
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(SaveAnywhere.animal_path, "Pet_Save_Info_");
string mylocation2 = mylocation + myname;
string mylocation3 = mylocation2 + ".txt";
if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
{
}
else
{
string[] readtext = File.ReadAllLines(mylocation3);
pet_map_name = Convert.ToString(readtext[3]);
pet_tile_x = Convert.ToInt32(readtext[5]);
pet_tile_y = Convert.ToInt32(readtext[7]);
get_pet();
pet_point = new Microsoft.Xna.Framework.Point();
pet_point.X = pet_tile_x;
pet_point.Y = pet_tile_y;
Game1.warpCharacter((StardewValley.NPC)my_pet, pet_map_name, pet_point, false, true);
}
}
public static void get_pet()
{
if (Game1.player.hasPet() == false) return;
foreach (var location in Game1.locations)
{
foreach (var npc in location.characters)
{
if (npc is StardewValley.Characters.Dog || npc is StardewValley.Characters.Cat)
{
pet_map_name = location.name;
pet_tile_x = npc.getTileX();
pet_tile_y = npc.getTileY();
is_pet_outside = location.isOutdoors;
my_pet = npc;
}
}
}
}
public static void get_player_info()
{
get_x();
get_y();
get_current_map_name();
get_facing_direction();
}
public static void get_x()
{
player_x_tile = Game1.player.getTileX();
}
public static void get_y()
{
player_y_tile = Game1.player.getTileY();
}
public static void get_current_map_name()
{
players_current_map_name = Game1.player.currentLocation.name;
}
public static void get_facing_direction()
{
player_facing_direction = Game1.player.facingDirection;
}
public static void save_player_info()
{
get_player_info();
string name = StardewValley.Game1.player.name;
SaveAnywhere.player_path = Path.Combine(SaveAnywhere.mod_path, "Save_Data", name);
if (!Directory.Exists(SaveAnywhere.player_path))
{
Directory.CreateDirectory(SaveAnywhere.player_path);
}
string mylocation = Path.Combine(SaveAnywhere.player_path, "Player_Save_Info_");
string mylocation2 = mylocation + name;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
SaveAnywhere.thisMonitor.Log("Save Anywhere: The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now.", LogLevel.Info);
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Player: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Player Current Game Time";
mystring3[3] = Game1.timeOfDay.ToString();
mystring3[4] = "Player Current Map Name";
mystring3[5] = players_current_map_name.ToString();
mystring3[6] = "Player X Position";
mystring3[7] = player_x_tile.ToString();
mystring3[8] = "Player Y Position";
mystring3[9] = player_y_tile.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
else
{
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[0] = "Player: Save_Anywhere Info. Editing this might break some things.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Player Current Game Time";
mystring3[3] = Game1.timeOfDay.ToString();
mystring3[4] = "Player Current Map Name";
mystring3[5] = players_current_map_name.ToString();
mystring3[6] = "Player X Position";
mystring3[7] = player_x_tile.ToString();
mystring3[8] = "Player Y Position";
mystring3[9] = player_y_tile.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
}
public static void load_player_info()
{
string name = StardewValley.Game1.player.name;
SaveAnywhere.player_path = Path.Combine(SaveAnywhere.mod_path, "Save_Data", name);
if (!Directory.Exists(SaveAnywhere.player_path))
{
Directory.CreateDirectory(SaveAnywhere.player_path);
}
string mylocation = Path.Combine(SaveAnywhere.player_path, "Player_Save_Info_");
string mylocation2 = mylocation + name;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
{
// Console.WriteLine("Can't load custom save info since the file doesn't exist.");
SaveUtilities.has_player_warped_yet = true;
}
else
{
// Console.WriteLine("HEY THERE IM LOADING DATA");
string[] readtext = File.ReadAllLines(mylocation3);
player_game_time = Convert.ToInt32(readtext[3]);
players_current_map_name = Convert.ToString(readtext[5]);
player_x_tile = Convert.ToInt32(readtext[7]);
player_y_tile = Convert.ToInt32(readtext[9]);
Game1.timeOfDay = player_game_time;
}
}
public static void warp_player()
{
GameLocation new_location = Game1.getLocationFromName(players_current_map_name);
Game1.player.previousLocationName = Game1.player.currentLocation.name;
Game1.locationAfterWarp = new_location;
Game1.xLocationAfterWarp = player_x_tile;
Game1.yLocationAfterWarp = player_y_tile;
Game1.facingDirectionAfterWarp = player_facing_direction;
Game1.fadeScreenToBlack();
Game1.warpFarmer(players_current_map_name, player_x_tile, player_y_tile, false);
SaveAnywhere.thisMonitor.Log("WARP THE PLAYER");
Game1.player.faceDirection(player_facing_direction);
if (Directory.Exists(SaveAnywhere.player_path))
{
// Directory.Delete(player_path, true);
}
}
}
}