diff options
Diffstat (limited to 'net/inventory.py')
-rw-r--r-- | net/inventory.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/net/inventory.py b/net/inventory.py new file mode 100644 index 0000000..de927d7 --- /dev/null +++ b/net/inventory.py @@ -0,0 +1,51 @@ +import mapserv + + +def get_item_index(item_id): + for index, (id_, _) in mapserv.player_inventory.iteritems(): + if id_ == item_id: + return index + + return -10 + + +def remove_from_inventory(index, amount): + item_id, curr_amount = mapserv.player_inventory[index] + curr_amount -= amount + if curr_amount <= 0: + del mapserv.player_inventory[index] + else: + mapserv.player_inventory[index] = item_id, curr_amount + + +def add_to_inventory(index, item_id, amount): + if index not in mapserv.player_inventory: + mapserv.player_inventory[index] = item_id, amount + else: + _, curr_amount = mapserv.player_inventory[index] + mapserv.player_inventory[index] = item_id, curr_amount + amount + + +def get_storage_index(item_id): + for index, (id_, _) in mapserv.player_storage.iteritems(): + if id_ == item_id: + return index + + return -10 + + +def remove_from_storage(index, amount): + item_id, curr_amount = mapserv.player_storage[index] + curr_amount -= amount + if curr_amount <= 0: + del mapserv.player_storage[index] + else: + mapserv.player_storage[index] = item_id, curr_amount + + +def add_to_storage(index, item_id, amount): + if index not in mapserv.player_storage: + mapserv.player_storage[index] = item_id, amount + else: + _, curr_amount = mapserv.player_storage[index] + mapserv.player_storage[index] = item_id, curr_amount + amount |