PotatoPlan/Game1/Sources/Objects/InventorySystem/Inventory.cs
2020-05-10 01:38:08 +02:00

160 lines
4.0 KiB
C#

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 Microsoft.Xna.Framework.Input;
class Inventory
{
private int Weight = 0;
private int maxWeight = 350;
private Cargo cargo = new Cargo();
private Cargo itemStorage = new Cargo();
// Item list by index:
// ---------------------------------------
// (0) Fertilizers
// 1: 10-26-26
// 2: 14-35-14
// 3: 17-17-17
// 4: 20-20
// 5: 28-28
// 6: DAP
// 7: Urea
// (1) Crops:
// 1: Barley
// 2: Cotton
// 3: Ground Nuts
// 4: Maize
// 5: Millets
// 6: Oil Seeds
// 7: Paddy
// 8: Pulses
// 9: Sugarcane
// 10: Tobacco
// 11: Wheat
//
// Number - 1 to get the index in the array
// Adds all the items to the houses inventory for pickup at the houses position
public void initInventorySystem()
{
itemStorage.initStorageItems();
}
public int getWeight()
{
return Weight;
}
// Adds item to the tractor.
// 0 = Fertilizer
// 1 = Crops
public bool addItem(int newItemIndex, int Type)
{
Items newItem;
newItem = itemStorage.getItemByIndex(newItemIndex, Type);
if (maxWeight >= Weight + newItem.getWeight())
{
cargo.addItem(newItem, Type);
Weight = Weight + newItem.getWeight();
return true;
}
else
{
return false;
}
}
// Uses an item from the tractor.
// 0 = Fertilizer
// 1 = Crops
public bool useItem(int Index, int Type)
{
if (cargo.itemExists(Index, Type))
{
removeItem(Index, Type);
return true;
}
return false;
}
public int getMaxWeight()
{
return maxWeight;
}
// Checks whether or not the tractor has the item in its inventory.
// 0 = Fertilizer
// 1 = Crops
public bool itemExists(int Index, int Type)
{
return cargo.itemExists(Index, Type);
}
public void removeItem(int Index, int Type)
{
Weight = Weight - itemStorage.getItemByIndex(Index, Type).getWeight();
cargo.removeItem(Index, Type);
}
public Cargo getPredefinedItems()
{
return itemStorage;
}
public void clearInventory()
{
for (int i = 0; i <= 6; i++)
while (useItem(i, 0)) ;
for (int i = 0; i <= 10; i++)
while (useItem(i, 1)) ;
}
public void fillWithFertilizer()
{
int i = 0;
while (getWeight() < getMaxWeight())
{
if (i > 6)
i = 0;
addItem(i, 0);
i++;
}
}
public bool isMissingFertilizer()
{
for (int i = 0; i <= 6; i++)
{
if (!itemExists(i, 0))
return true;
}
return false;
}
public void printItems(Input input, SpriteBatch spriteBatch, SpriteFont Bold)
{
spriteBatch.DrawString(Bold, "Crops: ", new Vector2(470, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
for (int i = 0; i < 11; i++) //Print Crops
{
spriteBatch.DrawString(Bold, cargo.getCount(i, 1) + " " + itemStorage.getItemByIndex(i, 1).getItemType(), new Vector2(470, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue);
}
spriteBatch.DrawString(Bold, "Fertilizers: ", new Vector2(700, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
for (int i = 0; i < 7; i++) //Print Fertilizers
{
spriteBatch.DrawString(Bold, cargo.getCount(i, 0) + " " + itemStorage.getItemByIndex(i, 0).getItemType(), new Vector2(700, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue);
}
}
}