using System.Collections.Generic;
namespace Cyber.Items {
///
/// A drive containing items, and has a limited capacity that cannot be changed.
///
public class Drive {
private List- Items = new List
- ();
///
/// The capacity of the drive, meaning how much stuff can this drive contain.
///
public readonly float Capacity;
///
/// The interface-class of this Drive.
///
public DriveInterface Interface;
///
/// Creates a drive with given capacity. Capacity cannot be changed after this.
///
/// Capacity of the drive
public Drive(float capacity) {
Capacity = capacity;
Interface = new DriveInterface(this);
}
///
/// Current total weight of all the items combined.
///
/// The totam weight
public float TotalWeight() {
float sum = 0;
foreach (Item item in Items) {
sum += item.Weight;
}
return sum;
}
///
/// Current free space in the drive. Literally is Capacity - TotalWeight()
///
/// Current Free space.
public float FreeSpace() {
return Capacity - TotalWeight();
}
///
/// Clears the drive, completely wiping it empty. Mainly used for
///
///
public void Clear() {
Items.Clear();
}
///
/// Adds the item in the drive. If the addition was not successful, returns false, true otherwise.
///
/// Weather the drive had enough space.
public bool AddItem(Item item) {
if (item.Weight > FreeSpace()) {
return false;
}
Interface.AddNewItem(Items.Count);
Items.Add(item);
return true;
}
///
/// Gets the item at the given index, or null if there is nothing.
///
/// The index of the desired item
/// The item or null if nothing was found.
public Item GetItem(int idx) {
if (idx < 0 || idx > Items.Count) {
return null;
}
return Items[idx];
}
///
/// Returns the list of all items currently in the drive.
///
///
public List
- GetItems() {
return Items;
}
}
}