using System.Collections.Generic; using CustomNPCFramework.Framework.NPCS; using Microsoft.Xna.Framework; using StardewValley; namespace CustomNPCFramework.Framework.Utilities { /// Used to keep track of all of the custom npcs. public class NpcTracker { /// A list used to keep track of the npcs. public List moddedNpcs; /// Construct an instance. public NpcTracker() { this.moddedNpcs = new List(); } /// Use this to add a new npc into the game. /// The game location to add the npc to. /// The extended npc to add to the location. public void addNewNpcToLocation(GameLocation loc, ExtendedNpc npc) { this.moddedNpcs.Add(npc); npc.defaultLocation = loc; npc.currentLocation = loc; loc.addCharacter(npc); } /// Add a npc to a location. /// The game location to add an npc to. /// The extended npc to add to the location. /// The tile position at the game location to add the mpc to. public void addNewNpcToLocation(GameLocation loc, ExtendedNpc npc, Vector2 tilePosition) { this.moddedNpcs.Add(npc); npc.defaultLocation = loc; npc.currentLocation = loc; npc.position.Value = tilePosition * Game1.tileSize; loc.addCharacter(npc); } /// Use this simply to remove a single npc from a location. public void removeCharacterFromLocation(GameLocation loc, ExtendedNpc npc) { loc.characters.Remove(npc); } /// Use this to completly remove and npc from the game as it is removed from the location and is no longer tracked. /// The npc to remove from the location. public void removeFromLocationAndTrackingList(ExtendedNpc npc) { npc.currentLocation?.characters.Remove(npc); this.moddedNpcs.Remove(npc); } /// Use this to clean up all of the npcs before the game is saved. public void cleanUpBeforeSave() { foreach (ExtendedNpc npc in this.moddedNpcs) { //npc.currentLocation.characters.Remove(npc); //Game1.removeThisCharacterFromAllLocations(npc); Game1.removeCharacterFromItsLocation(npc.Name); Class1.ModMonitor.Log("Removed an npc!"); //Do some saving code here. } } /// Use this to load in all of the npcs again after saving. public void afterSave() { foreach (ExtendedNpc npc in this.moddedNpcs) npc.defaultLocation.addCharacter(npc); } } }