So I have a static item list which stores a few classes, and in those classes are variables such as "int ID", "string name", "string description", "int currentAmount", etc.
ItemDatabase.cs...
public static List<Item> Items
static void LoadItemData()
{
Items.Add(new item);
...
}
I then have a separate item list which will have items added to it for use by the player.
Player.cs...
List<Item> playerItems;
Then in other classes, I have AddItem(int ID)
methods:
void AddItem(int id)
{
foreach (Item i in ItemDatabase.Items)
if (i.ID == id)
playerItems.Add(i);
}
I'm currently adding in entities that will make use of the same data. But when I modify the Item added to the playerItems, it modifies ItemDatabase.Items (Obviously, due to referencing).
I can't make the Item class into a struct, because I have other classes which derive from it. I need the "currentAmount" integer to be by value. Is there any way I can do this?
P.S., I've tried deep cloning, and that doesn't play nicely with my Item class.