Stardew_Valley_Mods/Save_Anywhere/Class1.cs

998 lines
37 KiB
C#
Raw Normal View History

2016-04-23 07:53:14 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StardewValley;
using StardewModdingAPI;
using StardewValley.Menus;
using System.IO;
using System.Timers;
using System.Windows.Input;
2016-04-25 05:41:26 +08:00
using StardewValley.Characters;
using Microsoft.Xna.Framework;
2016-04-23 07:53:14 +08:00
/*
TO DO:
*/
namespace Stardew_Save_Anywhere_Mod
{
public class Class1 : Mod
{
2016-04-25 09:41:40 +08:00
// string save_path="";
bool initialize = false;
2016-04-23 07:53:14 +08:00
string key_binding="K";
bool game_loaded = false;
2016-04-25 05:41:26 +08:00
string player_map_name;
2016-04-23 07:53:14 +08:00
int player_tile_x;
int player_tile_Y;
bool player_flop = false;
2016-04-25 09:41:40 +08:00
2016-04-23 07:53:14 +08:00
int game_time;
2016-04-25 01:05:56 +08:00
double timer_interval = 3500;
2016-04-23 07:53:14 +08:00
bool timer = true;
2016-06-09 00:10:16 +08:00
bool game_updated_and_loaded;
bool time_updated;
2016-04-23 07:53:14 +08:00
2016-04-25 09:41:40 +08:00
bool warped = false;
bool simulate_time;
bool warp_character;
2016-04-25 05:41:26 +08:00
2016-04-25 01:05:56 +08:00
Timer aTimer = new Timer(3500); //fires every X miliseconds. 3500 is 4 times faster than the game's normal speed //originally this was 2000
2016-04-23 07:53:14 +08:00
string npc_name;
string npc_map_name;
bool npc_map_outside;
Microsoft.Xna.Framework.Point npc_point;
int npc_x;
int npc_y;
public override void Entry(params object[] objects)
{
2016-04-25 01:05:56 +08:00
//set up all of my events here
2016-04-23 07:53:14 +08:00
StardewModdingAPI.Events.PlayerEvents.LoadedGame += PlayerEvents_LoadedGame;
2016-04-25 01:05:56 +08:00
// StardewModdingAPI.Events.TimeEvents.TimeOfDayChanged += TimeEvents_TimeOfDayChanged; Not used as of version 1.0.1
2016-04-23 07:53:14 +08:00
StardewModdingAPI.Events.TimeEvents.DayOfMonthChanged += TimeEvents_DayOfMonthChanged;
StardewModdingAPI.Events.GameEvents.OneSecondTick += GameEvents_OneSecondTick;
StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed;
}
public void TimeEvents_DayOfMonthChanged(object sender, StardewModdingAPI.Events.EventArgsIntChanged e)
{
if (game_loaded == true)
{
2016-04-25 09:41:40 +08:00
file_clean_up();
2016-04-25 01:05:56 +08:00
game_time = 600; //resets the game time so that simulation doesn't happen every day.
2016-04-23 07:53:14 +08:00
game_updated_and_loaded = true; //prevents the next day from being updated
2016-04-25 01:05:56 +08:00
StardewValley.Game1.player.canMove = true; //do I even use this?
2016-04-23 07:53:14 +08:00
}
}
public void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e)
{
2016-04-25 09:41:40 +08:00
//DataLoader_Settings(); //update the key if players changed it while playing.
2016-04-25 01:05:56 +08:00
if (e.KeyPressed.ToString() ==key_binding) //if the key is pressed, load my cusom save function
2016-04-23 07:53:14 +08:00
{
my_save();
}
}
public void GameEvents_OneSecondTick(object sender, EventArgs e)
2016-04-25 01:05:56 +08:00
{ //updates the info every second
2016-04-25 09:41:40 +08:00
2016-04-23 07:53:14 +08:00
if (game_loaded == true)
{
2016-04-25 05:41:26 +08:00
2016-04-25 09:41:40 +08:00
if (initialize == false)
{
// DataLoader_Settings(); //load up the mod config file.
DataLoader_Horse();
DataLoader_NPC(false); //loads the NPC's with original location info
initialize = true;
2016-04-25 05:41:26 +08:00
2016-04-23 07:53:14 +08:00
2016-04-26 06:30:01 +08:00
if (simulate_time == true)
{
timer = false;
2016-06-09 00:10:16 +08:00
// simulate_time = false;
2016-04-26 06:30:01 +08:00
}
else timer = true;
if (warp_character == true && game_updated_and_loaded == false)
{
warped = false;
//warp_character = false;
}
2016-04-25 05:41:26 +08:00
}
2016-04-26 06:30:01 +08:00
2016-04-25 05:41:26 +08:00
else warped = true;
2016-04-25 09:41:40 +08:00
DataLoader_Player(); //warps the character and changes the game time. WTF HOW DID THIS BREAK???
2016-04-25 05:41:26 +08:00
if (warped == false)
{
2016-04-23 07:53:14 +08:00
game_updated_and_loaded = false;
2016-04-25 05:41:26 +08:00
if (StardewValley.Game1.player.currentLocation.name != player_map_name && warped==false)
2016-04-23 07:53:14 +08:00
{
2016-04-25 01:05:56 +08:00
MyWritter_NPC(true); //writes in the NPC's info. May be redundant?
warped = true;
StardewValley.Game1.warpFarmer(player_map_name, player_tile_x, player_tile_Y, player_flop); //player flop is always false. //Just incase I run this a couple of times.
StardewValley.Game1.warpFarmer(player_map_name, player_tile_x, player_tile_Y, player_flop); //player flop is always false. //probably bad programming practice.
2016-04-25 05:41:26 +08:00
StardewValley.Game1.warpFarmer(player_map_name, player_tile_x, player_tile_Y, player_flop); //player flop is always false.
2016-04-23 07:53:14 +08:00
Log.Success("WARPED");
2016-04-25 05:41:26 +08:00
//timer = false; //activate my timer. False means that it hasn't been initialized.
2016-04-25 09:41:40 +08:00
game_updated_and_loaded = true;
2016-04-25 05:41:26 +08:00
}
2016-04-23 07:53:14 +08:00
}
2016-04-25 05:41:26 +08:00
2016-04-23 07:53:14 +08:00
// DataLoader_NPC(false);
if (warped == true && timer == false)
{
2016-04-25 01:05:56 +08:00
//load config info for the timer here.
aTimer.Interval = timer_interval; //this should update the timer to run at the config amount of seconds.
2016-04-23 07:53:14 +08:00
2016-04-25 01:05:56 +08:00
timer = true; //timer is now running
aTimer.AutoReset = true;
2016-04-23 07:53:14 +08:00
aTimer.Enabled = true;
aTimer.Elapsed += ATimer_Elapsed;
//simulate time here
2016-04-25 01:05:56 +08:00
if (Game1.timeOfDay >= game_time) aTimer.Enabled = false; //disable my timer
2016-04-23 07:53:14 +08:00
//aTimer.Enabled = false;
}
}
}
public void ATimer_Elapsed(object sender, ElapsedEventArgs e)
{
2016-06-09 00:10:16 +08:00
if (time_updated == true) return;
2016-04-23 07:53:14 +08:00
if (Game1.timeOfDay < game_time)
{
Game1.performTenMinuteClockUpdate();
/*
if (create_original == false)
{
MyWritter_NPC(true);
create_original = true;
}
*/
Log.Info("This is the current time: Keep simulating :" + Game1.timeOfDay);
foreach (StardewValley.GameLocation asdf in Game1.locations)
{
GameLocation NPClocation = (GameLocation)asdf;
foreach (StardewValley.NPC obj in NPClocation.characters)
{
2016-04-25 01:05:56 +08:00
obj.addedSpeed = 7; //changes how fast npc's move in the world. Default added speed I put was 9 when timer_interval was 2000 miliseconds
2016-04-23 07:53:14 +08:00
}
}
}
if (Game1.timeOfDay >= game_time)
{
2016-06-09 00:10:16 +08:00
time_updated = true;
2016-04-23 07:53:14 +08:00
Game1.player.canMove = true;
2016-04-25 01:05:56 +08:00
game_time = 600; //reset the game_time so that oversimulation doesn't happen again while playing.
2016-04-23 07:53:14 +08:00
}
}
2016-04-25 01:05:56 +08:00
/*
2016-04-23 07:53:14 +08:00
public void TimeEvents_TimeOfDayChanged(object sender, StardewModdingAPI.Events.EventArgsIntChanged e)
{
if (Game1.timeOfDay < game_time)
{
2016-04-25 01:05:56 +08:00
2016-04-23 07:53:14 +08:00
if (game_loaded == true)
{
2016-04-25 01:05:56 +08:00
//do nothing right now. I might need this later though.
2016-04-23 07:53:14 +08:00
}
2016-04-25 01:05:56 +08:00
2016-04-23 07:53:14 +08:00
GameLocation farm = StardewValley.Game1.getLocationFromName("Farm");
StardewValley.TerrainFeatures.HoeDirt mydirt;
foreach (StardewValley.TerrainFeatures.TerrainFeature dirty in farm.terrainFeatures.Values)
{
// Log.Error("IS THIS WRONG?");
if (dirty is StardewValley.TerrainFeatures.HoeDirt)
{
// Log.Error("JELLO SAUCE!!!");
mydirt =(StardewValley.TerrainFeatures.HoeDirt)dirty;
Log.Info("CONVERSION");
if (mydirt.state.Equals(0)) //0 is dry, 1 is watered
{
Log.Error("NEED SOME WATER");
}
if (mydirt.state.Equals(1)) //0 is dry, 1 is watered
{
Log.Success("NICE AND WET");
}
}
}
2016-04-25 01:05:56 +08:00
//This originally was the code to preserve soil, but Ape apparently covered that in the save functionality. Still I'll keep it here incase I need to update the farm later.
2016-04-23 07:53:14 +08:00
} //end game loaded if
}
2016-04-25 01:05:56 +08:00
*/
2016-04-23 07:53:14 +08:00
public void PlayerEvents_LoadedGame(object sender, StardewModdingAPI.Events.EventArgsLoadedGameChanged e)
{
game_loaded = true;
2016-04-25 05:41:26 +08:00
DataLoader_Settings();
2016-04-23 07:53:14 +08:00
MyWritter_Settings();
2016-06-09 00:10:16 +08:00
if (simulate_time == true) aTimer = new Timer(timer_interval);
2016-04-23 07:53:14 +08:00
}
2016-04-25 05:41:26 +08:00
2016-04-23 07:53:14 +08:00
void DataLoader_Settings()
{
//loads the data to the variables upon loading the game.
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(PathOnDisk, "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.
{
// Console.WriteLine("Can't load custom save info since the file doesn't exist.");
key_binding = "K";
2016-04-25 01:05:56 +08:00
timer_interval = 3500;
2016-04-25 09:41:40 +08:00
warp_character = true;
simulate_time = true;
2016-04-23 07:53:14 +08:00
// Log.Info("KEY TIME");
}
else
{
// Console.WriteLine("HEY THERE IM LOADING DATA");
string[] readtext = File.ReadAllLines(mylocation3);
key_binding = Convert.ToString(readtext[3]);
2016-04-25 05:41:26 +08:00
timer_interval = Convert.ToDouble(readtext[5]);
simulate_time = Convert.ToBoolean(readtext[7]);
warp_character = Convert.ToBoolean(readtext[9]);
2016-04-25 01:05:56 +08:00
// Log.Info(key_binding);
// Log.Info(Convert.ToString(readtext[3]));
2016-04-23 07:53:14 +08:00
}
}
void MyWritter_Settings()
{
2016-04-25 01:05:56 +08:00
//write all of my info to a text file.
2016-04-23 07:53:14 +08:00
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(PathOnDisk, "Save_Anywhere_Config");
string mylocation2 = mylocation;
string mylocation3 = mylocation2 + ".txt";
2016-04-25 01:05:56 +08:00
2016-04-25 05:41:26 +08:00
string[] mystring3 = new string[20];
2016-04-23 07:53:14 +08:00
if (!File.Exists(mylocation3))
{
Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now.");
mystring3[0] = "Config: Save_Anywhere Info. Feel free to mess with these settings.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Key binding for saving anywhere. Press this key to save anywhere!";
mystring3[3] = key_binding.ToString();
2016-04-25 01:05:56 +08:00
mystring3[4] = "Timer interval for NPCs. Default 3500 which simulates game time at 4x speed.";
mystring3[5] = timer_interval.ToString();
2016-04-25 05:41:26 +08:00
mystring3[6] = "Simulate game time? Game time will be sped up until restored before saving";
mystring3[7] = simulate_time.ToString();
mystring3[8] = "Warp player when loading?";
mystring3[9] = warp_character.ToString();
2016-04-25 01:05:56 +08:00
2016-04-23 07:53:14 +08:00
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] = "Config: Save_Anywhere Info. Feel free to mess with these settings.";
mystring3[1] = "====================================================================================";
mystring3[2] = "Key binding for saving anywhere. Press this key to save anywhere!";
mystring3[3] = key_binding.ToString();
2016-04-25 01:05:56 +08:00
mystring3[4] = "Timer interval for NPCs. Default 3500 which simulates game time at 4x speed.";
mystring3[5] = timer_interval.ToString();
2016-04-25 05:41:26 +08:00
mystring3[6] = "Simulate game time? Game time will be sped up until restored before saving";
mystring3[7] = simulate_time.ToString();
mystring3[8] = "Warp player when loading?";
mystring3[9] = warp_character.ToString();
2016-04-23 07:53:14 +08:00
File.WriteAllLines(mylocation3, mystring3);
}
}
void MyWritter_Player()
{
MyWritter_Settings();
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(PathOnDisk, "Player_Save_Info_");
string mylocation2 = mylocation + myname;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
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] = "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] = player_map_name.ToString();
mystring3[6] = "Player X Position";
mystring3[7] = player_tile_x.ToString();
mystring3[8] = "Player Y Position";
mystring3[9] = player_tile_Y.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] = player_map_name.ToString();
mystring3[6] = "Player X Position";
mystring3[7] = player_tile_x.ToString();
mystring3[8] = "Player Y Position";
mystring3[9] = player_tile_Y.ToString();
File.WriteAllLines(mylocation3, mystring3);
}
}
2016-04-25 05:41:26 +08:00
void DataLoader_Player()
{
// DataLoader_Settings();
//loads the data to the variables upon loading the game.
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(PathOnDisk, "Player_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.
{
// Console.WriteLine("Can't load custom save info since the file doesn't exist.");
warped = true;
}
else
{
// Console.WriteLine("HEY THERE IM LOADING DATA");
string[] readtext = File.ReadAllLines(mylocation3);
game_time = Convert.ToInt32(readtext[3]);
player_map_name = Convert.ToString(readtext[5]);
player_tile_x = Convert.ToInt32(readtext[7]);
player_tile_Y = Convert.ToInt32(readtext[9]);
}
}
void MyWritter_Horse()
{
Horse horse = Utility.findHorse();
if (horse == null)
{
//Game1.getFarm().characters.Add((NPC)new Horse(this.player_tile_x + 1, this.player_tile_Y + 1));
Log.Info("NEIGH: No horse exists");
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(PathOnDisk, "Horse_Save_Info_");
string mylocation2 = mylocation + myname;
string mylocation3 = mylocation2 + ".txt";
string[] mystring3 = new string[20];
if (!File.Exists(mylocation3))
{
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] = "Player Current Map Name";
mystring3[3] = horse.currentLocation.name.ToString();
mystring3[4] = "Player X Position";
mystring3[5] = horse.getTileX().ToString();
mystring3[6] = "Player 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] = "Player Current Map Name";
mystring3[3] = horse.currentLocation.name.ToString();
mystring3[4] = "Player X Position";
mystring3[5] = horse.getTileX().ToString();
mystring3[6] = "Player Y Position";
mystring3[7] = horse.getTileY().ToString();
File.WriteAllLines(mylocation3, mystring3);
}
}
void DataLoader_Horse()
{
Horse horse = Utility.findHorse();
if (horse == null)
{
//Game1.getFarm().characters.Add((NPC)new Horse(this.player_tile_x + 1, this.player_tile_Y + 1));
Log.Info("NEIGH: No horse exists");
return;
}
// else
//Game1.warpCharacter((NPC)horse, Game1.player.currentLocation.name, StardewValley.Game1.player.getTileLocationPoint(), false, true);
// DataLoader_Settings();
//loads the data to the variables upon loading the game.
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(PathOnDisk, "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.
{
// Console.WriteLine("Can't load custom save info since the file doesn't exist.");
}
else
{
string horse_map_name = "";
int horse_x;
int horse_y;
Point horse_point;
// Console.WriteLine("HEY THERE IM LOADING DATA");
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);
}
}
2016-04-23 07:53:14 +08:00
void my_save()
{
2016-04-26 06:30:01 +08:00
if (Game1.player.currentLocation.name == "CommunityCenter")
{
Log.Error("There is an issue saving in the community center. Blame the Junimos not being saved to the player's save file.");
Log.Error("Your data has not been saved. Sorry for the issue.");
return;
}
2016-04-25 01:05:56 +08:00
2016-04-26 06:30:01 +08:00
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.
2016-04-23 07:53:14 +08:00
if (Enumerable.Count<Item>((IEnumerable<Item>)Game1.getFarm().shippingBin) > 0)
{
Game1.endOfNightMenus.Push((IClickableMenu)new ShippingMenu(Game1.getFarm().shippingBin));
2016-04-25 01:05:56 +08:00
Game1.showEndOfNightStuff(); //shows the nightly shipping menu.
Game1.getFarm().shippingBin.Clear(); //clears out the shipping bin to prevent exploits
2016-04-23 07:53:14 +08:00
}
2016-04-25 01:05:56 +08:00
Game1.activeClickableMenu = new StardewValley.Menus.SaveGameMenu(); //This command is what allows the player to save anywhere as it calls the saving function.
2016-04-23 07:53:14 +08:00
2016-04-25 01:05:56 +08:00
//grab the player's info
2016-04-23 07:53:14 +08:00
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;
2016-04-25 01:05:56 +08:00
MyWritter_Player(); //write my info to a text file
2016-04-23 07:53:14 +08:00
2016-04-25 05:41:26 +08:00
MyWritter_Horse();
2016-04-23 07:53:14 +08:00
2016-04-25 01:05:56 +08:00
DataLoader_Settings(); //load settings. Prevents acidental overwrite.
MyWritter_Settings(); //save settings.
2016-04-23 07:53:14 +08:00
2016-04-26 06:30:01 +08:00
//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.
2016-04-23 07:53:14 +08:00
//so this is essentially the basics of the code...
2016-04-25 01:05:56 +08:00
// Log.Error("IS THIS BREAKING?");
2016-04-23 07:53:14 +08:00
}
2016-04-25 05:41:26 +08:00
void file_clean_up()
{
string myname = StardewValley.Game1.player.name;
string mylocation = Path.Combine(PathOnDisk, "Player_Save_Info_");
string mylocation2 = mylocation + myname;
string mylocation3 = mylocation2 + ".txt";
if (File.Exists(mylocation3)) //delete the custom save when going to bed.
{
File.Delete(mylocation3); //clean up the player's save info
}
mylocation = Path.Combine(PathOnDisk, "Horse_Save_Info_");
mylocation2 = mylocation + myname;
mylocation3 = mylocation2 + ".txt";
if (File.Exists(mylocation3)) //delete the custom save when going to bed.
{
File.Delete(mylocation3); //clean up the player's horse save info
}
}
2016-04-23 07:53:14 +08:00
void DataLoader_NPC(bool sleep)
{
//loads the data to the variables upon loading the game.
string myname = StardewValley.Game1.player.name;
2016-06-09 23:37:51 +08:00
string mylocation = Path.Combine(PathOnDisk, "NPC_Original_Save_Info_"+myname);
string mylocation_save = Path.Combine(PathOnDisk, "NPC_Original_Save_Info_"+myname);
2016-04-23 07:53:14 +08:00
if (sleep == true)
{
2016-06-09 23:37:51 +08:00
mylocation = Path.Combine(PathOnDisk, "NPC_Save_Info_"+myname);
2016-04-23 07:53:14 +08:00
}
string myloc2B = mylocation_save;
string mylocation2 = mylocation;
string mylocation3 = mylocation2 + ".txt";
string myloc3B = myloc2B + ".txt";
if (!File.Exists(myloc3B)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
{
// Log.Error(" I CAN NOT LOAD Can't load original save info since the file doesn't exist.");
return;
}
if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
{
// Log.Error(" I CAN NOT LOAD Can't load custom save info since the file doesn't exist.");
return;
}
int i = 3;
if (sleep == true)
{
2016-06-09 23:37:51 +08:00
mylocation = Path.Combine(PathOnDisk, "NPC_Save_Info_"+myname);
2016-04-23 07:53:14 +08:00
}
if (!File.Exists(myloc3B)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
{
// Log.Error(" I CAN NOT LOAD Can't load original save info since the file doesn't exist.");
}
if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
{
// Log.Error(" I CAN NOT LOAD Can't load custom save info since the file doesn't exist.");
}
else
{
// Console.WriteLine("HEY THERE IM LOADING DATA");
2016-04-25 01:05:56 +08:00
//Saves all of the info for NPC's into a file.
2016-04-23 07:53:14 +08:00
string[] readtext = File.ReadAllLines(mylocation3);
string[] readtexty = File.ReadAllLines(myloc3B);
int j = 0;
2016-04-25 01:05:56 +08:00
List<NPC> list = new List<NPC>(); //This will collect all of the info for the NPC's and save it into a list
2016-04-23 07:53:14 +08:00
foreach (StardewValley.GameLocation asdf in Game1.locations)
{
var NPClocationd = (GameLocation)asdf;
2016-04-25 01:05:56 +08:00
Log.Error(asdf.name); //show the loaded location's name.
2016-04-25 05:41:26 +08:00
System.Threading.Thread.Sleep(50); //prevent the game from loading characters too quickly by delaying time 10 miliseconds.
if (asdf.name == "Farm") continue;
2016-04-26 06:30:01 +08:00
if (asdf.name == "CommunityCenter") continue;
2016-04-23 07:53:14 +08:00
foreach (StardewValley.NPC obj in NPClocationd.characters)
{
Log.Success(obj.name);
2016-04-25 01:05:56 +08:00
list.Add(obj); //add the character to the list. Warping them inside of this loop here breaks things.
2016-04-23 07:53:14 +08:00
}
2016-04-25 01:05:56 +08:00
foreach (NPC item in list) //iterate across my NPC list
2016-04-23 07:53:14 +08:00
{
i = 3;
2016-04-25 01:05:56 +08:00
while (item.name != readtexty[i]) //look across the NPC_Origina_Info file
2016-04-23 07:53:14 +08:00
{
i += 11;
}
2016-04-25 01:05:56 +08:00
Log.Info(i); //tell me where I am at. Line # = i+1
2016-04-23 07:53:14 +08:00
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
if (readtext[i] == "") break;
if (readtext[i] == "\n") break;
//npc_name = Convert.ToString(readtexty[i]);
Log.Info(npc_name);
2016-04-25 01:05:56 +08:00
// Log.Error("WHAT IS THIS?");
2016-04-23 07:53:14 +08:00
//System.Threading.Thread.Sleep(1000);
i += 2;
npc_map_name = Convert.ToString(readtexty[i]);
Log.Info(npc_map_name);
//System.Threading.Thread.Sleep(1000);
i += 2;
npc_map_outside = Convert.ToBoolean(readtexty[i]);
Log.Info(npc_map_outside);
//System.Threading.Thread.Sleep(1000);
i += 2;
npc_x = Convert.ToInt32(readtexty[i]);
Log.Info(npc_x);
//System.Threading.Thread.Sleep(1000);
i += 2;
npc_y = Convert.ToInt32(readtexty[i]);
Log.Info(npc_y);
//System.Threading.Thread.Sleep(3000);
i += 3;
Log.Info(i);
// System.Threading.Thread.Sleep(100);
npc_point.X = npc_x;
npc_point.Y = npc_y;
Microsoft.Xna.Framework.Vector2 myvector2;
myvector2.X = npc_x;
myvector2.Y = npc_y;
Log.Info("character warp!");
2016-04-25 01:05:56 +08:00
//basically I just filled the console with debugging information. You are welcome.
2016-04-23 07:53:14 +08:00
2016-04-25 01:05:56 +08:00
Game1.warpCharacter(item, npc_map_name, npc_point, true, true); //warp my npc back to original location
2016-04-23 07:53:14 +08:00
//list.Remove(item);
i = 3;
}
2016-04-25 01:05:56 +08:00
list.Clear(); //clean up my list
2016-04-23 07:53:14 +08:00
}
//timer = false;
} //end for eaches
}
void MyWritter_NPC(bool sleep)
{
2016-04-25 01:05:56 +08:00
//basically grabs all of the Npc's info and saves it to a text document. Takes a second or so.
2016-04-23 07:53:14 +08:00
string myname = StardewValley.Game1.player.name;
string mylocation;
string mylocation2;
if (sleep == false)
{
2016-06-09 23:37:51 +08:00
mylocation = Path.Combine(PathOnDisk, "NPC_Save_Info_"+myname);
2016-04-23 07:53:14 +08:00
mylocation2 = mylocation;
}
else
{
2016-06-09 23:37:51 +08:00
mylocation = Path.Combine(PathOnDisk, "NPC_Original_Save_Info_"+myname);
2016-04-23 07:53:14 +08:00
mylocation2 = mylocation;
}
string mylocation3 = mylocation2 + ".txt";
int counter = 1;
GameLocation NPClocation;
foreach (StardewValley.GameLocation asdf in Game1.locations)
{
NPClocation = (GameLocation)asdf;
foreach (StardewValley.NPC obj in NPClocation.characters)
{
counter += 11;
}
}
string[] mystring3 = new string[counter];
if (!File.Exists(mylocation3))
{
int i = 0;
mystring3[i] = "NPC : SAVE ANYWHERE INFO. DON'T TOUCH THIS";
i++;
foreach (StardewValley.GameLocation asdf in Game1.locations)
{
NPClocation = (GameLocation)asdf;
2016-04-26 06:30:01 +08:00
if (NPClocation.name == "CommunityCenter")
{
continue;
}
2016-04-23 07:53:14 +08:00
2016-04-26 06:30:01 +08:00
2016-04-23 07:53:14 +08:00
foreach (StardewValley.NPC obj in NPClocation.characters)
{
//grab all of the NPC INFO.
// Log.Info(obj.getName());
npc_name = obj.getName();
System.Threading.Thread.Sleep(5);
// Log.Info(obj.currentLocation.name);
npc_map_name = obj.currentLocation.name;
System.Threading.Thread.Sleep(5);
// Log.Info(NPClocation.isOutdoors);
npc_map_outside = NPClocation.isOutdoors;
System.Threading.Thread.Sleep(5);
npc_point.X = obj.getTileX();
npc_point.Y = obj.getTileY();
//Log.Info(obj.getTileLocationPoint());
//npc_point = obj.getTileLocationPoint();
//System.Threading.Thread.Sleep(5);
Log.Success("Let's save all of the NPCS in the world!");
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[i] = "====================================================================================";
i++;
mystring3[i] = "NPC NAME";
i++;
mystring3[i] = obj.getName().ToString();
i++;
mystring3[i] = "NPC Current Map Name";
i++;
mystring3[i] = obj.currentLocation.name.ToString();
i++;
mystring3[i] = "NPC IS OUTSIDE?";
i++;
mystring3[i] = NPClocation.isOutdoors.ToString();
i++;
mystring3[i] = "NPC TILE LOCATION : X";
i++;
mystring3[i] = npc_point.X.ToString();
i++;
mystring3[i] = "NPC TILE LOCATION : Y";
i++;
mystring3[i] = npc_point.Y.ToString();
i++;
//NPCS WILL FIGURE OUT MOVEMENT ON THEIR OWN.
//I CAN SIMPLY (SIMULATE TIME) OR (WARP THEM??)
}
}
File.WriteAllLines(mylocation3, mystring3);
}
else
{
int i = 0;
mystring3[i] = "NPC : SAVE ANYWHERE INFO. DON'T TOUCH THIS";
i++;
foreach (StardewValley.GameLocation asdf in Game1.locations)
{
NPClocation = (GameLocation)asdf;
foreach (StardewValley.NPC obj in NPClocation.characters)
{
//grab all of the NPC INFO.
Log.Info(obj.getName());
npc_name = obj.getName();
System.Threading.Thread.Sleep(5);
Log.Info(obj.currentLocation.name);
npc_map_name = obj.currentLocation.name;
System.Threading.Thread.Sleep(5);
Log.Info(NPClocation.isOutdoors);
npc_map_outside = NPClocation.isOutdoors;
System.Threading.Thread.Sleep(5);
npc_point.X = obj.getTileX();
npc_point.Y = obj.getTileY();
//Log.Info(obj.getTileLocationPoint());
//npc_point = obj.getTileLocationPoint();
//System.Threading.Thread.Sleep(5);
Log.Success("Let's save all of the NPCS in the world!");
//write out the info to a text file at the end of a day. This will run if it doesnt exist.
mystring3[i] = "====================================================================================";
i++;
mystring3[i] = "NPC NAME";
i++;
mystring3[i] = obj.getName().ToString();
i++;
mystring3[i] = "NPC Current Map Name";
i++;
mystring3[i] = obj.currentLocation.name.ToString();
i++;
mystring3[i] = "NPC IS OUTSIDE?";
i++;
mystring3[i] = NPClocation.isOutdoors.ToString();
i++;
mystring3[i] = "NPC TILE LOCATION : X";
i++;
mystring3[i] = npc_point.X.ToString();
i++;
mystring3[i] = "NPC TILE LOCATION : Y";
i++;
mystring3[i] = npc_point.Y.ToString();
i++;
//NPCS WILL FIGURE OUT MOVEMENT ON THEIR OWN.
//I CAN SIMPLY (SIMULATE TIME) OR (WARP THEM??)
}
}
File.WriteAllLines(mylocation3, mystring3);
}
}
}
}
//end class