using StardewValley; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EventSystem.Framework { public class EventManager { public Dictionary> mapEvents; /// /// Constructor. /// public EventManager() { this.mapEvents = new Dictionary>(); foreach(var v in Game1.locations) { 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() { List events = new List(); if (Game1.player == null) return; if (Game1.hasLoadedGame == false) return; bool ok=this.mapEvents.TryGetValue(Game1.player.currentLocation, out events); if (ok == false) return; else { foreach(var v in events) { v.update(); } } } } }