2018-12-30 18:00:05 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using CustomNPCFramework.Framework.NPCS;
|
2018-03-19 07:06:49 +08:00
|
|
|
using Microsoft.Xna.Framework;
|
2018-03-04 19:36:19 +08:00
|
|
|
using StardewValley;
|
|
|
|
|
|
|
|
namespace CustomNPCFramework.Framework.Utilities
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Used to keep track of all of the custom npcs.</summary>
|
|
|
|
public class NpcTracker
|
2018-03-04 19:36:19 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>A list used to keep track of the npcs.</summary>
|
|
|
|
public List<ExtendedNpc> moddedNpcs;
|
2018-03-04 19:36:19 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
|
|
|
public NpcTracker()
|
2018-03-04 19:36:19 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
this.moddedNpcs = new List<ExtendedNpc>();
|
2018-03-04 19:36:19 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Use this to add a new npc into the game.</summary>
|
2018-03-20 14:01:43 +08:00
|
|
|
/// <param name="loc">The game location to add the npc to.</param>
|
|
|
|
/// <param name="npc">The extended npc to add to the location.</param>
|
2018-12-30 18:00:05 +08:00
|
|
|
public void addNewNpcToLocation(GameLocation loc, ExtendedNpc npc)
|
2018-03-04 19:36:19 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
this.moddedNpcs.Add(npc);
|
2018-03-04 19:36:19 +08:00
|
|
|
npc.defaultLocation = loc;
|
2018-03-19 07:06:49 +08:00
|
|
|
npc.currentLocation = loc;
|
|
|
|
loc.addCharacter(npc);
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Add a npc to a location.</summary>
|
2018-03-20 14:01:43 +08:00
|
|
|
/// <param name="loc">The game location to add an npc to.</param>
|
|
|
|
/// <param name="npc">The extended npc to add to the location.</param>
|
|
|
|
/// <param name="tilePosition">The tile position at the game location to add the mpc to.</param>
|
2018-12-30 18:00:05 +08:00
|
|
|
public void addNewNpcToLocation(GameLocation loc, ExtendedNpc npc, Vector2 tilePosition)
|
2018-03-19 07:06:49 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
this.moddedNpcs.Add(npc);
|
2018-03-19 07:06:49 +08:00
|
|
|
npc.defaultLocation = loc;
|
|
|
|
npc.currentLocation = loc;
|
2018-12-30 18:00:05 +08:00
|
|
|
npc.position.Value = tilePosition * Game1.tileSize;
|
2018-03-04 19:36:19 +08:00
|
|
|
loc.addCharacter(npc);
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Use this simply to remove a single npc from a location.</summary>
|
|
|
|
public void removeCharacterFromLocation(GameLocation loc, ExtendedNpc npc)
|
2018-03-04 19:36:19 +08:00
|
|
|
{
|
|
|
|
loc.characters.Remove(npc);
|
|
|
|
}
|
2018-12-30 18:00:05 +08:00
|
|
|
|
|
|
|
/// <summary>Use this to completly remove and npc from the game as it is removed from the location and is no longer tracked.</summary>
|
2018-03-20 14:01:43 +08:00
|
|
|
/// <param name="npc">The npc to remove from the location.</param>
|
2018-12-30 18:00:05 +08:00
|
|
|
public void removeFromLocationAndTrackingList(ExtendedNpc npc)
|
2018-03-04 19:36:19 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
npc.currentLocation?.characters.Remove(npc);
|
|
|
|
this.moddedNpcs.Remove(npc);
|
2018-03-04 19:36:19 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Use this to clean up all of the npcs before the game is saved.</summary>
|
2018-03-04 19:36:19 +08:00
|
|
|
public void cleanUpBeforeSave()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
foreach (ExtendedNpc npc in this.moddedNpcs)
|
2018-03-04 19:36:19 +08:00
|
|
|
{
|
|
|
|
//npc.currentLocation.characters.Remove(npc);
|
|
|
|
//Game1.removeThisCharacterFromAllLocations(npc);
|
2018-05-01 09:21:31 +08:00
|
|
|
Game1.removeCharacterFromItsLocation(npc.Name);
|
2018-03-04 19:36:19 +08:00
|
|
|
Class1.ModMonitor.Log("Removed an npc!");
|
|
|
|
//Do some saving code here.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Use this to load in all of the npcs again after saving.</summary>
|
2018-03-04 19:36:19 +08:00
|
|
|
public void afterSave()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
foreach (ExtendedNpc npc in this.moddedNpcs)
|
2018-03-04 19:36:19 +08:00
|
|
|
npc.defaultLocation.addCharacter(npc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|