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