public async Task Handle(StartGame command) { var room = await _roomFetcher.Fetch(RoomId.Parse(command.RoomId)); if (room != null) { room.StartGame(new PlayerId(command.PlayerId)); await _persister.TryStore(room); await _eventHub.DispatchAll(room); } }
public async Task Handle(CreateRoom command) { Room room; var playerId = new PlayerId(command.HostPlayerId); do { room = Room.CreateRoom(playerId, command.HostPlayerName, CharacterKey.Parse(command.SelectedCharacter)); }while (!(await _persister.TryStore(room))); await _eventHub.DispatchAll(room); }
public async Task Handle(JoinRoom command) { if (RoomCode.TryParse(command.RoomCode, out RoomCode code, out string error)) { var room = await _fetcher.Fetch(code); if (room == null) { await _eventHub.Dispatch(new JoinRoomFailed() { PlayerId = command.PlayerId, RoomCode = command.RoomCode, UserName = command.UserName, Reason = "Room not found" }); } else { room.AddGuest(new PlayerId(command.PlayerId), command.UserName, CharacterKey.Parse(command.SelectedCharacter)); await _persister.TryStore(room); await _eventHub.DispatchAll(room); } }