def pool_replace_item(self, item_pools, item_group, player_id, new_item, worlds): removed_item = self.pool_remove_item(item_pools, item_group, 1, world_id=player_id)[0] item_matcher = lambda item: pattern_matcher(new_item)(item.name) if self.item_pool[removed_item.name].count > 1: self.item_pool[removed_item.name].count -= 1 else: del self.item_pool[removed_item.name] if new_item == "#Junk": if self.distribution.settings.enable_distribution_file: return ItemFactory(get_junk_item(1, self.base_pool, self.item_pool))[0] else: # Generator settings that add junk to the pool should not be strict about the item_pool definitions return ItemFactory(get_junk_item(1))[0] return random.choice(list(ItemIterator(item_matcher, worlds[player_id])))
def pool_add_item(self, pool, item_name, count): if item_name == '#Junk': added_items = get_junk_item(count, pool=pool, plando_pool=self.item_pool) elif is_pattern(item_name): add_matcher = lambda item: pattern_matcher(item_name)(item.name) candidates = [ item.name for item in ItemIterator(predicate=add_matcher) if item.name not in self.item_pool or self.item_pool[item.name].count != 0 ] # Only allow items to be candidates if they haven't been set to 0 if len(candidates) == 0: raise RuntimeError("Unknown item, or item set to 0 in the item pool could not be added: " + item_name) added_items = random_choices(candidates, k=count) else: if not IsItem(item_name): raise RuntimeError("Unknown item could not be added: " + item_name) added_items = [item_name] * count for item in added_items: pool.append(item) return added_items
def pool_add_item(self, pool, item_name, count): added_items = [] if item_name == '#Junk': added_items = get_junk_item(count) elif is_pattern(item_name): add_matcher = lambda item: pattern_matcher(item_name)(item.name) candidates = [ item.name for item in ItemIterator(predicate=add_matcher) ] if len(candidates) == 0: raise RuntimeError("Unknown item could not be added: " + item_name) added_items = random_choices(candidates, k=count) else: if not IsItem(item_name): raise RuntimeError("Unknown item could not be added: " + item_name) added_items = [item_name] * count for item in added_items: pool.append(item) return added_items