|
|
@ -14,7 +14,7 @@ class Material: |
|
|
|
class Inventaire: |
|
|
|
def __init__(self, id, item=None): |
|
|
|
self._id = id |
|
|
|
self._slots = [] |
|
|
|
self._potions = [] |
|
|
|
self.append(item) |
|
|
|
self.append(Material.POTION) |
|
|
|
|
|
|
@ -22,17 +22,25 @@ class Inventaire: |
|
|
|
conn = Connection() |
|
|
|
conn.db.execute("INSERT INTO inventaire (personnage_id, item_type) VALUES (?, ?);", (self._id, item_type)) |
|
|
|
conn.commit() |
|
|
|
if item_type == "POTION": |
|
|
|
conn.db.execute("SELECT last_insert_rowid();") |
|
|
|
self._slots.append(conn.db.fetchone()[0]) |
|
|
|
slot = conn.db.fetchone()[0] |
|
|
|
self._potions.append(slot) |
|
|
|
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] |
|
|
|
conn.close() |
|
|
|
|
|
|
|
def pop_potion(self): |
|
|
|
if len(self._potions) == 0: |
|
|
|
return None |
|
|
|
v = self._potions[0] |
|
|
|
del self._potions[0] |
|
|
|
return v |
|
|
|
|
|
|
|
def has(self, item_type): |
|
|
|
conn = Connection() |
|
|
|
conn.db.execute("SELECT slot FROM inventaire WHERE personnage_id=? AND item_type=?", (self._id, item_type)) |
|
|
|