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(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());
         });
     });
 }
 private void FindEqualVersionMatchWithParticipant(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, string participantId, Action <bool> onFailure, Action <GooglePlayGames.Native.PInvoke.MultiplayerParticipant, NativeTurnBasedMatch> onFoundParticipantAndMatch)
 {
     this.FindEqualVersionMatch(match, onFailure, (Action <NativeTurnBasedMatch>)(foundMatch =>
     {
         if (participantId == null)
         {
             using (GooglePlayGames.Native.PInvoke.MultiplayerParticipant multiplayerParticipant = GooglePlayGames.Native.PInvoke.MultiplayerParticipant.AutomatchingSentinel())
                 onFoundParticipantAndMatch(multiplayerParticipant, foundMatch);
         }
         else
         {
             using (GooglePlayGames.Native.PInvoke.MultiplayerParticipant multiplayerParticipant = foundMatch.ParticipantWithId(participantId))
             {
                 if (multiplayerParticipant == null)
                 {
                     Logger.e(string.Format("Located match {0} but desired participant with ID {1} could not be found", (object)match.MatchId, (object)participantId));
                     onFailure(false);
                 }
                 else
                 {
                     onFoundParticipantAndMatch(multiplayerParticipant, foundMatch);
                 }
             }
         }
     }));
 }
        private void FindEqualVersionMatchWithParticipant(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, string participantId, Action <bool> onFailure, Action <GooglePlayGames.Native.PInvoke.MultiplayerParticipant, NativeTurnBasedMatch> onFoundParticipantAndMatch)
        {
            FindEqualVersionMatch(match, onFailure, delegate(NativeTurnBasedMatch foundMatch)
            {
                if (participantId == null)
                {
                    using (GooglePlayGames.Native.PInvoke.MultiplayerParticipant arg = GooglePlayGames.Native.PInvoke.MultiplayerParticipant.AutomatchingSentinel())
                    {
                        onFoundParticipantAndMatch(arg, foundMatch);
                        return;

                        IL_0023:;
                    }
                }
                using (GooglePlayGames.Native.PInvoke.MultiplayerParticipant multiplayerParticipant = foundMatch.ParticipantWithId(participantId))
                {
                    if (multiplayerParticipant == null)
                    {
                        Logger.e($"Located match {match.MatchId} but desired participant with ID {participantId} could not be found");
                        onFailure(false);
                    }
                    else
                    {
                        onFoundParticipantAndMatch(multiplayerParticipant, foundMatch);
                    }
                }
            });
        }
Пример #5
0
 public static Participant GetOpponent(TurnBasedMatch match) {
 	foreach (Participant p in match.Participants) {
 		if (!p.ParticipantId.Equals(match.SelfParticipantId)) {
 			return p;
 		}
 	}
 	return null;
 }
    protected void OnMatchStarted(bool success, TurnBasedMatch match) {
        EndStandBy();
        if (!success) {
            mErrorMessage = "There was a problem setting up the match.\nPlease try again.";
            return;
        }

        gameObject.GetComponent<PlayGui>().LaunchMatch(match);
    }
 public void AcknowledgeFinished(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, Action <bool> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback(callback);
     FindEqualVersionMatch(match, callback, delegate(NativeTurnBasedMatch foundMatch)
     {
         mTurnBasedManager.ConfirmPendingCompletion(foundMatch, delegate(TurnBasedManager.TurnBasedMatchResponse response)
         {
             callback(response.RequestSucceeded());
         });
     });
 }
 public void LeaveDuringTurn(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, string pendingParticipantId, Action <bool> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback(callback);
     FindEqualVersionMatchWithParticipant(match, pendingParticipantId, callback, delegate(GooglePlayGames.Native.PInvoke.MultiplayerParticipant pendingParticipant, NativeTurnBasedMatch foundMatch)
     {
         mTurnBasedManager.LeaveDuringMyTurn(foundMatch, pendingParticipant, delegate(CommonErrorStatus.MultiplayerStatus status)
         {
             callback(status > (CommonErrorStatus.MultiplayerStatus) 0);
         });
     });
 }
 public void Cancel(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, Action <bool> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback(callback);
     FindEqualVersionMatch(match, callback, delegate(NativeTurnBasedMatch foundMatch)
     {
         mTurnBasedManager.CancelMatch(foundMatch, delegate(CommonErrorStatus.MultiplayerStatus status)
         {
             callback(status > (CommonErrorStatus.MultiplayerStatus) 0);
         });
     });
 }
 public void Rematch(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, Action <bool, GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback(callback);
     FindEqualVersionMatch(match, delegate
     {
         callback(false, null);
     }, delegate(NativeTurnBasedMatch foundMatch)
     {
         mTurnBasedManager.Rematch(foundMatch, BridgeMatchToUserCallback(delegate(UIStatus status, GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch m)
         {
             callback(status == UIStatus.Valid, m);
         }));
     });
 }
 protected void OnGotMatch(TurnBasedMatch match, bool shouldAutoLaunch) {
     if (shouldAutoLaunch) {
     	// if shouldAutoLaunch is true, we know the user has indicated (via an external UI)
     	// that they wish to play this match right now, so we take the user to the
     	// game screen without further delay:
         OnMatchStarted(true, match);
     } else {
     	// if shouldAutoLaunch is false, this means it's not clear that the user
     	// wants to jump into the game right away (for example, we might have received
     	// this match from a background push notification). So, instead, we will
     	// calmly hold on to the match and show a prompt so they can decide
     	mIncomingMatch = match;
     }
 }
Пример #12
0
    private void Reset() {
        mMatch = null;
        mMatchData = null;
        mFinalMessage = null;
        mMyMark = '\0';
        mEndTurnCountdown = MaxTurnTime;
        mBlockInFlight = false;
        mEndingTurn = false;
        mShowInstructions = false;
        Util.MakeVisible(Playfield, false);
        UpdateLargeMarks();

        foreach (GameObject o in GetAllGameBlocks()) {
            GameObject.Destroy(o);
        }
    }
Пример #13
0
    public void LaunchMatch(TurnBasedMatch match)
    {
        Reset();
        mMatch = match;
        MakeActive();

        if (mMatch == null) {
            throw new System.Exception("PlayGui can't be started without a match!");
        }
        try {
            // Note that mMatch.Data might be null (when we are starting a new match).
            // MatchData.MatchData() correctly deals with that and initializes a
            // brand-new match in that case.
            mMatchData = new MatchData(mMatch.Data);
        } catch (MatchData.UnsupportedMatchFormatException ex) {
            mFinalMessage = "Your game is out of date. Please update your game\n" +
                "in order to play this match.";
            Debug.LogWarning("Failed to parse board data: " + ex.Message);
            return;
        }

        // determine if I'm the 'X' or the 'O' player
        mMyMark = mMatchData.GetMyMark(match.SelfParticipantId);

        bool canPlay = (mMatch.Status == TurnBasedMatch.MatchStatus.Active &&
                mMatch.TurnStatus == TurnBasedMatch.MatchTurnStatus.MyTurn);

        if (canPlay) {
            mShowInstructions = true;
        } else {
            mFinalMessage = ExplainWhyICantPlay();
        }

        // if the match is in the completed state, acknowledge it
        if (mMatch.Status == TurnBasedMatch.MatchStatus.Complete) {
            PlayGamesPlatform.Instance.TurnBased.AcknowledgeFinished(mMatch,
                    (bool success) => {
                if (!success) {
                    Debug.LogError("Error acknowledging match finish.");
                }
            });
        }

        // set up the objects to show the match to the player
        SetupObjects(canPlay);
    }
        private Action <TurnBasedManager.TurnBasedMatchResponse> BridgeMatchToUserCallback(Action <UIStatus, GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch> userCallback)
        {
            return(delegate(TurnBasedManager.TurnBasedMatchResponse callbackResult)
            {
                using (NativeTurnBasedMatch nativeTurnBasedMatch = callbackResult.Match())
                {
                    if (nativeTurnBasedMatch == null)
                    {
                        UIStatus arg = UIStatus.InternalError;
                        switch (callbackResult.ResponseStatus())
                        {
                        case CommonErrorStatus.MultiplayerStatus.VALID:
                            arg = UIStatus.Valid;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.VALID_BUT_STALE:
                            arg = UIStatus.Valid;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.ERROR_INTERNAL:
                            arg = UIStatus.InternalError;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.ERROR_NOT_AUTHORIZED:
                            arg = UIStatus.NotAuthorized;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.ERROR_VERSION_UPDATE_REQUIRED:
                            arg = UIStatus.VersionUpdateRequired;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.ERROR_TIMEOUT:
                            arg = UIStatus.Timeout;
                            break;
                        }
                        userCallback(arg, null);
                    }
                    else
                    {
                        GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch turnBasedMatch = nativeTurnBasedMatch.AsTurnBasedMatch(mNativeClient.GetUserId());
                        Logger.d("Passing converted match to user callback:" + turnBasedMatch);
                        userCallback(UIStatus.Valid, turnBasedMatch);
                    }
                }
            });
        }
 public void TakeTurn(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, byte[] data, string pendingParticipantId, Action <bool> callback)
 {
     Logger.describe(data);
     callback = Callbacks.AsOnGameThreadCallback <bool>(callback);
     this.FindEqualVersionMatchWithParticipant(match, pendingParticipantId, callback, (Action <GooglePlayGames.Native.PInvoke.MultiplayerParticipant, NativeTurnBasedMatch>)((pendingParticipant, foundMatch) => this.mTurnBasedManager.TakeTurn(foundMatch, data, pendingParticipant, (Action <TurnBasedManager.TurnBasedMatchResponse>)(result =>
     {
         if (result.RequestSucceeded())
         {
             callback(true);
         }
         else
         {
             Logger.d("Taking turn failed: " + (object)result.ResponseStatus());
             callback(false);
         }
     }))));
 }
        private Action <TurnBasedManager.TurnBasedMatchResponse> BridgeMatchToUserCallback(Action <GooglePlayGames.BasicApi.UIStatus, GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch> userCallback)
        {
            return((Action <TurnBasedManager.TurnBasedMatchResponse>)(callbackResult =>
            {
                using (NativeTurnBasedMatch nativeTurnBasedMatch = callbackResult.Match())
                {
                    if (nativeTurnBasedMatch == null)
                    {
                        GooglePlayGames.BasicApi.UIStatus uiStatus = GooglePlayGames.BasicApi.UIStatus.InternalError;
                        switch (callbackResult.ResponseStatus() + 5)
                        {
                        case ~(CommonErrorStatus.MultiplayerStatus.ERROR_INTERNAL | CommonErrorStatus.MultiplayerStatus.VALID):
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.Timeout;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.VALID:
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.VersionUpdateRequired;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.VALID_BUT_STALE:
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.NotAuthorized;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.VALID | CommonErrorStatus.MultiplayerStatus.VALID_BUT_STALE:
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.InternalError;
                            break;

                        case ~CommonErrorStatus.MultiplayerStatus.ERROR_MATCH_ALREADY_REMATCHED:
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.Valid;
                            break;

                        case ~CommonErrorStatus.MultiplayerStatus.ERROR_INACTIVE_MATCH:
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.Valid;
                            break;
                        }
                        userCallback(uiStatus, (GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch)null);
                    }
                    else
                    {
                        GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch turnBasedMatch = nativeTurnBasedMatch.AsTurnBasedMatch(this.mNativeClient.GetUserId());
                        Logger.d("Passing converted match to user callback:" + (object)turnBasedMatch);
                        userCallback(GooglePlayGames.BasicApi.UIStatus.Valid, turnBasedMatch);
                    }
                }
            }));
        }
 public void AcceptFromInbox(Action <bool, GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback(callback);
     mTurnBasedManager.ShowInboxUI(delegate(TurnBasedManager.MatchInboxUIResponse callbackResult)
     {
         using (NativeTurnBasedMatch nativeTurnBasedMatch = callbackResult.Match())
         {
             if (nativeTurnBasedMatch == null)
             {
                 callback(false, null);
             }
             else
             {
                 GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch turnBasedMatch = nativeTurnBasedMatch.AsTurnBasedMatch(mNativeClient.GetUserId());
                 Logger.d("Passing converted match to user callback:" + turnBasedMatch);
                 callback(true, turnBasedMatch);
             }
         }
     });
 }
 public void TakeTurn(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, byte[] data, string pendingParticipantId, Action <bool> callback)
 {
     Logger.describe(data);
     callback = Callbacks.AsOnGameThreadCallback(callback);
     FindEqualVersionMatchWithParticipant(match, pendingParticipantId, callback, delegate(GooglePlayGames.Native.PInvoke.MultiplayerParticipant pendingParticipant, NativeTurnBasedMatch foundMatch)
     {
         mTurnBasedManager.TakeTurn(foundMatch, data, pendingParticipant, delegate(TurnBasedManager.TurnBasedMatchResponse result)
         {
             if (result.RequestSucceeded())
             {
                 callback(true);
             }
             else
             {
                 Logger.d("Taking turn failed: " + result.ResponseStatus());
                 callback(false);
             }
         });
     });
 }
 public void GetAllMatches(Action <GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch[]> callback)
 {
     this.mTurnBasedManager.GetAllTurnbasedMatches((Action <TurnBasedManager.TurnBasedMatchesResponse>)(allMatches =>
     {
         GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch[] turnBasedMatchArray = new GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch[allMatches.MyTurnMatchesCount() + allMatches.TheirTurnMatchesCount() + allMatches.CompletedMatchesCount()];
         int num = 0;
         foreach (NativeTurnBasedMatch myTurnMatch in allMatches.MyTurnMatches())
         {
             turnBasedMatchArray[num++] = myTurnMatch.AsTurnBasedMatch(this.mNativeClient.GetUserId());
         }
         foreach (NativeTurnBasedMatch theirTurnMatch in allMatches.TheirTurnMatches())
         {
             turnBasedMatchArray[num++] = theirTurnMatch.AsTurnBasedMatch(this.mNativeClient.GetUserId());
         }
         foreach (NativeTurnBasedMatch completedMatch in allMatches.CompletedMatches())
         {
             turnBasedMatchArray[num++] = completedMatch.AsTurnBasedMatch(this.mNativeClient.GetUserId());
         }
         callback(turnBasedMatchArray);
     }));
 }
 public void GetAllMatches(Action <GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch[]> callback)
 {
     mTurnBasedManager.GetAllTurnbasedMatches(delegate(TurnBasedManager.TurnBasedMatchesResponse allMatches)
     {
         int num = allMatches.MyTurnMatchesCount() + allMatches.TheirTurnMatchesCount() + allMatches.CompletedMatchesCount();
         GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch[] array = new GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch[num];
         int num2 = 0;
         foreach (NativeTurnBasedMatch item in allMatches.MyTurnMatches())
         {
             array[num2++] = item.AsTurnBasedMatch(mNativeClient.GetUserId());
         }
         foreach (NativeTurnBasedMatch item2 in allMatches.TheirTurnMatches())
         {
             array[num2++] = item2.AsTurnBasedMatch(mNativeClient.GetUserId());
         }
         foreach (NativeTurnBasedMatch item3 in allMatches.CompletedMatches())
         {
             array[num2++] = item3.AsTurnBasedMatch(mNativeClient.GetUserId());
         }
         callback(array);
     });
 }
 private void FindEqualVersionMatch(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, Action <bool> onFailure, Action <NativeTurnBasedMatch> onVersionMatch)
 {
     this.mTurnBasedManager.GetMatch(match.MatchId, (Action <TurnBasedManager.TurnBasedMatchResponse>)(response =>
     {
         using (NativeTurnBasedMatch nativeTurnBasedMatch = response.Match())
         {
             if (nativeTurnBasedMatch == null)
             {
                 Logger.e(string.Format("Could not find match {0}", (object)match.MatchId));
                 onFailure(false);
             }
             else if ((int)nativeTurnBasedMatch.Version() != (int)match.Version)
             {
                 Logger.e(string.Format("Attempted to update a stale version of the match. Expected version was {0} but current version is {1}.", (object)match.Version, (object)nativeTurnBasedMatch.Version()));
                 onFailure(false);
             }
             else
             {
                 onVersionMatch(nativeTurnBasedMatch);
             }
         }
     }));
 }
 private void FindEqualVersionMatch(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, Action <bool> onFailure, Action <NativeTurnBasedMatch> onVersionMatch)
 {
     mTurnBasedManager.GetMatch(match.MatchId, delegate(TurnBasedManager.TurnBasedMatchResponse response)
     {
         using (NativeTurnBasedMatch nativeTurnBasedMatch = response.Match())
         {
             if (nativeTurnBasedMatch == null)
             {
                 Logger.e($"Could not find match {match.MatchId}");
                 onFailure(false);
             }
             else if (nativeTurnBasedMatch.Version() != match.Version)
             {
                 Logger.e($"Attempted to update a stale version of the match. Expected version was {match.Version} but current version is {nativeTurnBasedMatch.Version()}.");
                 onFailure(false);
             }
             else
             {
                 onVersionMatch(nativeTurnBasedMatch);
             }
         }
     });
 }
Пример #23
0
    void DoTbmpLeave()
    {
        if (mMatch == null) {
            mStatus = "No match is active.";
            return;
        }
        if (mMatch.TurnStatus == TurnBasedMatch.MatchTurnStatus.MyTurn) {
            mStatus = "It's my turn; use 'Leave During Turn'.";
            return;
        }

        SetStandBy("Leaving match...");
        PlayGamesPlatform.Instance.TurnBased.Leave(mMatch.MatchId, (bool success) => {
            EndStandBy();
            ShowEffect(success);
            mStatus = success ? "Successfully left match." : "Failed to leave match.";
            if (success) {
                mMatch = null;
                mUi = Ui.Tbmp;
            }
        });
    }
 private void OnMatchFromNotification(TurnBasedMatch match, bool fromNotification)
 {
     if (fromNotification)
     {
         mUi = Ui.TbmpMatch;
         mMatch = match;
         mStatus = "Got match from notification! " + match;
     }
     else
     {
         mStatus = "Got match a update not from notification.";
     }
 }
 public void Rematch(TurnBasedMatch match, Action<bool, TurnBasedMatch> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback(callback);
     FindEqualVersionMatch(match, failed => callback(false, null), foundMatch =>
         {
             mTurnBasedManager.Rematch(foundMatch, BridgeMatchToUserCallback(
                 (status, m) => callback(status == UIStatus.Valid, m)));
         });
 }
 private void DoTbmpQuickGame()
 {
     SetStandBy("Creating TBMP quick match...");
     PlayGamesPlatform.Instance.TurnBased.CreateQuickMatch(
         1,
         1,
         0,
         (bool success, TurnBasedMatch match) =>
         {
             ShowEffect(success);
             EndStandBy();
             mMatch = match;
             mStatus = success ? "Match created" : "Match creation failed";
             if (success)
             {
                 mUi = Ui.TbmpMatch;
             }
         });
 }
    private void DoTbmpTakeTurn()
    {
        if (mMatch == null)
        {
            mStatus = "No match is active.";
            return;
        }

        if (mMatch.TurnStatus != TurnBasedMatch.MatchTurnStatus.MyTurn)
        {
            mStatus = "Not my turn.";
            return;
        }

        SetStandBy("Taking turn...");
        PlayGamesPlatform.Instance.TurnBased.TakeTurn(
            mMatch,
            System.Text.ASCIIEncoding.Default.GetBytes(GenString()),
            GetNextToPlay(mMatch),
            (bool success) =>
            {
                EndStandBy();
                ShowEffect(success);
                mStatus = success ? "Successfully took turn." : "Failed to take turn.";
                if (success)
                {
                    mMatch = null;
                    mUi = Ui.Tbmp;
                }
            });
    }
    private void DoTbmpAckFinish()
    {
        if (mMatch == null)
        {
            mStatus = "No match is active.";
            return;
        }

        if (mMatch.Status != TurnBasedMatch.MatchStatus.Complete)
        {
            mStatus = "Match is not complete";
            return;
        }

        SetStandBy("Ack'ing finished match");
        PlayGamesPlatform.Instance.TurnBased.AcknowledgeFinished(
            mMatch,
            (bool success) =>
            {
                EndStandBy();
                ShowEffect(success);
                mStatus = success ? "Successfully ack'ed finish." : "Failed to ack finish.";
                if (success)
                {
                    mMatch = null;
                    mUi = Ui.Tbmp;
                }
            });
    }
    private void DoTbmpFinish()
    {
        if (mMatch == null)
        {
            mStatus = "No match is active.";
            return;
        }

        if (mMatch.TurnStatus != TurnBasedMatch.MatchTurnStatus.MyTurn)
        {
            mStatus = "Not my turn.";
            return;
        }

        // I win; every one else loses
        MatchOutcome outcome = new MatchOutcome();
        foreach (Participant p in mMatch.Participants)
        {
            if (p.ParticipantId.Equals(mMatch.SelfParticipantId))
            {
                outcome.SetParticipantResult(p.ParticipantId, MatchOutcome.ParticipantResult.Win, 1);
            }
            else
            {
                outcome.SetParticipantResult(p.ParticipantId, MatchOutcome.ParticipantResult.Loss, 2);
            }
        }

        SetStandBy("Finishing match...");
        PlayGamesPlatform.Instance.TurnBased.Finish(
            mMatch,
            System.Text.ASCIIEncoding.Default.GetBytes("the end!"),
            outcome,
            (bool success) =>
            {
                EndStandBy();
                ShowEffect(success);
                mStatus = success ? "Successfully finished match." : "Failed to finish match.";
                if (success)
                {
                    mMatch = null;
                    mUi = Ui.Tbmp;
                }
            });
    }
        private void FindEqualVersionMatchWithParticipant(TurnBasedMatch match,
                                                      string participantId, Action<bool> onFailure,
                                                      Action<MultiplayerParticipant, NativeTurnBasedMatch> onFoundParticipantAndMatch)
        {
            FindEqualVersionMatch(match, onFailure, foundMatch =>
                {
                    // If we received a null participantId, we're using an automatching player instead -
                    // issue the callback using that.
                    if (participantId == null)
                    {
                        using (var sentinelParticipant = MultiplayerParticipant.AutomatchingSentinel())
                        {
                            onFoundParticipantAndMatch(sentinelParticipant, foundMatch);
                            return;
                        }
                    }

                    using (var participant = foundMatch.ParticipantWithId(participantId))
                    {
                        if (participant == null)
                        {
                            Logger.e(string.Format("Located match {0} but desired participant with ID " +
                                    "{1} could not be found", match.MatchId, participantId));
                            onFailure(false);
                            return;
                        }

                        onFoundParticipantAndMatch(participant, foundMatch);
                    }
                });
        }
        private void FindEqualVersionMatch(TurnBasedMatch match, Action<bool> onFailure,
                                       Action<NativeTurnBasedMatch> onVersionMatch)
        {
            mTurnBasedManager.GetMatch(match.MatchId, response =>
                {
                    using (var foundMatch = response.Match())
                    {
                        if (foundMatch == null)
                        {
                            Logger.e(string.Format("Could not find match {0}", match.MatchId));
                            onFailure(false);
                            return;
                        }

                        if (foundMatch.Version() != match.Version)
                        {
                            Logger.e(string.Format("Attempted to update a stale version of the " +
                                    "match. Expected version was {0} but current version is {1}.",
                                    match.Version, foundMatch.Version()));
                            onFailure(false);
                            return;
                        }

                        onVersionMatch(foundMatch);
                    }
                });
        }
 public void AcknowledgeFinished(TurnBasedMatch match, Action<bool> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback(callback);
     FindEqualVersionMatch(match, callback, foundMatch =>
         {
             mTurnBasedManager.ConfirmPendingCompletion(
                 foundMatch, response => callback(response.RequestSucceeded()));
         });
 }
        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 Leave(TurnBasedMatch match, Action<bool> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback(callback);
     FindEqualVersionMatch(match, callback, foundMatch =>
         {
             mTurnBasedManager.LeaveMatchDuringTheirTurn(foundMatch, status => callback(status > 0));
         });
 }
 public void LeaveDuringTurn(TurnBasedMatch match, string pendingParticipantId,
                         Action<bool> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback(callback);
     FindEqualVersionMatchWithParticipant(match, pendingParticipantId, callback,
         (pendingParticipant, foundMatch) =>
         {
             mTurnBasedManager.LeaveDuringMyTurn(foundMatch, pendingParticipant,
                 status => callback(status > 0));
         });
 }
 public void Cancel(TurnBasedMatch match, Action<bool> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback(callback);
     FindEqualVersionMatch(match, callback, foundMatch =>
         {
             mTurnBasedManager.CancelMatch(foundMatch, status => callback(status > 0));
         });
 }
 private void DoTbmpAcceptFromInbox()
 {
     SetStandBy("Accepting TBMP from inbox...");
     PlayGamesPlatform.Instance.TurnBased.AcceptFromInbox((bool success, TurnBasedMatch match) =>
         {
             ShowEffect(success);
             EndStandBy();
             mMatch = match;
             mStatus = success ? "Successfully accepted from inbox!" : "Failed to accept from inbox";
             if (success)
             {
                 mUi = Ui.TbmpMatch;
             }
         });
 }
 public void Rematch(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, Action <bool, GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback <bool, GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch>(callback);
     this.FindEqualVersionMatch(match, (Action <bool>)(failed => callback(false, (GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch)null)), (Action <NativeTurnBasedMatch>)(foundMatch => this.mTurnBasedManager.Rematch(foundMatch, this.BridgeMatchToUserCallback((Action <GooglePlayGames.BasicApi.UIStatus, GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch>)((status, m) => callback(status == GooglePlayGames.BasicApi.UIStatus.Valid, m))))));
 }
    private void DoTbmpAcceptIncoming()
    {
        if (mLastInvitationId == null)
        {
            mStatus = "No incoming invitation received from listener.";
            return;
        }

        SetStandBy("Accepting TBMP invitation...");
        PlayGamesPlatform.Instance.TurnBased.AcceptInvitation(
            mLastInvitationId,
            (bool success, TurnBasedMatch match) =>
            {
                ShowEffect(success);
                EndStandBy();
                mMatch = match;
                mStatus = success ? "Successfully accepted invitation!" :
                "Failed to accept invitation";
                if (success)
                {
                    mUi = Ui.TbmpMatch;
                }
            });
    }
 public void Cancel(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, Action <bool> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback <bool>(callback);
     this.FindEqualVersionMatch(match, callback, (Action <NativeTurnBasedMatch>)(foundMatch => this.mTurnBasedManager.CancelMatch(foundMatch, (Action <CommonErrorStatus.MultiplayerStatus>)(status => callback(status > ~(CommonErrorStatus.MultiplayerStatus.ERROR_INTERNAL | CommonErrorStatus.MultiplayerStatus.VALID))))));
 }
    private void DoTbmpCancel()
    {
        if (mMatch == null)
        {
            mStatus = "No match is active.";
            return;
        }

        if (mMatch.Status != TurnBasedMatch.MatchStatus.Active)
        {
            mStatus = "Match is not active.";
            return;
        }

        SetStandBy("Cancelling match...");
        PlayGamesPlatform.Instance.TurnBased.Cancel(
            mMatch,
            (bool success) =>
            {
                EndStandBy();
                ShowEffect(success);
                mStatus = success ? "Successfully cancelled match." : "Failed to cancel match.";
                if (success)
                {
                    mMatch = null;
                    mUi = Ui.Tbmp;
                }
            });
    }
 public void LeaveDuringTurn(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, string pendingParticipantId, Action <bool> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback <bool>(callback);
     this.FindEqualVersionMatchWithParticipant(match, pendingParticipantId, callback, (Action <GooglePlayGames.Native.PInvoke.MultiplayerParticipant, NativeTurnBasedMatch>)((pendingParticipant, foundMatch) => this.mTurnBasedManager.LeaveDuringMyTurn(foundMatch, pendingParticipant, (Action <CommonErrorStatus.MultiplayerStatus>)(status => callback(status > ~(CommonErrorStatus.MultiplayerStatus.ERROR_INTERNAL | CommonErrorStatus.MultiplayerStatus.VALID))))));
 }
    private void DoTbmpLeaveDuringTurn()
    {
        if (mMatch == null)
        {
            mStatus = "No match is active.";
            return;
        }

        if (mMatch.TurnStatus != TurnBasedMatch.MatchTurnStatus.MyTurn)
        {
            mStatus = "It's not my turn.";
            return;
        }

        SetStandBy("Leaving match during turn...");
        PlayGamesPlatform.Instance.TurnBased.LeaveDuringTurn(
            mMatch,
            GetNextToPlay(mMatch),
            (bool success) =>
            {
                EndStandBy();
                ShowEffect(success);
                mStatus = success ? "Successfully left match during turn." :
                "Failed to leave match during turn.";
                if (success)
                {
                    mMatch = null;
                    mUi = Ui.Tbmp;
                }
            });
    }
 public void AcknowledgeFinished(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, Action <bool> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback <bool>(callback);
     this.FindEqualVersionMatch(match, callback, (Action <NativeTurnBasedMatch>)(foundMatch => this.mTurnBasedManager.ConfirmPendingCompletion(foundMatch, (Action <TurnBasedManager.TurnBasedMatchResponse>)(response => callback(response.RequestSucceeded())))));
 }
    private void DoTbmpRematch()
    {
        if (mMatch == null)
        {
            mStatus = "No match is active.";
            return;
        }

        if (!mMatch.CanRematch)
        {
            mStatus = "Match can't be rematched.";
            return;
        }

        SetStandBy("Rematching match...");
        PlayGamesPlatform.Instance.TurnBased.Rematch(
            mMatch,
            (bool success, TurnBasedMatch match) =>
            {
                EndStandBy();
                ShowEffect(success);
                mMatch = match;
                mStatus = success ? "Successfully rematched." : "Failed to rematch.";
                if (success)
                {
                    // if we succeed, it will be our turn, so go to the appropriate UI
                    mUi = Ui.TbmpMatch;
                }
            });
    }
Пример #46
0
        private void OnMatchFromNotification(TurnBasedMatch match, bool fromNotification)
        {
            Debug.Log("In OnMatchFromNotification: fromNotification: " + fromNotification +
                " match: " + match);
            if (fromNotification)
            {
                mUi = Ui.TbmpMatch;
                mMatch = match;
                Status = "Got match from notification! " + match;
                Debug.Log("Got match from notification! " + match);
            }
            else
            {
                Debug.Log("OnMatchFrom Notification = " + match.MatchId + " "
                    + match.Status + " " + match.TurnStatus);
                mMatch = match;
                if (mMatch.Status == TurnBasedMatch.MatchStatus.Complete ||
                    mMatch.Status == TurnBasedMatch.MatchStatus.Cancelled)
                {
                    mUi = Ui.Tbmp;
                }
                else
                    {
                    mUi = Ui.TbmpMatch;
                    }

                Status = "Got match a update not from notification: " + mMatch;
            }
        }
    // figure out who is next to play
    private string GetNextToPlay(TurnBasedMatch match)
    {
        if (mMatch.AvailableAutomatchSlots > 0)
        {
            // next to play is an automatch player
            return null;
        }

        // WARNING: The following code for determining "who is next" MUST NOT BE USED
        // in a production game. It is here for debug purposes only. This code will
        // not take into account the order in which the first round (while there were
        // automatch slots open) was played, and will always produce round-robin next
        // participants based on the participant ID, which might make the second (and
        // subsequent) rounds have a different play order than the first round, which is,
        // for most games, a very bad experience.
        //
        // In your production game, consider storing the play order in the match data
        // to help determine who plays next.

        // what is my index in the list of participants?
        int index = -1;
        List<Participant> participants = mMatch.Participants;

        for (int i = 0; i < participants.Count; i++)
        {
            Participant p = participants[i];
            if (p.ParticipantId.Equals(mMatch.SelfParticipantId))
            {
                index = i;
                break;
            }
        }

        GooglePlayGames.OurUtils.Logger.d("My index = " + index);

        // who is the next participant in the Joined state?
        for (int j = 1; j <= participants.Count; j++)
        {
            Participant p = participants[(index + j) % participants.Count];
            if (p.Status == Participant.ParticipantStatus.Joined ||
                    p.Status == Participant.ParticipantStatus.Invited ||
                    p.Status == Participant.ParticipantStatus.NotInvitedYet)
            {
                GooglePlayGames.OurUtils.Logger.d("Using index = " + ((index + j) % participants.Count));
                return p.ParticipantId;
            }
        }

        Debug.LogError("*** ERROR: Failed to get next participant to play. No one available.");
        return null;
    }
Пример #48
0
 void DoTbmpCreateGame()
 {
     SetStandBy("Creating TBMP match...");
     PlayGamesPlatform.Instance.TurnBased.CreateWithInvitationScreen(1, 7, 0,
             (bool success, TurnBasedMatch match) => {
         ShowEffect(success);
         EndStandBy();
         mMatch = match;
         mStatus = success ? "Match created" : "Match creation failed";
         if (success) {
             mUi = Ui.TbmpMatch;
         }
     });
 }
        private static TurnBasedMatch GetMatchFromJsonString(string matchAsJson) {
            Dictionary<string, object> parsedMatch = Json.Deserialize(matchAsJson) as Dictionary<string, object>;
            
            // Let's create our participant list
            List<Participant> participantList = new List<Participant>();
            
            List<object> parsedParticipants = parsedMatch["participants"] as List<object>;
            foreach (Dictionary<string, object> nextParticipant in parsedParticipants) {
                Dictionary<string, object> playerRepresentation = nextParticipant["player"] as Dictionary<string, object>;
                Player participantAsPlayer = new Player((string)playerRepresentation["playerDisplayName"],
                                                        (string)playerRepresentation["playerId"]);
                Participant participant = new Participant((string)nextParticipant["displayName"],
                                                          (string)nextParticipant["participantId"],
                                                          convertIntFromiOSToParticipantStatus(Convert.ToInt32((System.Int64)nextParticipant["status"])),
                                                          participantAsPlayer,
                                                          (bool)nextParticipant["isConnectedToRoom"]);
                participantList.Add(participant);
                Debug.Log("Adding participant " + participant.ToString());
            }
            
            
            string matchData = (string)parsedMatch["matchData"];
            byte[] bytes;
            if (matchData == null) {
                Debug.Log ("Got a null matchData.");
                bytes = null;
            } else {
                bytes = System.Convert.FromBase64String(matchData);
            }
            
            
            TurnBasedMatch matchCreated = new TurnBasedMatch((string)parsedMatch["matchId"],
                                              bytes,
                                              (bool)parsedMatch["canRematch"],
                                              (string)parsedMatch["localParticipantId"],
                                              participantList,
                                              Convert.ToInt32((System.Int64)parsedMatch["availableAutomatchSlots"]),
                                              (string)parsedMatch["pendingParticipantId"],
                                              convertIntoFromiOSToMatchTurnStatus(Convert.ToInt32((System.Int64)parsedMatch["turnStatus"])),
                                              convertIntoFromiOSToMatchStatus(Convert.ToInt32((System.Int64)parsedMatch["matchStatus"])),
                                              Convert.ToInt32((System.Int64)parsedMatch["variant"]));
            
            Debug.Log("Final parsed match object is " + matchCreated.ToString());
            return matchCreated;

        }
Пример #50
0
    void ShowIncomingMatchUi()
    {
        switch (mIncomingMatch.Status) {
        case TurnBasedMatch.MatchStatus.Cancelled:
          GuiLabel (CenterLabelCfg, Util.GetOpponentName (mIncomingMatch) + " declined your invitation");
          if (GuiButton (OkButtonCfg)) {
            mIncomingMatch = null;
          }
        break;
        case TurnBasedMatch.MatchStatus.Complete:
          GuiLabel (CenterLabelCfg, "Your match with " + Util.GetOpponentName (mIncomingMatch) + " is over...");
          if (GuiButton (OkButtonCfg)) {
            TurnBasedMatch match = mIncomingMatch;
            mIncomingMatch = null;
            OnMatchStarted (true, match);
          }
        break;

        default:
          switch (mIncomingMatch.TurnStatus) {
          case TurnBasedMatch.MatchTurnStatus.MyTurn:
            GuiLabel (CenterLabelCfg, "It's your turn against " + Util.GetOpponentName (mIncomingMatch)
                  + " " + mIncomingMatch.Status + " turn = " + mIncomingMatch.TurnStatus);
            if (GuiButton (PlayButtonCfg)) {
              TurnBasedMatch match = mIncomingMatch;
              mIncomingMatch = null;
              OnMatchStarted (true, match);
            } else if (GuiButton (NotNowButtonCfg)) {
              mIncomingMatch = null;
            }
          break;
          default:
            GuiLabel (CenterLabelCfg, Util.GetOpponentName (mIncomingMatch) + " accepted your invitation");
            if (GuiButton (OkButtonCfg)) {
              mIncomingMatch = null;
            }
          break;
          }
        break;

        } // end match status
    }
Пример #51
0
 public static string GetOpponentName(TurnBasedMatch match) {
 	Participant p = GetOpponent(match);
 	return p == null ? "(anonymous)" : p.DisplayName;
 }
Пример #52
0
 protected override void OnGotMatch(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, bool shouldAutoLaunch)
 {
     //throw new System.NotImplementedException ();
 }