2016-06-04 00:23:52 +08:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using StardewValley ;
using StardewModdingAPI ;
using System.IO ;
/ * TODO :
* /
/ *
Issues :
- Mail can ' t be wiped without destroying all mail .
- Lighting transition does not work if it is raining .
- set the weather to clear if you are stayig up late .
- transition still doesnt work . However atleast it is dark now .
2016-06-04 15:28:37 +08:00
- Known glitched
2016-06-04 00:23:52 +08:00
* /
namespace Stardew_NightOwl
{
public class Class1 : Mod
{
int player_x ;
int player_y ;
string prior_map ;
2016-06-30 01:32:42 +08:00
bool reset_check ;
2016-06-04 00:23:52 +08:00
bool was_raining ;
bool time_reset ;
int prior_money ;
int post_money ;
float pre_stam ;
int pre_health ;
bool lighting_transition ; //if true transition happens. If false, game starts out bright at 2AM. Good to remove that awkward change from dark to bright.
bool warp ;
bool stay_up ;
2016-06-30 01:32:42 +08:00
bool wipe_mail ;
2016-06-04 00:23:52 +08:00
bool protect_money ;
bool persistant_health ;
bool persistant_stamina ;
bool game_loaded ;
2016-06-04 15:28:37 +08:00
bool once ;
bool up_late ;
2016-06-30 01:32:42 +08:00
bool first_check ;
bool warped_check ;
2016-06-04 15:28:37 +08:00
2016-06-30 01:32:42 +08:00
bool super_map_warping_check ;
2016-06-04 15:28:37 +08:00
2016-06-04 00:23:52 +08:00
public override void Entry ( params object [ ] objects )
{
StardewModdingAPI . Events . TimeEvents . TimeOfDayChanged + = TimeEvents_TimeOfDayChanged ;
2016-06-30 01:32:42 +08:00
// StardewModdingAPI.Events.TimeEvents.DayOfMonthChanged += TimeEvents_DayOfMonthChanged;
StardewModdingAPI . Events . TimeEvents . OnNewDay + = TimeEvents_DayOfMonthChanged ;
2016-06-04 00:23:52 +08:00
StardewModdingAPI . Events . PlayerEvents . LoadedGame + = PlayerEvents_LoadedGame ;
2016-06-04 15:28:37 +08:00
StardewModdingAPI . Events . GameEvents . FourthUpdateTick + = GameEvents_FourthUpdateTick ;
}
public void GameEvents_FourthUpdateTick ( object sender , EventArgs e )
{
if ( game_loaded = = false ) return ;
if ( Game1 . timeOfDay = = 600 )
{
if ( once = = true )
{
// Log.AsyncM("NEW MONEY" + Game1.player.money);
2016-06-30 01:32:42 +08:00
// Game1.player.money = Game1.player.money + post_money;
2016-06-04 15:28:37 +08:00
once = false ;
}
}
2016-06-30 01:32:42 +08:00
if ( warped_check = = false )
{
if ( warp = = true )
{
Log . Info ( "Warping!!!" ) ;
Game1 . warpFarmer ( prior_map , player_x , player_y , false ) ;
warped_check = true ;
super_map_warping_check = true ;
}
}
2016-06-04 15:28:37 +08:00
2016-06-04 00:23:52 +08:00
}
public void PlayerEvents_LoadedGame ( object sender , StardewModdingAPI . Events . EventArgsLoadedGameChanged e )
{
DataLoader ( ) ;
MyWritter ( ) ;
game_loaded = true ;
2016-06-04 15:28:37 +08:00
once = false ;
up_late = false ;
2016-06-30 01:32:42 +08:00
first_check = false ;
warped_check = true ;
super_map_warping_check = true ;
2016-06-04 00:23:52 +08:00
}
2016-06-30 01:32:42 +08:00
public void TimeEvents_DayOfMonthChanged ( object sender , StardewModdingAPI . Events . EventArgsNewDay e )
2016-06-04 00:23:52 +08:00
{
if ( game_loaded = = false ) return ;
2016-06-30 01:32:42 +08:00
if ( first_check = = false )
{
first_check = true ;
Log . Info ( "first" ) ;
return ;
}
else
{
first_check = false ;
Log . Info ( "Second" ) ;
}
Game1 . farmerShouldPassOut = false ; //make the farmer collapse.
reset_check = false ;
//Game1.farmerShouldPassOut = false; //make the farmer collapse.
2016-06-04 00:23:52 +08:00
DataLoader ( ) ;
MyWritter ( ) ;
2016-06-04 15:28:37 +08:00
//List<string> newmail = new List<string>();
2016-06-30 01:32:42 +08:00
Queue < string > newmail = new Queue < string > ( ) ;
2016-06-04 15:28:37 +08:00
up_late = false ;
2016-06-30 01:32:42 +08:00
2016-06-04 00:23:52 +08:00
if ( time_reset = = true )
{
was_raining = false ;
if ( persistant_stamina = = true ) Game1 . player . stamina = pre_stam ; //reset health and stam upon collapsing
if ( persistant_health = = true ) Game1 . player . health = pre_health ;
2016-06-04 15:28:37 +08:00
//post_money = Game1.player.money;
if ( protect_money = = true ) {
2016-06-30 01:32:42 +08:00
Game1 . player . money + = post_money ;
2016-06-04 15:28:37 +08:00
once = true ;
2016-06-30 01:32:42 +08:00
2016-06-04 15:28:37 +08:00
} //add the money back from colapsing.
2016-06-04 00:23:52 +08:00
time_reset = false ; //reset my bool.
if ( warp = = true ) Game1 . warpFarmer ( prior_map , player_x , player_y , false ) ;
2016-06-04 15:28:37 +08:00
// very_old_money = (safety_cash - Game1.player.money);
//Game1.player.money += very_old_money;
2016-06-04 00:23:52 +08:00
}
2016-06-04 15:28:37 +08:00
2016-06-04 00:23:52 +08:00
if ( wipe_mail = = true )
{
foreach ( var i in Game1 . mailbox ) //delete those annoying charge messages. If only I could do this with mail IRL.
{
Log . Info ( i ) ;
if ( i . Contains ( "passedOut" ) )
{
Log . Info ( "Found bad mail" ) ;
}
else {
2016-06-30 01:32:42 +08:00
newmail . Enqueue ( i ) ;
2016-06-04 00:23:52 +08:00
}
}
Game1 . mailbox . Clear ( ) ;
foreach ( string mail in newmail )
{
2016-06-30 01:32:42 +08:00
Game1 . mailbox . Enqueue ( mail ) ;
2016-06-04 00:23:52 +08:00
}
}
2016-06-30 01:32:42 +08:00
warped_check = false ;
2016-06-04 00:23:52 +08:00
}
public void TimeEvents_TimeOfDayChanged ( object sender , StardewModdingAPI . Events . EventArgsIntChanged e )
{
if ( game_loaded = = false ) return ;
float color_mod ;
//transition the lighting for more "realistic" lighting from 2am to 11am. There is an awkward screen shuffle that happens because of this update.
2016-06-30 01:32:42 +08:00
2016-06-04 00:23:52 +08:00
if ( lighting_transition = = true )
{
if ( Game1 . timeOfDay > 200 & & Game1 . timeOfDay < 1100 )
{
2016-06-04 15:28:37 +08:00
color_mod = ( 1100 - Game1 . timeOfDay ) / 1000f ; //.7f
Game1 . outdoorLight = Game1 . ambientLight * color_mod ;
2016-06-04 00:23:52 +08:00
}
}
if ( stay_up = = true )
{
if ( Game1 . timeOfDay = = 2550 )
{
if ( StardewValley . Game1 . isRaining = = true )
{
was_raining = true ;
StardewValley . Game1 . isRaining = false ; //regardless make sure I change the weather. Otherwise lighting gets screwy.
}
2016-06-04 15:28:37 +08:00
StardewValley . Game1 . updateWeatherIcon ( ) ;
2016-06-04 00:23:52 +08:00
Game1 . timeOfDay = 150 ; //change it from 1:50 am late, to 1:50 am early
}
}
2016-06-04 15:28:37 +08:00
2016-06-30 01:32:42 +08:00
if ( Game1 . timeOfDay = = 550 ) //if the game time is 5:50 AM
2016-06-04 00:23:52 +08:00
{
2016-06-04 15:28:37 +08:00
up_late = true ;
}
2016-06-30 01:32:42 +08:00
if ( Game1 . timeOfDay = = 600 ) //when time is 6:00 AM after staying up
2016-06-04 15:28:37 +08:00
{
2016-06-30 01:32:42 +08:00
2016-06-04 15:28:37 +08:00
if ( up_late = = false )
{
2016-06-30 01:32:42 +08:00
return ;
2016-06-04 15:28:37 +08:00
}
2016-06-30 01:32:42 +08:00
if ( super_map_warping_check = = true )
2016-06-04 15:28:37 +08:00
{
2016-06-30 01:32:42 +08:00
if ( Game1 . currentMinigame ! = null ) Game1 . currentMinigame = null ;
//if (time_reset == false) return;
time_reset = true ;
player_x = Game1 . player . getTileX ( ) ;
player_y = Game1 . player . getTileY ( ) ;
prior_map = Game1 . player . currentLocation . name ;
2016-06-04 00:23:52 +08:00
2016-06-30 01:32:42 +08:00
Log . Info ( prior_map ) ;
Log . Info ( player_x ) ;
Log . Info ( player_y ) ;
super_map_warping_check = false ;
Game1 . farmerShouldPassOut = true ; //make the farmer collapse.
pre_stam = Game1 . player . stamina ;
pre_health = Game1 . player . health ;
prior_money = Game1 . player . money ;
if ( Game1 . player . money < = 10000 )
{
post_money = prior_money / 10 ;
}
else
{
post_money = 1000 ;
}
}
2016-06-04 15:28:37 +08:00
}
2016-06-30 01:32:42 +08:00
}
2016-06-04 00:23:52 +08:00
void MyWritter ( )
{
//saves the BuildEndurance_data at the end of a new day;
string myname = Game1 . player . name ;
string mylocation = Path . Combine ( PathOnDisk , "Night_Owl_Config_" ) ;
//string mylocation2 = mylocation + myname;
string mylocation3 = mylocation + ".txt" ;
string [ ] mystring3 = new string [ 20 ] ;
if ( ! File . Exists ( mylocation3 ) )
{
2016-06-30 01:32:42 +08:00
Log . Info ( "The data file for Night Owl wasn't found. Time to create it!" ) ;
2016-06-04 00:23:52 +08:00
mystring3 [ 0 ] = "Player: Night Owl Config. Feel free to edit." ;
mystring3 [ 1 ] = "====================================================================================" ;
mystring3 [ 2 ] = "Stay up to 6 AM?: Do you wan't to stay up till 6 AM the next morning?" ;
mystring3 [ 3 ] = stay_up . ToString ( ) ;
mystring3 [ 4 ] = "Custom Lighting Transition?: Do you want to have a lighting transition from 2AM to 5:50 AM? Setting this to false will keep the world dark until the player passes out or goes to bed." ;
mystring3 [ 5 ] = lighting_transition . ToString ( ) ;
mystring3 [ 6 ] = "Warp to collapse position?: True: Stay in the same place. False: Warp back home." ;
mystring3 [ 7 ] = warp . ToString ( ) ;
mystring3 [ 8 ] = "Keep Money?: True: Don't be charged for passing out." ;
mystring3 [ 9 ] = protect_money . ToString ( ) ;
mystring3 [ 10 ] = "Keep stamina when staying up? When the farmer passes out at 6, should their stamina be their stamina before collapsing?" ;
mystring3 [ 11 ] = persistant_stamina . ToString ( ) ;
mystring3 [ 12 ] = "Keep health when staying up? When the farmer passes out at 6, should their health be their health before collapsing?" ;
mystring3 [ 13 ] = persistant_health . ToString ( ) ;
2016-06-30 01:32:42 +08:00
mystring3 [ 14 ] = "Clean out charges mail?: Get rid of the annoying We charged X gold for your health fees, etc." ;
mystring3 [ 15 ] = wipe_mail . ToString ( ) ;
2016-06-04 00:23:52 +08:00
File . WriteAllLines ( mylocation3 , mystring3 ) ;
}
else
{
// Console.WriteLine("HEY IM SAVING DATA");
//write out the info to a text file at the end of a day.
mystring3 [ 0 ] = "Player: Night Owl Config. Feel free to edit." ;
mystring3 [ 1 ] = "====================================================================================" ;
mystring3 [ 2 ] = "Stay up to 6 AM?: Do you wan't to stay up till 6 AM the next morning?" ;
mystring3 [ 3 ] = stay_up . ToString ( ) ;
mystring3 [ 4 ] = "Custom Lighting Transition?: Do you want to have a lighting transition from 2AM to 5:50 AM? Setting this to false will keep the world dark until the player passes out or goes to bed." ;
mystring3 [ 5 ] = lighting_transition . ToString ( ) ;
mystring3 [ 6 ] = "Warp to collapse position?: True: Stay in the same place. False: Warp back home." ;
mystring3 [ 7 ] = warp . ToString ( ) ;
mystring3 [ 8 ] = "Keep Money?: True: Don't be charged for passing out." ;
mystring3 [ 9 ] = protect_money . ToString ( ) ;
mystring3 [ 10 ] = "Keep stamina when staying up? When the farmer passes out at 6, should their stamina be their stamina before collapsing?" ;
mystring3 [ 11 ] = persistant_stamina . ToString ( ) ;
mystring3 [ 12 ] = "Keep health when staying up? When the farmer passes out at 6, should their health be their health before collapsing?" ;
mystring3 [ 13 ] = persistant_health . ToString ( ) ;
2016-06-30 01:32:42 +08:00
mystring3 [ 14 ] = "Clean out charges mail?: Get rid of the annoying We charged X gold for your health fees, etc." ;
mystring3 [ 15 ] = wipe_mail . ToString ( ) ;
2016-06-04 00:23:52 +08:00
File . WriteAllLines ( mylocation3 , mystring3 ) ;
}
}
void DataLoader ( )
{
//loads the data to the variables upon loading the game.
string myname = StardewValley . Game1 . player . name ;
string mylocation = Path . Combine ( PathOnDisk , "Night_Owl_Config_" ) ;
//string mylocation2 = mylocation + myname;
string mylocation3 = mylocation + ".txt" ;
if ( ! File . Exists ( mylocation3 ) ) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out.
{
2016-06-30 01:32:42 +08:00
Log . Info ( "Loading Night_Owl_Config" ) ;
2016-06-04 00:23:52 +08:00
lighting_transition = true ;
warp = true ;
stay_up = true ;
persistant_health = true ;
persistant_stamina = true ;
2016-06-30 01:32:42 +08:00
wipe_mail = true ;
2016-06-04 00:23:52 +08:00
protect_money = true ;
}
else
{
string [ ] readtext = File . ReadAllLines ( mylocation3 ) ;
2016-06-30 01:32:42 +08:00
stay_up = Convert . ToBoolean ( readtext [ 3 ] ) ; //will the player stay up?
lighting_transition = Convert . ToBoolean ( readtext [ 5 ] ) ; //does the lighting transition occur?
warp = Convert . ToBoolean ( readtext [ 7 ] ) ; //does the player warp back to the spot they passed out at?
protect_money = Convert . ToBoolean ( readtext [ 9 ] ) ; //Is their money safe from stealing?
persistant_stamina = Convert . ToBoolean ( readtext [ 11 ] ) ; //Does the player have the same stam when collapsing?
persistant_health = Convert . ToBoolean ( readtext [ 13 ] ) ; //Ditto but with health.
wipe_mail = Convert . ToBoolean ( readtext [ 15 ] ) ; //will I clean out their mailbox?
2016-06-04 00:23:52 +08:00
}
}
}
}