Equippable & Consummable
This commit is contained in:
10
inventory.py
10
inventory.py
@@ -28,4 +28,12 @@ class Inventory(Serializable):
|
|||||||
self.items.remove(r_item)
|
self.items.remove(r_item)
|
||||||
return f'{r_item.name} was removed from the inventory'
|
return f'{r_item.name} was removed from the inventory'
|
||||||
else:
|
else:
|
||||||
return f'{r_item.name} is not present within the inventory'
|
return f'{r_item.name} is not present within the inventory'
|
||||||
|
|
||||||
|
def get_item(self, item_name:str):
|
||||||
|
for item in self.items:
|
||||||
|
if item.name == item_name:
|
||||||
|
return item
|
||||||
|
|
||||||
|
# The item was not found
|
||||||
|
return None
|
||||||
24
item.py
24
item.py
@@ -1,19 +1,33 @@
|
|||||||
from .serializable import Serializable
|
from .serializable import Serializable
|
||||||
|
|
||||||
class Item(Serializable):
|
class Item(Serializable):
|
||||||
def __init__(self,name:str, description:str, weight:float = 10.0):
|
def __init__(self,name:str, description:str, stat_modifier:str, weight:float = 10.0):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.name = name
|
self.name = name
|
||||||
self.description = description
|
self.description = description
|
||||||
|
self.stat_modifier = stat_modifier
|
||||||
self.weight = weight
|
self.weight = weight
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name + '(' + self.weight + ' kg)' + ': ' + self.description
|
return self.name + '(' + self.weight + ' kg)' + ': ' + self.description
|
||||||
|
|
||||||
class Equippable(Item):
|
class Equippable(Item):
|
||||||
def __init__(self, name, description, weight = 10):
|
def __init__(self, name, description, stat_modifier, equipped:bool, weight = 10.0):
|
||||||
super().__init__(name, description, weight)
|
super().__init__(name, description, stat_modifier, weight)
|
||||||
|
self.equipped = equipped
|
||||||
|
|
||||||
|
def equip(self):
|
||||||
|
self.equipped = True
|
||||||
|
|
||||||
|
def unequip(self):
|
||||||
|
self.equipped = False
|
||||||
|
|
||||||
class Consummable(Item):
|
class Consummable(Item):
|
||||||
def __init__(self, name, description, weight = 10):
|
def __init__(self, name, description, stat_modifier, nb_of_uses:int, weight = 10.0):
|
||||||
super().__init__(name, description, weight)
|
super().__init__(name, description, stat_modifier, weight)
|
||||||
|
self.nb_of_uses = nb_of_uses
|
||||||
|
|
||||||
|
def consumme(self):
|
||||||
|
if self.nb_of_uses > 0:
|
||||||
|
self.nb_of_uses -= 1
|
||||||
|
|
||||||
Reference in New Issue
Block a user