Items Changing Player Stats, Backpack increasing Inventory Size

I was just curious how this can be done. In a game like PUBG for example, when you pick up a backpack, the amount of items that one can carry will increase. I am having a bit of trouble wrapping my head around how to implement this concept.

Would you have a function that gets run whenever a specific backpack is picked up, or would you just have the backpack item edit the inventory system itself?

This item would need to act similarly to a power up no?

I guess it can be done in many ways. For example you can start with having base backpack class:

public abstract class Backpack
{
	private int maximumWeight;
	private List<Item> items;
	
	public Backpack(List<Item> items = null)
	{
		this.items = new List<Item>(); 
		this.items = items;
	}
}

The you can add three class (one per tier):

public class SmallBackpack : Backpack
{
	maximumWieght = 10;
}

public class NormalBackpack : Backpack
{
	maximumWeight = 15;
}

public class BigBackpack : Backpack
{
	maximumWeight = 20;
}

Some class containing information about player should have field and a method:

private Backpack playerBackpack;

public void ChangeBackpack(BackpackType newBackpackType)
{
	switch(newBackpackType)
	{
		case(small):
			playerBackpack = new SmallBackpack(playerBackpack.items); //it will move current items to new backpack
			break;
		case(normal):
			playerBackpack = new NormalBackpack(playerBackpack.items);
			break;
		case(big):
			playerBackpack = new BigBackpack(playerBackpack.items);
			break;
	}
}

After all another class, for example WorldItem can call Player.ChangeBackpack(BackpackType).

I’ve missed some null checks, correctness and in my opinion WorldItem calling method on player is basically bad idea, but I hope you get the point :slight_smile: