submitTurn method

Future<ServerResponse> submitTurn({
  1. required String ownerId,
  2. required String matchId,
  3. required int version,
  4. required Map<String, dynamic> jsonMatchState,
  5. String? pushNotificationMessage,
  6. String? nextPlayer,
  7. Map<String, dynamic>? jsonSummary,
  8. Map<String, dynamic>? jsonStatistics,
})

Submits a turn for the given match.

Service Name - AsyncMatch Service Operation - SubmitTurn

@param ownerId Match owner identfier

@param matchId Match identifier

@param version Game state version to ensure turns are submitted once and in order

@param jsonMatchState JSON provided by the caller

@param pushNotificationMessage Optional push notification message to send to the other party. Refer to the Push Notification functions for the syntax required.

@param nextPlayer Optionally, force the next player player to be a specific player

@param jsonSummary Optional JSON that other players will see as a summary of the game when listing their games

@param jsonStatistics Optional JSON provided by the caller

returns Future<ServerResponse>

Implementation

Future<ServerResponse> submitTurn(
    {required String ownerId,
    required String matchId,
    required int version,
    required Map<String, dynamic> jsonMatchState,
    String? pushNotificationMessage,
    String? nextPlayer,
    Map<String, dynamic>? jsonSummary,
    Map<String, dynamic>? jsonStatistics}) {
  Completer<ServerResponse> completer = Completer();
  Map<String, dynamic> data = {};

  data["ownerId"] = ownerId;
  data["matchId"] = matchId;
  data["version"] = version.toUnsigned(64);
  data["matchState"] = jsonMatchState;

  if (Util.isOptionalParameterValid(nextPlayer)) {
    Map<String, dynamic> status = {};
    status["currentPlayer"] = nextPlayer;
    data["status"] = status;
  }

  if (jsonSummary != null) {
    data["summary"] = jsonSummary;
  }

  if (jsonStatistics != null) {
    data["statistics"] = jsonStatistics;
  }

  if (pushNotificationMessage != null) {
    data["pushContent"] = pushNotificationMessage;
  }

  ServerCallback? callback = BrainCloudClient.createServerCallback(
      (response) => completer.complete(ServerResponse.fromJson(response)),
      (statusCode, reasonCode, statusMessage) => completer.complete(
          ServerResponse(
              statusCode: statusCode,
              reasonCode: reasonCode,
              error: statusMessage)));
  ServerCall sc = ServerCall(
      ServiceName.asyncMatch, ServiceOperation.submitTurn, data, callback);
  _clientRef.sendRequest(sc);

  return completer.future;
}