Changes

Jump to navigation Jump to search
→‎Possible breaking changes: + migration code for wasPetToday
Line 59: Line 59:  
| <tt>Pet</tt>
 
| <tt>Pet</tt>
 
| <tt>wasPetToday</tt>  
 
| <tt>wasPetToday</tt>  
| Replaced by <tt>lastPetDay</tt>, which is the <tt>Game1.Date.TotalDays</tt> value when it was last pet by each player.
+
| Replaced by <tt>lastPetDay</tt>, which is the <tt>Game1.Date.TotalDays</tt> value when it was last pet by each player. To check if ''any'' player pet them today:
 +
<source lang="c#">
 +
private bool WasPetToday(Pet pet)
 +
{
 +
    NetLongDictionary<int, NetInt> lastPettedDays = ModEntry.ReflectionHelper.GetField<NetLongDictionary<int, NetInt>>(pet, "lastPetDay").GetValue();
 +
    return lastPettedDays.Values.Any(day => day == Game1.Date.TotalDays);
 +
}
 +
</source>
 +
 
 +
To check if the current player pet them today:
 +
<source lang="c#">
 +
private bool WasPetTodayByCurrentPlayer(Pet pet)
 +
{
 +
    NetLongDictionary<int, NetInt> lastPettedDays = ModEntry.ReflectionHelper.GetField<NetLongDictionary<int, NetInt>>(pet, "lastPetDay").GetValue();
 +
    return lastPettedDays.TryGetValue(Game1.player.UniqueMultiplayerID, out int lastDay) && lastDay == Game1.Date.TotalDays;
 +
}
 +
</source>
 
|}</li>
 
|}</li>
 
</ul>
 
</ul>
translators
8,403

edits

Navigation menu