From 877e40ae395a8480817e65cbb335415a4ee900ba Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Mon, 9 Sep 2019 15:44:25 -0700 Subject: [PATCH] Added in simple machines and tested to make sure they produce items. They do for non-energy consuming items. Also added in the sandbox which is a wip. --- .../Graphics/Objects/Machines/Sandbox.png | Bin 0 -> 588 bytes .../Framework/Configs/ConfigManager.cs | 6 + .../Framework/Configs/GlobalMachineConfig.cs | 33 ++ .../Objects/Resources/OreFactoryInfo.cs | 2 +- .../Framework/Objects/CustomObject.cs | 3 +- .../OreResourceInformation.cs | 2 +- ...ceInformaton.cs => ResourceInformation.cs} | 17 +- .../Framework/Objects/Machines/Machine.cs | 356 +++++++++++++++++- .../Framework/Objects/MultiTiledComponent.cs | 61 +++ .../Framework/Objects/ObjectManager.cs | 33 ++ .../Framework/Objects/ResourceManager.cs | 14 +- .../Objects/Resources/OreVeins/OreVeinObj.cs | 2 +- .../Objects/Resources/OreVeins/OreVeinTile.cs | 14 +- GeneralMods/Revitalize/ModCore.cs | 8 +- GeneralMods/Revitalize/Revitalize.csproj | 6 +- 15 files changed, 533 insertions(+), 24 deletions(-) create mode 100644 GeneralMods/Revitalize/Content/Graphics/Objects/Machines/Sandbox.png create mode 100644 GeneralMods/Revitalize/Framework/Configs/GlobalMachineConfig.cs rename GeneralMods/Revitalize/Framework/Objects/InformationFiles/{ResourceInformaton.cs => ResourceInformation.cs} (89%) diff --git a/GeneralMods/Revitalize/Content/Graphics/Objects/Machines/Sandbox.png b/GeneralMods/Revitalize/Content/Graphics/Objects/Machines/Sandbox.png new file mode 100644 index 0000000000000000000000000000000000000000..0d6148dd5dc36492674cc4e79ad8a53853abbcc6 GIT binary patch literal 588 zcmV-S0<-;zP)Px%21!IgR9J=WmoZ2iQ5eU67F#M954p({ydDlt9ULk~M5t~qadmRDgpMhJ4($*J zA=I&I>g3d=YaIj?Qt<=_brA|J=MhX@j*{tUhtfgse0O^4|CVec$`? za)GY8>gt}=bMu;6N{y{`+Wez&($nj{F)l7yNF_REe(`evfL<{;H2AQC0Mr5iEUdi7 zwoFt_=g+SnJQ^H{oiuE{ZJDGqWdIJgr}^~ez4uuS0D!9LOynv+A5a0{sF17+;Ff?Bf}8t`0E{aNXEHX)lFs{M|P?TsMoS#qtSz_7dMy}}~OeBCT zaUTkR0-uGiUK=$QxvW3021FYs|{^KJ^D(!zVcB_Zm{{;Y<2J^T-d8HOu a*8c&1M!53P-5mJ<0000 + /// The config file to be used for machines. + /// + public GlobalMachineConfig machinesConfig; + public ConfigManager() { this.vanillaMachineConfig = VanillaMachineRecipeConfig.InitializeConfig(); this.shops_blacksmithConfig = Shops_BlacksmithConfig.InitializeConfig(); this.furnitureConfig = FurnitureConfig.InitializeConfig(); + this.machinesConfig = GlobalMachineConfig.InitializeConfig(); } } } diff --git a/GeneralMods/Revitalize/Framework/Configs/GlobalMachineConfig.cs b/GeneralMods/Revitalize/Framework/Configs/GlobalMachineConfig.cs new file mode 100644 index 00000000..47c23192 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Configs/GlobalMachineConfig.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Revitalize.Framework.Configs +{ + public class GlobalMachineConfig + { + + public bool doMachinesConsumeEnergy; + + + public GlobalMachineConfig() + { + this.doMachinesConsumeEnergy = true; + } + + public static GlobalMachineConfig InitializeConfig() + { + if (File.Exists(Path.Combine(ModCore.ModHelper.DirectoryPath, "Configs", "MachinesConfig.json"))) + return ModCore.ModHelper.Data.ReadJsonFile(Path.Combine("Configs", "MachinesConfig.json")); + else + { + GlobalMachineConfig Config = new GlobalMachineConfig(); + ModCore.ModHelper.Data.WriteJsonFile(Path.Combine("Configs", "MachinesConfig.json"), Config); + return Config; + } + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Factories/Objects/Resources/OreFactoryInfo.cs b/GeneralMods/Revitalize/Framework/Factories/Objects/Resources/OreFactoryInfo.cs index 80824a4e..09880810 100644 --- a/GeneralMods/Revitalize/Framework/Factories/Objects/Resources/OreFactoryInfo.cs +++ b/GeneralMods/Revitalize/Framework/Factories/Objects/Resources/OreFactoryInfo.cs @@ -24,7 +24,7 @@ namespace Revitalize.Framework.Factories.Objects.Resources /// /// Extra information that holds drop chances on extra drops. /// - public List ExtraDrops; + public List ExtraDrops; /// /// The health of the ore vein. /// diff --git a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs index 1937149c..82730f56 100644 --- a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs @@ -168,10 +168,11 @@ namespace Revitalize.Framework.Objects } } + [JsonIgnore] /// /// Accesses the energy manager for all objects. /// - public EnergyManager EnergyManager + public virtual EnergyManager EnergyManager { get { diff --git a/GeneralMods/Revitalize/Framework/Objects/InformationFiles/OreResourceInformation.cs b/GeneralMods/Revitalize/Framework/Objects/InformationFiles/OreResourceInformation.cs index 6f2fda10..24a5fcae 100644 --- a/GeneralMods/Revitalize/Framework/Objects/InformationFiles/OreResourceInformation.cs +++ b/GeneralMods/Revitalize/Framework/Objects/InformationFiles/OreResourceInformation.cs @@ -9,7 +9,7 @@ using StardewValley; namespace Revitalize.Framework.Objects.InformationFiles { - public class OreResourceInformation:ResourceInformaton + public class OreResourceInformation:ResourceInformation { diff --git a/GeneralMods/Revitalize/Framework/Objects/InformationFiles/ResourceInformaton.cs b/GeneralMods/Revitalize/Framework/Objects/InformationFiles/ResourceInformation.cs similarity index 89% rename from GeneralMods/Revitalize/Framework/Objects/InformationFiles/ResourceInformaton.cs rename to GeneralMods/Revitalize/Framework/Objects/InformationFiles/ResourceInformation.cs index a6fa0b48..e74af499 100644 --- a/GeneralMods/Revitalize/Framework/Objects/InformationFiles/ResourceInformaton.cs +++ b/GeneralMods/Revitalize/Framework/Objects/InformationFiles/ResourceInformation.cs @@ -10,7 +10,7 @@ namespace Revitalize.Framework.Objects.InformationFiles /// /// Deals with information reguarding resources. /// - public class ResourceInformaton + public class ResourceInformation { /// /// The item to drop. @@ -60,7 +60,7 @@ namespace Revitalize.Framework.Objects.InformationFiles /// /// Empty constructor. /// - public ResourceInformaton() + public ResourceInformation() { } @@ -79,7 +79,7 @@ namespace Revitalize.Framework.Objects.InformationFiles /// /// /// - public ResourceInformaton(StardewValley.Object I, int MinDropAmount, int MaxDropAmount, int MinNumberOfNodes, int MaxNumberOfNodes,double ChanceToSpawn=1f,double ChanceToDrop=1f, double SpawnChanceLuckFactor = 0f, double SpawnAmountLuckFactor = 0f,double DropChanceLuckFactor=0f, double DropAmountLuckFactor = 0f) + public ResourceInformation(StardewValley.Object I, int MinDropAmount, int MaxDropAmount, int MinNumberOfNodes, int MaxNumberOfNodes,double ChanceToSpawn=1f,double ChanceToDrop=1f, double SpawnChanceLuckFactor = 0f, double SpawnAmountLuckFactor = 0f,double DropChanceLuckFactor=0f, double DropAmountLuckFactor = 0f) { this.droppedItem = I; this.minResourcePerDrop = MinDropAmount; @@ -174,5 +174,16 @@ namespace Revitalize.Framework.Objects.InformationFiles if (this.chanceToDrop >= chance) return true; else return false; } + + /// + /// Gets an item that should be dropped from this resource with the appropriate drop amount; + /// + /// + public Item getItemDrops() + { + Item I = this.droppedItem.getOne(); + I.Stack = this.getNumberOfDropsToSpawn(); + return I; + } } } diff --git a/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs b/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs index 02c5cf55..70d3350b 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Machines/Machine.cs @@ -3,10 +3,364 @@ 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 Machine + public class Machine:MultiTiledComponent { + + [JsonIgnore] + public override string ItemInfo + { + get + { + string info = Revitalize.ModCore.Serializer.ToJSONString(this.info); + string guidStr = this.guid.ToString(); + string pyTkData = ModCore.Serializer.ToJSONString(this.data); + string offsetKey = this.offsetKey != null ? ModCore.Serializer.ToJSONString(this.offsetKey) : ""; + string container = this.containerObject != null ? this.containerObject.guid.ToString() : ""; + string resources = ModCore.Serializer.ToJSONString(this.producedResources); + string energyRequired = this.energyRequiredPer10Minutes.ToString(); + string timeToProduce = this.timeToProduce.ToString(); + string updatesContainer = this.updatesContainerObjectForProduction.ToString(); + + return info + "<" + guidStr + "<" + pyTkData + "<" + offsetKey + "<" + container+"<"+resources+"<"+energyRequired+"<"+timeToProduce+"<"+updatesContainer; + } + set + { + if (string.IsNullOrEmpty(value)) return; + string[] data = value.Split('<'); + string infoString = data[0]; + string guidString = data[1]; + string pyTKData = data[2]; + string offsetVec = data[3]; + string containerObject = data[4]; + string resourcesString = data[5]; + string energyRequired = data[6]; + string time = data[7]; + string updates = data[8]; + this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(infoString, typeof(BasicItemInformation)); + this.data = Revitalize.ModCore.Serializer.DeserializeFromJSONString(pyTKData); + this.energyRequiredPer10Minutes = Convert.ToInt32(energyRequired); + this.timeToProduce = Convert.ToInt32(time); + this.updatesContainerObjectForProduction = Convert.ToBoolean(updates); + if (string.IsNullOrEmpty(offsetVec)) return; + if (string.IsNullOrEmpty(containerObject)) return; + this.offsetKey = ModCore.Serializer.DeserializeFromJSONString(offsetVec); + Guid oldGuid = this.guid; + this.guid = Guid.Parse(guidString); + if (ModCore.CustomObjects.ContainsKey(this.guid)) + { + //ModCore.log("Update item with guid: " + this.guid); + ModCore.CustomObjects[this.guid] = this; + } + else + { + //ModCore.log("Add in new guid: " + this.guid); + ModCore.CustomObjects.Add(this.guid, this); + } + + if (this.containerObject == null) + { + //ModCore.log(containerObject); + Guid containerGuid = Guid.Parse(containerObject); + if (ModCore.CustomObjects.ContainsKey(containerGuid)) + { + this.containerObject = (MultiTiledObject)ModCore.CustomObjects[containerGuid]; + this.containerObject.removeComponent(this.offsetKey); + this.containerObject.addComponent(this.offsetKey, this); + //ModCore.log("Set container object from existing object!"); + } + else + { + //ModCore.log("Container hasn't been synced???"); + MultiplayerUtilities.RequestGuidObject(containerGuid); + MultiplayerUtilities.RequestGuidObject_Tile(this.guid); + } + } + else + { + this.containerObject.updateInfo(); + } + + if (ModCore.CustomObjects.ContainsKey(oldGuid) && ModCore.CustomObjects.ContainsKey(this.guid)) + { + if (ModCore.CustomObjects[oldGuid] == ModCore.CustomObjects[this.guid] && oldGuid != this.guid) + { + //ModCore.CustomObjects.Remove(oldGuid); + } + } + + if (string.IsNullOrEmpty(resourcesString) == false) + { + this.producedResources = ModCore.Serializer.DeserializeFromJSONString>(resourcesString); + } + else + { + if (this.producedResources == null) this.producedResources = new List(); + } + } + } + + public List producedResources; + public int energyRequiredPer10Minutes; + public int timeToProduce; + public bool updatesContainerObjectForProduction; + + [JsonIgnore] + public bool ProducesItems + { + get + { + return this.producedResources.Count > 0; + } + } + + [JsonIgnore] + public bool ConsumesEnergy + { + get + { + if (ModCore.Configs.machinesConfig.doMachinesConsumeEnergy == false) return false; + if (this.energyRequiredPer10Minutes == 0) return false; + if (this.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Consumes) return true; + return false; + } + } + + public Machine() { } + + public Machine(CustomObjectData PyTKData, BasicItemInformation info,List ProducedResources=null, int EnergyRequiredPer10Minutes = 0,int TimeToProduce=0,bool UpdatesContainer=false) : base(PyTKData, info) { + this.producedResources = ProducedResources?? new List(); + this.energyRequiredPer10Minutes = EnergyRequiredPer10Minutes; + this.timeToProduce = TimeToProduce; + this.updatesContainerObjectForProduction = UpdatesContainer; + this.MinutesUntilReady = TimeToProduce; + } + + public Machine(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, List ProducedResources=null,int EnergyRequiredPer10Minutes=0,int TimeToProduce=0,bool UpdatesContainer=false,MultiTiledObject obj=null) : base(PyTKData, info, TileLocation) + { + this.containerObject = obj; + this.producedResources = ProducedResources ?? new List(); + this.energyRequiredPer10Minutes = EnergyRequiredPer10Minutes; + this.timeToProduce = TimeToProduce; + this.updatesContainerObjectForProduction = UpdatesContainer; + this.MinutesUntilReady = TimeToProduce; + } + + public Machine(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, Vector2 offsetKey,List ProducedResources=null, int EnergyRequiredPer10Minutes = 0, int TimeToProduce=0,bool UpdatesContainer=false,MultiTiledObject obj = null) : base(PyTKData, info, TileLocation) + { + this.offsetKey = offsetKey; + this.containerObject = obj; + this.producedResources = ProducedResources?? new List(); + this.timeToProduce = TimeToProduce; + this.updatesContainerObjectForProduction = UpdatesContainer; + this.MinutesUntilReady = TimeToProduce; + } + + public override void updateWhenCurrentLocation(GameTime time, GameLocation environment) + { + base.updateWhenCurrentLocation(time, environment); + } + + + public override bool minutesElapsed(int minutes, GameLocation environment) + { + if (this.updatesContainerObjectForProduction) + { + //ModCore.log("Update container object for production!"); + //this.MinutesUntilReady -= minutes; + int remaining = minutes; + //ModCore.log("Minutes elapsed: " + remaining); + List energySources = new List(); + if (this.ConsumesEnergy) + { + energySources = this.EnergyGraphSearchSources(); //Only grab the network once. + } + + + if (this.ProducesItems) + { + //ModCore.log("This produces items!"); + while (remaining > 0) + { + + if (this.ConsumesEnergy) + { + this.drainEnergyFromNetwork(energySources); //Continually drain from the network. + if (this.EnergyManager.remainingEnergy < this.energyRequiredPer10Minutes) return false; + } + else + { + //ModCore.log("Does not produce energy!"); + } + remaining -= 10; + this.containerObject.MinutesUntilReady -= 10; + + if (this.containerObject.MinutesUntilReady <= 0) + { + this.produceItem(); + this.containerObject.MinutesUntilReady = this.timeToProduce; + } + } + } + if (this.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Produces) + { + while (remaining > 0) + { + remaining -= 10; + this.produceEnergy(); + } + } + return false; + } + else + { + + return false; + } + + //return base.minutesElapsed(minutes, environment); + } + + public override bool rightClicked(Farmer who) + { + if (this.location == null) + this.location = Game1.player.currentLocation; + if (Game1.menuUp || Game1.currentMinigame != null) return false; + if (this.containerObject.info.inventory != null && Game1.activeClickableMenu == null) + { + Game1.activeClickableMenu = new Revitalize.Framework.Menus.InventoryTransferMenu(100, 100, 500, 500, this.containerObject.info.inventory.items, this.containerObject.info.inventory.capacity); + } + //ModCore.playerInfo.sittingInfo.sit(this, Vector2.Zero); + + return true; + } + + public override Item getOne() + { + Machine component = new Machine(this.data, this.info.Copy(), this.TileLocation, this.offsetKey, this.producedResources,this.energyRequiredPer10Minutes,this.timeToProduce,this.updatesContainerObjectForProduction,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"])); + Machine 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.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; + + + 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; + } + else if (this.info.ignoreBoundingBox) + { + addedDepth += 1.0f; + } + 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)); + + } + + public virtual void produceItem() + { + foreach(ResourceInformation r in this.producedResources) + { + if (r.shouldDropResource()) + { + Item i = r.getItemDrops(); + this.InventoryManager.addItem(i); + //ModCore.log("Produced an item!"); + } + } + + } + + public virtual void produceEnergy() + { + if (this.EnergyManager.canReceieveEnergy) + { + this.EnergyManager.produceEnergy(this.energyRequiredPer10Minutes); + } + + } + + } } diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs index 8548401f..3915889d 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs @@ -4,7 +4,9 @@ using System.IO; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json; using PyTK.CustomElementHandler; +using Revitalize.Framework.Energy; using Revitalize.Framework.Utilities; using StardewValley; using StardewValley.Objects; @@ -14,6 +16,7 @@ namespace Revitalize.Framework.Objects public class MultiTiledComponent : CustomObject,ISaveElement { + [JsonIgnore] public override string ItemInfo { get @@ -89,6 +92,53 @@ namespace Revitalize.Framework.Objects public Vector2 offsetKey; + [JsonIgnore] + public override EnergyManager EnergyManager + { + get + { + if (this.info == null || this.containerObject==null) + { + this.updateInfo(); + if (this.containerObject == null) return null; + return this.containerObject.info.EnergyManager; + } + else + { + return this.containerObject.info.EnergyManager; + } + } + set + { + this.containerObject.info.EnergyManager = value; + } + } + + /// + /// The inventory for the object. + /// + [JsonIgnore] + public virtual InventoryManager InventoryManager + { + get + { + if (this.info == null || this.containerObject == null) + { + this.updateInfo(); + if (this.containerObject == null) return null; + return this.containerObject.info.inventory; + } + else + { + return this.containerObject.info.inventory; + } + } + set + { + this.containerObject.info.inventory = value; + } + } + public MultiTiledComponent() { } public MultiTiledComponent(CustomObjectData PyTKData,BasicItemInformation info) : base(PyTKData,info) { } @@ -562,6 +612,17 @@ namespace Revitalize.Framework.Objects } } + public void drainEnergyFromNetwork(List energySources) + { + int index = 0; + + for (int i = 0; i < energySources.Count; i++) + { + this.EnergyManager.transferEnergyFromAnother(energySources[i].EnergyManager, this.EnergyManager.capacityRemaining); + if (this.EnergyManager.hasMaxEnergy) break; + } + } + /// /// Gets all of the nodes in a connected energy network and tries to store the necessary amount of energy from the network. /// diff --git a/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs index c41e3713..481ae93a 100644 --- a/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs +++ b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs @@ -9,6 +9,7 @@ using Revitalize.Framework.Objects.Extras; using Revitalize.Framework.Objects.Furniture; using Revitalize.Framework.Objects.Interfaces; using Revitalize.Framework.Objects.Items.Tools; +using Revitalize.Framework.Objects.Machines; using Revitalize.Framework.Utilities; using StardewModdingAPI; using StardewValley; @@ -147,6 +148,38 @@ namespace Revitalize.Framework.Objects trashCan.addComponent(new Vector2(0, 1), trash2); this.AddItem("TrashCan", trashCan); + + + + MultiTiledObject sandBox = new MultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Sandbox", TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Sandbox", "Omegasis.Revitalize.Objects.Machines.Sandbox", "A sandbox which slowly produces sand. Unfortunately you can't sit in this one.", "Machine", Color.SteelBlue, -300, 0, false, 750, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), new AnimationManager(), Color.White, true, new InventoryManager(36), null, null)); + Machine sandBox_0_0 = new Machine(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Sandbox", TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), typeof(Machine), Color.White, true), new BasicItemInformation("Sandbox", "Omegasis.Revitalize.Objects.Machines.Sandbox", "A sandbox which slowly produces sand. Unfortunately you can't sit in this one.", "Machine", Color.SteelBlue, -300, 0, false, 750, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "Sandbox"),new Animation(0,0,16,16)), Color.White, false, new InventoryManager(36), null, null), new List() + { + new InformationFiles.ResourceInformation(new StardewValley.Object((int)Enums.SDVObject.Clay,1),1,1,1,1,1,1,0,0,0,0) + + }, 0, 10, true); + Machine sandBox_1_0 = new Machine(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Sandbox", TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), typeof(Machine), Color.White, true), new BasicItemInformation("Sandbox", "Omegasis.Revitalize.Objects.Machines.Sandbox", "A sandbox which slowly produces sand. Unfortunately you can't sit in this one.", "Machine", Color.SteelBlue, -300, 0, false, 750, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "Sandbox"), new Animation(16, 0, 16, 16)), Color.White, false, new InventoryManager(36), null, null), new List() + { + new InformationFiles.ResourceInformation(new StardewValley.Object((int)Enums.SDVObject.Clay,1),1,1,1,1,1,1,0,0,0,0) + + }, 0, 10, false); + Machine sandBox_0_1 = new Machine(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Sandbox", TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), typeof(Machine), Color.White, true), new BasicItemInformation("Sandbox", "Omegasis.Revitalize.Objects.Machines.Sandbox", "A sandbox which slowly produces sand. Unfortunately you can't sit in this one.", "Machine", Color.SteelBlue, -300, 0, false, 750, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "Sandbox"), new Animation(0, 16, 16, 16)), Color.White, false, new InventoryManager(36), null, null), new List() + { + new InformationFiles.ResourceInformation(new StardewValley.Object((int)Enums.SDVObject.Clay,1),1,1,1,1,1,1,0,0,0,0) + + }, 0, 10, false); + Machine sandBox_1_1 = new Machine(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Sandbox", TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), typeof(Machine), Color.White, true), new BasicItemInformation("Sandbox", "Omegasis.Revitalize.Objects.Machines.Sandbox", "A sandbox which slowly produces sand. Unfortunately you can't sit in this one.", "Machine", Color.SteelBlue, -300, 0, false, 750, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "Sandbox"), new Animation(16, 16, 16, 16)), Color.White, false, new InventoryManager(36), null, null), new List() + { + new InformationFiles.ResourceInformation(new StardewValley.Object((int)Enums.SDVObject.Clay,1),1,1,1,1,1,1,0,0,0,0) + + }, 0, 10, false); + + sandBox.addComponent(new Vector2(0,0),sandBox_0_0); + sandBox.addComponent(new Vector2(1, 0), sandBox_1_0); + sandBox.addComponent(new Vector2(0, 1), sandBox_0_1); + sandBox.addComponent(new Vector2(1, 1), sandBox_1_1); + + this.AddItem("SandBox", sandBox); + } private void loadInTools() diff --git a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs index ec5dae79..fb0b0412 100644 --- a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs +++ b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs @@ -141,7 +141,7 @@ namespace Revitalize.Framework.Objects }, new List() { new IntRange(0,9999) - }, null,null, 0.80d, 0.20d, 0.25d, 1d, 1d, 1, 1, 1, 1), new List(), 4); + }, null,null, 0.80d, 0.20d, 0.25d, 1d, 1d, 1, 1, 1, 1), new List(), 4); OreFactoryInfo tinOre_0_0_file = new OreFactoryInfo(tinOre_0_0); OreFactoryInfo tinOre_file = new OreFactoryInfo(tinOre); @@ -161,7 +161,7 @@ namespace Revitalize.Framework.Objects }, new List() { new IntRange(0,9999) - }, null, null, .70d, 0.16d, 0.20d, 1d, 1d, 0, 0, 0, 0), new List(), 5); + }, null, null, .70d, 0.16d, 0.20d, 1d, 1d, 0, 0, 0, 0), new List(), 5); OreFactoryInfo bauxiteOre_0_0_file = new OreFactoryInfo(bauxiteOre_0_0); OreFactoryInfo bauxiteOre_file = new OreFactoryInfo(bauxiteOre); @@ -181,7 +181,7 @@ namespace Revitalize.Framework.Objects }, new List() { new IntRange(0,9999) - }, null, null, .50d, 0.10d, 0.14d, 1d, 1d, 0, 0, 0, 0), new List(), 6); + }, null, null, .50d, 0.10d, 0.14d, 1d, 1d, 0, 0, 0, 0), new List(), 6); OreFactoryInfo silverOre_0_0_file = new OreFactoryInfo(silverOre_0_0); OreFactoryInfo silverOre_file = new OreFactoryInfo(silverOre); @@ -201,7 +201,7 @@ namespace Revitalize.Framework.Objects }, new List() { new IntRange(0,9999) - }, null, null, .60d, 0.13d, 0.17d, 1d, 1d, 0, 0, 0, 0), new List(), 7); + }, null, null, .60d, 0.13d, 0.17d, 1d, 1d, 0, 0, 0, 0), new List(), 7); OreFactoryInfo leadOre_0_0_file = new OreFactoryInfo(leadOre_0_0); OreFactoryInfo leadOre_file = new OreFactoryInfo(leadOre); @@ -222,7 +222,7 @@ namespace Revitalize.Framework.Objects }, new List() { new IntRange(0,9999) - }, null, null, .40d, 0.05d, 0.10d, 1d, 1d, 0, 0, 0, 0), new List(), 8); + }, null, null, .40d, 0.05d, 0.10d, 1d, 1d, 0, 0, 0, 0), new List(), 8); OreFactoryInfo titaniumOre_0_0_file = new OreFactoryInfo(titaniumOre_0_0); OreFactoryInfo titaniumOre_file = new OreFactoryInfo(titaniumOre); @@ -241,7 +241,7 @@ namespace Revitalize.Framework.Objects new IntRange(1,9999) }, new List() { - }, null, null, .05d, 0.01d, 0.01d, 0.10, 1d, 1, 1, 1,1), new List(), 10); + }, null, null, .05d, 0.01d, 0.01d, 0.10, 1d, 1, 1, 1,1), new List(), 10); OreFactoryInfo prismaticOre_0_0_file = new OreFactoryInfo(prismaticOre_0_0); OreFactoryInfo prismaticOre_file = new OreFactoryInfo(prismaticOre); @@ -336,7 +336,7 @@ namespace Revitalize.Framework.Objects } } - public List getExtraDropInformationFromOres(string id) + public List getExtraDropInformationFromOres(string id) { if (this.oreVeins.ContainsKey(id)) { diff --git a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs index 26dd84b4..89dd1d47 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs @@ -15,7 +15,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins public class OreVeinObj:MultiTiledObject { [JsonIgnore] - public ResourceInformaton resourceInfo + public ResourceInformation resourceInfo { get { diff --git a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs index da2bcc55..47d7fcdd 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs @@ -21,7 +21,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins /// Deals with information tied to the resource itself. /// public OreResourceInformation resourceInfo; - public List extraDrops; + public List extraDrops; private int _healthValue; public int healthValue @@ -70,7 +70,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins //Instead of serializing this info it's static pretty much always so just pull the info from the resource manager. OreResourceInformation oreResource = ModCore.ObjectManager.resources.getOreResourceInfo(this.info.id); - List extraDrops = ModCore.ObjectManager.resources.getExtraDropInformationFromOres(this.info.id); + List extraDrops = ModCore.ObjectManager.resources.getExtraDropInformationFromOres(this.info.id); if (this.resourceInfo == null) { this.resourceInfo = oreResource; @@ -137,21 +137,21 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins } - public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info, OreResourceInformation Resource,List ExtraDrops,int Health) : base(PyTKData, Info) + public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info, OreResourceInformation Resource,List ExtraDrops,int Health) : base(PyTKData, Info) { this.healthValue = Health; this.resourceInfo = Resource; - this.extraDrops = ExtraDrops != null ? ExtraDrops : new List(); + this.extraDrops = ExtraDrops != null ? ExtraDrops : new List(); this.setHealth(this.healthValue); this.Price = Info.price; } - public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info, Vector2 TileLocation, OreResourceInformation Resource, List ExtraDrops,int Health) : base(PyTKData, Info, TileLocation) + public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info, Vector2 TileLocation, OreResourceInformation Resource, List ExtraDrops,int Health) : base(PyTKData, Info, TileLocation) { this.healthValue = Health; this.resourceInfo = Resource; - this.extraDrops = ExtraDrops != null ? ExtraDrops : new List(); + this.extraDrops = ExtraDrops != null ? ExtraDrops : new List(); this.setHealth(this.healthValue); this.Price = Info.price; } @@ -292,7 +292,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins if (this.extraDrops != null) { - foreach (ResourceInformaton extra in this.extraDrops) + foreach (ResourceInformation extra in this.extraDrops) { if (extra.shouldDropResource()) { diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 9906fa8d..b9b5ad2d 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -294,6 +294,8 @@ namespace Revitalize { TextureManager.AddTextureManager(Manifest, "Furniture"); TextureManager.GetTextureManager(Manifest, "Furniture").searchForTextures(ModHelper, this.ModManifest, Path.Combine("Content", "Graphics", "Objects", "Furniture")); + TextureManager.AddTextureManager(Manifest, "Machines"); + TextureManager.GetTextureManager(Manifest, "Machines").searchForTextures(ModHelper, this.ModManifest, Path.Combine("Content", "Graphics", "Objects", "Machines")); TextureManager.AddTextureManager(Manifest, "InventoryMenu"); TextureManager.GetTextureManager(Manifest, "InventoryMenu").searchForTextures(ModHelper, this.ModManifest, Path.Combine("Content", "Graphics", "Menus", "InventoryMenu")); TextureManager.AddTextureManager(Manifest, "Resources.Ore"); @@ -523,12 +525,16 @@ namespace Revitalize //Game1.player.addItemToInventory(ObjectManager.getChair("Omegasis.Revitalize.Furniture.Chairs.OakChair")); Game1.player.addItemToInventoryBool(ObjectManager.GetItem("Workbench")); + + + //PickaxeExtended pick = new PickaxeExtended(new BasicItemInformation("My First Pickaxe", "Omegasis.Revitalize.Items.Tools.MyFirstPickaxe", "A testing pickaxe. Does it work?", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(Manifest, "Tools", "Pickaxe"), new AnimationManager(TextureManager.GetExtendedTexture(Manifest, "Tools", "Pickaxe"), new Animation(0, 0, 16, 16)), Color.White, true, null, null),2,TextureManager.GetExtendedTexture(Manifest,"Tools","TestingPickaxeWorking")); Game1.player.addItemsByMenuIfNecessary(new List() { new StardewValley.Object((int)Enums.SDVObject.Wood,100), ModCore.ObjectManager.GetItem("SteelIngot", 20), - ModCore.ObjectManager.GetItem("TrashCan",1) + ModCore.ObjectManager.GetItem("TrashCan",1), + ModCore.ObjectManager.GetItem("SandBox",1) }); } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 690a59ad..aef4baaa 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -55,6 +55,7 @@ + @@ -145,7 +146,7 @@ - + @@ -386,6 +387,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest