Changes

Jump to navigation Jump to search
2,469 bytes added ,  21:08, 28 September 2019
→‎Inject static content: Shuffling section around
Line 374: Line 374:  
}
 
}
 
</source>
 
</source>
 +
 +
===Send a letter (using static content)===
 +
 +
To make uses of this class in your own project, thereby making the static mail data available, hook into the OnGameLaunch event, for example.
 +
 +
<source lang="c#">
 +
    /// <summary>
 +
    /// Fires after game is launched, right before first update tick. Happens once per game session (unrelated to loading saves).
 +
    /// All mods are loaded and initialized at this point, so this is a good time to set up mod integrations.
 +
    /// </summary>
 +
    private void OnGameLaunched(object sender, GameLaunchedEventArgs e)
 +
    {
 +
        Helper.Content.AssetEditors.Add(new MyModMail());
 +
    }
 +
</source>
 +
 +
Now that you have your letter loaded, it's time to send it to the player.  There are a couple different methods available to accomplish this as well, depending on your need.  Two examples are shown below.  The distinction between the two methods will be explained below:
 +
 +
<source lang="c#">
 +
    Game1.player.mailbox.Add("MyModMail1");
 +
    Game1.addMailForTomorrow("MyModMail2");
 +
</source>
 +
 +
The first method (Game1.player.mailbox.Add) adds the letter directly into the mailbox for the current day.  This can be accomplished in your "DayStaring" event code, for example.  Mail added directly to the mailbox is not "remembered" as being sent even after a save.  This is useful in some scenarios depending on your need.
 +
 +
The second method (Game1.addMailForTomorrow) will, as the name implies, add the letter to the player's mailbox on the next day.  This method remembers the mail (Id) sent making it possible not to send the same letter over and over.  This can be handled in "DayStaring", "DayEnding" or other events, as dictated by your need.
 +
 +
You may be able to put the letter directly into the mailbox and also have it be remembered using the mailRecieved collection.  You can simply add your mailId manually if you want it to be remembered when using the add directly to mailbox method.
 +
 +
If you want Stardew Valley to forget that a specific letter has already been sent, you can remove it from the mailReceived collection.  You can iterate through the collection as well using a foreach should you need to remove mail en mass.
 +
 +
<source lang="c#">
 +
    Game1.player.mailReceived.Remove("MyModMail1");
 +
</source>
 +
 +
That is all there is to sending a simple letter.  Attaching objects and sending money via letter is straight-forward, but sending recipes is more complicated  and will need some additional explanation at a future time.
    
===Inject dynamic content===
 
===Inject dynamic content===
49

edits

Navigation menu