class Recipe:
def __init__(self, data):
self.ingredients = [Ingredient(items.get(i, Item(i)), j) for i, j in zip(data[0], data[1])]
self._quantity = data[2]
self.time = data[3]
self.rate = self._quantity/self.time
self.data = data
def __mul__(self, multiplier: int):
if not isinstance(multiplier, int): return self
new_data = [self.data[0], list(map(lambda _: _*multiplier, self.data[1])), self.data[2]*multiplier, self.data[3]*multiplier]
new_recipe = Recipe(new_data)
for i in range(len(new_recipe.ingredients)):
if new_recipe.ingredients[i].recipe is not None:
new_recipe.ingredients[i].recipe *= multiplier
return new_recipe
# Recipe format #
# [
# [item names],
# [item quantities],
# recipe yield,
# recipe time
# ]
items['iron plate'].recipe = Recipe([['iron ore', 'copper plate'], [8,4], 5, 3])
items['iron ore'].recipe = Recipe([['a', 'b'], [1,2], 3,4])
items['a'].recipe = Recipe([['c'], [1], 2, 3])
when i try to multiple iron ore recipe, a recipe suddenly becomes None instead of multiplying as well 