From ea100b10842c68ac0c1740ac1aff21693f43f690 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Wed, 18 Sep 2019 13:05:31 -0700 Subject: [PATCH] Added in wires, the battery bin, fixed machines not consuming energy. --- .../Graphics/Objects/Machines/BatteryBin.png | Bin 0 -> 353 bytes .../Objects/Machines/Wires/CopperWire.png | Bin 0 -> 270 bytes .../Framework/Crafting/CraftingRecipeBook.cs | 6 + .../Framework/Objects/Machines/Machine.cs | 33 +++- .../Framework/Objects/Machines/Wire.cs | 146 ++++++++++++++++++ .../Framework/Objects/ObjectManager.cs | 24 +++ .../Framework/Utilities/TimeUtilities.cs | 10 +- GeneralMods/Revitalize/ModCore.cs | 4 +- GeneralMods/Revitalize/Revitalize.csproj | 7 + 9 files changed, 217 insertions(+), 13 deletions(-) create mode 100644 GeneralMods/Revitalize/Content/Graphics/Objects/Machines/BatteryBin.png create mode 100644 GeneralMods/Revitalize/Content/Graphics/Objects/Machines/Wires/CopperWire.png create mode 100644 GeneralMods/Revitalize/Framework/Objects/Machines/Wire.cs diff --git a/GeneralMods/Revitalize/Content/Graphics/Objects/Machines/BatteryBin.png b/GeneralMods/Revitalize/Content/Graphics/Objects/Machines/BatteryBin.png new file mode 100644 index 0000000000000000000000000000000000000000..1ae15cf02f9d4a6d5b3a088bfa6054228c29e390 GIT binary patch literal 353 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D%zr9E97Lo9le z6AmyRI(+zldwcu;F6P%w6Gfov58qBm!{ZZ~Us}Tqu{(79x(|@l%$zetEkNuC2#kz^;=iDxv z3Y218XQ}Pm(|GcYW(-dxFOR{(?6$`GxRF`hCjGqyY~?+}eW@FM{AXEhrNSKGD<&kCHbHEnE5{y3Glr8(IUMCQ)K~(p z2F{uAAa2L!H|ot@BGxgF?%v)WanoR{!GRM84jf2OQ+Ew(v;6u(Quz)m+oeY;nfpF` sQ9Z(HXlUrWo$u{x)#I#LWqxNFlD5R9FFKV!3m9e$p00i_>zopr0NY895dZ)H literal 0 HcmV?d00001 diff --git a/GeneralMods/Revitalize/Content/Graphics/Objects/Machines/Wires/CopperWire.png b/GeneralMods/Revitalize/Content/Graphics/Objects/Machines/Wires/CopperWire.png new file mode 100644 index 0000000000000000000000000000000000000000..fca1663882166b7c38e019657572c7fa9224f3aa GIT binary patch literal 270 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|PI$UFhFJ8T zow$&%DL|yHUZOQkNjCS;v5Zd)c_wa8bu;#Ht$!dqp_Z8=kEM~#d?rtx$hPbPE9U1c zW^=dS`S92J_qlq8XRdr-o+i9hYVDKB&`U33VAylORp@sR%QTk5ci0%#wDe>+xF{@o z%I39FUc!U7UaG)yvB$#6H{563R#4JddhdT>eVh1>&1=rMnUr!D?-tB<2;Q#q`WI*0 zmP5IFtJfKXyb*X^(rU=A#QrPvLG6kIPyapWi8s~QESPGhXP)s&EY`l0S#CRvx9@F6 SnMXiBF?hQAxvX() + { + new CraftingRecipeComponent(new StardewValley.Object((int)Enums.SDVObject.CopperBar,1),1), + }, new CraftingRecipeComponent(ModCore.ObjectManager.GetItem("CopperWire"),2),null,0),true)); + + if (CraftingRecipesByGroup.ContainsKey(WorkbenchRecipes.craftingGroup)) { foreach(KeyValuePair recipe in WorkbenchRecipes.craftingRecipes) diff --git a/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs b/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs index 3087e042..5bf4401b 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs @@ -137,9 +137,22 @@ namespace Revitalize.Framework.Objects.Machines { get { - if (ModCore.Configs.machinesConfig.doMachinesConsumeEnergy == false) return false; - if (this.energyRequiredPer10Minutes == 0) return false; - if (this.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Consumes) return true; + if (ModCore.Configs.machinesConfig.doMachinesConsumeEnergy == false) + { + ModCore.log("Machine config disables energy consumption."); + return false; + } + if (this.energyRequiredPer10Minutes == 0) + { + ModCore.log("Machine rquires 0 energy to run."); + return false; + } + if (this.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Consumes) + { + ModCore.log("Machine does consume energy."); + return true; + } + ModCore.log("Unknown energy configuration."); return false; } } @@ -171,6 +184,7 @@ namespace Revitalize.Framework.Objects.Machines this.offsetKey = offsetKey; this.containerObject = obj; this.producedResources = ProducedResources?? new List(); + this.energyRequiredPer10Minutes = EnergyRequiredPer10Minutes; this.timeToProduce = TimeToProduce; this.updatesContainerObjectForProduction = UpdatesContainer; this.MinutesUntilReady = TimeToProduce; @@ -194,23 +208,28 @@ namespace Revitalize.Framework.Objects.Machines List energySources = new List(); if (this.ConsumesEnergy) { - energySources = this.EnergyGraphSearchSources(); //Only grab the network once. + ModCore.log("This machine drains energy: " + this.info.name); + energySources = this.EnergyGraphSearchSources(); //Only grab the network once. } if (this.ProducesItems) { - //ModCore.log("This produces items!"); + ModCore.log("This machine produces items: "+this.info.name); while (remaining > 0) { if (this.ConsumesEnergy) { - this.drainEnergyFromNetwork(energySources); //Continually drain from the network. + this.drainEnergyFromNetwork(energySources); //Continually drain from the network. if (this.EnergyManager.remainingEnergy < this.energyRequiredPer10Minutes) return false; + else + { + this.EnergyManager.consumeEnergy(this.energyRequiredPer10Minutes); //Consume the required amount of energy necessary. + } } else { - //ModCore.log("Does not produce energy!"); + //ModCore.log("Does not produce energy or consume energy so do whatever!"); } remaining -= 10; this.containerObject.MinutesUntilReady -= 10; diff --git a/GeneralMods/Revitalize/Framework/Objects/Machines/Wire.cs b/GeneralMods/Revitalize/Framework/Objects/Machines/Wire.cs new file mode 100644 index 00000000..fc6bb1cd --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Objects/Machines/Wire.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json; +using PyTK.CustomElementHandler; +using Revitalize.Framework.Objects.InformationFiles; +using Revitalize.Framework.Utilities; +using StardewValley; + +namespace Revitalize.Framework.Objects.Machines +{ + public class Wire: Machine + { + + public Wire() { } + + public Wire(CustomObjectData PyTKData, BasicItemInformation info) : base(PyTKData, info,null,0,0,true,"") + { + } + + public Wire(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, MultiTiledObject obj = null) : base(PyTKData, info, TileLocation,null,0,0,true,"",obj) + { + } + + public Wire(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, Vector2 offsetKey, MultiTiledObject obj = null) : base(PyTKData, info, TileLocation,offsetKey,null,0,0,true,"",obj) + { + } + + + public override bool minutesElapsed(int minutes, GameLocation environment) + { + return false; + } + + public override bool rightClicked(Farmer who) + { + if (this.location == null) + this.location = Game1.player.currentLocation; + if (Game1.menuUp || Game1.currentMinigame != null) return false; + + //ModCore.playerInfo.sittingInfo.sit(this, Vector2.Zero); + return true; + } + + /// + /// Creates the necessary components to display the machine menu properly. + /// + + public override Item getOne() + { + Wire component = new Wire(this.data, this.info.Copy(), this.TileLocation, this.offsetKey,this.containerObject); + return component; + } + + 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 + + Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"])); + Wire 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 void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f) + { + this.updateInfo(); + + 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; + + + if (Revitalize.ModCore.playerInfo.sittingInfo.SittingObject == this.containerObject && this.info.facingDirection == Enums.Direction.Up) + { + addedDepth += (this.containerObject.Height - 1) - ((int)(this.offsetKey.Y)); + if (this.info.ignoreBoundingBox) addedDepth += 1.5f; + } + //this.determineWireOrientation(); + 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)); + + } + + private void determineWireOrientation() + { + //TODO: Make this so that the correct wire orientation is used if I want to get fancy with wires and their graphics. + } + + + } +} diff --git a/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs index 05a4639e..2ab18da0 100644 --- a/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs +++ b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs @@ -168,6 +168,10 @@ namespace Revitalize.Framework.Objects private void loadInMachines() { + this.loadInWires(); + + + MultiTiledObject trashCan = new MultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Misc.TrashCan", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "TrashCan"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Trash Can", "Omegasis.Revitalize.Furniture.Misc.TrashCan", "A trash can where you can throw away unnecessary objects. It empties out at the beginning of each new day.", "Machine", Color.SteelBlue, -300, 0, false, 650, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "TrashCan"), new AnimationManager(), Color.White, true, new InventoryManager(36), null, null)); TrashCanTile trash1 = new TrashCanTile(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Misc.TrashCan", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "TrashCan"), typeof(TrashCanTile), Color.White, true), new BasicItemInformation("Trash Can", "Omegasis.Revitalize.Furniture.Misc.TrashCan", "A trash can where you can throw away unnecessary objects. It empties out at the beginning of each new day.", "Machine", Color.SteelBlue, -300, 0, false, 650, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "TrashCan"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "TrashCan"), new Animation(0, 0, 16, 16)), Color.White, true, new InventoryManager(36), null, null)); TrashCanTile trash2 = new TrashCanTile(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Furniture.Misc.TrashCan", TextureManager.GetTexture(ModCore.Manifest, "Furniture", "TrashCan"), typeof(TrashCanTile), Color.White, true), new BasicItemInformation("Trash Can", "Omegasis.Revitalize.Furniture.Misc.TrashCan", "A trash can where you can throw away unnecessary objects. It empties out at the beginning of each new day.", "Machine", Color.SteelBlue, -300, 0, false, 650, true, true, TextureManager.GetTexture(ModCore.Manifest, "Furniture", "TrashCan"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Furniture", "TrashCan"), new Animation(0, 16, 16, 16)), Color.White, false, new InventoryManager(36), null, null)); @@ -225,6 +229,26 @@ namespace Revitalize.Framework.Objects solarArray1Container.addComponent(new Vector2(0, 1), solarA3V1); solarArray1Container.addComponent(new Vector2(1, 1), solarA4V1); this.AddItem("SolarArrayTier1", solarArray1Container); + + + ///Consumes energy. Produces batteries. + MultiTiledObject batteryBin = new MultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.BatteryBin", TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Battery Bin", "Omegasis.Revitalize.Objects.Machines.BatteryBin", "Consumes energy over time to produce battery packs.", "Machine", Color.SteelBlue, -300, 0, false, 500, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "BatteryBin"), new Animation(0, 0, 16, 16)), Color.White, false, new InventoryManager(1), null, new Energy.EnergyManager(500, Enums.EnergyInteractionType.Consumes))); + Machine batteryBin_0_0 = new Machine(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.BatteryBin", TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Battery Bin", "Omegasis.Revitalize.Objects.Machines.BatteryBin", "Consumes energy over time to produce battery packs.", "Machine", Color.SteelBlue, -300, 0, false, 500, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "BatteryBin"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "BatteryBin"), new Animation(0, 0, 16, 16)), Color.White, false, new InventoryManager(1), null, new Energy.EnergyManager(500, Enums.EnergyInteractionType.Consumes)), new List() + { + new InformationFiles.ResourceInformation(new StardewValley.Object((int)Enums.SDVObject.BatteryPack,1),1,1,1,1,1,1,0,0,0,0) + + }, 1, TimeUtilities.GetMinutesFromTime(0, 1, 0), true, ""); + batteryBin.addComponent(new Vector2(0, 0), batteryBin_0_0); + this.AddItem("BatteryBin", batteryBin); + + } + + private void loadInWires() + { + MultiTiledObject copperWire = new MultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Wires.CopperWire", TextureManager.GetTexture(ModCore.Manifest, "Machines", "CopperWire"), typeof(Wire), Color.White, true), new BasicItemInformation("Copper Wire", "Omegasis.Revitalize.Objects.Machines.Wire.CopperWire", "Wire made from copper bars. Transfers energy between sources.", "Machine", Color.SteelBlue, -300, 0, false, 15, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "CopperWire"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "CopperWire"), new Animation(0, 0, 16, 16)), Color.White, true, null, null, new Energy.EnergyManager(100, Enums.EnergyInteractionType.Transfers), false)); + Wire copperWire_0_0 = new Wire(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Wires.CopperWire", TextureManager.GetTexture(ModCore.Manifest, "Machines", "CopperWire"), typeof(Wire), Color.White, true), new BasicItemInformation("Copper Wire", "Omegasis.Revitalize.Objects.Machines.Wire.CopperWire", "Wire made from copper bars. Transfers energy between sources.", "Machine", Color.SteelBlue, -300, 0, false, 15, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "CopperWire"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "CopperWire"), new Animation(0, 0, 16, 16)), Color.White, true, null, null, new Energy.EnergyManager(100, Enums.EnergyInteractionType.Transfers), false)); + copperWire.addComponent(new Vector2(0, 0), copperWire_0_0); + this.AddItem("CopperWire", copperWire); } private void loadInTools() diff --git a/GeneralMods/Revitalize/Framework/Utilities/TimeUtilities.cs b/GeneralMods/Revitalize/Framework/Utilities/TimeUtilities.cs index 22f5ff7e..ca340909 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/TimeUtilities.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/TimeUtilities.cs @@ -35,15 +35,15 @@ namespace Revitalize.Framework.Utilities private void parse(int Minutes) { this.years = Minutes / 60 / 24 / 7 / 4 / 4; - Minutes -= (Minutes / 60 / 24 / 7 / 4 / 4); + Minutes -= (this.years * 60 * 24 * 7 * 4 * 4); this.seasons = Minutes / 60 / 24 / 7 / 4; - Minutes -= (Minutes / 60 / 24 / 7 / 4); + Minutes -= (this.seasons * 60 * 24 * 7 * 4); this.weeks = Minutes / 60 / 24 / 7; - Minutes -= (Minutes / 60 / 24 / 7); + Minutes -= (this.weeks * 60 * 24 * 7); this.days = Minutes / 60 / 24; - Minutes -= (Minutes / 60 / 24); + Minutes -= (this.days * 60 * 24); this.hours = Minutes / 60; - this.minutes -= (Minutes / 60); + Minutes -= (this.hours * 60); this.minutes = Minutes; } diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index d5584915..81a2b7c4 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -562,7 +562,9 @@ namespace Revitalize ModCore.ObjectManager.GetItem("SolarPanelTier1",1), ModCore.ObjectManager.GetItem("SolarArrayTier1",1), new StardewValley.Object(Vector2.Zero,(int)Enums.SDVBigCraftable.Furnace,false), - ModCore.ObjectManager.GetItem("Lighthouse",1) + ModCore.ObjectManager.GetItem("Lighthouse",1), + ModCore.ObjectManager.GetItem("CopperWire"), + ModCore.ObjectManager.GetItem("BatteryBin",1) }); } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index b91c15d3..5e72e8c9 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -156,6 +156,7 @@ + @@ -414,6 +415,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -423,6 +427,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest