6 def __init__(self
, contents
):
7 self
.contents
= contents
8 self
.redo_stocked_contents()
10 def redo_stocked_contents(self
):
11 self
.stocked_contents
= [item
for item
in self
.contents
if item
.count
> 0]
13 def getContents(self
):
14 return self
.stocked_contents
16 def buy(self
, stocked_item
, num
= 1):
17 # Translate stocked_item back into the index for self.contents.
19 for real_item
in self
.contents
:
20 if real_item
== self
.stocked_contents
[stocked_item
]:
24 price
= self
.contents
[item
].value
26 if num
> self
.contents
[item
].count
:
27 return "The store doesn't have that many.\n"
28 elif party
.gold
< total
:
29 return "Not enough money.\n"
31 player_item
= self
.contents
[item
].split(num
)
32 party
.got_item(player_item
)
33 if self
.contents
[item
].count
<= 0:
34 self
.redo_stocked_contents()
36 def sell(self
, item
, num
= 1):
37 if party
.items
[item
].count
< num
:
38 return "You don't have that many.\n"
39 shop_price
= party
.items
[item
].value
40 price
= shop_price
/ 2
41 party
.gold
+= num
* price
42 for shop_item
in self
.contents
:
43 if shop_item
== party
.items
[item
]:
44 shop_item
.count
+= num
45 self
.redo_stocked_contents()
47 party
.lost_item(item
, num
)
49 def make_shop(level
=1, weapons
= False, armor
= False, magic
= False, other
= False, random
= True, contents
= None):
54 contents
.append(sword
.make(1))
56 contents
.append(shield
.make(1))
58 contents
.append(fire_stone
.make(1))
59 contents
.append(healing_stone
.make(1))
61 contents
.append(potion
.make(1))