Added in wires, the battery bin, fixed machines not consuming energy.

This commit is contained in:
JoshuaNavarro 2019-09-18 13:05:31 -07:00
parent 72da92e842
commit ea100b1084
9 changed files with 217 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

View File

@ -333,6 +333,12 @@ namespace Revitalize.Framework.Crafting
new CraftingRecipeComponent(new StardewValley.Object((int)Enums.SDVObject.Stone,20),20),
}, new CraftingRecipeComponent(new StardewValley.Tools.WateringCan() { UpgradeLevel = 0 }, 1)), true));
WorkbenchRecipes.addCraftingRecipe("Copper Wire", new UnlockableCraftingRecipe("Default", new Recipe(new List<CraftingRecipeComponent>()
{
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<string, UnlockableCraftingRecipe> recipe in WorkbenchRecipes.craftingRecipes)

View File

@ -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<ResourceInformation>();
this.energyRequiredPer10Minutes = EnergyRequiredPer10Minutes;
this.timeToProduce = TimeToProduce;
this.updatesContainerObjectForProduction = UpdatesContainer;
this.MinutesUntilReady = TimeToProduce;
@ -194,23 +208,28 @@ namespace Revitalize.Framework.Objects.Machines
List<MultiTiledObject> energySources = new List<MultiTiledObject>();
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;

View File

@ -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;
}
/// <summary>
/// Creates the necessary components to display the machine menu properly.
/// </summary>
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<string, string> 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<Wire>(additionalSaveData["GUID"]);
if (self == null)
{
return null;
}
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"]))
{
//Get new container
MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledObject>(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.
}
}
}

View File

@ -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<InformationFiles.ResourceInformation>()
{
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()

View File

@ -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;
}

View File

@ -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)
});
}

View File

@ -156,6 +156,7 @@
<Compile Include="Framework\Objects\Items\Tools\WateringCanExtended.cs" />
<Compile Include="Framework\Objects\Machines\EnergyGeneration\SolarPanel.cs" />
<Compile Include="Framework\Objects\Machines\Machine.cs" />
<Compile Include="Framework\Objects\Machines\Wire.cs" />
<Compile Include="Framework\Objects\MultiTiledComponent.cs" />
<Compile Include="Framework\Objects\MultiTiledObject.cs" />
<Compile Include="Framework\Objects\ObjectManager.cs" />
@ -414,6 +415,9 @@
<Content Include="Content\Graphics\Objects\Furniture\Tables\Oak Table.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Graphics\Objects\Machines\BatteryBin.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Graphics\Objects\Machines\Sandbox.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -423,6 +427,9 @@
<Content Include="Content\Graphics\Objects\Machines\SolarPanelTier1.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Graphics\Objects\Machines\Wires\CopperWire.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Graphics\Objects\Resources\Ore\Bauxite.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>