2018-02-24 05:55:51 +08:00
|
|
|
using System.Collections.Generic;
|
2018-12-30 18:00:05 +08:00
|
|
|
using StardewValley;
|
2018-02-24 05:55:51 +08:00
|
|
|
|
|
|
|
namespace EventSystem.Framework
|
|
|
|
{
|
|
|
|
public class EventManager
|
|
|
|
{
|
|
|
|
public Dictionary<GameLocation, List<MapEvent>> mapEvents;
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Construct an instance.</summary>
|
2018-02-24 05:55:51 +08:00
|
|
|
public EventManager()
|
|
|
|
{
|
|
|
|
this.mapEvents = new Dictionary<GameLocation, List<MapEvent>>();
|
2018-12-30 18:00:05 +08:00
|
|
|
foreach (var v in Game1.locations)
|
|
|
|
this.addLocation(v.Name, false);
|
2018-02-24 05:55:51 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Adds an event to the map given the name of the map.</summary>
|
|
|
|
public virtual void addEvent(string mapName, MapEvent mapEvent)
|
2018-02-24 05:55:51 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
foreach (var pair in this.mapEvents)
|
2018-02-24 05:55:51 +08:00
|
|
|
{
|
2018-05-01 09:21:31 +08:00
|
|
|
if (pair.Key.Name == mapName)
|
2018-02-24 05:55:51 +08:00
|
|
|
pair.Value.Add(mapEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Adds an event to a map.</summary>
|
|
|
|
public virtual void addEvent(GameLocation location, MapEvent mapEvent)
|
2018-02-24 05:55:51 +08:00
|
|
|
{
|
|
|
|
foreach (var pair in this.mapEvents)
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
if (pair.Key == location)
|
2018-02-24 05:55:51 +08:00
|
|
|
pair.Value.Add(mapEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Adds a location to have events handled.</summary>
|
|
|
|
/// <param name="location">The location to handle events.</param>
|
|
|
|
public virtual void addLocation(GameLocation location)
|
2018-02-24 05:55:51 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
EventSystem.ModMonitor.Log($"Adding event processing for location: {location.Name}");
|
|
|
|
this.mapEvents.Add(location, new List<MapEvent>());
|
2018-02-24 05:55:51 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Adds a location to have events handled.</summary>
|
|
|
|
public virtual void addLocation(GameLocation location, List<MapEvent> events)
|
2018-02-24 05:55:51 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
EventSystem.ModMonitor.Log($"Adding event processing for location: {location.Name}");
|
|
|
|
this.mapEvents.Add(location, events);
|
2018-02-24 05:55:51 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Adds a location to handle events.</summary>
|
|
|
|
/// <param name="location">The name of the location. Can include farm buildings.</param>
|
2018-02-24 05:55:51 +08:00
|
|
|
/// <param name="isStructure">Used if the building is a stucture. True=building.</param>
|
2018-12-30 18:00:05 +08:00
|
|
|
public virtual void addLocation(string location, bool isStructure)
|
2018-02-24 05:55:51 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
EventSystem.ModMonitor.Log($"Adding event processing for location: {location}");
|
|
|
|
this.mapEvents.Add(Game1.getLocationFromName(location, isStructure), new List<MapEvent>());
|
2018-02-24 05:55:51 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Adds a location to have events handled.</summary>
|
|
|
|
/// <param name="location">The name of the location. Can include farm buildings.</param>
|
2018-02-24 05:55:51 +08:00
|
|
|
/// <param name="isStructure">Used if the building is a stucture. True=building.</param>
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <param name="events">A list of pre-initialized events.</param>
|
|
|
|
public virtual void addLocation(string location, bool isStructure, List<MapEvent> events)
|
2018-02-24 05:55:51 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
EventSystem.ModMonitor.Log($"Adding event processing for location: {location}");
|
|
|
|
this.mapEvents.Add(Game1.getLocationFromName(location, isStructure), events);
|
2018-02-24 05:55:51 +08:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Updates all events associated with the event manager.</summary>
|
2018-02-24 05:55:51 +08:00
|
|
|
public virtual void update()
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
if (Game1.player == null)
|
|
|
|
return;
|
|
|
|
if (!Game1.hasLoadedGame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this.mapEvents.TryGetValue(Game1.player.currentLocation, out List<MapEvent> events))
|
2018-02-24 05:55:51 +08:00
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
foreach (var v in events)
|
2018-02-24 05:55:51 +08:00
|
|
|
v.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|