using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework; using Revitalize.Framework.Objects.Furniture; using Revitalize.Framework.Objects.Interfaces; using Revitalize.Framework.Objects.Items.Tools; using StardewModdingAPI; using StardewValley; using StardustCore.Animations; using StardustCore.UIUtilities; 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; public Dictionary ItemsByName; public Dictionary Tools; /// /// 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(); this.ItemsByName = new Dictionary(); this.Tools = new Dictionary(); } /// /// Loads in the items for the object and resource managers. /// public void loadInItems() { this.resources.loadInItems(); this.loadInTools(); } private void loadInTools() { PickaxeExtended bronzePick = new PickaxeExtended(new BasicItemInformation("Bronze Pickaxe", "Omegasis.Revitalize.Items.Tools.BronzePickaxe", "A sturdy pickaxe made from bronze.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "BronzePickaxe"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "BronzePickaxe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 2, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "BronzePickaxeWorking")); PickaxeExtended steelPick = new PickaxeExtended(new BasicItemInformation("Hardened Pickaxe", "Omegasis.Revitalize.Items.Tools.HardenedPickaxe", "A sturdy pickaxe made from hardened alloy.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "HardenedPickaxe"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "HardenedPickaxe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 3, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "HardenedPickaxeWorking")); PickaxeExtended titaniumPick = new PickaxeExtended(new BasicItemInformation("Titanium Pickaxe", "Omegasis.Revitalize.Items.Tools.TitaniumPickaxe", "A sturdy pickaxe made from titanium.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "TitaniumPickaxe"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "TitaniumPickaxe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 4, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "TitaniumPickaxeWorking")); AxeExtended bronzeAxe= new AxeExtended(new BasicItemInformation("Bronze Axe", "Omegasis.Revitalize.Items.Tools.BronzeAxe", "A sturdy axe made from bronze.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "BronzeAxe"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "BronzeAxe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 2, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "BronzeAxeWorking")); AxeExtended steelAxe = new AxeExtended(new BasicItemInformation("Hardened Axe", "Omegasis.Revitalize.Items.Tools.HardenedAxe", "A sturdy axe made from hardened alloy.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "HardenedAxe"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "HardenedAxe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null),3,TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "HardenedAxeWorking")); AxeExtended titaniumAxe = new AxeExtended(new BasicItemInformation("Titanium Axe", "Omegasis.Revitalize.Items.Tools.TitaniumAxe", "A sturdy axe made from Titanium.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "TitaniumAxe"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "TitaniumAxe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 4, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "TitaniumAxeWorking")); HoeExtended bronzeHoe = new HoeExtended(new BasicItemInformation("Bronze Hoe", "Omegasis.Revitalize.Items.Tools.BronzeHoe", "A sturdy hoe made from bronze.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "BronzeHoe"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "BronzeHoe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 2, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "BronzeHoeWorking")); HoeExtended steelHoe = new HoeExtended(new BasicItemInformation("Hardened Hoe", "Omegasis.Revitalize.Items.Tools.HardenedHoe", "A sturdy hoe made from hardened alloy.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "HardenedHoe"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "HardenedHoe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 3, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "HardenedHoeWorking")); HoeExtended titaniumHoe = new HoeExtended(new BasicItemInformation("Titanium Hoe", "Omegasis.Revitalize.Items.Tools.TitaniumHoe", "A sturdy hoe made from titanium.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "TitaniumHoe"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "TitaniumHoe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 4, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "TitaniumHoeWorking")); WateringCanExtended bronzeCan = new WateringCanExtended(new BasicItemInformation("Bronze Watering Can", "Omegasis.Revitalize.Items.Tools.BronzeWateringCan", "A sturdy watering can made from bronze.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "BronzeWateringCan"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "BronzeWateringCan"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 1, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "BronzeWateringCanWorking"),70); WateringCanExtended steelCan = new WateringCanExtended(new BasicItemInformation("Hardened Watering Can", "Omegasis.Revitalize.Items.Tools.HardenedWateringCan", "A sturdy watering can made from hardened alloy.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "HardenedWateringCan"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "HardenedWateringCan"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 2, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "HardenedWateringCanWorking"), 100); WateringCanExtended titaniumCan = new WateringCanExtended(new BasicItemInformation("Titanium Watering Can", "Omegasis.Revitalize.Items.Tools.TitaniumWateringCan", "A sturdy watering can made from titanium.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "TitaniumWateringCan"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "TitaniumWateringCan"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 3, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "TitaniumWateringCanWorking"), 125); this.Tools.Add("BronzePickaxe", bronzePick); this.Tools.Add("HardenedPickaxe", steelPick); this.Tools.Add("TitaniumPickaxe", titaniumPick); this.Tools.Add("BronzeAxe", bronzeAxe); this.Tools.Add("HardenedAxe", steelAxe); this.Tools.Add("TitaniumAxe", titaniumAxe); this.Tools.Add("BronzeHoe", bronzeHoe); this.Tools.Add("HardenedHoe", steelHoe); this.Tools.Add("TitaniumHoe", titaniumHoe); this.Tools.Add("BronzeWateringCan", bronzeCan); this.Tools.Add("HardenedWateringCan", steelCan); this.Tools.Add("TitaniumWateringCan", titaniumCan); } /// /// 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 in an item to be tracked by the mod's object manager. /// /// /// public void AddItem(string key, CustomObject I) { if (this.ItemsByName.ContainsKey(key)) { throw new Exception("Item with the same key has already been added into the mod!"); } else { this.ItemsByName.Add(key, I); } } /// /// Gets an item from the list of modded items. /// /// /// /// public CustomObject GetItem(string Key,int Stack=1) { if (this.ItemsByName.ContainsKey(Key)) { Item I= this.ItemsByName[Key].getOne(); I.Stack = Stack; return (CustomObject)I; } else { return null; } } /// /// Gets a tool from the list of managed tools. /// /// /// public Item GetTool(string Name) { if (this.Tools.ContainsKey("Name")) return this.Tools[Name].getOne(); else return null; } /// /// 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() { } /// /// Scans all mod items to try to find a match. /// /// /// /// public Item getItemByIDAndType(string ID,Type T) { foreach(var v in this.chairs) { if(v.Value.GetType()==T && v.Value.info.id == ID) { Item I= v.Value.getOne(); return I; } } foreach(var v in this.furnitureStorage) { if (v.Value.GetType() == T && v.Value.info.id == ID) { Item I = v.Value.getOne(); return I; } } foreach(var v in this.generic) { if (v.Value.GetType() == T && v.Value.info.id == ID) { Item I = v.Value.getOne(); return I; } } foreach(var v in this.ItemsByName) { if (v.Value.GetType() == T && v.Value.info.id == ID) { Item I = v.Value.getOne(); return I; } } foreach(var v in this.lamps) { if (v.Value.GetType() == T && v.Value.info.id == ID) { Item I = v.Value.getOne(); return I; } } foreach(var v in this.miscellaneous) { if (v.Value.GetType() == T && v.Value.info.id == ID) { Item I = v.Value.getOne(); return I; } } foreach(var v in this.rugs) { if (v.Value.GetType() == T && v.Value.info.id == ID) { Item I = v.Value.getOne(); return I; } } foreach(var v in this.tables) { if (v.Value.GetType() == T && v.Value.info.id == ID) { Item I = v.Value.getOne(); return I; } } foreach(var v in this.resources.ores) { if (v.Value.GetType() == T && v.Value.info.id == ID) { Item I = v.Value.getOne(); return I; } } foreach(var v in this.resources.oreVeins) { if (v.Value.GetType() == T && v.Value.info.id == ID) { Item I = v.Value.getOne(); return I; } } foreach(var v in this.Tools) { if (v.Value.GetType() == T && (v.Value as IItemInfo).Info.id == ID) { Item I = v.Value.getOne(); return I; } } return null; } } }