예제 #1
0
파일: turn.py 프로젝트: coolkat64/rolling
def run(args: argparse.Namespace) -> None:
    # Configure logging
    if args.debug:
        configure_logging(logging.DEBUG)
    else:
        configure_logging(logging.INFO)

    kernel = get_kernel(args.world_map_source, args.tile_maps_folder, args.game_config_folder)
    character_lib = CharacterLib(kernel)
    stuff_lib = StuffLib(kernel)
    turn_lib = TurnLib(kernel, character_lib, stuff_lib, logger=server_logger)
    turn_lib.execute_turn()
예제 #2
0
    async def test_unit__character_die__ok__affinity_relations_discard(
        self,
        worldmapc_kernel: Kernel,
        turn_lib: TurnLib,
        xena: CharacterDocument,
        arthur: CharacterDocument,
        worldmapc_web_app: TestClient,
        descr_serializer: serpyco.Serializer,
    ) -> None:
        session = worldmapc_kernel.server_db_session
        session.refresh(xena)
        session.refresh(arthur)
        web = worldmapc_web_app
        kernel = worldmapc_kernel

        # fixtures
        await web.post(f"/affinity/{xena.id}/new", json={"name": "MyAffinity"})
        affinity: AffinityDocument = kernel.server_db_session.query(
            AffinityDocument).one()
        affinity.join_type = AffinityJoinType.ACCEPT_ALL.value
        kernel.server_db_session.add(affinity)
        kernel.server_db_session.commit()
        resp = await web.post(
            f"/affinity/{arthur.id}/edit-relation/{affinity.id}?request=1&fighter=1"
        )
        assert 200 == resp.status

        # see affinity
        resp = await web.post(f"/affinity/{arthur.id}/see/{1}")
        descr = descr_serializer.load(await resp.json())
        assert "MyAffinity" == descr.title
        assert "2 membre(s)" in descr.items[1].text
        assert f"2 prêt(s)" in descr.items[1].text

        # make turn kill arthur
        arthur_doc = kernel.character_lib.get_document(arthur.id)
        arthur_doc.life_points = 0
        kernel.server_db_session.add(arthur_doc)
        kernel.server_db_session.commit()
        turn_lib.execute_turn()

        arthur_doc = kernel.character_lib.get_document(arthur.id, dead=True)
        assert not arthur_doc.alive

        # see affinity
        resp = await web.post(f"/affinity/{xena.id}/see/{1}")
        descr = descr_serializer.load(await resp.json())
        assert "MyAffinity" == descr.title
        assert "1 membre(s)" in descr.items[1].text
        assert f"1 prêt(s)" in descr.items[1].text
예제 #3
0
    def test_eat__ok__eat_stuff(self, worldmapc_kernel: Kernel,
                                turn_lib: TurnLib,
                                xena: CharacterDocument) -> None:
        kernel = worldmapc_kernel

        apple = create_stuff(kernel, "APPLE")
        kernel.stuff_lib.set_carried_by(apple.id, xena.id)

        with unittest.mock.patch(
                "rolling.server.effect.EffectManager.enable_effect"
        ) as fake_enable_effect:
            turn_lib.execute_turn()

        assert not kernel.stuff_lib.have_stuff_count(character_id=xena.id,
                                                     stuff_id="APPLE")
        assert fake_enable_effect.called
        assert fake_enable_effect.call_args_list[0][0][
            1].id == "HUNGRY_SATISFIED"
예제 #4
0
    def test_eat__ok__eat_resource(self, worldmapc_kernel: Kernel,
                                   turn_lib: TurnLib,
                                   xena: CharacterDocument) -> None:
        kernel = worldmapc_kernel

        kernel.resource_lib.add_resource_to(character_id=xena.id,
                                            resource_id="VEGETAL_FOOD_FRESH",
                                            quantity=1.0)
        with unittest.mock.patch(
                "rolling.server.effect.EffectManager.enable_effect"
        ) as fake_enable_effect:
            turn_lib.execute_turn()

        assert not kernel.resource_lib.have_resource(
            character_id=xena.id, resource_id="VEGETAL_FOOD_FRESH")
        assert fake_enable_effect.called
        assert fake_enable_effect.call_args_list[0][0][
            1].id == "HUNGRY_SATISFIED"
예제 #5
0
def turn_lib(
    worldmapc_kernel: Kernel,
    worldmapc_with_zones_server_character_lib: CharacterLib,
    worldmapc_with_zones_stuff_lib: StuffLib,
) -> TurnLib:
    return TurnLib(
        worldmapc_kernel,
        character_lib=worldmapc_with_zones_server_character_lib,
        stuff_lib=worldmapc_with_zones_stuff_lib,
        logger=logging.getLogger("tests"),
    )
예제 #6
0
    def test_eat__ko__eat_resource_but_not_enough(
            self, worldmapc_kernel: Kernel, turn_lib: TurnLib,
            xena: CharacterDocument) -> None:
        kernel = worldmapc_kernel

        kernel.resource_lib.add_resource_to(
            character_id=xena.id,
            resource_id="VEGETAL_FOOD_FRESH",
            quantity=0.5  # not enough
        )
        with unittest.mock.patch(
                "rolling.server.effect.EffectManager.enable_effect"
        ) as fake_enable_effect:
            turn_lib.execute_turn()

        assert kernel.resource_lib.have_resource(
            character_id=xena.id,
            resource_id="VEGETAL_FOOD_FRESH",
            quantity=0.5)
        assert not fake_enable_effect.called
예제 #7
0
    def test_alive_since_evolution(
        self,
        worldmapc_kernel: Kernel,
        turn_lib: TurnLib,
        xena: CharacterDocument,
        arthur: CharacterDocument,
    ) -> None:
        session = worldmapc_kernel.server_db_session
        session.refresh(xena)
        session.refresh(arthur)

        assert 0 == xena.alive_since
        assert 0 == arthur.alive_since

        turn_lib.execute_turn()

        session.refresh(xena)
        session.refresh(arthur)

        assert 1 == xena.alive_since
        assert 1 == arthur.alive_since
예제 #8
0
    def test_lp_up__ok__natural_needs(
        self,
        worldmapc_kernel: Kernel,
        turn_lib: TurnLib,
        xena: CharacterDocument,
        feel_thirsty: bool,
        feel_hungry: bool,
        before_lp: float,
        after_lp: float,
    ) -> None:
        kernel = worldmapc_kernel

        xena.life_points = before_lp
        xena.feel_thirsty = feel_thirsty
        xena.feel_hungry = feel_hungry
        kernel.character_lib.update(xena)

        turn_lib.execute_turn()

        xena = kernel.character_lib.get_document(xena.id)
        assert xena.life_points == after_lp