summaryrefslogtreecommitdiff
path: root/net/inventory.py
blob: de927d7bdf0b5a26bba50346212fe150a4606e15 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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