diff --git a/GeneralMods/Revitalize/Framework/Crafting/Recipe.cs b/GeneralMods/Revitalize/Framework/Crafting/Recipe.cs index 40906ab2..dcb607c4 100644 --- a/GeneralMods/Revitalize/Framework/Crafting/Recipe.cs +++ b/GeneralMods/Revitalize/Framework/Crafting/Recipe.cs @@ -21,13 +21,14 @@ namespace Revitalize.Framework.Crafting public string outputDescription; public string outputName; + public StatCost statCost; public Recipe() { } /// Constructor for single item output. /// All the ingredients required to make the output. /// The item given as output with how many - public Recipe(Dictionary inputs, KeyValuePair output) + public Recipe(Dictionary inputs, KeyValuePair output, StatCost StatCost=null) { this.ingredients = inputs; this.DisplayItem = output.Key; @@ -37,15 +38,17 @@ namespace Revitalize.Framework.Crafting { [output.Key] = output.Value }; + this.statCost = StatCost ?? new StatCost(); } - public Recipe(Dictionary inputs, Dictionary outputs, string OutputName, string OutputDescription, Item DisplayItem = null) + public Recipe(Dictionary inputs, Dictionary outputs, string OutputName, string OutputDescription, Item DisplayItem = null,StatCost StatCost=null) { this.ingredients = inputs; this.outputs = outputs; this.outputName = OutputName; this.outputDescription = OutputDescription; this.DisplayItem = DisplayItem; + this.statCost = StatCost ?? new StatCost(); } /// Checks if a player contains all recipe ingredients. @@ -90,7 +93,7 @@ namespace Revitalize.Framework.Crafting public void consume(ref List from) { - if (!this.InventoryContainsAllIngredient(from)) + if (this.InventoryContainsAllIngredient(from)==false) return; InventoryManager manager = new InventoryManager(from); @@ -154,11 +157,12 @@ namespace Revitalize.Framework.Crafting Game1.player.Items = playerItems; //Set the items to be post consumption. foreach (Item I in outPutItems) Game1.player.addItemToInventory(I); //Add all items produced. + this.statCost.payCost(); } public bool PlayerCanCraft() { - return this.PlayerContainsAllIngredients(); + return this.PlayerContainsAllIngredients() && this.statCost.canSafelyAffordCost(); } public bool CanCraft(List items) diff --git a/GeneralMods/Revitalize/Framework/Crafting/StatCost.cs b/GeneralMods/Revitalize/Framework/Crafting/StatCost.cs new file mode 100644 index 00000000..682f8c42 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Crafting/StatCost.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using StardewValley; + +namespace Revitalize.Framework.Crafting +{ + public class StatCost + { + int health; + int stamina; + int magic; + int gold; + + public StatCost(int Stamina = 0, int Health = 0, int Gold = 0, int Magic = 0){ + this.stamina = Stamina; + this.health = Health; + this.gold = Gold; + this.magic = Magic; + } + + /// + /// Checks if the player can afford the cost but allows for player to collapse. + /// + /// + public bool canAffordCost() { + + if (Game1.player.stamina >= this.stamina && Game1.player.health >= this.health && Game1.player.Money >= this.gold && Revitalize.ModCore.playerInfo.magicManager.currentMagic >= this.magic) return true; + return false; + + } + + /// + /// Same as affording the cost but prevents the player from collapsing. + /// + /// + public bool canSafelyAffordCost() + { + if (Game1.player.stamina > this.stamina && Game1.player.health > this.health && Game1.player.Money >= this.gold && Revitalize.ModCore.playerInfo.magicManager.currentMagic >= this.magic) return true; + return false; + } + + /// + /// Consume all necessary components for this cost. + /// + public void payCost() + { + if (canSafelyAffordCost()) + { + Game1.player.stamina -= this.stamina; + Game1.player.health -= this.health; + Game1.player.Money = Game1.player.Money - this.gold; + Revitalize.ModCore.playerInfo.magicManager.currentMagic -= this.magic; + } + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Player/Managers/MagicManager.cs b/GeneralMods/Revitalize/Framework/Player/Managers/MagicManager.cs new file mode 100644 index 00000000..1ad80afe --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Player/Managers/MagicManager.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Revitalize.Framework.Player.Managers +{ + public class MagicManager + { + public int maxMagic; + public int currentMagic; + + public MagicManager() + { + this.currentMagic = 100; + this.maxMagic = 100; + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Player/Managers/SittingInfo.cs b/GeneralMods/Revitalize/Framework/Player/Managers/SittingInfo.cs index c2688648..27b53a7b 100644 --- a/GeneralMods/Revitalize/Framework/Player/Managers/SittingInfo.cs +++ b/GeneralMods/Revitalize/Framework/Player/Managers/SittingInfo.cs @@ -7,7 +7,6 @@ namespace Revitalize.Framework.Player.Managers // TODO: // - Make chair // - animate player better - // - have it where when player is sitting on chair it is passable so it can't be destoryed underneath public class SittingInfo { /// If the player is currently sitting. diff --git a/GeneralMods/Revitalize/Framework/Player/PlayerInfo.cs b/GeneralMods/Revitalize/Framework/Player/PlayerInfo.cs index 3c0dc322..275e6355 100644 --- a/GeneralMods/Revitalize/Framework/Player/PlayerInfo.cs +++ b/GeneralMods/Revitalize/Framework/Player/PlayerInfo.cs @@ -5,10 +5,12 @@ namespace Revitalize.Framework.Player public class PlayerInfo { public SittingInfo sittingInfo; + public MagicManager magicManager; public PlayerInfo() { this.sittingInfo = new SittingInfo(); + this.magicManager = new MagicManager(); } public void update() diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index d5d18eb8..f24478ea 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -149,16 +149,16 @@ namespace Revitalize Recipe pie = new Recipe(new Dictionary() { [bigObject] = 1 - }, new KeyValuePair(new Furniture(3, Vector2.Zero), 1)); + }, new KeyValuePair(new Furniture(3, Vector2.Zero), 1),new StatCost(100,50,0,0)); new InventoryItem(bigObject, 100, 1).addToNPCShop("Gus"); Game1.player.addItemToInventory(bigObject); - //if (pie.PlayerCanCraft()) - //{ - // pie.craft(); - //} + if (pie.PlayerCanCraft()) + { + pie.craft(); + } } public static void log(object message) diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index dc74ff89..94c75140 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -47,6 +47,7 @@ + @@ -57,8 +58,13 @@ + + + + +