コード例 #1
0
ファイル: event.py プロジェクト: coolkat64/rolling
class PlayerMoveProcessor(EventProcessor):
    def __init__(self, kernel: "Kernel", zone_events_manager: "ZoneEventsManager") -> None:
        super().__init__(kernel, zone_events_manager)
        self._character_lib = CharacterLib(self._kernel)

    async def _process(
        self,
        row_i: int,
        col_i: int,
        event: ZoneEvent[PlayerMoveData],
        sender_socket: web.WebSocketResponse,
    ) -> None:
        # FIXME BS 2019-01-23: Check what move is possible (tile can be a rock, or water ...)
        # TODO BS 2019-01-23: Check given character id is authenticated used (security)
        # FIXME BS 2020-07-04: Check there is no build with traversable false
        # FIXME BS 2020-07-04: check move is just near previous position + refuse move event
        character = self._character_lib.get(event.data.character_id)
        self._character_lib.move_on_zone(
            character, to_row_i=event.data.to_row_i, to_col_i=event.data.to_col_i
        )

        event_str = self._event_serializer_factory.get_serializer(event.type).dump_json(event)
        for socket in self._zone_events_manager.get_sockets(row_i, col_i):
            server_logger.debug(f"Send event on socket: {event_str}")

            try:
                await socket.send_str(event_str)
            except Exception as exc:
                server_logger.exception(exc)
コード例 #2
0
ファイル: manage.py プロジェクト: coolkat64/rolling
def create(game_config_dir: str, character_name: str, stuff_id: str) -> None:
    click.echo("Preparing libs ...")
    kernel = get_kernel(game_config_folder=game_config_dir)
    stuff_lib = StuffLib(kernel)
    character_lib = CharacterLib(kernel)

    click.echo("Preparing libs ... OK")
    click.echo("Search character by name")
    character_ = character_lib.get_by_name(character_name)

    click.echo("Create stuff")
    stuff_properties = kernel.game.stuff_manager.get_stuff_properties_by_id(stuff_id)
    stuff_doc = stuff_lib.create_document_from_stuff_properties(stuff_properties)
    stuff_doc.carried_by_id = character_.id
    click.echo("Commit changes")
    kernel.server_db_session.add(stuff_doc)
    kernel.server_db_session.commit()
コード例 #3
0
 def __init__(
     self,
     kernel: Kernel,
     character_lib: typing.Optional[CharacterLib] = None,
     stuff_lib: typing.Optional[StuffLib] = None,
 ) -> None:
     super().__init__(kernel)
     self._tile_lib = ZoneLib(self._kernel)
     self._character_lib = character_lib or CharacterLib(self._kernel)
     self._stuff_lib = stuff_lib or StuffLib(self._kernel)
コード例 #4
0
    def test_inventory_one_weight_item(
        self,
        worldmapc_kernel: Kernel,
        jose: CharacterDocument,
        half_filled_plastic_bottle: StuffDocument,
        character_lib: CharacterLib,
    ) -> None:
        inventory = character_lib.get_inventory(jose.id)
        assert 0 == inventory.clutter
        assert 0 == inventory.weight
        assert not inventory.stuff

        half_filled_plastic_bottle.carried_by_id = jose.id
        worldmapc_kernel.server_db_session.commit()

        inventory = character_lib.get_inventory(jose.id)
        assert 1.0 == inventory.clutter
        assert 0.50 == inventory.weight
        assert inventory.stuff
        assert 1 == len(inventory.stuff)
        assert "Plastic bottle" == inventory.stuff[0].name
コード例 #5
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()
コード例 #6
0
ファイル: kernel.py プロジェクト: coolkat64/rolling
 def character_lib(self) -> CharacterLib:
     if self._character_lib is None:
         self._character_lib = CharacterLib(self, stuff_lib=self.stuff_lib)
     return self._character_lib
コード例 #7
0
ファイル: fixtures.py プロジェクト: coolkat64/rolling
def worldmapc_with_zones_server_character_lib(worldmapc_kernel: Kernel) -> CharacterLib:
    return CharacterLib(worldmapc_kernel)
コード例 #8
0
ファイル: fixtures.py プロジェクト: coolkat64/rolling
def worldmapc_franck_model(franck: CharacterDocument, worldmapc_kernel: Kernel) -> CharacterModel:
    character_lib = CharacterLib(worldmapc_kernel)
    return character_lib.document_to_model(franck)
コード例 #9
0
ファイル: fixtures.py プロジェクト: coolkat64/rolling
def worldmapc_arthur_model(arthur: CharacterDocument, worldmapc_kernel: Kernel) -> CharacterModel:
    character_lib = CharacterLib(worldmapc_kernel)
    return character_lib.document_to_model(arthur)
コード例 #10
0
ファイル: fixtures.py プロジェクト: coolkat64/rolling
def worldmapc_xena_model(xena: CharacterDocument, worldmapc_kernel: Kernel) -> CharacterModel:
    character_lib = CharacterLib(worldmapc_kernel)
    return character_lib.document_to_model(xena)
コード例 #11
0
def character_lib(
    worldmapc_kernel: Kernel,
    worldmapc_with_zones_server_character_lib: CharacterLib,
    worldmapc_with_zones_stuff_lib: StuffLib,
) -> CharacterLib:
    return CharacterLib(worldmapc_kernel, stuff_lib=worldmapc_with_zones_stuff_lib)
コード例 #12
0
ファイル: event.py プロジェクト: coolkat64/rolling
 def __init__(self, kernel: "Kernel", zone_events_manager: "ZoneEventsManager") -> None:
     super().__init__(kernel, zone_events_manager)
     self._character_lib = CharacterLib(self._kernel)