Added additional costs to recipes such as magic, health, stamina, and gold.
This commit is contained in:
parent
87913f22ff
commit
2448f7ca01
|
@ -21,13 +21,14 @@ namespace Revitalize.Framework.Crafting
|
|||
public string outputDescription;
|
||||
public string outputName;
|
||||
|
||||
public StatCost statCost;
|
||||
|
||||
public Recipe() { }
|
||||
|
||||
/// <summary>Constructor for single item output.</summary>
|
||||
/// <param name="inputs">All the ingredients required to make the output.</param>
|
||||
/// <param name="output">The item given as output with how many</param>
|
||||
public Recipe(Dictionary<Item, int> inputs, KeyValuePair<Item, int> output)
|
||||
public Recipe(Dictionary<Item, int> inputs, KeyValuePair<Item, int> 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<Item, int> inputs, Dictionary<Item, int> outputs, string OutputName, string OutputDescription, Item DisplayItem = null)
|
||||
public Recipe(Dictionary<Item, int> inputs, Dictionary<Item, int> 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();
|
||||
}
|
||||
|
||||
/// <summary>Checks if a player contains all recipe ingredients.</summary>
|
||||
|
@ -90,7 +93,7 @@ namespace Revitalize.Framework.Crafting
|
|||
|
||||
public void consume(ref List<Item> 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<Item> items)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the player can afford the cost but allows for player to collapse.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Same as affording the cost but prevents the player from collapsing.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Consume all necessary components for this cost.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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
|
||||
{
|
||||
/// <summary>If the player is currently sitting.</summary>
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -149,16 +149,16 @@ namespace Revitalize
|
|||
Recipe pie = new Recipe(new Dictionary<Item, int>()
|
||||
{
|
||||
[bigObject] = 1
|
||||
}, new KeyValuePair<Item, int>(new Furniture(3, Vector2.Zero), 1));
|
||||
}, new KeyValuePair<Item, int>(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)
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Framework\Crafting\Recipe.cs" />
|
||||
<Compile Include="Framework\Crafting\StatCost.cs" />
|
||||
<Compile Include="Framework\Enums\Enums.cs" />
|
||||
<Compile Include="Framework\Environment\DarkerNight.cs" />
|
||||
<Compile Include="Framework\Environment\DarkerNightConfig.cs" />
|
||||
|
@ -57,8 +58,13 @@
|
|||
<Compile Include="Framework\Illuminate\LightManager.cs" />
|
||||
<Compile Include="Framework\Objects\BasicItemInformation.cs" />
|
||||
<Compile Include="Framework\Objects\CustomObject.cs" />
|
||||
<Compile Include="Framework\Objects\Furniture\Chair.cs" />
|
||||
<Compile Include="Framework\Objects\Furniture\FurnitureTileComponent.cs" />
|
||||
<Compile Include="Framework\Objects\InformationFiles\Furniture\ChairInformation.cs" />
|
||||
<Compile Include="Framework\Objects\InformationFiles\Furniture\FurnitureInformation.cs" />
|
||||
<Compile Include="Framework\Objects\MultiTiledComponent.cs" />
|
||||
<Compile Include="Framework\Objects\MultiTiledObject.cs" />
|
||||
<Compile Include="Framework\Player\Managers\MagicManager.cs" />
|
||||
<Compile Include="Framework\Player\Managers\SittingInfo.cs" />
|
||||
<Compile Include="Framework\Player\PlayerInfo.cs" />
|
||||
<Compile Include="Framework\Utilities\InventoryManager.cs" />
|
||||
|
|
Loading…
Reference in New Issue