using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Revitalize.Framework.Objects.Furniture; using StardewModdingAPI; using StardewValley; namespace Revitalize.Framework.Objects { /// /// Deals with handling all objects for the mod. /// public class ObjectManager { /// /// All of the object managers id'd by a mod's or content pack's unique id. /// public static Dictionary ObjectPools; /// /// The name of this object manager. /// public string name; /// /// All of the chairs held by this object pool. /// public Dictionary chairs; /// /// All of the tables held by this object pool. /// public Dictionary tables; /// /// All of the lamps held by this object pool. /// public Dictionary lamps; /// /// All of the rugs held by this object pool. /// public Dictionary rugs; public Dictionary furnitureStorage; public Dictionary generic; /// /// Misc. items for this mod. /// public Dictionary miscellaneous; public ResourceManager resources; /// /// Constructor. /// public ObjectManager() { this.initialize(); } /// /// Constructor. /// /// public ObjectManager(IManifest manifest) { this.name = manifest.UniqueID; this.initialize(); } /// /// Initialize all objects used to manage this class. /// private void initialize() { this.chairs = new Dictionary(); this.tables = new Dictionary(); this.lamps = new Dictionary(); this.rugs = new Dictionary(); this.furnitureStorage = new Dictionary(); this.generic = new Dictionary(); this.miscellaneous = new Dictionary(); this.resources = new ResourceManager(); } /// /// Gets a random object from the dictionary passed in. /// /// /// public Item getRandomObject(Dictionary dictionary) { if (dictionary.Count == 0) return null; List objs = new List(); foreach(KeyValuePair pair in dictionary) { objs.Add(pair.Value); } int rand = Game1.random.Next(0,objs.Count); return objs[rand].getOne(); } /// /// Gets an object from the dictionary that is passed in. /// /// /// /// public Item getObject(string objectName, Dictionary dictionary) { if (dictionary.ContainsKey(objectName)) { return dictionary[objectName].getOne(); } else { throw new Exception("Object pool doesn't contain said object."); } } public Item getObject(string objectName, Dictionary dictionary) { if (dictionary.ContainsKey(objectName)) { return dictionary[objectName].getOne(); } else { throw new Exception("Object pool doesn't contain said object."); } } /// /// Gets a chair from the object manager. /// /// /// public ChairMultiTiledObject getChair(string name) { if (this.chairs.ContainsKey(name)) { return (ChairMultiTiledObject)this.chairs[name].getOne(); } else { throw new Exception("Object pool doesn't contain said object."); } } /// /// Gets a table from the object manager. /// /// /// public TableMultiTiledObject getTable(string name) { if (this.tables.ContainsKey(name)) { return (TableMultiTiledObject)this.tables[name].getOne(); } else { throw new Exception("Object pool doesn't contain said object."); } } /// /// Gets a lamp from the object manager. /// /// /// public LampMultiTiledObject getLamp(string name) { if (this.lamps.ContainsKey(name)) { return (LampMultiTiledObject)this.lamps[name].getOne(); } else { throw new Exception("Object pool doesn't contain said object."); } } /// /// Gets storage furniture from the object manager. /// /// /// public StorageFurnitureOBJ getStorageFuriture(string name) { if (this.furnitureStorage.ContainsKey(name)) { return (StorageFurnitureOBJ)this.furnitureStorage[name].getOne(); } else { throw new Exception("Object pool doesn't contain said object."); } } /// /// Adds a new object manager to the master pool of managers. /// /// public static void AddObjectManager(IManifest Manifest) { if (ObjectPools == null) ObjectPools = new Dictionary(); ObjectPools.Add(Manifest.UniqueID, new ObjectManager(Manifest)); } /// /// Cleans up all stored information. /// public void returnToTitleCleanUp() { } } }