Merge pull request #21 from Pathoschild/reimplement-no-more-pets

Reimplement NoMorePets
This commit is contained in:
janavarro95 2017-08-05 20:15:45 -07:00 committed by GitHub
commit 80c4633e99
2 changed files with 9 additions and 15 deletions

View File

@ -1,7 +1,9 @@
using System; using System;
using System.Linq;
using StardewModdingAPI; using StardewModdingAPI;
using StardewModdingAPI.Events; using StardewModdingAPI.Events;
using StardewValley; using StardewValley;
using StardewValley.Characters;
namespace Omegasis.NoMorePets namespace Omegasis.NoMorePets
{ {
@ -15,30 +17,20 @@ namespace Omegasis.NoMorePets
/// <param name="helper">Provides simplified APIs for writing mods.</param> /// <param name="helper">Provides simplified APIs for writing mods.</param>
public override void Entry(IModHelper helper) public override void Entry(IModHelper helper)
{ {
GameEvents.UpdateTick += this.GameEvents_UpdateTick; SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
} }
/********* /*********
** Private methods ** Private methods
*********/ *********/
/// <summary>The method invoked when the game updates (roughly 60 times per second).</summary> /// <summary>The method invoked after the player loads a save.</summary>
/// <param name="sender">The event sender.</param> /// <param name="sender">The event sender.</param>
/// <param name="e">The event data.</param> /// <param name="e">The event data.</param>
public void GameEvents_UpdateTick(object sender, EventArgs e) public void SaveEvents_AfterLoad(object sender, EventArgs e)
{ {
if (!Context.IsWorldReady) foreach (Pet pet in Utility.getAllCharacters().OfType<Pet>().ToArray())
return; pet.currentLocation.characters.Remove(pet);
string petName = Game1.player.getPetName();
if (Game1.player.currentLocation is Farm)
{
foreach (NPC npc in Game1.player.currentLocation.characters.ToArray())
{
if (npc.name == petName)
Game1.removeCharacterFromItsLocation(petName);
}
}
} }
} }
} }

View File

@ -23,3 +23,5 @@ All your pets will be removed automatically when you play the save.
1.4: 1.4:
* Internal refactoring. * Internal refactoring.
* Fixed villagers being removed if they match your pet name.
* Fixed pet not being removed if it's inside your house.