KEYS updated, signed copy.
[realism.git] / engine / shop.py
blob7e67a1f231bbe5cf3b4cc3fc0ea3dde7440c93a4
1 # This file is part of Realism, which is Copyright FunnyMan3595 (Charlie Nolan)
2 # and licensed under the GNU GPL v3. For more details, see LICENSE in the main
3 # Realism directory.
5 from items import *
6 from game import game
7 party = game.party
9 class shop(object):
10 def __init__(self, contents):
11 self.contents = contents
12 self.redo_stocked_contents()
14 def redo_stocked_contents(self):
15 self.stocked_contents = [item for item in self.contents if item.count > 0]
17 def getContents(self):
18 return self.stocked_contents
20 def buy(self, stocked_item, num = 1):
21 # Translate stocked_item back into the index for self.contents.
22 item = 0
23 for real_item in self.contents:
24 if real_item == self.stocked_contents[stocked_item]:
25 break
26 item += 1
28 price = self.contents[item].value
29 total = num * price
30 if num > self.contents[item].count:
31 return "The store doesn't have that many.\n"
32 elif party.gold < total:
33 return "Not enough money.\n"
34 party.gold -= total
35 player_item = self.contents[item].split(num)
36 party.got_item(player_item)
37 if self.contents[item].count <= 0:
38 self.redo_stocked_contents()
40 def sell(self, item, num = 1):
41 if party.items[item].count < num:
42 return "You don't have that many.\n"
43 shop_price = party.items[item].value
44 price = shop_price / 2
45 party.gold += num * price
46 for shop_item in self.contents:
47 if shop_item == party.items[item]:
48 shop_item.count += num
49 self.redo_stocked_contents()
50 break
51 party.lost_item(item, num)
53 def make_shop(level=1, weapons = False, armor = False, magic = False, other = False, random = True, contents = None):
54 if random:
55 if contents == None:
56 contents = []
57 if weapons:
58 contents.append(sword.make(1))
59 if armor:
60 contents.append(shield.make(1))
61 if magic:
62 contents.append(fire_stone.make(1))
63 contents.append(healing_stone.make(1))
64 if other:
65 contents.append(potion.make(1))
67 return shop(contents)