From f194b5eb4f14b5e90551530796556f2f32ca4457 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Thu, 22 Aug 2019 20:04:49 -0700 Subject: [PATCH] Added in ores to be bought from Clints shop. Added in the rest of the vanilla furnace ingot smelting recipes. --- .../Framework/Crafting/VanillaRecipeBook.cs | 38 ++++++++- .../Framework/Hacks/ObjectInteractionHacks.cs | 1 - .../Revitalize/Framework/Hacks/ShopHacks.cs | 28 +++++++ .../Framework/Objects/CustomObject.cs | 80 ++++++++++++++----- .../Framework/Utilities/TimeUtilities.cs | 20 +++++ GeneralMods/Revitalize/ModCore.cs | 1 + GeneralMods/Revitalize/Revitalize.csproj | 2 + 7 files changed, 145 insertions(+), 25 deletions(-) create mode 100644 GeneralMods/Revitalize/Framework/Hacks/ShopHacks.cs create mode 100644 GeneralMods/Revitalize/Framework/Utilities/TimeUtilities.cs diff --git a/GeneralMods/Revitalize/Framework/Crafting/VanillaRecipeBook.cs b/GeneralMods/Revitalize/Framework/Crafting/VanillaRecipeBook.cs index f21403ed..a509f121 100644 --- a/GeneralMods/Revitalize/Framework/Crafting/VanillaRecipeBook.cs +++ b/GeneralMods/Revitalize/Framework/Crafting/VanillaRecipeBook.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Revitalize.Framework.Utilities; using StardewValley; namespace Revitalize.Framework.Crafting @@ -35,9 +36,41 @@ namespace Revitalize.Framework.Crafting { {ModCore.ObjectManager.resources.getOre("Tin"),5 }, {new StardewValley.Object(382,1),1} - }, new KeyValuePair(ModCore.ObjectManager.GetItem("TinIngot"), 1), 50, new StatCost(), false); + }, new KeyValuePair(ModCore.ObjectManager.GetItem("TinIngot"), 1), TimeUtilities.GetMinutesFromTime(0,0,50), new StatCost(), false); this.recipesByObjectName["Furnace"].Add("Tin Ore", furnace_tinOre); + + VanillaRecipe furnace_bauxiteOre = new VanillaRecipe(new Dictionary() + { + {ModCore.ObjectManager.resources.getOre("Bauxite"),5 }, + {new StardewValley.Object(382,1),1} + }, new KeyValuePair(ModCore.ObjectManager.GetItem("AluminumIngot"), 1), TimeUtilities.GetMinutesFromTime(0,1,30), new StatCost(), false); + + this.recipesByObjectName["Furnace"].Add("Bauxite Ore", furnace_bauxiteOre); + + VanillaRecipe furnace_leadOre = new VanillaRecipe(new Dictionary() + { + {ModCore.ObjectManager.resources.getOre("Lead"),5 }, + {new StardewValley.Object(382,1),1} + }, new KeyValuePair(ModCore.ObjectManager.GetItem("LeadIngot"), 1), TimeUtilities.GetMinutesFromTime(0,2,0), new StatCost(), false); + + this.recipesByObjectName["Furnace"].Add("Lead Ore", furnace_leadOre); + + VanillaRecipe furnace_silverOre = new VanillaRecipe(new Dictionary() + { + {ModCore.ObjectManager.resources.getOre("Silver"),5 }, + {new StardewValley.Object(382,1),1} + }, new KeyValuePair(ModCore.ObjectManager.GetItem("SilverIngot"), 1), TimeUtilities.GetMinutesFromTime(0,3,0), new StatCost(), false); + + this.recipesByObjectName["Furnace"].Add("Silver Ore", furnace_silverOre); + + VanillaRecipe furnace_titaniumOre = new VanillaRecipe(new Dictionary() + { + {ModCore.ObjectManager.resources.getOre("Titanium"),5 }, + {new StardewValley.Object(382,1),1} + }, new KeyValuePair(ModCore.ObjectManager.GetItem("TitaniumIngot"), 1), TimeUtilities.GetMinutesFromTime(0,4,0), new StatCost(), false); + + this.recipesByObjectName["Furnace"].Add("Titanium Ore", furnace_titaniumOre); } /// @@ -100,7 +133,6 @@ namespace Revitalize.Framework.Crafting { if (this.DoesARecipeExistForHeldObjectName(Machine)) { - ModCore.log("Recipe exists!"); VanillaRecipe rec = this.GetVanillaRecipeFromHeldObjectName(Machine); bool crafted=rec.craft(Machine); if(crafted)this.playCraftingSound(Machine); @@ -108,7 +140,7 @@ namespace Revitalize.Framework.Crafting } else { - ModCore.log("No recipe!"); + //ModCore.log("No recipe!"); return false; } } diff --git a/GeneralMods/Revitalize/Framework/Hacks/ObjectInteractionHacks.cs b/GeneralMods/Revitalize/Framework/Hacks/ObjectInteractionHacks.cs index 4ff7d8d9..2e00eed8 100644 --- a/GeneralMods/Revitalize/Framework/Hacks/ObjectInteractionHacks.cs +++ b/GeneralMods/Revitalize/Framework/Hacks/ObjectInteractionHacks.cs @@ -46,7 +46,6 @@ namespace Revitalize.Framework.Hacks if (obj == null) return; if (ObjectUtilities.IsObjectFurnace(obj) && ObjectUtilities.IsObjectHoldingItem(obj)==false) { - ModCore.log("Found a furnace!"); bool crafted=VanillaRecipeBook.VanillaRecipes.TryToCraftRecipe(obj); if (crafted == false) return; obj.initializeLightSource((Vector2)(obj.TileLocation), false); diff --git a/GeneralMods/Revitalize/Framework/Hacks/ShopHacks.cs b/GeneralMods/Revitalize/Framework/Hacks/ShopHacks.cs new file mode 100644 index 00000000..3c632cbc --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Hacks/ShopHacks.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PyTK.Types; + +namespace Revitalize.Framework.Hacks +{ + /// + /// Deals with modifications for SDV shops. + /// + public class ShopHacks + { + + /// + /// Adds in ore to clint's shop. + /// + public static void AddOreToClintsShop() + { + PyTK.Extensions.PyEvents.addToNPCShop(new InventoryItem(ModCore.ObjectManager.resources.getOre("Tin",1),100), "Clint"); + PyTK.Extensions.PyEvents.addToNPCShop(new InventoryItem(ModCore.ObjectManager.resources.getOre("Bauxite", 1), 150), "Clint"); + PyTK.Extensions.PyEvents.addToNPCShop(new InventoryItem(ModCore.ObjectManager.resources.getOre("Lead", 1), 200), "Clint"); + PyTK.Extensions.PyEvents.addToNPCShop(new InventoryItem(ModCore.ObjectManager.resources.getOre("Silver", 1), 250), "Clint"); + PyTK.Extensions.PyEvents.addToNPCShop(new InventoryItem(ModCore.ObjectManager.resources.getOre("Titanium", 1), 300), "Clint"); + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs index 209400c1..040a31e2 100644 --- a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs @@ -55,7 +55,7 @@ namespace Revitalize.Framework.Objects public Guid guid; - + /// The animation manager. public AnimationManager animationManager => this.info.animationManager; @@ -71,22 +71,23 @@ namespace Revitalize.Framework.Objects } set { - this.info =(BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(value, typeof(BasicItemInformation)); + this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(value, typeof(BasicItemInformation)); } } - - protected Netcode.NetString netItemInfo; + + protected Netcode.NetString netItemInfo; /// Empty constructor. - public CustomObject() { + public CustomObject() + { this.guid = Guid.NewGuid(); this.InitNetFields(); } /// Construct an instance. - public CustomObject(CustomObjectData PyTKData, BasicItemInformation info,int Stack=1) + public CustomObject(CustomObjectData PyTKData, BasicItemInformation info, int Stack = 1) : base(PyTKData, Vector2.Zero) { this.info = info; @@ -97,7 +98,7 @@ namespace Revitalize.Framework.Objects } /// Construct an instance. - public CustomObject(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation,int Stack=1) + public CustomObject(CustomObjectData PyTKData, BasicItemInformation info, Vector2 TileLocation, int Stack = 1) : base(PyTKData, TileLocation) { this.info = info; @@ -133,7 +134,7 @@ namespace Revitalize.Framework.Objects public override bool isPassable() { - return this.info.ignoreBoundingBox || Revitalize.ModCore.playerInfo.sittingInfo.SittingObject==this; + return this.info.ignoreBoundingBox || Revitalize.ModCore.playerInfo.sittingInfo.SittingObject == this; } public override Rectangle getBoundingBox(Vector2 tileLocation) @@ -147,7 +148,7 @@ namespace Revitalize.Framework.Objects /// Checks for interaction with the object. public override bool checkForAction(Farmer who, bool justCheckingForActivity = false) { - + MouseState mState = Mouse.GetState(); KeyboardState keyboardState = Game1.GetKeyboardState(); @@ -173,7 +174,7 @@ namespace Revitalize.Framework.Objects { CustomObjectData data = CustomObjectData.collection[additionalSaveData["id"]]; BasicItemInformation info = Revitalize.ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); - return new CustomObject(data,info,(replacement as Chest).TileLocation); + return new CustomObject(data, info, (replacement as Chest).TileLocation); } public override Dictionary getAdditionalSaveData() { @@ -213,8 +214,6 @@ namespace Revitalize.Framework.Objects { //ModCore.log("Clicky click!"); - ModCore.log(System.Environment.StackTrace); - return this.removeAndAddToPlayersInventory(); //return base.clicked(who); } @@ -276,6 +275,8 @@ namespace Revitalize.Framework.Objects /// Places an object down. public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) { + if (this.info.canBeSetIndoors == false && location.IsOutdoors == false) return false; + if (this.info.canBeSetOutdoors == false && location.IsOutdoors) return false; this.updateDrawPosition(x, y); this.location = location; return base.placementAction(location, x, y, who); @@ -283,7 +284,7 @@ namespace Revitalize.Framework.Objects public override bool canBePlacedHere(GameLocation l, Vector2 tile) { - if (this.info.ignoreBoundingBox && l.isObjectAtTile((int)tile.X,(int)tile.Y)==false) return true; + if (this.info.ignoreBoundingBox && l.isObjectAtTile((int)tile.X, (int)tile.Y) == false) return true; return base.canBePlacedHere(l, tile); } @@ -306,8 +307,8 @@ namespace Revitalize.Framework.Objects public string generateRotationalAnimationKey() - { - return (this.info.animationManager.currentAnimationName.Split('_')[0]) +"_"+ (int)this.info.facingDirection; + { + return (this.info.animationManager.currentAnimationName.Split('_')[0]) + "_" + (int)this.info.facingDirection; } public string generateDefaultRotationalAnimationKey() @@ -325,7 +326,7 @@ namespace Revitalize.Framework.Objects /// Gets a clone of the game object. public override Item getOne() { - return new CustomObject(this.data,this.info); + return new CustomObject(this.data, this.info); } /// What happens when the object is drawn at a tile location. @@ -353,7 +354,7 @@ namespace Revitalize.Framework.Objects int addedDepth = 0; if (this.info.ignoreBoundingBox) addedDepth++; if (Revitalize.ModCore.playerInfo.sittingInfo.SittingObject == this) addedDepth++; - 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)( (this.TileLocation.Y+addedDepth) * Game1.tileSize) / 10000f)); + 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)((this.TileLocation.Y + addedDepth) * Game1.tileSize) / 10000f)); try { this.animationManager.tickAnimation(); @@ -372,6 +373,7 @@ namespace Revitalize.Framework.Objects /// Draw the game object at a non-tile spot. Aka like debris. public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1f) { + /* if (Game1.eventUp && Game1.CurrentEvent.isTileWalkedOn(xNonTile / 64, yNonTile / 64)) return; if ((int)(this.ParentSheetIndex) != 590 && (int)(this.Fragility) != 2) @@ -389,6 +391,37 @@ namespace Revitalize.Framework.Objects double num4 = (double)layerDepth; spriteBatch1.Draw(this.displayTexture, local, this.animationManager.defaultDrawFrame.sourceRectangle, this.info.drawColor * alpha, (float)num1, origin, (float)4f, (SpriteEffects)num3, (float)num4); + */ + //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)(xNonTile), yNonTile)), 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, layerDepth)); + // Log.AsyncG("ANIMATION IS NULL?!?!?!?!"); + } + + else + { + //Log.AsyncC("Animation Manager is working!"); + int addedDepth = 0; + if (this.info.ignoreBoundingBox) addedDepth++; + if (Revitalize.ModCore.playerInfo.sittingInfo.SittingObject == this) addedDepth++; + this.animationManager.draw(spriteBatch, this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(xNonTile), yNonTile)), 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, layerDepth)); + 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)); + } /// What happens when the object is drawn in a menu. @@ -407,7 +440,7 @@ namespace Revitalize.Framework.Objects /// What happens when the object is drawn when held by a player. public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, StardewValley.Farmer f) { - + if (this.animationManager == null) Revitalize.ModCore.log("Animation Manager Null"); if (this.displayTexture == null) Revitalize.ModCore.log("Display texture is null"); if (f.ActiveObject.bigCraftable.Value) @@ -433,9 +466,14 @@ namespace Revitalize.Framework.Objects //base.drawWhenHeld(spriteBatch, objectPosition, f); } + public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location) + { + //Do nothing because this shouldn't be placeable anywhere. + } + public void InitNetFields() { - if (Game1.IsMultiplayer == false &&(Game1.IsClient==false || Game1.IsClient==false)) return; + if (Game1.IsMultiplayer == false && (Game1.IsClient == false || Game1.IsClient == false)) return; this.initNetFields(); this.syncObject = new PySync(this); this.NetFields.AddField(this.syncObject); @@ -449,7 +487,7 @@ namespace Revitalize.Framework.Objects /// public override Dictionary getSyncData() { - Dictionary syncData= base.getSyncData(); + Dictionary syncData = base.getSyncData(); syncData.Add("BasicItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); return syncData; } @@ -478,7 +516,7 @@ namespace Revitalize.Framework.Objects //ModCore.log("This is my BB: " + this.boundingBox.Value); } } - + public string getDisplayNameFromStringsFile(string objectID) { diff --git a/GeneralMods/Revitalize/Framework/Utilities/TimeUtilities.cs b/GeneralMods/Revitalize/Framework/Utilities/TimeUtilities.cs new file mode 100644 index 00000000..681054cd --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Utilities/TimeUtilities.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Revitalize.Framework.Utilities +{ + public class TimeUtilities + { + public static int GetMinutesFromTime(int Days, int Hours, int Minutes) + { + int amount=0; + amount += Days * 24 * 60; + amount += Hours * 60; + amount += Minutes; + return amount; + } + } +} diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 8bd7c24e..3b6be6c3 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -384,6 +384,7 @@ namespace Revitalize throw new Exception("Can't run Revitalize in multiplayer due to lack of current support!"); } Serializer.afterLoad(); + ShopHacks.AddOreToClintsShop(); // Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.BigTiledTest")); diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 0c7ea374..a380750a 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -68,6 +68,7 @@ + @@ -157,6 +158,7 @@ +