Ejemplo n.º 1
0
def make_player_with_hh_type(entity_map: EntityMapBuilder,
                             hh_type: EntityType):
    hh_entity_db = EntityDBEntry(id=hh_type)
    hh_entity = Player(type=hh_entity_db)
    hh_id = entity_map.add_entity(hh_entity)

    return Player(linked_companion_child=hh_id)
Ejemplo n.º 2
0
def test_could_tp_mount(mount_type, expected_could_tp):
    mount = Mount(type=EntityDBEntry(id=mount_type))
    poly_mount = PolyPointer(101, mount, MemContext())
    player = Player(overlay=poly_mount)

    run_state = RunState()
    assert run_state.could_tp(player, set(), set()) == expected_could_tp
Ejemplo n.º 3
0
def test_compute_player_motion_mount_and_active_floor():
    elevator = Movable(
        type=EntityDBEntry(id=EntityType.ACTIVEFLOOR_ELEVATOR),
        position_x=0.5,
        position_y=0.7,
        velocity_x=-0.1,
        velocity_y=-0.3,
    )
    poly_elevator = PolyPointer(101, elevator, MemContext())
    # Turkey on an elevator
    mount = Mount(
        type=EntityDBEntry(id=EntityType.MOUNT_TURKEY),
        position_x=18,
        position_y=13,
        velocity_x=-2,
        velocity_y=-7,
        overlay=poly_elevator,
    )
    poly_mount = PolyPointer(102, mount, MemContext())
    player = Player(position_x=5,
                    position_y=7,
                    velocity_x=-1,
                    velocity_y=-3,
                    overlay=poly_mount)
    expected_motion = PlayerMotion(position_x=18.5,
                                   position_y=13.7,
                                   velocity_x=-2.1,
                                   velocity_y=-7.3)
    run_state = RunState()
    assert run_state.compute_player_motion(player) == expected_motion
Ejemplo n.º 4
0
def test_compute_player_motion_wo_overlay():
    player = Player(position_x=5, position_y=7, velocity_x=-1, velocity_y=-3)
    expected_motion = PlayerMotion(position_x=5,
                                   position_y=7,
                                   velocity_x=-1,
                                   velocity_y=-3)
    run_state = RunState()
    assert run_state.compute_player_motion(player) == expected_motion
Ejemplo n.º 5
0
def test_starting_resources_health(char_state, prev_health, cur_health,
                                   expected_low, expected_no):
    run_state = RunState()
    run_state.health = prev_health

    player = Player(state=char_state, health=cur_health)
    run_state.update_starting_resources(player, WinState.NO_WIN)
    assert run_state.health == cur_health

    is_low = Label.LOW in run_state.run_label._set
    assert is_low == expected_low

    is_no = Label.NO in run_state.run_label._set
    assert is_no == expected_no
Ejemplo n.º 6
0
def test_starting_resources_bombs(prev_bombs, cur_bombs, expected_low,
                                  expected_no):
    run_state = RunState()
    run_state.bombs = prev_bombs

    inventory = Inventory(bombs=cur_bombs)
    player = Player(inventory=inventory)
    run_state.update_starting_resources(player, WinState.NO_WIN)

    assert run_state.bombs == cur_bombs

    is_low = Label.LOW in run_state.run_label._set
    assert is_low == expected_low

    is_no = Label.NO in run_state.run_label._set
    assert is_no == expected_no
Ejemplo n.º 7
0
def test_starting_resources_ropes(level_start_ropes, prev_ropes, cur_ropes,
                                  win_state, expected_low, expected_no):
    run_state = RunState()
    run_state.level_start_ropes = level_start_ropes
    run_state.ropes = prev_ropes

    inventory = Inventory(ropes=cur_ropes)
    player = Player(inventory=inventory)
    run_state.update_starting_resources(player, win_state)

    assert run_state.ropes == cur_ropes

    is_low = Label.LOW in run_state.run_label._set
    assert is_low == expected_low

    is_no = Label.NO in run_state.run_label._set
    assert is_no == expected_no
Ejemplo n.º 8
0
def test_compute_player_motion_mount():
    mount = Mount(
        type=EntityDBEntry(id=EntityType.MOUNT_TURKEY),
        position_x=18,
        position_y=13,
        velocity_x=-2,
        velocity_y=-7,
    )
    poly_mount = PolyPointer(101, mount, MemContext())
    player = Player(position_x=5,
                    position_y=7,
                    velocity_x=-1,
                    velocity_y=-3,
                    overlay=poly_mount)
    expected_motion = PlayerMotion(position_x=18,
                                   position_y=13,
                                   velocity_x=-2,
                                   velocity_y=-7)
    run_state = RunState()
    assert run_state.compute_player_motion(player) == expected_motion
Ejemplo n.º 9
0
def test_compute_player_motion_active_floor():
    elevator = Movable(
        type=EntityDBEntry(id=EntityType.ACTIVEFLOOR_ELEVATOR),
        position_x=0.5,
        position_y=0.7,
        velocity_x=-0.1,
        velocity_y=-0.3,
    )
    poly_elevator = PolyPointer(101, elevator, MemContext())
    player = Player(position_x=5,
                    position_y=7,
                    velocity_x=-1,
                    velocity_y=-3,
                    overlay=poly_elevator)
    expected_motion = PlayerMotion(position_x=5.5,
                                   position_y=7.7,
                                   velocity_x=-1.1,
                                   velocity_y=-3.3)
    run_state = RunState()
    assert run_state.compute_player_motion(player) == expected_motion
Ejemplo n.º 10
0
def test_no_tp(
    player_x,
    player_y,
    player_vx,
    player_vy,
    idle_counter,
    shadow_x,
    shadow_y,
    expected_no_tp,
):
    fx_shadow_type = EntityDBEntry(id=EntityType.FX_TELEPORTSHADOW)
    new_entities = []
    src_shadow = LightEmitter(type=fx_shadow_type,
                              idle_counter=idle_counter,
                              emitted_light=Illumination())
    new_entities.append(poly_pointer_no_mem(src_shadow))

    dest_illumination = Illumination(light_pos_x=shadow_x,
                                     light_pos_y=shadow_y)
    dest_shadow = LightEmitter(type=fx_shadow_type,
                               idle_counter=idle_counter,
                               emitted_light=dest_illumination)
    new_entities.append(poly_pointer_no_mem(dest_shadow))

    player = Player(
        position_x=player_x,
        position_y=player_y,
        velocity_x=player_vx,
        velocity_y=player_vy,
    )
    item_set = {EntityType.ITEM_TELEPORTER_BACKPACK}
    prev_item_set = set()

    run_state = RunState()
    run_state.new_entities = new_entities
    run_state.update_no_tp(player, item_set, prev_item_set)

    is_no_tp = Label.NO_TELEPORTER in run_state.run_label._set
    assert is_no_tp == expected_no_tp
Ejemplo n.º 11
0
def test_could_tp_items(item_set, prev_item_set, expected_could_tp):
    run_state = RunState()
    assert run_state.could_tp(Player(), item_set,
                              prev_item_set) == expected_could_tp
Ejemplo n.º 12
0
def make_player_with_hh_items(entity_map: EntityMapBuilder,
                              hh_item_types: Iterable[EntityType]):
    hh_item_ids = entity_map.add_trivial_entities(hh_item_types)
    hh_id = entity_map.add_entity(Player(items=hh_item_ids))

    return Player(linked_companion_child=hh_id)
Ejemplo n.º 13
0
    duat_chain = DuatChain()
    result = duat_chain.visit_city_of_gold(game_state, player_item_set)

    assert result.status == expected_status
    if expected_status.in_progress:
        assert result.next_step.__name__ == expected_step_name


@pytest.mark.parametrize(
    "world,level,player,player_item_set,expected_status,expected_step_name",
    [
        (
            4,
            3,
            Player(),
            {EntityType.ITEM_POWERUP_CROWN, EntityType.ITEM_POWERUP_ANKH},
            ChainStatus.IN_PROGRESS,
            "keep_ankh",
        ),
        # No Ankh, no Duat
        (
            4,
            3,
            Player(),
            {EntityType.ITEM_POWERUP_CROWN},
            ChainStatus.FAILED,
            None,
        ),
        # No player, we assume this is due to sacrifice
        (