|
@ -12,17 +12,45 @@ class Material: |
|
|
|
|
|
|
|
|
#TODO: inventaire mysql |
|
|
#TODO: inventaire mysql |
|
|
class Inventaire: |
|
|
class Inventaire: |
|
|
def __init__(self, id, item): |
|
|
def __init__(self, id, item=None): |
|
|
self._id = id |
|
|
self._id = id |
|
|
|
|
|
self._slots = [] |
|
|
|
|
|
self.append(item) |
|
|
|
|
|
self.append(Material.POTION) |
|
|
|
|
|
|
|
|
|
|
|
def append(self, item_type): |
|
|
def append(self, item): |
|
|
|
|
|
conn = Connection() |
|
|
conn = Connection() |
|
|
conn.db.execute("INSERT INTO inventaire (personnage_id, nom) VALUES (?, ?);", (self._id, item)) |
|
|
conn.db.execute("INSERT INTO inventaire (personnage_id, item_type) VALUES (?, ?);", (self._id, item_type)) |
|
|
|
|
|
conn.commit() |
|
|
conn.db.execute("SELECT last_insert_rowid();") |
|
|
conn.db.execute("SELECT last_insert_rowid();") |
|
|
|
|
|
self._slots.append(conn.db.fetchone()[0]) |
|
|
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
|
|
|
def remove(self, slot): |
|
|
|
|
|
conn = Connection() |
|
|
|
|
|
conn.db.execute("DELETE FROM inventaire WHERE personnage_id=? AND slot=?", (self._id, slot)) |
|
|
|
|
|
conn.commit() |
|
|
self._id = conn.db.fetchone()[0] |
|
|
self._id = conn.db.fetchone()[0] |
|
|
conn.close() |
|
|
conn.close() |
|
|
|
|
|
|
|
|
|
|
|
def has(self, item_type): |
|
|
|
|
|
conn = Connection() |
|
|
|
|
|
conn.db.execute("SELECT slot FROM inventaire WHERE personnage_id=? AND item_type=?", (self._id, item_type)) |
|
|
|
|
|
conn.commit() |
|
|
|
|
|
l = len(conn.db.fetchall()) |
|
|
|
|
|
conn.close() |
|
|
|
|
|
return False if l == 0 else True |
|
|
|
|
|
|
|
|
|
|
|
def get_items(self): |
|
|
|
|
|
conn = Connection() |
|
|
|
|
|
conn.db.execute("SELECT item_type FROM inventaire WHERE personnage_id=?;", (self._id,)) |
|
|
|
|
|
values = conn.db.fetchall() |
|
|
|
|
|
conn.close() |
|
|
|
|
|
return values |
|
|
|
|
|
|
|
|
|
|
|
def __len__(self): |
|
|
|
|
|
return len(self.get_items()) |
|
|
|
|
|
|
|
|
class Personnage: |
|
|
class Personnage: |
|
|
def __init__(self, nom, cat, personnage_type): |
|
|
def __init__(self, nom, cat, personnage_type): |
|
|
expcoef = None |
|
|
expcoef = None |
|
@ -122,4 +150,4 @@ class Personnage: |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
def affiche_inventaire(self): |
|
|
def affiche_inventaire(self): |
|
|
return ["- "+item for item in self.inventaire] |
|
|
return ["- "+item[0] for item in self.inventaire.get_items()] |
|
|