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