2021-05-08 22:15:26 +02:00
|
|
|
class InventoryComponent:
|
2021-05-24 17:35:08 +02:00
|
|
|
def __init__(self, maxitems=100):
|
2021-05-08 22:15:26 +02:00
|
|
|
self.maxitems = maxitems
|
|
|
|
self.items = {}
|
|
|
|
|
2021-05-24 13:10:10 +02:00
|
|
|
def add_item(self, item, count):
|
2021-05-08 22:15:26 +02:00
|
|
|
if item not in self.items:
|
|
|
|
self.items[item] = count
|
|
|
|
else:
|
|
|
|
self.items[item] = self.items[item] + count
|
|
|
|
if self.items[item] > self.maxitems:
|
|
|
|
self.items[item] = self.maxitems
|
|
|
|
|
2021-05-24 13:10:10 +02:00
|
|
|
def remove_item(self, item, count):
|
|
|
|
if item in self.items:
|
2021-05-08 22:15:26 +02:00
|
|
|
self.items[item] = self.items[item] - count
|
2021-05-24 13:10:10 +02:00
|
|
|
if self.items[item] < 0:
|
|
|
|
self.items[item] = 0
|
2021-05-08 22:15:26 +02:00
|
|
|
|
2021-05-24 13:10:10 +02:00
|
|
|
def has_item(self, item):
|
|
|
|
return item in self.items and self.items[item] != 0
|