示例#1
0
def fill_dungeons_restrictive(world, shuffled_locations):
    all_state_base = world.get_all_state()

    for player in range(1, world.players + 1):
        pinball_room = world.get_location('Skull Woods - Pinball Room', player)
        if world.retro:
            world.push_item(pinball_room,
                            ItemFactory('Small Key (Universal)', player),
                            False)
        else:
            world.push_item(pinball_room,
                            ItemFactory('Small Key (Skull Woods)', player),
                            False)
        pinball_room.event = True
        pinball_room.locked = True
        shuffled_locations.remove(pinball_room)

    if world.keysanity:
        #in keysanity dungeon items are distributed as part of the normal item pool
        for item in world.get_items():
            if item.key:
                item.advancement = True
            elif item.map or item.compass:
                item.priority = True
        return

    dungeon_items = get_dungeon_item_pool(world)

    # sort in the order Big Key, Small Key, Other before placing dungeon items
    sort_order = {"BigKey": 3, "SmallKey": 2}
    dungeon_items.sort(key=lambda item: sort_order.get(item.type, 1))

    fill_restrictive(world, all_state_base, shuffled_locations, dungeon_items)
示例#2
0
 def setUp(self):
     self.world = World(1, {1: 'vanilla'}, {1: 'owglitches'}, {1: 'open'},
                        {1: 'random'}, {1: 'normal'}, {1: 'normal'},
                        {1: False}, {1: 'on'}, {1: 'ganon'}, 'balanced',
                        {1: 'items'}, True, {1: False}, False, None,
                        {1: False})
     self.world.difficulty_requirements[1] = difficulties['normal']
     create_regions(self.world, 1)
     create_dungeons(self.world, 1)
     create_shops(self.world, 1)
     link_entrances(self.world, 1)
     generate_itempool(self.world, 1)
     self.world.required_medallions[1] = ['Ether', 'Quake']
     self.world.itempool.extend(get_dungeon_item_pool(self.world))
     self.world.itempool.extend(
         ItemFactory([
             'Green Pendant', 'Red Pendant', 'Blue Pendant',
             'Beat Agahnim 1', 'Beat Agahnim 2', 'Crystal 1', 'Crystal 2',
             'Crystal 3', 'Crystal 4', 'Crystal 5', 'Crystal 6', 'Crystal 7'
         ], 1))
     self.world.get_location('Agahnim 1', 1).item = None
     self.world.get_location('Agahnim 2', 1).item = None
     self.world.precollected_items.clear()
     self.world.itempool.append(ItemFactory('Pegasus Boots', 1))
     mark_dark_world_regions(self.world, 1)
     set_rules(self.world, 1)
def fill_dungeons_restrictive(world, shuffled_locations):
    all_state_base = world.get_all_state()

    skull_woods_big_chest = world.get_location('Skull Woods - Pinball Room')
    if world.retro:
        world.push_item(skull_woods_big_chest,
                        ItemFactory('Small Key (Universal)'), False)
    else:
        world.push_item(skull_woods_big_chest,
                        ItemFactory('Small Key (Skull Woods)'), False)
    skull_woods_big_chest.event = True
    shuffled_locations.remove(skull_woods_big_chest)

    if world.keysanity:
        #in keysanity dungeon items are distributed as part of the normal item pool
        for item in world.get_items():
            if item.key:
                item.advancement = True
            elif item.map or item.compass:
                item.priority = True
        return

    dungeon_items = get_dungeon_item_pool(world)

    # sort in the order Big Key, Small Key, Other before placing dungeon items
    sort_order = {"BigKey": 3, "SmallKey": 2}
    dungeon_items.sort(key=lambda item: sort_order.get(item.type, 1))

    fill_restrictive(world, all_state_base, shuffled_locations, dungeon_items)

    world.state.clear_cached_unreachable()
示例#4
0
    def run_tests(self, access_pool):
        for location, access, *item_pool in access_pool:
            items = item_pool[0]
            all_except = item_pool[1] if len(item_pool) > 1 else None
            with self.subTest(location=location,
                              access=access,
                              items=items,
                              all_except=all_except):
                if all_except and len(all_except) > 0:
                    items = self.world.itempool[:]
                    items = [
                        item for item in items if item.name not in all_except
                        and not ("Bottle" in item.name
                                 and "AnyBottle" in all_except)
                    ]
                    items.extend(ItemFactory(item_pool[0], 1))
                else:
                    items = ItemFactory(items, 1)
                state = CollectionState(self.world)
                for item in items:
                    item.advancement = True
                    state.collect(item)

                self.assertEqual(
                    self.world.get_location(location, 1).can_reach(state),
                    access)
示例#5
0
def create_shops(world, player: int):
    option = world.shop_shuffle[player]

    player_shop_table = shop_table.copy()
    if "w" in option:
        player_shop_table["Potion Shop"] = player_shop_table["Potion Shop"]._replace(locked=False)
        dynamic_shop_slots = total_dynamic_shop_slots + 3
    else:
        dynamic_shop_slots = total_dynamic_shop_slots

    num_slots = min(dynamic_shop_slots, max(0, int(world.shop_shuffle_slots[player])))  # 0 to 30
    single_purchase_slots: List[bool] = [True] * num_slots + [False] * (dynamic_shop_slots - num_slots)
    world.random.shuffle(single_purchase_slots)

    if 'g' in option or 'f' in option:
        default_shop_table = [i for l in [shop_generation_types[x] for x in ['arrows', 'bombs', 'potions', 'shields', 'bottle'] if not world.retro[player] or x != 'arrows'] for i in l]
        new_basic_shop = world.random.sample(default_shop_table, k=3)
        new_dark_shop = world.random.sample(default_shop_table, k=3)
        for name, shop in player_shop_table.items():
            typ, shop_id, keeper, custom, locked, items, sram_offset = shop
            if not locked:
                new_items = world.random.sample(default_shop_table, k=3)
                if 'f' not in option:
                    if items == _basic_shop_defaults:
                        new_items = new_basic_shop
                    elif items == _dark_world_shop_defaults:
                        new_items = new_dark_shop
                keeper = world.random.choice([0xA0, 0xC1, 0xFF])
                player_shop_table[name] = ShopData(typ, shop_id, keeper, custom, locked, new_items, sram_offset)
    if world.mode[player] == "inverted":
        player_shop_table["Dark Lake Hylia Shop"] = \
            player_shop_table["Dark Lake Hylia Shop"]._replace(locked=True, items=_inverted_hylia_shop_defaults)
    for region_name, (room_id, type, shopkeeper, custom, locked, inventory, sram_offset) in player_shop_table.items():
        region = world.get_region(region_name, player)
        shop: Shop = shop_class_mapping[type](region, room_id, shopkeeper, custom, locked, sram_offset)
        region.shop = shop
        world.shops.append(shop)
        for index, item in enumerate(inventory):
            shop.add_inventory(index, *item)
            if not locked and num_slots:
                slot_name = "{} Slot {}".format(region.name, index + 1)
                loc = Location(player, slot_name, address=shop_table_by_location[slot_name],
                               parent=region, hint_text="for sale")
                loc.shop_slot = True
                loc.locked = True
                if single_purchase_slots.pop():
                    if world.goal[player] != 'icerodhunt':
                        additional_item = 'Rupees (50)'  # world.random.choice(['Rupees (50)', 'Rupees (100)', 'Rupees (300)'])
                    else:
                        additional_item = 'Nothing'
                    loc.item = ItemFactory(additional_item, player)
                else:
                    loc.item = ItemFactory('Nothing', player)
                    loc.shop_slot_disabled = True
                shop.region.locations.append(loc)
                world.dynamic_locations.append(loc)
                world.clear_location_cache()
示例#6
0
 def _get_items(self, item_pool, all_except):
     if all_except and len(all_except) > 0:
         items = self.world.itempool[:]
         items = [item for item in items if
                  item.name not in all_except and not ("Bottle" in item.name and "AnyBottle" in all_except)]
         items.extend(ItemFactory(item_pool[0], 1))
     else:
         items = ItemFactory(item_pool[0], 1)
     return self.get_state(items)
示例#7
0
def generate_itempool(world):
    # set up item pool
    (pool, placed_items) = get_pool_core(world)
    world.itempool = ItemFactory(pool, world)
    for (location, item) in placed_items.items():
        world.push_item(location, ItemFactory(item, world))
        world.get_location(location).event = True

    fill_bosses(world)

    world.initialize_items()
示例#8
0
    def get_item(self, level):
        _chart = self.__pick_chart()            
        _pick = _chart[choice(_chart.keys())]
    
        _if = ItemFactory()
        if _pick[1] > 0:
            _item = _if.get_stack(_pick[0], _pick[1], True)
        else:
            _item = _if.gen_item(_pick[0], True)

        return _item
示例#9
0
 def beemizer(item):
     if world.beemizer[
             item.
             player] and not item.advancement and not item.priority and not item.type:
         choice = random.choices(
             list(beeweights[world.beemizer[item.player]].keys()),
             weights=list(
                 beeweights[world.beemizer[item.player]].values()))[0]
         return item if not choice else ItemFactory(
             "Bee Trap", player) if choice == 'trap' else ItemFactory(
                 "Bee", player)
     return item
示例#10
0
文件: Rooms.py 项目: DanaL/crashRun
def place_repair_shop_items(dm, room, level):
    _if = ItemFactory()
    for j in range(1,randrange(5)):
        _roll = randrange(10)
        if _roll < 8:
            _item = _if.get_stack('battery',5, True)
        elif _roll == 8:
            _item = _if.gen_item('infra-red goggles', True)
        else:
            _item = _if.gen_item('targeting wizard', True)
            
        _floor = choice(room)
        level.add_item_to_sqr(_floor[0], _floor[1], _item)
示例#11
0
文件: Rooms.py 项目: DanaL/crashRun
def get_moreau_box():
    _if  = ItemFactory()
    _box = Items.Box('box')
    
    for j in range(randrange(1,4)):
        _roll = randrange(7)
        if _roll < 3:
            _box.add_item(_if.get_stack('stimpak', 4, True))
        elif _roll < 6:
            _box.add_item(_if.get_stack('shotgun shell', 10, True))
        else:
            _box.add_item(_if.gen_item('shotgun', True))
        
    return _box
示例#12
0
def fill_prizes(world, attempts=15):
    all_state = world.get_all_state(keys=True)
    for player in range(1, world.players + 1):
        crystals = ItemFactory(['Red Pendant', 'Blue Pendant', 'Green Pendant', 'Crystal 1', 'Crystal 2', 'Crystal 3', 'Crystal 4', 'Crystal 7', 'Crystal 5', 'Crystal 6'], player)
        crystal_locations = [world.get_location('Turtle Rock - Prize', player), world.get_location('Eastern Palace - Prize', player), world.get_location('Desert Palace - Prize', player), world.get_location('Tower of Hera - Prize', player), world.get_location('Palace of Darkness - Prize', player),
                             world.get_location('Thieves\' Town - Prize', player), world.get_location('Skull Woods - Prize', player), world.get_location('Swamp Palace - Prize', player), world.get_location('Ice Palace - Prize', player),
                             world.get_location('Misery Mire - Prize', player)]
        placed_prizes = [loc.item.name for loc in crystal_locations if loc.item is not None]
        unplaced_prizes = [crystal for crystal in crystals if crystal.name not in placed_prizes]
        empty_crystal_locations = [loc for loc in crystal_locations if loc.item is None]
        for attempt in range(attempts):
            try:
                prizepool = list(unplaced_prizes)
                prize_locs = list(empty_crystal_locations)
                world.random.shuffle(prizepool)
                world.random.shuffle(prize_locs)
                fill_restrictive(world, all_state, prize_locs, prizepool, True)
            except FillError as e:
                logging.getLogger('').exception("Failed to place dungeon prizes (%s). Will retry %s more times", e,
                                                attempts - attempt)
                for location in empty_crystal_locations:
                    location.item = None
                continue
            break
        else:
            raise FillError('Unable to place dungeon prizes')
示例#13
0
 def setUp(self):
     self.world = World(1, {1: 'vanilla'}, {1: 'noglitches'}, {1: 'open'},
                        {1: 'random'}, {1: 'normal'}, {1: 'normal'},
                        {1: False}, {1: 'on'}, {1: 'ganon'}, 'balanced',
                        {1: 'items'}, True, {1: False}, False, None,
                        {1: False})
     self.starting_regions = []  # Where to start exploring
     self.remove_exits = []  # Block dungeon exits
     self.world.difficulty_requirements[1] = difficulties['normal']
     create_regions(self.world, 1)
     create_dungeons(self.world, 1)
     create_shops(self.world, 1)
     for exitname, regionname in mandatory_connections:
         connect_simple(self.world, exitname, regionname, 1)
     connect_simple(self.world, 'Big Bomb Shop', 'Big Bomb Shop', 1)
     self.world.get_region('Menu', 1).exits = []
     self.world.swamp_patch_required[1] = True
     set_rules(self.world, 1)
     generate_itempool(self.world, 1)
     self.world.itempool.extend(get_dungeon_item_pool(self.world))
     self.world.itempool.extend(
         ItemFactory([
             'Green Pendant', 'Red Pendant', 'Blue Pendant',
             'Beat Agahnim 1', 'Beat Agahnim 2', 'Crystal 1', 'Crystal 2',
             'Crystal 3', 'Crystal 4', 'Crystal 5', 'Crystal 6', 'Crystal 7'
         ], 1))
示例#14
0
文件: Rooms.py 项目: DanaL/crashRun
def get_medical_lab_box():
    _if = ItemFactory()
    _box = Items.Box('box')
    
    for j in range(randrange(1,4)):
        _roll = random()
        if _roll < 0.25:
            _box.add_item(_if.get_stack('medkit', 4, True))
        elif _roll < 0.50:
            _box.add_item(_if.get_stack('ritalin', 7, True))
        elif _roll < 0.75:
            _box.add_item(_if.get_stack('amphetamine', 5, True))
        else:
            _box.add_item(_if.get_stack('battery', 3, True))

    return _box
示例#15
0
文件: Rooms.py 项目: DanaL/crashRun
def get_locker_for_minor_armoury():
    _if = ItemFactory()
    _box = Items.Box('footlocker')
    
    for j in range(randrange(4)):
        _roll = random()
        if _roll < 0.333:
            _box.add_item(_if.get_stack('shotgun shell', 8, True))
        elif _roll < 0.666:
            _box.add_item(_if.get_stack('grenade', 4, True))
        elif _roll < 0.9:
            _box.add_item(_if.get_stack('stimpak', 5, True))
        else:
            _box.add_item(_if.gen_item('shotgun', True))

    return _box
示例#16
0
文件: Rooms.py 项目: DanaL/crashRun
def place_science_lab_items(dm, room, level):
    _floor = choice(room)
    _if = ItemFactory()
    for j in range(1,randrange(5)):
        _roll = randrange(10)
        if _roll < 3:
            _item = _if.get_stack('stimpak',3, True)
        elif _roll < 6:
            _item = _if.get_stack('amphetamine',7, True)
        elif _roll < 9:
            _item = _if.get_stack('shotgun shell',10, True)
        else:
            _item = _if.gen_item('infra-red goggles', True)
            
        _floor = choice(room)
        level.add_item_to_sqr(_floor[0], _floor[1], _item)
示例#17
0
def generate_itempool(world):
    for location, item in eventlocations.items():
        world.push_item(location, ItemFactory(item, world))
        world.get_location(location).locked = True

    # set up item pool
    (pool, placed_items) = get_pool_core(world)
    world.itempool = ItemFactory(pool, world)
    for (location, item) in placed_items.items():
        world.push_item(location, ItemFactory(item, world))
        world.get_location(location).locked = True

    choose_trials(world)
    fill_bosses(world)

    world.initialize_items()
示例#18
0
def fill_bosses(world, bossCount=4):
    boss_rewards = ItemFactory(rewardlist)
    boss_locations = [
        world.get_location('Odolwa'),
        world.get_location('Goht'),
        world.get_location('Gyorg'),
        world.get_location('Twinmold')
    ]
    placed_prizes = [
        loc.item.name for loc in boss_locations if loc.item is not None
    ]
    unplaced_prizes = [
        item for item in boss_rewards if item.name not in placed_prizes
    ]
    empty_boss_locations = [loc for loc in boss_locations if loc.item is None]
    prizepool = list(unplaced_prizes)
    prize_locs = list(empty_boss_locations)

    while bossCount:
        bossCount -= 1
        random.shuffle(prizepool)
        random.shuffle(prize_locs)
        item = prizepool.pop()
        loc = prize_locs.pop()
        world.push_item(loc, item, False)
        world.get_location(loc).event = True
示例#19
0
def generate_itempool(world):

    world.push_item('Majoras Wrath', ItemFactory('Majora Mask'), False)
    world.get_location('Majoras Wrath').event = True
    world.push_item('Gift from Skull Kid', ItemFactory('Fairy Ocarina'), False)
    world.get_location('Gift from Skull Kid').event = True

    # set up item pool
    (pool, placed_items) = get_pool_core(world.place_dungeon_items)
    world.itempool = ItemFactory(pool)
    for (location, item) in placed_items:
        world.push_item(location, ItemFactory(item), False)
        world.get_location(location).event = True

    fill_bosses(world)
    fill_songs(world)
示例#20
0
    def get_all_state(self, keys=False):
        ret = CollectionState(self)

        def soft_collect(item):
            if item.advancement or item.key:
                ret.prog_items.append(item.name)

        for item in self.itempool:
            soft_collect(item)
        from Items import ItemFactory
        if keys:
            for item in ItemFactory(['Small Key (Forest Temple)'] * 5 + [
                    'Boss Key (Forest Temple)', 'Boss Key (Fire Temple)',
                    'Boss Key (Water Temple)', 'Boss Key (Shadow Temple)',
                    'Boss Key (Spirit Temple)', 'Boss Key (Ganons Castle)'
            ] + ['Small Key (Bottom of the Well)'] * 3 +
                                    ['Small Key (Fire Temple)'] * 8 +
                                    ['Small Key (Water Temple)'] * 6 +
                                    ['Small Key (Shadow Temple)'] * 5 +
                                    ['Small Key (Gerudo Training Grounds)'] *
                                    9 + ['Small Key (Spirit Temple)'] * 5 +
                                    ['Small Key (Ganons Castle)'] * 2):
                soft_collect(item)
        ret.sweep_for_events()
        ret.clear_cached_unreachable()
        return ret
示例#21
0
def fill_bosses(world, bossCount=9):
    boss_rewards = ItemFactory(rewardlist)
    boss_locations = [
        world.get_location('Queen Gohma'),
        world.get_location('King Dodongo'),
        world.get_location('Barinade'),
        world.get_location('Phantom Ganon'),
        world.get_location('Volvagia'),
        world.get_location('Morpha'),
        world.get_location('Bongo Bongo'),
        world.get_location('Twinrova'),
        world.get_location('Links Pocket')
    ]
    placed_prizes = [
        loc.item.name for loc in boss_locations if loc.item is not None
    ]
    unplaced_prizes = [
        item for item in boss_rewards if item.name not in placed_prizes
    ]
    empty_boss_locations = [loc for loc in boss_locations if loc.item is None]
    prizepool = list(unplaced_prizes)
    prize_locs = list(empty_boss_locations)

    while bossCount:
        bossCount -= 1
        random.shuffle(prizepool)
        random.shuffle(prize_locs)
        item = prizepool.pop()
        loc = prize_locs.pop()
        world.push_item(loc, item)
示例#22
0
def shuffle_shops(world, items, player: int):
    option = world.shop_shuffle[player]
    if 'u' in option:
        if world.retro[player]:
            new_items = ["Bomb Upgrade (+5)"] * 7
        else:
            new_items = ["Bomb Upgrade (+5)", "Arrow Upgrade (+5)"] * 7
        for shop in world.shops:
            if shop.type == ShopType.UpgradeShop and shop.region.player == player and \
                    shop.region.name == "Capacity Upgrade":
                shop.clear_inventory()

        for i, item in enumerate(items):
            if not "Heart" in item.name:
                items[i] = ItemFactory(new_items.pop(), player)
                if not new_items:
                    break
        else:
            logging.warning(
                f"Not all upgrades put into Player{player}' item pool. Still missing: {new_items}"
            )

    if 'p' in option or 'i' in option:
        shops = []
        upgrade_shops = []
        total_inventory = []
        for shop in world.shops:
            if shop.region.player == player:
                if shop.type == ShopType.UpgradeShop:
                    upgrade_shops.append(shop)
                elif shop.type == ShopType.Shop and shop.region.name != 'Potion Shop':
                    shops.append(shop)
                    total_inventory.extend(shop.inventory)

        if 'p' in option:

            def price_adjust(price: int) -> int:
                # it is important that a base price of 0 always returns 0 as new price!
                return int(price * (0.5 + world.random.random() * 1.5))

            def adjust_item(item):
                if item:
                    item["price"] = price_adjust(item["price"])
                    item['replacement_price'] = price_adjust(item["price"])

            for item in total_inventory:
                adjust_item(item)
            for shop in upgrade_shops:
                for item in shop.inventory:
                    adjust_item(item)

        if 'i' in option:
            world.random.shuffle(total_inventory)
            i = 0
            for shop in shops:
                slots = shop.slots
                shop.inventory = total_inventory[i:i + slots]
                i += slots
def set_up_take_anys(world, player):
    # these are references, do not modify these lists in-place
    if world.mode[player] == 'inverted':
        take_any_locs = take_any_locations_inverted
    else:
        take_any_locs = take_any_locations

    regions = world.random.sample(take_any_locs, 5)

    old_man_take_any = Region("Old Man Sword Cave", RegionType.Cave,
                              'the sword cave', player)
    world.regions.append(old_man_take_any)
    world.dynamic_regions.append(old_man_take_any)

    reg = regions.pop()
    entrance = world.get_region(reg, player).entrances[0]
    connect_entrance(world, entrance.name, old_man_take_any.name, player)
    entrance.target = 0x58
    old_man_take_any.shop = TakeAny(old_man_take_any, 0x0112, 0xE2, True, True,
                                    total_shop_slots)
    world.shops.append(old_man_take_any.shop)

    swords = [
        item for item in world.itempool
        if item.type == 'Sword' and item.player == player
    ]
    if swords:
        sword = world.random.choice(swords)
        world.itempool.remove(sword)
        world.itempool.append(ItemFactory('Rupees (20)', player))
        old_man_take_any.shop.add_inventory(0,
                                            sword.name,
                                            0,
                                            0,
                                            create_location=True)
    else:
        old_man_take_any.shop.add_inventory(0, 'Rupees (300)', 0, 0)

    for num in range(4):
        take_any = Region("Take-Any #{}".format(num + 1), RegionType.Cave,
                          'a cave of choice', player)
        world.regions.append(take_any)
        world.dynamic_regions.append(take_any)

        target, room_id = world.random.choice([(0x58, 0x0112), (0x60, 0x010F),
                                               (0x46, 0x011F)])
        reg = regions.pop()
        entrance = world.get_region(reg, player).entrances[0]
        connect_entrance(world, entrance.name, take_any.name, player)
        entrance.target = target
        take_any.shop = TakeAny(take_any, room_id, 0xE3, True, True,
                                total_shop_slots + num + 1)
        world.shops.append(take_any.shop)
        take_any.shop.add_inventory(0, 'Blue Potion', 0, 0)
        take_any.shop.add_inventory(1, 'Boss Heart Container', 0, 0)

    world.initialize_regions()
示例#24
0
def FillDisabledShopSlots(world):
    shop_slots: Set[Location] = {location for shop_locations in (shop.region.locations for shop in world.shops)
                                 for location in shop_locations if location.shop_slot and location.shop_slot_disabled}
    for location in shop_slots:
        location.shop_slot_disabled = True
        slot_num = int(location.name[-1]) - 1
        shop: Shop = location.parent_region.shop
        location.item = ItemFactory(shop.inventory[slot_num]['item'], location.player)
        location.item_rule = lambda item: item.name == location.item.name and item.player == location.player
示例#25
0
def set_up_take_anys(world, player):
    if world.mode == 'inverted' and 'Dark Sanctuary Hint' in take_any_locations:
        take_any_locations.remove('Dark Sanctuary Hint')

    regions = random.sample(take_any_locations, 5)

    old_man_take_any = Region("Old Man Sword Cave", RegionType.Cave,
                              'the sword cave', player)
    world.regions.append(old_man_take_any)
    world.dynamic_regions.append(old_man_take_any)

    reg = regions.pop()
    entrance = world.get_region(reg, player).entrances[0]
    connect_entrance(world, entrance, old_man_take_any, player)
    entrance.target = 0x58
    old_man_take_any.shop = Shop(old_man_take_any, 0x0112, ShopType.TakeAny,
                                 0xE2, True)
    world.shops.append(old_man_take_any.shop)
    old_man_take_any.shop.active = True

    swords = [
        item for item in world.itempool
        if item.type == 'Sword' and item.player == player
    ]
    if swords:
        sword = random.choice(swords)
        world.itempool.remove(sword)
        world.itempool.append(ItemFactory('Rupees (20)', player))
        old_man_take_any.shop.add_inventory(0,
                                            sword.name,
                                            0,
                                            0,
                                            create_location=True)
    else:
        old_man_take_any.shop.add_inventory(0, 'Rupees (300)', 0, 0)

    for num in range(4):
        take_any = Region("Take-Any #{}".format(num + 1), RegionType.Cave,
                          'a cave of choice', player)
        world.regions.append(take_any)
        world.dynamic_regions.append(take_any)

        target, room_id = random.choice([(0x58, 0x0112), (0x60, 0x010F),
                                         (0x46, 0x011F)])
        reg = regions.pop()
        entrance = world.get_region(reg, player).entrances[0]
        connect_entrance(world, entrance, take_any, player)
        entrance.target = target
        take_any.shop = Shop(take_any, room_id, ShopType.TakeAny, 0xE3, True)
        world.shops.append(take_any.shop)
        take_any.shop.active = True
        take_any.shop.add_inventory(0, 'Blue Potion', 0, 0)
        take_any.shop.add_inventory(1, 'Boss Heart Container', 0, 0)

    world.intialize_regions()
示例#26
0
def fill_dungeons_restrictive(world, shuffled_locations):
    all_state_base = world.get_all_state()

    for player in range(1, world.players + 1):
        pinball_room = world.get_location('Skull Woods - Pinball Room', player)
        if world.retro[player]:
            world.push_item(pinball_room,
                            ItemFactory('Small Key (Universal)', player),
                            False)
        else:
            world.push_item(pinball_room,
                            ItemFactory('Small Key (Skull Woods)', player),
                            False)
        pinball_room.event = True
        pinball_room.locked = True
        shuffled_locations.remove(pinball_room)

    # with shuffled dungeon items they are distributed as part of the normal item pool
    for item in world.get_items():
        if (item.smallkey and world.keyshuffle[item.player]) or (
                item.bigkey and world.bigkeyshuffle[item.player]):
            all_state_base.collect(item, True)
            item.advancement = True
        elif (item.map and world.mapshuffle[item.player]) or (
                item.compass and world.compassshuffle[item.player]):
            item.priority = True

    dungeon_items = [
        item for item in get_dungeon_item_pool(world)
        if ((item.smallkey and not world.keyshuffle[item.player]) or (
            item.bigkey and not world.bigkeyshuffle[item.player]) or (
                item.map and not world.mapshuffle[item.player]) or (
                    item.compass and not world.compassshuffle[item.player]))
    ]

    # sort in the order Big Key, Small Key, Other before placing dungeon items
    sort_order = {"BigKey": 3, "SmallKey": 2}
    dungeon_items.sort(key=lambda item: sort_order.get(item.type, 1))

    fill_restrictive(world, all_state_base, shuffled_locations, dungeon_items,
                     True)
示例#27
0
    def get_all_state(self, keys=False):
        ret = CollectionState(self)

        def soft_collect(item):
            if item.name.startswith('Progressive '):
                if 'Sword' in item.name:
                    if ret.has('Golden Sword'):
                        pass
                    elif ret.has('Tempered Sword'):
                        ret.prog_items.append('Golden Sword')
                    elif ret.has('Master Sword'):
                        ret.prog_items.append('Tempered Sword')
                    elif ret.has('Fighter Sword'):
                        ret.prog_items.append('Master Sword')
                    else:
                        ret.prog_items.append('Fighter Sword')
                elif 'Glove' in item.name:
                    if ret.has('Titans Mitts'):
                        pass
                    elif ret.has('Power Glove'):
                        ret.prog_items.append('Titans Mitts')
                    else:
                        ret.prog_items.append('Power Glove')

            elif item.advancement or item.key:
                ret.prog_items.append(item.name)

        for item in self.itempool:
            soft_collect(item)
        if keys:
            from Items import ItemFactory
            for item in ItemFactory([
                    'Small Key (Escape)', 'Big Key (Eastern Palace)',
                    'Big Key (Desert Palace)', 'Small Key (Desert Palace)',
                    'Big Key (Tower of Hera)', 'Small Key (Tower of Hera)',
                    'Small Key (Agahnims Tower)', 'Small Key (Agahnims Tower)',
                    'Big Key (Palace of Darkness)'
            ] + ['Small Key (Palace of Darkness)'] * 6 + [
                    'Big Key (Thieves Town)', 'Small Key (Thieves Town)',
                    'Big Key (Skull Woods)'
            ] + ['Small Key (Skull Woods)'] * 3 + [
                    'Big Key (Swamp Palace)', 'Small Key (Swamp Palace)',
                    'Big Key (Ice Palace)'
            ] + ['Small Key (Ice Palace)'] * 2 + [
                    'Big Key (Misery Mire)', 'Big Key (Turtle Rock)',
                    'Big Key (Ganons Tower)'
            ] + ['Small Key (Misery Mire)'] * 3 +
                                    ['Small Key (Turtle Rock)'] * 4 +
                                    ['Small Key (Ganons Tower)'] * 4):
                soft_collect(item)
        ret.sweep_for_events()
        ret._clear_cache()
        return ret
示例#28
0
 def make_repair_shop(self, building):
     _doc = MonsterFactory.get_monster_by_name(self.dm, "repair bot", 0, 0)
     place_monster(building, self, _doc)
     
     for j in range(randrange(2)):
         _ed = MonsterFactory.get_monster_by_name(self.dm, "ed-209", 0, 0)
         place_monster(building, self, _ed)
     for j in range(randrange(1,4)):
         _sb = MonsterFactory.get_monster_by_name(self.dm, "security bot", 0, 0)
         place_monster(building, self, _sb)
     
     _if = ItemFactory()
     for j in range(randrange(1,4)):
         _roll = randrange(10)
         if _roll < 7:
             _item = _if.get_stack('battery', 3, True)
         elif _roll < 9:
             _item = _if.gen_item('targeting wizard')
         else:
             _item = _if.gen_item('icannon')
         place_item(building, self, _item)
示例#29
0
    def run_tests(self, access_pool):
        for exit in self.remove_exits:
            self.world.get_entrance(
                exit, 1).connected_region = self.world.get_region('Menu', 1)

        for location, access, *item_pool in access_pool:
            items = item_pool[0]
            all_except = item_pool[1] if len(item_pool) > 1 else None
            with self.subTest(location=location,
                              access=access,
                              items=items,
                              all_except=all_except):
                if all_except and len(all_except) > 0:
                    items = self.world.itempool[:]
                    items = [
                        item for item in items if item.name not in all_except
                        and not ("Bottle" in item.name
                                 and "AnyBottle" in all_except)
                    ]
                    items.extend(ItemFactory(item_pool[0], 1))
                else:
                    items = ItemFactory(items, 1)
                state = CollectionState(self.world)
                state.reachable_regions[1].add(self.world.get_region(
                    'Menu', 1))
                for region_name in self.starting_regions:
                    region = self.world.get_region(region_name, 1)
                    state.reachable_regions[1].add(region)
                    for exit in region.exits:
                        if exit.connected_region is not None:
                            state.blocked_connections[1].add(exit)

                for item in items:
                    item.advancement = True
                    state.collect(item)

                self.assertEqual(
                    self.world.get_location(location, 1).can_reach(state),
                    access)
示例#30
0
def create_dungeons(world):
    def make_dungeon(name, dungeon_regions, big_key, small_keys, dungeon_items):
        dungeon = Dungeon(name, dungeon_regions, big_key, [] if world.retro else small_keys, dungeon_items)
        for region in dungeon.regions:
            world.get_region(region).dungeon = dungeon
        return dungeon

    ES = make_dungeon('Hyrule Castle', ['Hyrule Castle', 'Sewers', 'Sewer Drop', 'Sewers (Dark)', 'Sanctuary'], None, [ItemFactory('Small Key (Escape)')], [ItemFactory('Map (Escape)')])
    EP = make_dungeon('Eastern Palace', ['Eastern Palace'], ItemFactory('Big Key (Eastern Palace)'), [], ItemFactory(['Map (Eastern Palace)', 'Compass (Eastern Palace)']))
    DP = make_dungeon('Desert Palace', ['Desert Palace North', 'Desert Palace Main (Inner)', 'Desert Palace Main (Outer)', 'Desert Palace East'], ItemFactory('Big Key (Desert Palace)'), [ItemFactory('Small Key (Desert Palace)')], ItemFactory(['Map (Desert Palace)', 'Compass (Desert Palace)']))
    ToH = make_dungeon('Tower of Hera', ['Tower of Hera (Bottom)', 'Tower of Hera (Basement)', 'Tower of Hera (Top)'], ItemFactory('Big Key (Tower of Hera)'), [ItemFactory('Small Key (Tower of Hera)')], ItemFactory(['Map (Tower of Hera)', 'Compass (Tower of Hera)']))
    AT = make_dungeon('Agahnims Tower', ['Agahnims Tower', 'Agahnim 1'], None, ItemFactory(['Small Key (Agahnims Tower)'] * 2), [])
    PoD = make_dungeon('Palace of Darkness', ['Palace of Darkness (Entrance)', 'Palace of Darkness (Center)', 'Palace of Darkness (Big Key Chest)', 'Palace of Darkness (Bonk Section)', 'Palace of Darkness (North)', 'Palace of Darkness (Maze)', 'Palace of Darkness (Harmless Hellway)', 'Palace of Darkness (Final Section)'], ItemFactory('Big Key (Palace of Darkness)'), ItemFactory(['Small Key (Palace of Darkness)'] * 6), ItemFactory(['Map (Palace of Darkness)', 'Compass (Palace of Darkness)']))
    TT = make_dungeon('Thieves Town', ['Thieves Town (Entrance)', 'Thieves Town (Deep)', 'Blind Fight'], ItemFactory('Big Key (Thieves Town)'), [ItemFactory('Small Key (Thieves Town)')], ItemFactory(['Map (Thieves Town)', 'Compass (Thieves Town)']))
    SW = make_dungeon('Skull Woods', ['Skull Woods Final Section (Entrance)', 'Skull Woods First Section', 'Skull Woods Second Section', 'Skull Woods Second Section (Drop)', 'Skull Woods Final Section (Mothula)', 'Skull Woods First Section (Right)', 'Skull Woods First Section (Left)', 'Skull Woods First Section (Top)'], ItemFactory('Big Key (Skull Woods)'), ItemFactory(['Small Key (Skull Woods)'] * 2), ItemFactory(['Map (Skull Woods)', 'Compass (Skull Woods)']))
    SP = make_dungeon('Swamp Palace', ['Swamp Palace (Entrance)', 'Swamp Palace (First Room)', 'Swamp Palace (Starting Area)', 'Swamp Palace (Center)', 'Swamp Palace (North)'], ItemFactory('Big Key (Swamp Palace)'), [ItemFactory('Small Key (Swamp Palace)')], ItemFactory(['Map (Swamp Palace)', 'Compass (Swamp Palace)']))
    IP = make_dungeon('Ice Palace', ['Ice Palace (Entrance)', 'Ice Palace (Main)', 'Ice Palace (East)', 'Ice Palace (East Top)', 'Ice Palace (Kholdstare)'], ItemFactory('Big Key (Ice Palace)'), ItemFactory(['Small Key (Ice Palace)'] * 2), ItemFactory(['Map (Ice Palace)', 'Compass (Ice Palace)']))
    MM = make_dungeon('Misery Mire', ['Misery Mire (Entrance)', 'Misery Mire (Main)', 'Misery Mire (West)', 'Misery Mire (Final Area)', 'Misery Mire (Vitreous)'], ItemFactory('Big Key (Misery Mire)'), ItemFactory(['Small Key (Misery Mire)'] * 3), ItemFactory(['Map (Misery Mire)', 'Compass (Misery Mire)']))
    TR = make_dungeon('Turtle Rock', ['Turtle Rock (Entrance)', 'Turtle Rock (First Section)', 'Turtle Rock (Chain Chomp Room)', 'Turtle Rock (Second Section)', 'Turtle Rock (Big Chest)', 'Turtle Rock (Crystaroller Room)', 'Turtle Rock (Dark Room)', 'Turtle Rock (Eye Bridge)', 'Turtle Rock (Trinexx)'], ItemFactory('Big Key (Turtle Rock)'), ItemFactory(['Small Key (Turtle Rock)'] * 4), ItemFactory(['Map (Turtle Rock)', 'Compass (Turtle Rock)']))
    GT = make_dungeon('Ganons Tower', ['Ganons Tower (Entrance)', 'Ganons Tower (Tile Room)', 'Ganons Tower (Compass Room)', 'Ganons Tower (Hookshot Room)', 'Ganons Tower (Map Room)', 'Ganons Tower (Firesnake Room)', 'Ganons Tower (Teleport Room)', 'Ganons Tower (Bottom)', 'Ganons Tower (Top)', 'Ganons Tower (Before Moldorm)', 'Ganons Tower (Moldorm)', 'Agahnim 2'], ItemFactory('Big Key (Ganons Tower)'), ItemFactory(['Small Key (Ganons Tower)'] * 4), ItemFactory(['Map (Ganons Tower)', 'Compass (Ganons Tower)']))

    world.dungeons = [ES, EP, DP, ToH, AT, PoD, TT, SW, SP, IP, MM, TR, GT]
示例#31
0
def create_dungeons(world):
    def make_dungeon(name, dungeon_regions, boss_key, small_keys, dungeon_items):
        dungeon = Dungeon(name, dungeon_regions, boss_key, small_keys, dungeon_items)
        for region in dungeon.regions:
            world.get_region(region).dungeon = dungeon
        return dungeon

    DT = make_dungeon('Deku Tree', ['Deku Tree Lobby', 'Deku Tree Slingshot Room', 'Deku Tree Boss Room'], None, [], ItemFactory(['Map (Deku Tree)', 'Compass (Deku Tree)']))
    DC = make_dungeon('Dodongos Cavern', ['Dodongos Cavern Beginning', 'Dodongos Cavern Lobby', 'Dodongos Cavern Climb', 'Dodongos Cavern Far Bridge'], None, [], ItemFactory(['Map (Dodongos Cavern)', 'Compass (Dodongos Cavern)']))
    JB = make_dungeon('Jabu Jabus Belly', ['Jabu Jabus Belly Beginning', 'Jabu Jabus Belly Main', 'Jabu Jabus Belly Depths', 'Jabu Jabus Belly Boss Area'], None, [], ItemFactory(['Map (Jabu Jabus Belly)', 'Compass (Jabu Jabus Belly)']))
    FoT = make_dungeon('Forest Temple', ['Forest Temple Lobby', 'Forest Temple NW Outdoors', 'Forest Temple NE Outdoors', 'Forest Temple Falling Room', 'Forest Temple Block Push Room', 'Forest Temple Straightened Hall', 'Forest Temple Outside Upper Ledge', 'Forest Temple Bow Region', 'Forest Temple Boss Region'], ItemFactory('Boss Key (Forest Temple)'), ItemFactory(['Small Key (Forest Temple)'] * 5), ItemFactory(['Map (Forest Temple)', 'Compass (Forest Temple)']))
    BW = make_dungeon('Bottom of the Well', ['Bottom of the Well'], None, ItemFactory(['Small Key (Bottom of the Well)'] * 2), ItemFactory(['Map (Bottom of the Well)', 'Compass (Bottom of the Well)']))
    FiT = make_dungeon('Fire Temple', ['Fire Temple Lower', 'Fire Temple Middle', 'Fire Temple Upper'], ItemFactory('Boss Key (Fire Temple)'), ItemFactory(['Small Key (Fire Temple)'] * 8), ItemFactory(['Map (Fire Temple)', 'Compass (Fire Temple)']))
    IC = make_dungeon('Ice Cavern', ['Ice Cavern'], None, [], ItemFactory(['Map (Ice Cavern)', 'Compass (Ice Cavern)']))
    WT = make_dungeon('Water Temple', ['Water Temple Lobby', 'Water Temple Middle Water Level', 'Water Temple Dark Link Region'], ItemFactory('Boss Key (Water Temple)'), ItemFactory(['Small Key (Water Temple)'] * 6), ItemFactory(['Map (Water Temple)', 'Compass (Water Temple)']))
    ShT = make_dungeon('Shadow Temple', ['Shadow Temple Beginning', 'Shadow Temple First Beamos', 'Shadow Temple Huge Pit', 'Shadow Temple Wind Tunnel', 'Shadow Temple Beyond Boat'], ItemFactory('Boss Key (Shadow Temple)'), ItemFactory(['Small Key (Shadow Temple)'] * 4), ItemFactory(['Map (Shadow Temple)', 'Compass (Shadow Temple)']))
    GTG = make_dungeon('Gerudo Training Grounds', ['Gerudo Training Grounds Lobby', 'Gerudo Training Grounds Central Maze', 'Gerudo Training Grounds Central Maze Right', 'Gerudo Training Grounds Lava Room', 'Gerudo Training Grounds Hammer Room', 'Gerudo Training Grounds Eye Statue Lower', 'Gerudo Training Grounds Eye Statue Upper', 'Gerudo Training Grounds Heavy Block Room'], None, ItemFactory(['Small Key (Gerudo Training Grounds)'] * 8), [])
    SpT = make_dungeon('Spirit Temple', ['Spirit Temple Lobby', 'Child Spirit Temple', 'Early Adult Spirit Temple', 'Spirit Temple Central Chamber', 'Spirit Temple Beyond Central Locked Door', 'Spirit Temple Beyond Final Locked Door'], ItemFactory('Boss Key (Spirit Temple)'), ItemFactory(['Small Key (Spirit Temple)'] * 5), ItemFactory(['Map (Spirit Temple)', 'Compass (Spirit Temple)']))
    GC = make_dungeon('Ganons Castle', ['Ganons Castle Lobby', 'Ganons Castle Forest Trial', 'Ganons Castle Fire Trial', 'Ganons Castle Water Trial', 'Ganons Castle Shadow Trial', 'Ganons Castle Spirit Trial', 'Ganons Castle Light Trial', 'Ganons Castle Tower'], None, ItemFactory(['Small Key (Ganons Castle)'] * 2), [])

 
    world.dungeons = [DT, DC, JB, FoT, BW, FiT, IC, WT, ShT, GTG, SpT, GC]
示例#32
0
    def run_entrance_tests(self, access_pool):
        for entrance, access, *item_pool in access_pool:
            items = item_pool[0]
            all_except = item_pool[1] if len(item_pool) > 1 else None
            with self.subTest(entrance=entrance,
                              access=access,
                              items=items,
                              all_except=all_except):
                if all_except and len(all_except) > 0:
                    items = self.world.itempool[:]
                    items = [
                        item for item in items if item.name not in all_except
                        and not ("Bottle" in item.name
                                 and "AnyBottle" in all_except)
                    ]
                    items.extend(ItemFactory(item_pool[0], 1))
                else:
                    items = ItemFactory(items, 1)
                state = self.get_state(items)

                self.assertEqual(
                    self.world.get_entrance(entrance, 1).can_reach(state),
                    access)
示例#33
0
def create_dynamic_shop_locations(world):
    for shop in world.shops:
        for i, item in enumerate(shop.inventory):
            if item is None:
                continue
            if item['create_location']:
                loc = Location("{} Item {}".format(shop.region.name, i+1), parent=shop.region)
                shop.region.locations.append(loc)
                world.dynamic_locations.append(loc)

                world.clear_location_cache()

                world.push_item(loc, ItemFactory(item['item']), False)
                loc.event = True
def create_dungeons(world, player):
    def make_dungeon(name, default_boss, dungeon_regions, big_key, small_keys, dungeon_items):
        dungeon = Dungeon(name, dungeon_regions, big_key, [] if world.retro[player] else small_keys, dungeon_items, player)
        dungeon.boss = BossFactory(default_boss, player)
        for region in dungeon.regions:
            world.get_region(region, player).dungeon = dungeon
            dungeon.world = world
        return dungeon

    ES = make_dungeon('Hyrule Castle', None, ['Hyrule Castle', 'Sewers', 'Sewer Drop', 'Sewers (Dark)', 'Sanctuary'],
                      None, [ItemFactory('Small Key (Hyrule Castle)', player)],
                      [ItemFactory('Map (Hyrule Castle)', player)])
    EP = make_dungeon('Eastern Palace', 'Armos Knights', ['Eastern Palace'],
                      ItemFactory('Big Key (Eastern Palace)', player), [],
                      ItemFactory(['Map (Eastern Palace)', 'Compass (Eastern Palace)'], player))
    DP = make_dungeon('Desert Palace', 'Lanmolas', ['Desert Palace North', 'Desert Palace Main (Inner)', 'Desert Palace Main (Outer)', 'Desert Palace East'], ItemFactory('Big Key (Desert Palace)', player), [ItemFactory('Small Key (Desert Palace)', player)], ItemFactory(['Map (Desert Palace)', 'Compass (Desert Palace)'], player))
    ToH = make_dungeon('Tower of Hera', 'Moldorm', ['Tower of Hera (Bottom)', 'Tower of Hera (Basement)', 'Tower of Hera (Top)'], ItemFactory('Big Key (Tower of Hera)', player), [ItemFactory('Small Key (Tower of Hera)', player)], ItemFactory(['Map (Tower of Hera)', 'Compass (Tower of Hera)'], player))
    PoD = make_dungeon('Palace of Darkness', 'Helmasaur King', ['Palace of Darkness (Entrance)', 'Palace of Darkness (Center)', 'Palace of Darkness (Big Key Chest)', 'Palace of Darkness (Bonk Section)', 'Palace of Darkness (North)', 'Palace of Darkness (Maze)', 'Palace of Darkness (Harmless Hellway)', 'Palace of Darkness (Final Section)'], ItemFactory('Big Key (Palace of Darkness)', player), ItemFactory(['Small Key (Palace of Darkness)'] * 6, player), ItemFactory(['Map (Palace of Darkness)', 'Compass (Palace of Darkness)'], player))
    TT = make_dungeon('Thieves Town', 'Blind', ['Thieves Town (Entrance)', 'Thieves Town (Deep)', 'Blind Fight'], ItemFactory('Big Key (Thieves Town)', player), [ItemFactory('Small Key (Thieves Town)', player)], ItemFactory(['Map (Thieves Town)', 'Compass (Thieves Town)'], player))
    SW = make_dungeon('Skull Woods', 'Mothula', ['Skull Woods Final Section (Entrance)', 'Skull Woods First Section', 'Skull Woods Second Section', 'Skull Woods Second Section (Drop)', 'Skull Woods Final Section (Mothula)', 'Skull Woods First Section (Right)', 'Skull Woods First Section (Left)', 'Skull Woods First Section (Top)'], ItemFactory('Big Key (Skull Woods)', player), ItemFactory(['Small Key (Skull Woods)'] * 3, player), ItemFactory(['Map (Skull Woods)', 'Compass (Skull Woods)'], player))
    SP = make_dungeon('Swamp Palace', 'Arrghus', ['Swamp Palace (Entrance)', 'Swamp Palace (First Room)', 'Swamp Palace (Starting Area)', 'Swamp Palace (Center)', 'Swamp Palace (North)'], ItemFactory('Big Key (Swamp Palace)', player), [ItemFactory('Small Key (Swamp Palace)', player)], ItemFactory(['Map (Swamp Palace)', 'Compass (Swamp Palace)'], player))
    IP = make_dungeon('Ice Palace', 'Kholdstare', ['Ice Palace (Entrance)', 'Ice Palace (Main)', 'Ice Palace (East)', 'Ice Palace (East Top)', 'Ice Palace (Kholdstare)'], ItemFactory('Big Key (Ice Palace)', player), ItemFactory(['Small Key (Ice Palace)'] * 2, player), ItemFactory(['Map (Ice Palace)', 'Compass (Ice Palace)'], player))
    MM = make_dungeon('Misery Mire', 'Vitreous', ['Misery Mire (Entrance)', 'Misery Mire (Main)', 'Misery Mire (West)', 'Misery Mire (Final Area)', 'Misery Mire (Vitreous)'], ItemFactory('Big Key (Misery Mire)', player), ItemFactory(['Small Key (Misery Mire)'] * 3, player), ItemFactory(['Map (Misery Mire)', 'Compass (Misery Mire)'], player))
    TR = make_dungeon('Turtle Rock', 'Trinexx', ['Turtle Rock (Entrance)', 'Turtle Rock (First Section)', 'Turtle Rock (Chain Chomp Room)', 'Turtle Rock (Second Section)', 'Turtle Rock (Big Chest)', 'Turtle Rock (Crystaroller Room)', 'Turtle Rock (Dark Room)', 'Turtle Rock (Eye Bridge)', 'Turtle Rock (Trinexx)'], ItemFactory('Big Key (Turtle Rock)', player), ItemFactory(['Small Key (Turtle Rock)'] * 4, player), ItemFactory(['Map (Turtle Rock)', 'Compass (Turtle Rock)'], player))

    if world.mode[player] != 'inverted':
        AT = make_dungeon('Agahnims Tower', 'Agahnim', ['Agahnims Tower', 'Agahnim 1'], None, ItemFactory(['Small Key (Agahnims Tower)'] * 2, player), [])
        GT = make_dungeon('Ganons Tower', 'Agahnim2', ['Ganons Tower (Entrance)', 'Ganons Tower (Tile Room)', 'Ganons Tower (Compass Room)', 'Ganons Tower (Hookshot Room)', 'Ganons Tower (Map Room)', 'Ganons Tower (Firesnake Room)', 'Ganons Tower (Teleport Room)', 'Ganons Tower (Bottom)', 'Ganons Tower (Top)', 'Ganons Tower (Before Moldorm)', 'Ganons Tower (Moldorm)', 'Agahnim 2'], ItemFactory('Big Key (Ganons Tower)', player), ItemFactory(['Small Key (Ganons Tower)'] * 4, player), ItemFactory(['Map (Ganons Tower)', 'Compass (Ganons Tower)'], player))
    else:
        AT = make_dungeon('Inverted Agahnims Tower', 'Agahnim', ['Inverted Agahnims Tower', 'Agahnim 1'], None, ItemFactory(['Small Key (Agahnims Tower)'] * 2, player), [])
        GT = make_dungeon('Inverted Ganons Tower', 'Agahnim2', ['Inverted Ganons Tower (Entrance)', 'Ganons Tower (Tile Room)', 'Ganons Tower (Compass Room)', 'Ganons Tower (Hookshot Room)', 'Ganons Tower (Map Room)', 'Ganons Tower (Firesnake Room)', 'Ganons Tower (Teleport Room)', 'Ganons Tower (Bottom)', 'Ganons Tower (Top)', 'Ganons Tower (Before Moldorm)', 'Ganons Tower (Moldorm)', 'Agahnim 2'], ItemFactory('Big Key (Ganons Tower)', player), ItemFactory(['Small Key (Ganons Tower)'] * 4, player), ItemFactory(['Map (Ganons Tower)', 'Compass (Ganons Tower)'], player))

    GT.bosses['bottom'] = BossFactory('Armos Knights', player)
    GT.bosses['middle'] = BossFactory('Lanmolas', player)
    GT.bosses['top'] = BossFactory('Moldorm', player)

    world.dungeons += [ES, EP, DP, ToH, AT, PoD, TT, SW, SP, IP, MM, TR, GT]
示例#35
0
def fill_dungeons_restrictive(world, shuffled_locations):
    all_state_base = world.get_all_state()

    skull_woods_big_chest = world.get_location('Skull Woods - Pinball Room')
    world.push_item(skull_woods_big_chest, ItemFactory('Small Key (Skull Woods)'), False)
    skull_woods_big_chest.event = True
    shuffled_locations.remove(skull_woods_big_chest)

    dungeon_items = [item for dungeon in world.dungeons for item in dungeon.all_items if item.key or world.place_dungeon_items]

    # sort in the order Big Key, Small Key, Other before placing dungeon items
    sort_order = {"BigKey": 3, "SmallKey": 2}
    dungeon_items.sort(key=lambda item: sort_order.get(item.type, 1))

    fill_restrictive(world, all_state_base, shuffled_locations, dungeon_items)

    world.state._clear_cache()
示例#36
0
def create_dynamic_shop_locations(world, player):
    for shop in world.shops:
        if shop.region.player == player:
            for i, item in enumerate(shop.inventory):
                if item is None:
                    continue
                if item['create_location']:
                    loc = Location(player, "{} Slot {}".format(shop.region.name, i + 1), parent=shop.region)
                    shop.region.locations.append(loc)
                    world.dynamic_locations.append(loc)

                    world.clear_location_cache()

                    world.push_item(loc, ItemFactory(item['item'], player), False)
                    loc.shop_slot = True
                    loc.event = True
                    loc.locked = True
示例#37
0
def fill_songs(world, attempts=15):
    songs = ItemFactory(songlist)
    song_locations = [
        world.get_location('Song from Composer Grave'),
        world.get_location('Impa at Castle'),
        world.get_location('Song from Malon'),
        world.get_location('Song from Saria'),
        world.get_location('Song from Ocarina of Time'),
        world.get_location('Song at Windmill'),
        world.get_location('Sheik Forest Song'),
        world.get_location('Sheik at Temple'),
        world.get_location('Sheik in Crater'),
        world.get_location('Sheik in Ice Cavern'),
        world.get_location('Sheik in Kakariko'),
        world.get_location('Sheik at Colossus')
    ]
    placed_prizes = [
        loc.item.name for loc in song_locations if loc.item is not None
    ]
    unplaced_prizes = [
        song for song in songs if song.name not in placed_prizes
    ]
    empty_song_locations = [loc for loc in song_locations if loc.item is None]

    while attempts:
        attempts -= 1
        try:
            prizepool = list(unplaced_prizes)
            prize_locs = list(empty_song_locations)
            random.shuffle(prizepool)
            random.shuffle(prize_locs)
            fill_restrictive(
                world, world.get_all_state(keys=True), prize_locs, prizepool
            )  #TODO: Set keys to true once keys are properly implemented
        except FillError:
            logging.getLogger('').info(
                "Failed to place songs. Will retry %s more times", attempts)
            for location in empty_song_locations:
                location.item = None
            continue
        break
    else:
        raise FillError('Unable to place songs')
示例#38
0
 def make_barracks(self, building):
     for j in range(randrange(2,4)):
         _cy = MonsterFactory.get_monster_by_name(self.dm, "cyborg soldier", 0, 0)
         place_monster(building, self, _cy)
     
     _if = ItemFactory()
     _box = Items.Box('footlocker')
     for j in range(randrange(3)):
         _roll = randrange(6)
         if _roll == 0:
             _box.add_item(_if.get_stack('shotgun shell', 6, True))
         elif _roll == 1:
             _box.add_item(_if.get_stack('grenade', 4, True))
         elif _roll == 2:
             _box.add_item(_if.get_stack('stimpak', 3, True))
         elif _roll == 3:
             _box.add_item(_if.get_stack('machine gun clip', 3, True))
         elif _roll == 4:
             _box.add_item(_if.get_stack('9mm clip', 3, True))
         else:
             _box.add_item(_if.get_stack('medkit', 3, True))
     place_item(building, self, _box)
示例#39
0
    def __generate_map(self):
        _map = []
        
        _if = ItemFactory()
        _tf = TerrainFactory()
        
        # make all border squares walls
        # This could be moved to a superclass
        row = []
        for j in range(0, self.lvl_width):
            row.append(_tf.get_terrain_tile(PERM_WALL))
        _map.append(row)

        for r in range(1, self.lvl_length-1):
            row = []
            row.append(_tf.get_terrain_tile(PERM_WALL))

            for c in range(1, self.lvl_width-1):
                rnd = random()
                
                if rnd < 0.50:
                    row.append(_tf.get_terrain_tile(ROAD))
                elif rnd < 0.90:
                    row.append(_tf.get_terrain_tile(GRASS))
                else:
                    row.append(_tf.get_terrain_tile(TREE))
            row.append(_tf.get_terrain_tile(PERM_WALL))
            _map.append(row)
        row = []
        for j in range(0, self.lvl_width):
            row.append(_tf.get_terrain_tile(PERM_WALL))
        _map.append(row)
        
        # generate the tower section
        _tower = TowerFactory(length = 20, width = 30, top = True, bottom = False)
        _tower.gen_map()
        self.upStairs = None
        self.downStairs = _tower.downStairs
        
        for r in range(0, 20):
            for c in range(0, 30):
                _row = 10 + r
                _col = self.lvl_width- 31 + c
                _map[_row][_col] = _tower.get_cell(r,c)
                if _map[_row][_col].get_type() == DOOR and random() > 0.6:
                    _map[_row][_col].broken = True
                    _map[_row][_col].open()
                
        # beat up the tower a bit
        for x in range(randrange(100, 200)):
            r = 10 + randrange(0,20)
            c = self.lvl_width - 31 + randrange(0, 30)
            if _map[r][c].get_type() != DOWN_STAIRS:
                if random() < 0.75:
                    _map[r][c] = _tf.get_terrain_tile(ROAD)
                else:
                    _map[r][c] = _tf.get_terrain_tile(GRASS)

        # Add double door main entrance
        for r in range(15,25):
            if _map[r][self.lvl_width-30].get_type() == FLOOR and _map[r+1][self.lvl_width-30].get_type() == FLOOR:
                break
        _map[r][self.lvl_width-31] = _tf.get_terrain_tile(DOOR)
        _map[r+1][self.lvl_width-31] = _tf.get_terrain_tile(DOOR)

        for c in range(0, 30):
            _map[29][self.lvl_width-31+c] = _tf.get_terrain_tile(WALL)

        _box = Items.Box()
        _box_placed = False
        while not _box_placed:
            _col = randrange(self.lvl_width-30, self.lvl_width)
            _row = randrange(self.lvl_length-20, self.lvl_length)
            if _map[_row][_col].get_type() not in (DOOR, WALL, PERM_WALL, DOWN_STAIRS):
                self.add_item_to_sqr(_row, _col, _box)
                _box_placed = True

        for x in range(randrange(7)):
            _box.add_item(_if.gen_item('ritalin', 1))
        for x in range(randrange(19)):
            _box.add_item(_if.gen_item('shotgun shell', 1))
        for x in range(randrange(4)):
            _box.add_item(_if.gen_item('flare', 1))
        if randrange(4) > 2:
            _box.add_item(_if.gen_item('medkit', 1))
            
        return _map
示例#40
0
    def __set_standard_kit(self):
        _if = ItemFactory()

        self.__player.inventory.add_item(_if.gen_item('shotgun', 1), 0)

        for j in range(randrange(24, 37)):
            self.__player.inventory.add_item(_if.gen_item('shotgun shell',1), 1)

        self.__player.inventory.add_item(_if.gen_item('stylish leather jacket', 1), 1)
        self.__player.inventory.add_item(_if.gen_item('stylish sunglasses', 1), 1)
        self.__player.inventory.add_item(_if.gen_item('wristwatch', 1), 1)
        self.__player.inventory.add_item(_if.gen_item('high-tech sandals', 1), 1)
        self.__player.inventory.add_item(_if.gen_item('C4 Charge', 1), 0)
        self.__player.inventory.add_item(_if.gen_item('C4 Charge', 1), 0)
        self.__player.inventory.add_item(_if.gen_item('C4 Charge', 1), 0)

        self.__player.inventory.add_item(_if.gen_item('truncheon', 1), 1)

        for j in range(randrange(12, 25)):
            self.__player.inventory.add_item(_if.gen_item('amphetamine', 1), 0)

        self.__player.inventory.add_item(_if.gen_item('lockpick', 1), 0)
示例#41
0
 def __fighting_is_hard_lets_go_shopping(self):
     _if = ItemFactory()
     _cash = 150
     
     # This stuff the player gets for free
     self.__player.inventory.add_item(_if.gen_item('stylish leather jacket', 1), 1)
     self.__player.inventory.add_item(_if.gen_item('stylish sunglasses', 1), 1)
     self.__player.inventory.add_item(_if.gen_item('wristwatch', 1), 1)
     for j in range(randrange(12, 25)):
         self.__player.inventory.add_item(_if.gen_item('amphetamine', 1), 0)
         
     _menu = []
     _menu.append(('a', 'Shotgun - $50', ('shotgun', 50)))
     _menu.append(('b', 'P90 Assault Rifle - $80', ('p90 assault rifle', 80)))
     _menu.append(('c', 'M1911A1 - $75', ('m1911a1', 75)))
     _menu.append(('d', 'Shotgun Shells - $10/dozen', ('shell', 10)))
     _menu.append(('e', 'Machine Gun Clip - $15', ('machine gun clip', 15)))
     _menu.append(('f', '9mm Clip - $15', ('9mm clip', 15)))
     _menu.append(('g', 'Grenade - $17', ('grenade', 17)))
     _menu.append(('h', 'Truncheon - $15', ('truncheon', 15)))
     _menu.append(('i', 'Combat Knife - $10', ('combat knife', 10)))
     _menu.append(('j', 'Army Helmet - $25', ('army helmet', 25)))
     _menu.append(('k', 'Combat Boots - $25', ('combat boots', 25)))
     _menu.append(('l', 'High-Tech Sandals - $15', ('high-tech sandals', 15)))
     _menu.append(('m', 'C4 Charge - $10', ('C4 Charge', 10)))
     _menu.append(('n', 'Medkit - $10', ('medkit', 10)))
     _menu.append(('o', 'Lockpick - $10', ('lockpick', 10)))
     _menu.append(('p', 'Flare - $5', ('flare', 5)))
     _menu.append(('r', 'Flashlight - $10', ('flashlight', 10)))
     _menu.append(('s', 'Spare Battery - $5', ('battery', 5)))
     _menu.append(('q', 'Quit and begin your mission', 'quit'))
     
     while True:
         _header = ['You have $%d remaining.' % (_cash)]
         _choice = self.dui.ask_menued_question(_header, _menu)
         
         if _choice == '':
             continue 
             
         if _choice == 'quit':
             break
         
         if _cash < _choice[1]:
             self.dui.display_message(" You can't afford that!", True)
         else:
             _cash -= _choice[1]
             self.dui.clear_msg_line()
             
             if _choice[0] == 'shell':
                 for j in range(12):
                     self.__player.inventory.add_item(_if.gen_item('shotgun shell', 1), 0)
                 self.dui.display_message(" You buy some shotgun shells.", True)
             elif _choice[0] == 'flashlight':
                 _fl = _if.gen_item('flashlight', 1)
                 _fl.charge = _fl.maximum_charge # seemed mean not to
                 self.dui.display_message(" You buy a flashlight.", True)
                 self.__player.inventory.add_item(_fl, 0)
             elif _choice[0] in ('m1911a1', 'p90 assault rifle'):
                 _gun = _if.gen_item(_choice[0], 1)
                 _gun.current_ammo = 0
                 self.__player.inventory.add_item(_gun, 0)
                 _name = _gun.get_name(2)
                 self.dui.display_message(" You buy " + _name + ".", True)
             else:
                 _item = _if.gen_item(_choice[0], 1)
                 self.__player.inventory.add_item(_item, 0)
                 _name = _item.get_name(2)
                 self.dui.display_message(" You buy " + _name + ".", True)