PotatoPlan/Game1/Sources/Objects/InventorySystem/Inventory.cs

177 lines
5.0 KiB
C#
Raw Normal View History

2020-05-06 16:22:30 +02:00
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;
2020-05-10 01:38:08 +02:00
private int maxWeight = 350;
2020-05-11 01:11:00 +02:00
private int[] totalHarvested = new int[11];
private int[] totalFertilizerUsed = new int[8];
2020-05-06 16:22:30 +02:00
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;
2020-05-11 01:11:00 +02:00
if (Type == 1)
{
totalHarvested[newItemIndex]++;
}
2020-05-06 16:22:30 +02:00
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
2020-05-11 01:11:00 +02:00
public bool useItem(int Index, int Type, bool isClearing)
2020-05-06 16:22:30 +02:00
{
if (cargo.itemExists(Index, Type))
{
2020-05-11 01:11:00 +02:00
if (Type == 0 && !isClearing)
{
totalFertilizerUsed[Index]++;
}
2020-05-06 16:22:30 +02:00
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)
{
2020-05-11 01:11:00 +02:00
2020-05-10 01:38:08 +02:00
Weight = Weight - itemStorage.getItemByIndex(Index, Type).getWeight();
2020-05-06 16:22:30 +02:00
cargo.removeItem(Index, Type);
}
public Cargo getPredefinedItems()
{
return itemStorage;
}
2020-05-10 01:38:08 +02:00
public void clearInventory()
{
for (int i = 0; i <= 6; i++)
2020-05-11 01:11:00 +02:00
while (useItem(i, 0, true)) ;
2020-05-10 01:38:08 +02:00
for (int i = 0; i <= 10; i++)
2020-05-11 01:11:00 +02:00
while (useItem(i, 1, true)) ;
2020-05-10 01:38:08 +02:00
}
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;
}
2020-05-06 16:22:30 +02:00
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);
2020-05-11 01:11:00 +02:00
spriteBatch.DrawString(Bold, "Harvested:", new Vector2(600, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
2020-05-06 16:22:30 +02:00
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);
2020-05-11 01:11:00 +02:00
spriteBatch.DrawString(Bold, totalHarvested[i].ToString(), new Vector2(620, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue);
2020-05-06 16:22:30 +02:00
}
spriteBatch.DrawString(Bold, "Fertilizers: ", new Vector2(700, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
2020-05-11 01:11:00 +02:00
spriteBatch.DrawString(Bold, "Used ", new Vector2(830, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 2), Color.DarkRed);
2020-05-06 16:22:30 +02:00
for (int i = 0; i < 7; i++) //Print Fertilizers
{
2020-05-11 01:11:00 +02:00
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);
spriteBatch.DrawString(Bold, totalFertilizerUsed[i].ToString(), new Vector2(835, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20 * i + 22), Color.DarkBlue);
2020-05-06 16:22:30 +02:00
}
2020-05-11 01:11:00 +02:00
2020-05-06 16:22:30 +02:00
}
}