def test2(): # create an inventory with an altar and the ingredients needed for a spell m = mansion() m.char.inventory.put_away(ALTAR()) for ingredient in m.crafter.ingredients_by_spell(SPELLS.PROTECTION): m.char.inventory.put_away(ingredient) # this causes the side effect of adding craft names as ingredients, they should be ignored or removed # test remove for ing in m.char.inventory.ingredients.items: # check items against the ingredient list if not ing.name in [e for e in ingredient_name]: # throw away everything that isn't an ingredient m.char.inventory.throw_away(ing) # now that everything is cleaned up, craft the spells! # hand the sublist of selected ingredients to the craft engine. print("Items accounted for? {}".format( m.crafter.check_spell_prerequisites(m.char.inventory, SPELLS.PROTECTION) )) prot = _craft(craft_type=craft_engine().spells, craft_name=SPELLS.PROTECTION, ingredients_list=\ m.char.inventory.ingredients.items+\ m.char.inventory.spells.items) # This is where you would remove the selected item subset, but we're not doing that here # instead, we'll just blow away the whole list and replace it with the new subset m.char.inventory.ingredients.items = [] # kabloosh now it's empty m.char.inventory.spells.items = [] # kabloosh now it's empty # next craft, now without any comments: for ingredient in m.crafter.ingredients_by_spell(SPELLS.PROTECTION2): m.char.inventory.put_away(ingredient) for ing in m.char.inventory.ingredients.items: if not ing.name in [e for e in ingredient_name]: m.char.inventory.throw_away(ing) m.char.inventory.put_away(prot) # okay, one comment. This spell requires the craft we made before print("Items accounted for? {}".format( m.crafter.check_spell_prerequisites(m.char.inventory, SPELLS.PROTECTION2) )) prot2 = _craft(craft_type=craft_engine().spells, craft_name=SPELLS.PROTECTION2, ingredients_list=\ m.char.inventory.ingredients.items+\ m.char.inventory.spells.items) m.char.inventory.ingredients.items = [] m.char.inventory.spells.items = [] # and 3 for ingredient in m.crafter.ingredients_by_spell(SPELLS.PROTECTION3): m.char.inventory.put_away(ingredient) for ing in m.char.inventory.ingredients.items: if not ing.name in [e for e in ingredient_name]: m.char.inventory.throw_away(ing) m.char.inventory.put_away(prot2) # same thing as before print("Items accounted for? {}".format( m.crafter.check_spell_prerequisites(m.char.inventory, SPELLS.PROTECTION3) )) prot3 = _craft(craft_type=craft_engine().spells, craft_name=SPELLS.PROTECTION3, ingredients_list=\ m.char.inventory.ingredients.items+\ m.char.inventory.spells.items) m.char.inventory.put_away(prot) # need to put this back in because we blew away the inventory containing it m.char.inventory.put_away(prot3) print(m.char.inventory) # should just contain the list from protection3, since I didn't blow that one away, and the three crafts
def craft(self, item_type, item_name): """ Wraps the _craft() constructor with inventory checks :param item_type: craft_engine subtype dict :param item_name: _abstr enum (e.g. SPELLS.WISHFORHELP) """ # check spell prerequisites and altar existence new_craft = None if self.check_craft_prerequisites(item_type, item_name): new_craft = _craft(craft_type=item_type, craft_name=item_name, ingredients_list=self.selected) self.selected = [] return new_craft
def test1(): m = mansion() for i in range(0, 4): print(_craft(craft_type=craft_engine().spells)) print(_craft(craft_type=craft_engine().tools)) print(_craft(craft_type=craft_engine().traps)) print(_craft(craft_type=craft_engine().weapons)) print(_craft(craft_type=craft_engine().spells, craft_name=SPELLS.INTROSPECTION)) c = _craft(craft_type=craft_engine().spells, craft_name=SPELLS.DUPLICATION) print(c) for i in c.functions: print(i)
class ingredients: def __init__(self): self.items = [] def __str__(self): return "ingredients:\n" + "\n".join([e.__str__() for e in self.items]) class specials: def __init__(self): self.items = [] def __str__(self): return "specials:\n" + "\n".join([e.__str__() for e in self.items]) if __name__ == "__main__": inv = inventory() for i in range(0, 10): c = _craft() print(c) if not inv.put_away(c): print("didn't go in") for i in range(0, 10): c = random.choice([BOOK(), ALTAR(), INGREDIENT()]) if not inv.put_away(c): print("didn't go in") print(inv.current_weight) inv.show_subinv(item_type.WEAPON)
def RANDOMIZE_CRAFT(self, craft_type=None, craft_name=None, effect_funcs=[], quantity=""): return _craft(craft_type, craft_name, effect_funcs, quantity)