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
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.
23 for real_item
in self
.contents
:
24 if real_item
== self
.stocked_contents
[stocked_item
]:
28 price
= self
.contents
[item
].value
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"
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()
51 party
.lost_item(item
, num
)
53 def make_shop(level
=1, weapons
= False, armor
= False, magic
= False, other
= False, random
= True, contents
= None):
58 contents
.append(sword
.make(1))
60 contents
.append(shield
.make(1))
62 contents
.append(fire_stone
.make(1))
63 contents
.append(healing_stone
.make(1))
65 contents
.append(potion
.make(1))