From 14fb72fdb947b394dd4bcad68bda0d28d87ac52c Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Fri, 16 Aug 2019 17:19:20 -0700 Subject: [PATCH] Added in tin ore and made ore be stored in ResourceManager.cs --- .../Graphics/Items/Resources/Ore/TinOre.png | Bin 0 -> 204 bytes .../Framework/Objects/Items/Resources/Ore.cs | 224 ++++++++++++++++++ .../Framework/Objects/ResourceManager.cs | 54 ++++- GeneralMods/Revitalize/ModCore.cs | 8 +- GeneralMods/Revitalize/Revitalize.csproj | 4 + 5 files changed, 277 insertions(+), 13 deletions(-) create mode 100644 GeneralMods/Revitalize/Content/Graphics/Items/Resources/Ore/TinOre.png create mode 100644 GeneralMods/Revitalize/Framework/Objects/Items/Resources/Ore.cs diff --git a/GeneralMods/Revitalize/Content/Graphics/Items/Resources/Ore/TinOre.png b/GeneralMods/Revitalize/Content/Graphics/Items/Resources/Ore/TinOre.png new file mode 100644 index 0000000000000000000000000000000000000000..d93efb604edc39a1dc20bab9e9c2cce0739f35ef GIT binary patch literal 204 zcmV;-05kuIP)M2=APlaces an object down. + public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) + { + /* + this.updateDrawPosition(x, y); + this.location = location; + + if (this.location == null) this.location = Game1.player.currentLocation; + this.TileLocation = new Vector2((int)(x / Game1.tileSize), (int)(y / Game1.tileSize)); + //ModCore.log("TileLocation: " + this.TileLocation); + /* + return base.placementAction(location, x, y, who); + + //this.updateLightManager(); + + this.performDropDownAction(who); + location.objects.Add(this.TileLocation, this); + */ + //return true; + return false; + } + + + public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow) + { + if (drawStackNumber && this.maximumStackSize() > 1 && ((double)scaleSize > 0.3 && this.Stack != int.MaxValue) && this.Stack > 1) + Utility.drawTinyDigits(this.Stack, spriteBatch, location + new Vector2((float)(Game1.tileSize - Utility.getWidthOfTinyDigitString(this.Stack, 3f * scaleSize)) + 3f * scaleSize, (float)((double)Game1.tileSize - 18.0 * (double)scaleSize + 2.0)), 3f * scaleSize, 1f, Color.White); + if (drawStackNumber && this.Quality > 0) + { + float num = this.Quality < 4 ? 0.0f : (float)((Math.Cos((double)Game1.currentGameTime.TotalGameTime.Milliseconds * Math.PI / 512.0) + 1.0) * 0.0500000007450581); + spriteBatch.Draw(Game1.mouseCursors, location + new Vector2(12f, (float)(Game1.tileSize - 12) + num), new Microsoft.Xna.Framework.Rectangle?(this.Quality < 4 ? new Microsoft.Xna.Framework.Rectangle(338 + (this.Quality - 1) * 8, 400, 8, 8) : new Microsoft.Xna.Framework.Rectangle(346, 392, 8, 8)), Color.White * transparency, 0.0f, new Vector2(4f, 4f), (float)(3.0 * (double)scaleSize * (1.0 + (double)num)), SpriteEffects.None, layerDepth); + } + spriteBatch.Draw(this.displayTexture, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * transparency, 0f, new Vector2((float)(this.animationManager.currentAnimation.sourceRectangle.Width / 2), (float)(this.animationManager.currentAnimation.sourceRectangle.Height)), scaleSize*4f, SpriteEffects.None, layerDepth); + } + + public override Item getOne() + { + Ore component = new Ore(this.data, this.info.Copy(), this.TileLocation); + component.Stack = 1; + return component; + } + + public override object getReplacement() + { + return base.getReplacement(); + } + + public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) + { + //instead of using this.offsetkey.x use get additional save data function and store offset key there + + Ore self = Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["GUID"]); + if (self == null) + { + return null; + } + + /* + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"])) + { + //Get new container + MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["ParentGUID"]); + self.containerObject = obj; + obj.addComponent(offsetKey, self); + //Revitalize.ModCore.log("ADD IN AN OBJECT!!!!"); + Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["ParentGUID"], (MultiTiledObject)obj); + } + else + { + self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["ParentGUID"]]; + Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]].addComponent(offsetKey, self); + //Revitalize.ModCore.log("READD AN OBJECT!!!!"); + } + */ + return (ICustomObject)self; + } + + public override Dictionary getAdditionalSaveData() + { + Dictionary saveData = base.getAdditionalSaveData(); + saveData.Add("GUID", this.guid.ToString()); + Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); + + return saveData; + + } + + protected string recreateParentId(string id) + { + StringBuilder b = new StringBuilder(); + string[] splits = id.Split('.'); + for (int i = 0; i < splits.Length - 1; i++) + { + b.Append(splits[i]); + if (i == splits.Length - 2) continue; + b.Append("."); + } + return b.ToString(); + } + + /// What happens when the object is drawn at a tile location. + public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f) + { + if (this.info.ignoreBoundingBox == true) + { + x *= -1; + y *= -1; + } + + if (this.info == null) + { + Revitalize.ModCore.log("info is null"); + if (this.syncObject == null) Revitalize.ModCore.log("DEAD SYNC"); + } + if (this.animationManager == null) Revitalize.ModCore.log("Animation Manager Null"); + if (this.displayTexture == null) Revitalize.ModCore.log("Display texture is null"); + + //The actual planter box being drawn. + if (this.animationManager == null) + { + if (this.animationManager.getExtendedTexture() == null) + ModCore.ModMonitor.Log("Tex Extended is null???"); + + spriteBatch.Draw(this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(y * Game1.tileSize) / 10000f)); + // Log.AsyncG("ANIMATION IS NULL?!?!?!?!"); + } + + else + { + //Log.AsyncC("Animation Manager is working!"); + float addedDepth = 0; + this.animationManager.draw(spriteBatch, this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)((y + addedDepth) * Game1.tileSize) / 10000f) + .00001f); + try + { + this.animationManager.tickAnimation(); + // Log.AsyncC("Tick animation"); + } + catch (Exception err) + { + ModCore.ModMonitor.Log(err.ToString()); + } + } + + // spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)((double)tileLocation.X * (double)Game1.tileSize + (((double)tileLocation.X * 11.0 + (double)tileLocation.Y * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2), (float)((double)tileLocation.Y * (double)Game1.tileSize + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2))), new Rectangle?(new Rectangle((int)((double)tileLocation.X * 51.0 + (double)tileLocation.Y * 77.0) % 3 * 16, 128 + this.whichForageCrop * 16, 16, 16)), Color.White, 0.0f, new Vector2(8f, 8f), (float)Game1.pixelZoom, SpriteEffects.None, (float)(((double)tileLocation.Y * (double)Game1.tileSize + (double)(Game1.tileSize / 2) + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) / 10000.0)); + + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs index 2be73957..2e591434 100644 --- a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs +++ b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.Xna.Framework; using Revitalize.Framework.Factories.Objects.Resources; using Revitalize.Framework.Objects.InformationFiles; +using Revitalize.Framework.Objects.Items.Resources; using Revitalize.Framework.Objects.Resources.OreVeins; using Revitalize.Framework.Utilities; using StardewValley; @@ -28,8 +29,9 @@ namespace Revitalize.Framework.Objects /// /// A list of all of the ores held by the resource manager. /// - public Dictionary ores; + public Dictionary oreVeins; public Dictionary oreResourceInformationTable; + public Dictionary ores; /// /// A list of all visited floors on the current visit to the mines. @@ -42,12 +44,14 @@ namespace Revitalize.Framework.Objects public ResourceManager() { self = this; - this.ores = new Dictionary(); + this.oreVeins = new Dictionary(); this.oreResourceInformationTable = new Dictionary(); + this.ores = new Dictionary(); this.visitedFloors = new List(); - this.serializeOre(); + this.serializeOreVeins(); this.loadOreVeins(); + this.loadInOreItems(); } /// @@ -111,7 +115,7 @@ namespace Revitalize.Framework.Objects } foreach (var v in objs) { - this.ores.Add(v.Value.info.id, v.Value); + this.oreVeins.Add(v.Value.info.id, v.Value); //ModCore.ObjectManager.lamps.Add(v.Value.info.id, v.Value); } } @@ -121,7 +125,7 @@ namespace Revitalize.Framework.Objects /// /// Serializes an example ore to eb /// - private void serializeOre() { + private void serializeOreVeins() { OreVeinObj testOre = new OreVeinObj(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Resources.Ore.Test", TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Test"), typeof(OreVeinTile), Color.White), new BasicItemInformation("Test Ore Vein", "Omegasis.Revitalize.Resources.Ore.Test", "A ore vein that is used for testing purposes.", "Revitalize.Ore", Color.Black, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Test"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Resources.Ore", "Test"), new Animation(0, 0, 16, 16)), Color.White, false, null, null)); OreVeinTile testOre_0_0= new OreVeinTile(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Resources.Ore.Test", TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Test"), typeof(OreVeinTile), Color.White), new BasicItemInformation("Test Ore Vein", "Omegasis.Revitalize.Resources.Ore.Test", "A ore vein that is used for testing purposes.", "Revitalize.Ore", Color.Black, -300, 0, false, 350, true, true, TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Test"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Resources.Ore", "Test"), new Animation(0, 0, 16, 16)), Color.White, false, null, null), new InformationFiles.OreResourceInformation(new StardewValley.Object(211, 1), true, true, true, false, new List() @@ -138,11 +142,37 @@ namespace Revitalize.Framework.Objects OreFactoryInfo testOre_0_0_file = new OreFactoryInfo(testOre_0_0); OreFactoryInfo testOre_file = new OreFactoryInfo(testOre); - ModCore.Serializer.SerializeContentFile("TestOre_0_0", testOre_0_0_file, this.oreResourceDataPath); - ModCore.Serializer.SerializeContentFile("TestOre", testOre_file, this.oreResourceDataPath); + ModCore.Serializer.SerializeContentFile("TestOre_0_0", testOre_0_0_file,Path.Combine(this.oreResourceDataPath,"TestOre")); + ModCore.Serializer.SerializeContentFile("TestOre", testOre_file, Path.Combine(this.oreResourceDataPath, "TestOre")); } + private void loadInOreItems() + { + Ore tinOre = new Ore(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Items.Resources.Ore.TinOre", TextureManager.GetTexture(ModCore.Manifest, "Items.Resources.Ore", "TinOre"), typeof(Ore), Color.White, true), new BasicItemInformation("Tin Ore", "Omegasis.Revitalize.Items.Resources.Ore.TinOre", "Tin ore that can be smelted into tin ingots for further use.", "Ore", Color.Silver, -300, 0, false, 85, false, false, TextureManager.GetTexture(ModCore.Manifest, "Items.Resources.Ore", "TinOre"), new AnimationManager(), Color.White, true, null, null), 1); + this.ores.Add("Tin", tinOre); + } + + /// + /// Gets an ore from the list of stored ores in this mod. + /// + /// + /// + /// + public Ore getOre(string name,int Stack=1) + { + if (this.ores.ContainsKey(name)) + { + Ore o = (Ore)this.ores[name].getOne(); + o.Stack = Stack; + return o; + } + else + { + return null; + } + } + /// /// Checks to see if a resource can be spawned here. /// @@ -169,10 +199,10 @@ namespace Revitalize.Framework.Objects /// public bool spawnOreVein(string name, GameLocation Location, Vector2 TilePosition) { - if (this.ores.ContainsKey(name)) + if (this.oreVeins.ContainsKey(name)) { OreVeinObj spawn; - this.ores.TryGetValue(name, out spawn); + this.oreVeins.TryGetValue(name, out spawn); if (spawn != null) { spawn = (OreVeinObj)spawn.getOne(); @@ -224,7 +254,7 @@ namespace Revitalize.Framework.Objects } List spawnableOreVeins = new List(); //Get a list of all of the ores that can spawn on this mine level. - foreach (KeyValuePair pair in this.ores) + foreach (KeyValuePair pair in this.oreVeins) { if (pair.Value.resourceInfo.canSpawnAtLocation() && (pair.Value.resourceInfo as OreResourceInformation).canSpawnOnCurrentMineLevel()) { @@ -294,7 +324,7 @@ namespace Revitalize.Framework.Objects { List spawnableOreVeins = new List(); //Get a list of all of the ores that can spawn on this mine level. - foreach (KeyValuePair pair in this.ores) + foreach (KeyValuePair pair in this.oreVeins) { if ((pair.Value.resourceInfo as OreResourceInformation).spawnsInQuarry) { @@ -348,7 +378,7 @@ namespace Revitalize.Framework.Objects List spawnableOreVeins = new List(); //Get a list of all of the ores that can spawn on this mine level. - foreach (KeyValuePair pair in this.ores) + foreach (KeyValuePair pair in this.oreVeins) { if ((pair.Value.resourceInfo as OreResourceInformation).spawnsOnFarm) { diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 62877151..8ec245ec 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -21,6 +21,7 @@ using StardustCore.Animations; using StardewValley.Menus; using Revitalize.Framework.Objects.Extras; using Revitalize.Framework.Minigame.SeasideScrambleMinigame; +using Revitalize.Framework.Objects.Items.Resources; namespace Revitalize { @@ -208,6 +209,8 @@ namespace Revitalize TextureManager.GetTextureManager(Manifest, "InventoryMenu").searchForTextures(ModHelper, this.ModManifest, Path.Combine("Content", "Graphics", "Menus", "InventoryMenu")); TextureManager.AddTextureManager(Manifest, "Resources.Ore"); TextureManager.GetTextureManager(Manifest, "Resources.Ore").searchForTextures(ModHelper, this.ModManifest, Path.Combine("Content", "Graphics", "Objects", "Resources", "Ore")); + TextureManager.AddTextureManager(Manifest, "Items.Resources.Ore"); + TextureManager.GetTextureManager(Manifest, "Items.Resources.Ore").searchForTextures(ModHelper, this.ModManifest, Path.Combine("Content", "Graphics", "Items", "Resources", "Ore")); //TextureManager.addTexture("Furniture","Oak Chair", new Texture2DExtended(this.Helper, this.ModManifest, Path.Combine("Content","Graphics","Furniture", "Chairs", "Oak Chair.png"))); //Framework.Graphics.TextureManager.TextureManagers.Add("Furniture", new TextureManager(this.Helper.DirectoryPath, Path.Combine("Content", "Graphics", "Furniture"))); @@ -377,7 +380,7 @@ namespace Revitalize //Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Chairs.OakChair")); //Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Rugs.RugTest")); //Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Tables.OakTable")); - Game1.player.addItemToInventory(ObjectManager.getLamp("Omegasis.Revitalize.Furniture.Lamps.OakLamp")); + //Game1.player.addItemToInventory(ObjectManager.getLamp("Omegasis.Revitalize.Furniture.Lamps.OakLamp")); //Game1.player.addItemToInventory(ObjectManager.getObject("Omegasis.Revitalize.Furniture.Arcade.SeasideScramble",ObjectManager.miscellaneous)); //Game1.player.addItemToInventory(ObjectManager.getStorageFuriture("Omegasis.Revitalize.Furniture.Storage.OakCabinet")); @@ -389,6 +392,9 @@ namespace Revitalize */ //Game1.player.addItemToInventory(ObjectManager.resources.ores["Test"].getOne()); + + Game1.player.addItemToInventory(ObjectManager.resources.getOre("Tin",19)); + ObjectManager.resources.spawnOreVein("Omegasis.Revitalize.Resources.Ore.Test", new Vector2(8, 7)); } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 66600b1c..85d1a9db 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -125,6 +125,7 @@ + @@ -167,6 +168,9 @@ + + PreserveNewest + Always