2018-03-04 19:36:19 +08:00
|
|
|
|
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;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace CustomNPCFramework.Framework.Utilities
|
|
|
|
|
{
|
2018-03-20 14:01:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to keep track of all of the custom npcs.
|
|
|
|
|
/// </summary>
|
2018-03-04 19:36:19 +08:00
|
|
|
|
public class NPCTracker
|
|
|
|
|
{
|
2018-03-04 20:36:46 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A list used to keep track of the npcs.
|
|
|
|
|
/// </summary>
|
2018-03-04 19:36:19 +08:00
|
|
|
|
public List<ExtendedNPC> moddedNPCS;
|
|
|
|
|
|
2018-03-04 20:36:46 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor.
|
|
|
|
|
/// </summary>
|
2018-03-04 19:36:19 +08:00
|
|
|
|
public NPCTracker()
|
|
|
|
|
{
|
|
|
|
|
this.moddedNPCS = new List<ExtendedNPC>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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-03-04 19:36:19 +08:00
|
|
|
|
public void addNewNPCToLocation(GameLocation loc,ExtendedNPC npc)
|
|
|
|
|
{
|
|
|
|
|
this.moddedNPCS.Add(npc);
|
|
|
|
|
npc.defaultLocation = loc;
|
2018-03-19 07:06:49 +08:00
|
|
|
|
npc.currentLocation = loc;
|
|
|
|
|
loc.addCharacter(npc);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-20 14:01:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add a npc to a location.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <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-03-19 07:06:49 +08:00
|
|
|
|
public void addNewNPCToLocation(GameLocation loc, ExtendedNPC npc, Vector2 tilePosition)
|
|
|
|
|
{
|
|
|
|
|
this.moddedNPCS.Add(npc);
|
|
|
|
|
npc.defaultLocation = loc;
|
|
|
|
|
npc.currentLocation = loc;
|
2018-05-01 09:21:31 +08:00
|
|
|
|
npc.position.Value = tilePosition*Game1.tileSize;
|
2018-03-04 19:36:19 +08:00
|
|
|
|
loc.addCharacter(npc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use this simply to remove a single npc from a location.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="loc"></param>
|
|
|
|
|
/// <param name="npc"></param>
|
|
|
|
|
public void removeCharacterFromLocation(GameLocation loc, ExtendedNPC npc)
|
|
|
|
|
{
|
|
|
|
|
loc.characters.Remove(npc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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-03-04 19:36:19 +08:00
|
|
|
|
public void removeFromLocationAndTrackingList(ExtendedNPC npc)
|
|
|
|
|
{
|
|
|
|
|
if (npc.currentLocation != null)
|
|
|
|
|
{
|
|
|
|
|
npc.currentLocation.characters.Remove(npc);
|
|
|
|
|
}
|
|
|
|
|
this.moddedNPCS.Remove(npc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use this to clean up all of the npcs before the game is saved.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void cleanUpBeforeSave()
|
|
|
|
|
{
|
|
|
|
|
foreach(ExtendedNPC npc in this.moddedNPCS)
|
|
|
|
|
{
|
|
|
|
|
//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.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use this to load in all of the npcs again after saving.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void afterSave()
|
|
|
|
|
{
|
|
|
|
|
foreach(ExtendedNPC npc in this.moddedNPCS)
|
|
|
|
|
{
|
|
|
|
|
npc.defaultLocation.addCharacter(npc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|