def test_items_for_ammo_two_item(per_pickup: int, total_pickup: int, included: int): # Setup item_a = 1 item_b = 2 included_ammo_for_item = {item_a: included, item_b: included} previous_pickup_for_item = {} maximum = per_pickup * total_pickup + included ammo = Ammo("My Ammo", model_name="Model", maximum=maximum, items=(item_a, item_b), broad_category=ItemCategory.BEAM_RELATED) state = AmmoState(0, total_pickup) maximum_ammo = {item_a: maximum, item_b: maximum} # Run ammo_per_pickup = randovania.generator.item_pool.ammo.items_for_ammo( ammo, state, included_ammo_for_item, previous_pickup_for_item, maximum_ammo) # Assert assert previous_pickup_for_item == { item_a: ammo, item_b: ammo, } assert ammo_per_pickup == [[per_pickup, per_pickup]] * total_pickup
def test_items_for_ammo_two_item_diverging_values(): # Setup item_a = 1 item_b = 2 total_pickup = 10 maximum = 200 included_ammo_for_item = {item_a: 0, item_b: 100} previous_pickup_for_item = {} ammo = Ammo("My Ammo", maximum=maximum, items=(item_a, item_b), broad_category=ItemCategory.BEAM_RELATED) state = AmmoState(0, total_pickup) maximum_ammo = {item_a: maximum, item_b: maximum} # Run ammo_per_pickup = randovania.generator.item_pool.ammo.items_for_ammo(ammo, state, included_ammo_for_item, previous_pickup_for_item, maximum_ammo) # Assert assert previous_pickup_for_item == { item_a: ammo, item_b: ammo, } assert ammo_per_pickup == [[20, 10]] * total_pickup
def create_ammo_expansion( ammo: Ammo, ammo_count: Sequence[int], requires_major_item: bool, resource_database: ResourceDatabase, ) -> PickupEntry: """ Creates a Pickup for an expansion of the given ammo. :param ammo: :param ammo_count: :param requires_major_item: :param resource_database: :return: """ resources = [(resource_database.get_item(item), count) for item, count in zip(ammo.items, ammo_count)] if resource_database.item_percentage is not None: resources.append((resource_database.item_percentage, 1)) return PickupEntry( name=ammo.name, progression=(), extra_resources=tuple(resources), model=PickupModel( game=resource_database.game_enum, name=ammo.model_name, ), item_category=ammo.item_category, broad_category=ammo.broad_category, respects_lock=requires_major_item, resource_lock=ammo.create_resource_lock(resource_database), probability_multiplier=2, )
def test_items_for_ammo_one_item_non_divisible(): # Setup item_a = 1 maximum = 11 total_pickup = 5 included_ammo_for_item = {item_a: 0} previous_pickup_for_item = {} ammo = Ammo("My Ammo", model_name="Model", maximum=maximum, items=(item_a, ), broad_category=ItemCategory.BEAM_RELATED) state = AmmoState(0, total_pickup) maximum_ammo = {item_a: maximum} # Run ammo_per_pickup = randovania.generator.item_pool.ammo.items_for_ammo( ammo, state, included_ammo_for_item, previous_pickup_for_item, maximum_ammo) # Assert assert previous_pickup_for_item == {item_a: ammo} assert ammo_per_pickup == [[3]] + [[2]] * (total_pickup - 1)
def read_database(database_data: Dict, game: RandovaniaGame) -> ItemDatabase: """ :param database_data: :param game: :return: """ migrations.migrate_current(database_data) item_categories = { name: ItemCategory.from_json(name, value) for name, value in database_data["item_categories"].items() } major_items = { name: MajorItem.from_json(name, value, game, item_categories) for name, value in database_data["items"].items() } ammo = { name: Ammo.from_json(name, value, game, item_categories) for name, value in database_data["ammo"].items() } default_items = { item_categories[category_name]: tuple(major_items[item_name] for item_name in value) for category_name, value in database_data["default_items"].items() } return ItemDatabase(item_categories, major_items, ammo, default_items)
def read_database( major_items_data: Dict, ammo_data: Dict, ) -> ItemDatabase: """ :param major_items_data: :param ammo_data: :return: """ major_items = { name: MajorItem.from_json(name, value) for name, value in major_items_data["items"].items() } ammo = { name: Ammo.from_json(name, value) for name, value in ammo_data.items() } default_items = { ItemCategory(category_name): tuple(major_items[item_name] for item_name in value) for category_name, value in major_items_data["default_items"].items() } return ItemDatabase(major_items, ammo, default_items)
def test_create_ammo_expansion(requires_major_item: bool, echoes_resource_database): # Setup primary_a = echoes_resource_database.get_by_type_and_index( ResourceType.ITEM, 73) ammo_a = echoes_resource_database.get_by_type_and_index( ResourceType.ITEM, 40) ammo_b = echoes_resource_database.get_by_type_and_index( ResourceType.ITEM, 42) temporary_a = echoes_resource_database.get_by_type_and_index( ResourceType.ITEM, 71) temporary_b = echoes_resource_database.get_by_type_and_index( ResourceType.ITEM, 72) ammo = Ammo( name="The Item", maximum=100, items=(40, 42), unlocked_by=73, temporaries=(71, 72), models=(10, 20), ) ammo_count = [75, 150] item_resources = ( (ammo_a, ammo_count[0]), (ammo_b, ammo_count[1]), (echoes_resource_database.item_percentage, 1), ) temporary_resources = ( (temporary_a, ammo_count[0]), (temporary_b, ammo_count[1]), (echoes_resource_database.item_percentage, 1), ) # Run result = randovania.generator.item_pool.pickup_creator.create_ammo_expansion( ammo, ammo_count, requires_major_item, echoes_resource_database) # Assert assert result == PickupEntry( name="The Item", model_index=10, resources=( ConditionalResources("Temporary Missile", None, temporary_resources), ConditionalResources("The Item", primary_a, item_resources), ) if requires_major_item else (ConditionalResources(None, None, item_resources), ), item_category=ItemCategory.EXPANSION, probability_offset=0, )
def test_create_ammo_expansion(requires_major_item: bool, echoes_item_database, echoes_resource_database): # Setup primary_a = echoes_resource_database.get_item("MissileLauncher") ammo_a = echoes_resource_database.get_item("Missile") temporary_a = echoes_resource_database.get_item("Temporary1") ammo = Ammo( game=echoes_resource_database.game_enum, name="The Item", items=("Missile", ), broad_category=USELESS_ITEM_CATEGORY, unlocked_by="MissileLauncher", temporary="Temporary1", model_name="AmmoModel", ) ammo_count = (11, 150) # Run result = pickup_creator.create_ammo_expansion(ammo, ammo_count, requires_major_item, echoes_resource_database) # Assert assert result == PickupEntry( name="The Item", model=PickupModel(echoes_resource_database.game_enum, "AmmoModel"), progression=tuple(), extra_resources=( (ammo_a, ammo_count[0]), (echoes_resource_database.item_percentage, 1), ), item_category=AMMO_ITEM_CATEGORY, broad_category=USELESS_ITEM_CATEGORY, probability_offset=0, respects_lock=requires_major_item, resource_lock=ResourceLock( locked_by=primary_a, temporary_item=temporary_a, item_to_lock=ammo_a, ), )
def read_database(major_items_data: Dict, ammo_data: Dict, ) -> ItemDatabase: """ :param major_items_data: :param ammo_data: :return: """ major_items = { name: MajorItem.from_json(name, value) for name, value in major_items_data.items() } ammo = { name: Ammo.from_json(name, value) for name, value in ammo_data.items() } return ItemDatabase(major_items, ammo)
def test_items_for_ammo_one_item(per_pickup: int, total_pickup: int, included: int): # Setup item_a = 1 included_ammo_for_item = {item_a: included} previous_pickup_for_item = {} maximum = per_pickup * total_pickup + included ammo = Ammo("My Ammo", maximum=maximum, items=(item_a, )) state = AmmoState(0, total_pickup) maximum_ammo = {item_a: maximum} # Run ammo_per_pickup = randovania.generator.item_pool.ammo.items_for_ammo( ammo, state, included_ammo_for_item, previous_pickup_for_item, maximum_ammo) # Assert assert previous_pickup_for_item == {item_a: ammo} assert ammo_per_pickup == [[per_pickup]] * total_pickup
def test_create_ammo_expansion(requires_major_item: bool, echoes_resource_database): # Setup primary_a = echoes_resource_database.get_item(73) ammo_a = echoes_resource_database.get_item(40) temporary_a = echoes_resource_database.get_item(71) ammo = Ammo( name="The Item", maximum=100, items=(40,), broad_category=ItemCategory.ETM, unlocked_by=73, temporary=71, model_name="AmmoModel", ) ammo_count = [75, 150] # Run result = randovania.generator.item_pool.pickup_creator.create_ammo_expansion( ammo, ammo_count, requires_major_item, echoes_resource_database) # Assert assert result == PickupEntry( name="The Item", model=PickupModel(echoes_resource_database.game_enum, "AmmoModel"), progression=tuple(), extra_resources=( (ammo_a, ammo_count[0]), (echoes_resource_database.item_percentage, 1), ), item_category=ItemCategory.EXPANSION, broad_category=ItemCategory.ETM, probability_offset=0, respects_lock=requires_major_item, resource_lock=ResourceLock( locked_by=primary_a, temporary_item=temporary_a, item_to_lock=ammo_a, ), )