Item & Inventory

This commit is contained in:
KuMiShi
2026-01-23 17:10:04 +01:00
parent 831cbef7fa
commit 1c9d5fd4a8
5 changed files with 61 additions and 12 deletions

View File

@@ -1,5 +1,31 @@
from .serializable import Serializable
from .item import Item
class Inventory(Serializable):
def __init__(self):
super().__init__()
def __init__(self, max_capacity:float = 50.0):
super().__init__()
self.items:list[Item] = []
self.max_capacity = max_capacity # Weight (kg)
def current_capacity(self):
return sum([item.weight for item in self.items])
def list_items(self):
s_items = ''
for item in self.items:
s_items += item.__str__() + '; '
return s_items
def add_item(self, added_item:Item):
if added_item.weight + self.current_capacity() > self.max_capacity:
return f'{added_item.name} is too heavy to fit inside the inventory: {added_item.weight + self.current_capacity() - self.max_capacity}kg in surplus!'
else:
self.items.append(added_item)
return f'{added_item.name} added to inventory. Current items load: {self.current_capacity()}kg'
def remove_item(self, r_item):
if r_item in self.items:
self.items.remove(r_item)
return f'{r_item.name} was removed from the inventory'
else:
return f'{r_item.name} is not present within the inventory'