all repos — groupgardenbot @ e4f52f5ce1f7616839913d4f31984e447e9b2aff

An extension of the game "botany", originally designed for unix-based systems, to the Telegram Bot API.

restore mutations
Marco Andronaco andronacomarco@gmail.com
Sat, 24 Sep 2022 15:47:17 +0200
commit

e4f52f5ce1f7616839913d4f31984e447e9b2aff

parent

fb23f8c5149db93ac07f0c16d09da957b83e101a

2 files changed, 11 insertions(+), 8 deletions(-)

jump to
M Gardening.pyGardening.py

@@ -4,6 +4,7 @@

water_duration = 3600 * 24 stage_factors = (1, 3, 10, 20, 30) indicator_squares = 6 +mutation_rarity = 20000 # Increase this # to make mutation rarer (chance 1 out of x each second) class Plant(object): # This is your plant!

@@ -96,12 +97,10 @@ else:

self.watered_24h = False return False - def mutate_check(self): + def mutate_check(self, increase): # Create plant mutation - # Increase this # to make mutation rarer (chance 1 out of x each second) - CONST_MUTATION_RARITY = 20000 - mutation_seed = random.randint(1,CONST_MUTATION_RARITY) - if mutation_seed == CONST_MUTATION_RARITY: + mutation_seed = random.randint(increase, mutation_rarity) + if mutation_seed == mutation_rarity: # mutation gained! mutation = random.randint(0,len(self.mutation_list)-1) if self.mutation == 0:

@@ -143,9 +142,13 @@ now = int(time.time())

res1 = min(now - plant.last_water, water_duration) res2 = min(plant.last_update - plant.last_water, water_duration) + increase = max(0, res1 - res2) # max() not necessary but just in case - plant.points += max(0, res1 - res2) # max() not necessary but just in case - + plant.points += increase + + if increase != 0: + plant.mutate_check(increase) + plant.last_update = now stages = tuple(ti / plant.generation_bonus for ti in plant.life_stages) # bonus is applied to stage thresholds
M main.pymain.py

@@ -37,7 +37,7 @@ new = False

if plant is None: plant = Plant(user_id) - context.bot_data[update.effective_user.id] = { "plant" : Plant(user_id) } + context.bot_data[update.effective_user.id] = { "plant" : plant } new = True if plant.dead or plant.stage == 5: