-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitemsystems.py
175 lines (160 loc) · 5.43 KB
/
itemsystems.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from random import choice, randint
from engine import Item, Player
import battle
# -- Don't delete!! It is very important!!
dummy = Player("dummy")
class Generate:
def __init__(self):
self.prefixes = ['Bloody', 'Dirty', 'Shiny', 'Evil']
self.suffixes = ['Of Pain', 'Of Doom', 'Of Chaos', 'Of Light']
self.weapons = ['Sword', 'Dagger', 'Staff', 'Hammer']
self.armors = ['Cloak', 'Chain Mail', 'Plate Mail', 'Scale Mail', 'Leather Jacket']
self.shields = ['Buckler', 'Targe', 'Large Shield', 'Barrel Lid', 'Tortoise Shell']
self.trinkets = ['Tooth', 'Skull', 'Spine', 'Rune', 'Carrot', 'Potato']
def weapon(self):
# -- Make a name
name = choice(self.prefixes)
name += ' '+choice(self.weapons)+' '
name += choice(self.suffixes)
# -- Make some damage
min = randint(0,20)
max = randint(min+1, 40)
# -- Calculate Price
price = 0
price += round(((min+max)/2)*12.5)
q = price
q /= max-min
price += round(q)
# -- Make Stats string
stats = str(min)+'-'+str(max)+battle.dam().random()
return Item(name, price, stats, 1, 'weapon')
def armor(self):
# -- Make a name
name = choice(self.prefixes)
name += ' '+choice(self.armors)+' '
name += choice(self.suffixes)
# -- Roll the armor points
armor = randint(1, 250)
# -- Calculate the price
price = 0
price += armor*10
q = price
q /= armor
price += round(q)
# -- Make Stats string
stats = str(armor)+battle.bon()['arm']
return Item(name, price, stats, 1, 'armor')
def shield(self):
# -- Make a name
name = choice(self.prefixes)
name += ' '+choice(self.shields)+' '
name += choice(self.suffixes)
# -- Roll the armor points
armor = randint(1, 150)
# -- Calculate the price
price = 0
price += armor*10
q = price
q /= armor
price += round(q)
# -- Make Stats string
stats = str(armor)+battle.bon()['arm']
return Item(name, price, stats, 1, 'shield')
def trinket(self):
# -- Make a name
name = choice(self.prefixes)
name += ' '+choice(self.trinkets)+' '
name += choice(self.suffixes)
# -- Roll the armor points
bonus = randint(1, 50)
# -- Calculate the price
price = 0
price += bonus*15
q = price
q /= bonus
price += round(q)
# -- Make Stats string
stats = str(bonus)+battle.bon().random()
return Item(name, price, stats, 1, 'trinket')
def ItemLoot(player):
typech = choice(['weapon', 'armor', 'shield', 'trinket'])
item = eval("Generate().%s()" %typech)
player.inventory.add_item(item)
return item
class Store:
def __init__(self, player):
self.items = [ItemLoot(dummy) for e in range(randint(4, 16))]
self.player = player
def run(self):
print '\n'*25
print 'Welcome to Ye Olde Shop'
cmd = raw_input('Do you want to buy or sell? ')
while cmd != 'exit':
if cmd == 'buy':
print '\n'*25
self.buy_display()
elif cmd == 'sell':
print '\n'*25
self.sell_display()
else:
break
print 'Welcome to Ye Olde Shop'
cmd = raw_input('Do you want to buy or sell? ')
def buy_display(self):
print '#'*5+'Ye Olde Shop'+'#'*5
i = 1
for item in self.items:
print '(%s) %s'%(str(i), item)
i += 1
cmd = raw_input('What do you want to buy (type exit to exit)? ')
try:
if type(int(cmd)) == type(1):
self.buy(self.items.pop(int(cmd)-1))
else:
print "\n"*25
except:
print "\n"*25
def sell_display(self):
print '#'*5+'Ye Olde Shop'+'#'*5
i = 1
if self.player.inventory.items.keys():
for item in self.player.inventory.items.keys():
print '(%s) %s'%(str(i), self.player.inventory.get_item(item))
i += 1
cmd = raw_input('What do you want to sell (type exit to exit)? ')
try:
if type(int(cmd)) == type(1):
self.sell(self.player.inventory.get_item(self.player.inventory.items.keys()[int(cmd)-1]))
else:
print "\n"*25
except:
print "\n"*25
def buy(self, item):
if self.player.inventory.gold < item.price:
print 'You can\'t afford that!'
else:
self.player.inventory.take_gold(item.price)
self.player.inventory.add_item(item)
print 'Item bought!!'
print "\n"*25
self.buy_display()
def sell(self, item):
item = self.player.inventory.take_item(item.name)
self.player.inventory.add_gold(item.price)
print 'Item sold!!'
print "\n"*25
self.sell_display()
def test():
pla = Player('Kurt')
pla.inventory.gold = 1000
e = Generate()
print e.weapon()
print e.armor()
print e.shield()
print e.trinket()
print ItemLoot(pla)
a = Store(pla)
a.run()
if __name__=='__main__':
test()
a = Store(dummy)