Item & Inventory
This commit is contained in:
19
entity.py
19
entity.py
@@ -1,7 +1,20 @@
|
|||||||
from .serializable import Serializable
|
from .serializable import Serializable
|
||||||
|
from enum import Enum, IntEnum
|
||||||
|
|
||||||
|
class Action(Enum):
|
||||||
|
ATTACK = 'strength' # Physical Battle action
|
||||||
|
FORCE = 'strength' # Actions that requires physical effort
|
||||||
|
SPELL = 'intelligence' # Many kind of spell (battle or not)
|
||||||
|
SCAN = 'wisdom' # Danger in environment or NPC's lies
|
||||||
|
SPEECH = 'charisma' # To persuade or deceive
|
||||||
|
AGILE = 'dexterity' # Avoid traps or incoming attacks & spell
|
||||||
|
|
||||||
|
class BonusAction(IntEnum):
|
||||||
|
EQUIP_ITEM = 0
|
||||||
|
USE_CONSUMMABLE = 1
|
||||||
|
|
||||||
class Entity(Serializable):
|
class Entity(Serializable):
|
||||||
def __init__(self, name, strength, dexterity, intelligence, wisdom, charisma, hp, armor, speed):
|
def __init__(self, name, strength, dexterity, intelligence, wisdom, charisma, hp, armor, speed, equipped_item=None):
|
||||||
self.name =name
|
self.name =name
|
||||||
self.strength = strength
|
self.strength = strength
|
||||||
self.dexterity = dexterity
|
self.dexterity = dexterity
|
||||||
@@ -11,3 +24,7 @@ class Entity(Serializable):
|
|||||||
self.hp =hp
|
self.hp =hp
|
||||||
self.armor = armor
|
self.armor = armor
|
||||||
self.speed = speed
|
self.speed = speed
|
||||||
|
self.equipped_item = equipped_item
|
||||||
|
|
||||||
|
def make_a_turn(self, action:Action, bonus_action:BonusAction):
|
||||||
|
pass
|
||||||
28
inventory.py
28
inventory.py
@@ -1,5 +1,31 @@
|
|||||||
from .serializable import Serializable
|
from .serializable import Serializable
|
||||||
|
from .item import Item
|
||||||
|
|
||||||
class Inventory(Serializable):
|
class Inventory(Serializable):
|
||||||
def __init__(self):
|
def __init__(self, max_capacity:float = 50.0):
|
||||||
super().__init__()
|
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'
|
||||||
8
item.py
8
item.py
@@ -1,5 +1,11 @@
|
|||||||
from .serializable import Serializable
|
from .serializable import Serializable
|
||||||
|
|
||||||
class Item(Serializable):
|
class Item(Serializable):
|
||||||
def __init__(self):
|
def __init__(self,name:str, description:str, weight:float = 10.0):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.name = name
|
||||||
|
self.description = description
|
||||||
|
self.weight = weight
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name + '(' + self.weight + ' kg)' + ': ' + self.description
|
||||||
5
npc.py
5
npc.py
@@ -1,6 +1,5 @@
|
|||||||
from .entity import Entity
|
from .entity import Entity
|
||||||
|
|
||||||
class NPC(Entity):
|
class NPC(Entity):
|
||||||
def __init__(self, name, strength, dexterity, intelligence, wisdom, charisma, hp, armor, speed, item=None):
|
def __init__(self, name, strength, dexterity, intelligence, wisdom, charisma, hp, armor, speed, equipped_item=None):
|
||||||
super().__init__(name, strength, dexterity, intelligence, wisdom, charisma, hp, armor, speed)
|
super().__init__(name, strength, dexterity, intelligence, wisdom, charisma, hp, armor, speed, equipped_item)
|
||||||
self.item = item
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
from .entity import Entity
|
from .entity import Entity
|
||||||
|
from .inventory import Inventory
|
||||||
|
|
||||||
class Player(Entity):
|
class Player(Entity):
|
||||||
def __init__(self, name, strength, dexterity, intelligence, wisdom, charisma, hp, armor, speed, item=None):
|
def __init__(self, name, strength, dexterity, intelligence, wisdom, charisma, hp, armor, speed, equipped_item=None):
|
||||||
super().__init__(name, strength, dexterity, intelligence, wisdom, charisma, hp, armor, speed)
|
super().__init__(name, strength, dexterity, intelligence, wisdom, charisma, hp, armor, speed, equipped_item)
|
||||||
self.item = item
|
self.inventory = Inventory(max_capacity=50)
|
||||||
Reference in New Issue
Block a user