public void Finish(string matchId, byte[] data, MatchOutcome outcome, Action <bool> callback) { Logger.d(string.Format("iOSTbmpClient.Finish matchId={0}, outcome={1}", matchId, outcome.ToString())); // We probably need to convert our match outcome into something we can read in var resultsOutput = new List <Dictionary <string, object> >(); List <string> allParticipants = outcome.ParticipantIds; Dictionary <string, object> nextResult; foreach (string participantID in allParticipants) { Logger.d("Getting results for " + participantID); nextResult = new Dictionary <string, object>(); // Maybe don't add them if their result is unset? Check with Bruno on this one if (outcome.GetResultFor(participantID) != MatchOutcome.ParticipantResult.Unset) { nextResult["participantId"] = participantID; nextResult["placing"] = outcome.GetPlacementFor(participantID); nextResult["result"] = convertParticipantResultToiOSInt(outcome.GetResultFor(participantID)); } resultsOutput.Add(nextResult); } string resultsAsJson = Json.Serialize(resultsOutput); Logger.d("JSonified results are " + resultsAsJson); sCallbackSuccessId++; sMatchSuccessCallbacks.Add(sCallbackSuccessId, callback); GPGSTBMPFinishMatch(matchId, data, data.Length, resultsAsJson, sCallbackSuccessId, TbmpMatchSuccessCallback); }
public void Finish(string matchId, byte[] data, MatchOutcome outcome, Action <bool> callback) { Logger.d(string.Format("AndroidTbmpClient.Finish matchId={0}, data={1} outcome={2}", matchId, data == null ? "(null)" : data.Length + " bytes", outcome)); Logger.d("Preparing list of participant results as Android ArrayList."); AndroidJavaObject participantResults = new AndroidJavaObject("java.util.ArrayList"); if (outcome != null) { foreach (string pid in outcome.ParticipantIds) { Logger.d("Converting participant result to Android object: " + pid); AndroidJavaObject thisParticipantResult = new AndroidJavaObject( JavaConsts.ParticipantResultClass, pid, JavaUtil.GetAndroidParticipantResult(outcome.GetResultFor(pid)), outcome.GetPlacementFor(pid)); // (yes, the return type of ArrayList.add is bool, strangely) Logger.d("Adding participant result to Android ArrayList."); participantResults.Call <bool>("add", thisParticipantResult); thisParticipantResult.Dispose(); } } TbmpApiCall("tbmp finish w/ outcome", "finishMatch", callback, null, matchId, data, participantResults); }
public void Finish(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, byte[] data, MatchOutcome outcome, Action <bool> callback) { callback = Callbacks.AsOnGameThreadCallback(callback); FindEqualVersionMatch(match, callback, delegate(NativeTurnBasedMatch foundMatch) { GooglePlayGames.Native.PInvoke.ParticipantResults participantResults = foundMatch.Results(); foreach (string participantId in outcome.ParticipantIds) { Types.MatchResult matchResult = ResultToMatchResult(outcome.GetResultFor(participantId)); uint placementFor = outcome.GetPlacementFor(participantId); if (participantResults.HasResultsForParticipant(participantId)) { Types.MatchResult matchResult2 = participantResults.ResultsForParticipant(participantId); uint num = participantResults.PlacingForParticipant(participantId); if (matchResult != matchResult2 || placementFor != num) { Logger.e($"Attempted to override existing results for participant {participantId}: Placing {num}, Result {matchResult2}"); callback(false); return; } } else { GooglePlayGames.Native.PInvoke.ParticipantResults participantResults2 = participantResults; participantResults = participantResults2.WithResult(participantId, placementFor, matchResult); participantResults2.Dispose(); } } mTurnBasedManager.FinishMatchDuringMyTurn(foundMatch, data, participantResults, delegate(TurnBasedManager.TurnBasedMatchResponse response) { callback(response.RequestSucceeded()); }); }); }
public void Finish(string matchId, byte[] data, MatchOutcome outcome, Action <bool> callback) { Logger.d(string.Format("AndroidTbmpClient.Finish matchId={0}, data={1} outcome={2}", matchId, (data != null) ? (data.Length + " bytes") : "(null)", outcome)); Logger.d("Preparing list of participant results as Android ArrayList."); AndroidJavaObject androidJavaObject = new AndroidJavaObject("java.util.ArrayList", new object[0]); if (outcome != null) { foreach (string current in outcome.ParticipantIds) { Logger.d("Converting participant result to Android object: " + current); AndroidJavaObject androidJavaObject2 = new AndroidJavaObject("com.google.android.gms.games.multiplayer.ParticipantResult", new object[] { current, JavaUtil.GetAndroidParticipantResult(outcome.GetResultFor(current)), outcome.GetPlacementFor(current) }); Logger.d("Adding participant result to Android ArrayList."); androidJavaObject.Call <bool>("add", new object[] { androidJavaObject2 }); androidJavaObject2.Dispose(); } } this.TbmpApiCall("tbmp finish w/ outcome", "finishMatch", callback, null, new object[] { matchId, data, androidJavaObject }); }
public void Finish(TurnBasedMatch match, byte[] data, MatchOutcome outcome, Action <bool> callback) { callback = Callbacks.AsOnGameThreadCallback(callback); FindEqualVersionMatch(match, callback, foundMatch => { ParticipantResults results = foundMatch.Results(); foreach (string participantId in outcome.ParticipantIds) { Types.MatchResult matchResult = ResultToMatchResult(outcome.GetResultFor(participantId)); uint placing = outcome.GetPlacementFor(participantId); if (results.HasResultsForParticipant(participantId)) { // If the match already has results for this participant, make sure that they're // consistent with what's already there. var existingResults = results.ResultsForParticipant(participantId); var existingPlacing = results.PlacingForParticipant(participantId); if (matchResult != existingResults || placing != existingPlacing) { Logger.e(string.Format("Attempted to override existing results for " + "participant {0}: Placing {1}, Result {2}", participantId, existingPlacing, existingResults)); callback(false); return; } } else { // Otherwise, get updated results and dispose of the old ones. var oldResults = results; results = oldResults.WithResult(participantId, placing, matchResult); oldResults.Dispose(); } } mTurnBasedManager.FinishMatchDuringMyTurn(foundMatch, data, results, response => callback(response.RequestSucceeded())); }); }
public void Finish(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, byte[] data, MatchOutcome outcome, Action <bool> callback) { callback = Callbacks.AsOnGameThreadCallback <bool>(callback); this.FindEqualVersionMatch(match, callback, (Action <NativeTurnBasedMatch>)(foundMatch => { GooglePlayGames.Native.PInvoke.ParticipantResults results = foundMatch.Results(); using (List <string> .Enumerator enumerator = outcome.ParticipantIds.GetEnumerator()) { while (enumerator.MoveNext()) { string current = enumerator.Current; Types.MatchResult matchResult1 = NativeTurnBasedMultiplayerClient.ResultToMatchResult(outcome.GetResultFor(current)); uint placementFor = outcome.GetPlacementFor(current); if (results.HasResultsForParticipant(current)) { Types.MatchResult matchResult2 = results.ResultsForParticipant(current); uint num = results.PlacingForParticipant(current); if (matchResult1 != matchResult2 || (int)placementFor != (int)num) { Logger.e(string.Format("Attempted to override existing results for participant {0}: Placing {1}, Result {2}", (object)current, (object)num, (object)matchResult2)); callback(false); return; } } else { GooglePlayGames.Native.PInvoke.ParticipantResults participantResults = results; results = participantResults.WithResult(current, placementFor, matchResult1); participantResults.Dispose(); } } } this.mTurnBasedManager.FinishMatchDuringMyTurn(foundMatch, data, results, (Action <TurnBasedManager.TurnBasedMatchResponse>)(response => callback(response.RequestSucceeded()))); })); }
public void Finish(TurnBasedMatch match, byte[] data, MatchOutcome outcome, Action <bool> callback) { callback = ToOnGameThread(callback); GetMatchAndroidJavaObject(match.MatchId, (status, foundMatch) => { if (!status) { callback(false); return; } using (var results = new AndroidJavaObject("java.util.ArrayList")) { Dictionary <string, AndroidJavaObject> idToResult = new Dictionary <string, AndroidJavaObject>(); using (var participantList = foundMatch.Call <AndroidJavaObject>("getParticipants")) { int size = participantList.Call <int>("size"); for (int i = 0; i < size; ++i) { try { using (var participantResult = participantList.Call <AndroidJavaObject>("get", i) .Call <AndroidJavaObject>("getResult")) { string id = participantResult.Call <string>("getParticipantId"); idToResult[id] = participantResult; results.Call <AndroidJavaObject>("add", participantResult); } } catch (Exception e) { // if getResult returns null. } } } foreach (string participantId in outcome.ParticipantIds) { MatchOutcome.ParticipantResult result = outcome.GetResultFor(participantId); uint placing = outcome.GetPlacementFor(participantId); if (idToResult.ContainsKey(participantId)) { var existingResult = idToResult[participantId].Get <int>("result"); uint existingPlacing = (uint)idToResult[participantId].Get <int>("placing"); if (result != (MatchOutcome.ParticipantResult)existingResult || placing != existingPlacing) { OurUtils.Logger.e(string.Format("Attempted to override existing results for " + "participant {0}: Placing {1}, Result {2}", participantId, existingPlacing, existingResult)); callback(false); return; } } else { using (var participantResult = new AndroidJavaObject( "com.google.android.gms.games.multiplayer.ParticipantResult", participantId, (int)result, (int)placing)) { results.Call <bool>("add", participantResult); } } } using (var task = mClient.Call <AndroidJavaObject>("finishMatch", match.MatchId, data, results)) { AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>( task, turnBasedMatch => callback(true)); AndroidTaskUtils.AddOnFailureListener(task, e => callback(false)); } } }); }
private void finishMatch(TurnBasedMatch match, int other_score) { MatchOutcome outcome = new MatchOutcome(); var score = PlayerPrefs.GetInt("score"); bool selfWon = false; if (score > other_score) { selfWon = true; } foreach (Participant p in match.Participants) { MatchOutcome.ParticipantResult result; uint placement; if (p.ParticipantId.Equals(match.SelfParticipantId)) { if (selfWon) { result = MatchOutcome.ParticipantResult.Win; placement = 1; } else { result = MatchOutcome.ParticipantResult.Loss; placement = 2; } } else { if (selfWon) { result = MatchOutcome.ParticipantResult.Loss; placement = 2; } else { result = MatchOutcome.ParticipantResult.Win; placement = 1; } } var gm = GameObject.Find("MPController"); GameObject.DontDestroyOnLoad(gm); outcome.SetParticipantResult(p.ParticipantId, result, placement); } string winner; if (selfWon && !(isPlayerTwo)) { winner = "Player One Wins!"; } else { winner = "Player Two Wins!"; } PlayerPrefs.SetString("winner", winner); Debug.Log("In finish, winner ==> " + winner); Byte[] finalData = Encoding.ASCII.GetBytes(winner); PlayGamesPlatform.Instance.TurnBased.Finish(match, finalData, outcome, (bool success) => { if (success) { Debug.Log("Game over!"); StartCoroutine(resetMap()); var myout = outcome.GetResultFor(match.SelfParticipantId); if (myout == MatchOutcome.ParticipantResult.Win) { PlayerPrefs.SetString("winner", "You Won, score==> " + score); } else { PlayerPrefs.SetString("winner", "You Lost, score==> " + score); } Application.LoadLevel("gameover"); } }); }