Reorg to use dict length as parameters

pull/1/head
Jake Funke 2017-03-06 23:20:31 +00:00
parent 40ad3f64ed
commit 718f64f90d
1 changed files with 59 additions and 60 deletions

119
botany.py
View File

@ -48,58 +48,6 @@ import threading
class Plant: class Plant:
def __init__(self):
self.stage = 0
self.mutation = 0
self.species = random.randint(0,5)
self.color = random.randint(0,10)
self.rarity = self.rarity_check()
def rarity_check(self):
# todo: split this by math not literals
CONST_RARITY_MAX = 256.0
rare_seed = random.randint(1,CONST_RARITY_MAX)
common_range = round((2/3)*CONST_RARITY_MAX)
uncommon_range = round((2/3)*(CONST_RARITY_MAX-common_range))
rare_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range))
legendary_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range-rare_range))
godly_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range-rare_range-legendary_range))
# print common_range, uncommon_range, rare_range, legendary_range, godly_range
common_max = common_range
uncommon_max = common_max + uncommon_range
rare_max = uncommon_max + rare_range
legendary_max = rare_max + legendary_range
godly_max = legendary_max + godly_range
# print common_max, uncommon_max, rare_max, legendary_max, godly_max
if 0 <= rare_seed <= common_max:
rarity = 0
elif common_max < rare_seed <= uncommon_max:
rarity = 1
elif uncommon_max < rare_seed <= rare_max:
rarity = 2
elif rare_max < rare_seed <= legendary_max:
rarity = 3
elif legendary_max < rare_seed <= CONST_RARITY_MAX:
rarity = 4
return rarity
def growth(self):
if self.stage < 6:
self.stage += 1
# do stage growth stuff
CONST_MUTATION_RARITY = 9
mutation_seed = random.randint(0,CONST_MUTATION_RARITY)
if mutation_seed == CONST_MUTATION_RARITY:
mutation = random.randint(0,3)
if self.mutation == 0:
self.mutation = mutation
else:
# do stage 5 stuff (after fruiting)
1==1
def parse_plant(self):
stage_dict = { stage_dict = {
0: 'seed', 0: 'seed',
1: 'seedling', 1: 'seedling',
@ -136,7 +84,7 @@ class Plant:
0: 'poppy', 0: 'poppy',
1: 'cactus', 1: 'cactus',
2: 'aloe', 2: 'aloe',
3: 'rose', 3: 'venus flytrap',
4: 'cherry tree', 4: 'cherry tree',
5: 'fern', 5: 'fern',
} }
@ -144,21 +92,72 @@ class Plant:
mutation_dict = { mutation_dict = {
0: '', 0: '',
1: 'humming', 1: 'humming',
2: 'poisonous', 2: 'noxious',
3: 'vorpal', 3: 'vorpal',
4: 'glowing' 4: 'glowing'
} }
def __init__(self):
self.stage = 0
self.mutation = 0
self.species = random.randint(0,len(self.species_dict)-1)
self.color = random.randint(0,len(self.mutation_dict)-1)
self.rarity = self.rarity_check()
def rarity_check(self):
CONST_RARITY_MAX = 256.0
rare_seed = random.randint(1,CONST_RARITY_MAX)
common_range = round((2/3)*CONST_RARITY_MAX)
uncommon_range = round((2/3)*(CONST_RARITY_MAX-common_range))
rare_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range))
legendary_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range-rare_range))
godly_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range-rare_range-legendary_range))
# print common_range, uncommon_range, rare_range, legendary_range, godly_range
common_max = common_range
uncommon_max = common_max + uncommon_range
rare_max = uncommon_max + rare_range
legendary_max = rare_max + legendary_range
godly_max = legendary_max + godly_range
# print common_max, uncommon_max, rare_max, legendary_max, godly_max
if 0 <= rare_seed <= common_max:
rarity = 0
elif common_max < rare_seed <= uncommon_max:
rarity = 1
elif uncommon_max < rare_seed <= rare_max:
rarity = 2
elif rare_max < rare_seed <= legendary_max:
rarity = 3
elif legendary_max < rare_seed <= CONST_RARITY_MAX:
rarity = 4
return rarity
def growth(self):
if self.stage < 7:
self.stage += 1
# do stage growth stuff
CONST_MUTATION_RARITY = 9 # Increase this # to make mutation rarer (chance 1 out of x)
mutation_seed = random.randint(0,CONST_MUTATION_RARITY)
if mutation_seed == CONST_MUTATION_RARITY:
mutation = random.randint(0,len(self.mutation_dict)-1)
if self.mutation == 0: if self.mutation == 0:
print rarity_dict[self.rarity] +" "+ color_dict[self.color] +" "+ stage_dict[self.stage] +" "+ species_dict[self.species] self.mutation = mutation
else: else:
print rarity_dict[self.rarity] +" "+ mutation_dict[self.mutation] +" "+ color_dict[self.color] +" "+ stage_dict[self.stage] +" "+ species_dict[self.species] # do stage 5 stuff (after fruiting)
1==1
def parse_plant(self):
if self.mutation == 0:
print self.rarity_dict[self.rarity] +" "+ self.color_dict[self.color] +" "+ self.stage_dict[self.stage] +" "+ self.species_dict[self.species]
else:
print self.rarity_dict[self.rarity] +" "+ self.mutation_dict[self.mutation] +" "+ self.color_dict[self.color] +" "+ self.stage_dict[self.stage] +" "+ self.species_dict[self.species]
if __name__ == '__main__': if __name__ == '__main__':
my_plant = Plant() my_plant = Plant()
print my_plant.stage, my_plant.species, my_plant.color, my_plant.rarity print my_plant.stage, my_plant.species, my_plant.color, my_plant.rarity, my_plant.mutation
while my_plant.stage < 6: while my_plant.stage < 7:
raw_input("...") raw_input("...")
my_plant.growth()
my_plant.parse_plant() my_plant.parse_plant()
my_plant.growth()
print "end" print "end"