public GKTurnBasedParticipant(Dictionary <string, object> dict)
    {
        if (dict == null)
        {
            return;
        }

        if (dict.ContainsKey("playerId"))
        {
            playerId = dict["playerId"].ToString();
        }

        if (dict.ContainsKey("status"))
        {
            status = (GKTurnBasedParticipantStatus)int.Parse(dict["status"].ToString());
        }

        if (dict.ContainsKey("matchOutcome"))
        {
            matchOutcome = (GKTurnBasedMatchOutcome)int.Parse(dict["matchOutcome"].ToString());
        }

        // grab and convert the date
        if (dict.ContainsKey("lastTurnDate"))
        {
            var timeSinceEpoch = double.Parse(dict["lastTurnDate"].ToString());
            var intermediate   = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            lastTurnDate = intermediate.AddSeconds(timeSinceEpoch);
        }
    }
 // Resigns the player from the match when that player is not the current player. This action does not end the match.
 public static void participantQuitOutOfTurnWithOutcome(GKTurnBasedMatchOutcome outcome)
 {
     if (Application.platform == RuntimePlatform.IPhonePlayer)
     {
         _gcTurnBasedParticipantQuitOutOfTurnWithOutcome((int)outcome);
     }
 }
 // Sets the match outcome for the given participant
 public static void setMatchOutcomeForParticipant(GKTurnBasedMatchOutcome outcome, string participantPlayerId)
 {
     if (Application.platform == RuntimePlatform.IPhonePlayer)
     {
         _gcTurnBasedSetMatchOutcomeForParticipant((int)outcome, participantPlayerId);
     }
 }
 // Resigns the current player from the match without ending the match
 public static void participantQuitInTurnWithOutcome(GKTurnBasedMatchOutcome outcome, string nextParticipantPlayerId, byte[] data)
 {
     if (Application.platform == RuntimePlatform.IPhonePlayer)
     {
         _gcTurnBasedParticipantQuitInTurnWithOutcome((int)outcome, nextParticipantPlayerId, data, data.Length);
     }
 }
 // iOS 6+ only! Resigns the current player from the match without ending the match
 public static void participantQuitInTurnWithOutcome(GKTurnBasedMatchOutcome outcome, string[] nextParticipantPlayerIds, double timeout, string nextParticipantPlayerId, byte[] data)
 {
     if (Application.platform == RuntimePlatform.IPhonePlayer)
     {
         if (nextParticipantPlayerIds == null)
         {
             nextParticipantPlayerIds = new string[0];
         }
         _gcTurnBasedParticipantQuitInTurnWithOutcomeAndTimeout((int)outcome, string.Join(",", nextParticipantPlayerIds), timeout, data, data.Length);
     }
 }
예제 #6
0
        public static ParticipantResult ToParticipantResult(this GKTurnBasedMatchOutcome matchOutcome, out uint placement)
        {
            switch (matchOutcome.outcome)
            {
            case GKTurnBasedMatchOutcome.Outcome.Custom:
                placement = matchOutcome.customOutcome;
                return(ParticipantResult.CustomPlacement);

            case GKTurnBasedMatchOutcome.Outcome.First:
                placement = 1;
                return(ParticipantResult.CustomPlacement);

            case GKTurnBasedMatchOutcome.Outcome.Second:
                placement = 2;
                return(ParticipantResult.CustomPlacement);

            case GKTurnBasedMatchOutcome.Outcome.Third:
                placement = 3;
                return(ParticipantResult.CustomPlacement);

            case GKTurnBasedMatchOutcome.Outcome.Fourth:
                placement = 4;
                return(ParticipantResult.CustomPlacement);

            case GKTurnBasedMatchOutcome.Outcome.Won:
                placement = MatchOutcome.PlacementUnset;
                return(ParticipantResult.Won);

            case GKTurnBasedMatchOutcome.Outcome.Lost:
                placement = MatchOutcome.PlacementUnset;
                return(ParticipantResult.Lost);

            case GKTurnBasedMatchOutcome.Outcome.Tied:
                placement = MatchOutcome.PlacementUnset;
                return(ParticipantResult.Tied);

            case GKTurnBasedMatchOutcome.Outcome.None:
                placement = MatchOutcome.PlacementUnset;
                return(ParticipantResult.None);

            case GKTurnBasedMatchOutcome.Outcome.Quit:
            case GKTurnBasedMatchOutcome.Outcome.TimeExpired:
            default:
                placement = MatchOutcome.PlacementUnset;
                return(ParticipantResult.CustomPlacement);
            }
        }
예제 #7
0
        /// <summary>
        /// Resigns the current player from the match without ending the match.
        /// Raises QuitMatchCompleted and QuitMatchFailed events for success and error completion.
        /// On iOS 5.0, it only takes one next participant, and ignores the timeout.
        /// </summary>
        /// <param name="matchOutcome">The end outcome of the current player in the match.</param>
        /// <param name="matchData">A serialized blob of data reflecting the game-specific state for the match.</param>
        /// <param name="aMessage">A message to display reflecting the state of the match.</param>
        /// <param name="nextParticipants">An array of TurnBasedParticipant objects reflecting the order in which the players should act next.
        /// Each object in the array must be one of the objects stored in the match’s participants property.
        /// If null or not specified, it would use the next player in the order of the participants property.</param>
        /// <param name="timeout">The length of time the next player has to complete their turn; in seconds.</param>
        public void QuitDuringTurn(GKTurnBasedMatchOutcome matchOutcome, byte[] matchData, string aMessage = null, TurnBasedParticipant[] nextParticipants = null, double timeout = 0)
        {
            if (aMessage != null)
            {
                gkTurnBasedMatch.message = aMessage;
            }

            if (nextParticipants == null)
            {
                nextParticipants = _GetNextActiveParticipants();
            }

            //hack: apple server doesn't work if it takes an array, so popping all except 1 now
            if (nextParticipants.Length > 1)
            {
                nextParticipants = new TurnBasedParticipant[] { nextParticipants[0] }
            }
            ;

            if (gkTurnBasedMatch.RespondsToSelector("participantQuitInTurnWithOutcome:nextParticipants:turnTimeout:matchData:completionHandler:"))
            {
                gkTurnBasedMatch.ParticipantQuitInTurn(
                    matchOutcome,
                    TurnBasedParticipant.ToGKParticipants(nextParticipants),
                    timeout, NSData.FromByteArray(matchData),
                    _CreateCompleteFunction(_quitMatchCompletedHandlers, _quitMatchFailedHandlers));
            }
            else
            {
                gkTurnBasedMatch.ParticipantQuitInTurn(
                    matchOutcome,
                    TurnBasedParticipant.ToGKParticipants(nextParticipants)[0],
                    NSData.FromByteArray(matchData),
                    _CreateCompleteFunction(_quitMatchCompletedHandlers, _quitMatchFailedHandlers));
            }
        }
예제 #8
0
        public static GKTurnBasedMatchOutcome ToGKTurnBasedMatchOutcome(this MatchOutcome matchOutcome, string participantId)
        {
            var gkMatchOutcome = new GKTurnBasedMatchOutcome();
            var result         = matchOutcome.GetParticipantResult(participantId);
            var placement      = matchOutcome.GetParticipantPlacement(participantId);

            switch (result)
            {
            case ParticipantResult.CustomPlacement:
                gkMatchOutcome.outcome       = GKTurnBasedMatchOutcome.Outcome.Custom;
                gkMatchOutcome.customOutcome = placement;
                break;

            case ParticipantResult.Lost:
                gkMatchOutcome.outcome = GKTurnBasedMatchOutcome.Outcome.Lost;
                break;

            case ParticipantResult.None:
                gkMatchOutcome.outcome = GKTurnBasedMatchOutcome.Outcome.None;
                break;

            case ParticipantResult.Tied:
                gkMatchOutcome.outcome = GKTurnBasedMatchOutcome.Outcome.Tied;
                break;

            case ParticipantResult.Won:
                gkMatchOutcome.outcome = GKTurnBasedMatchOutcome.Outcome.Won;
                break;

            default:
                gkMatchOutcome.outcome = GKTurnBasedMatchOutcome.Outcome.None;
                break;
            }

            return(gkMatchOutcome);
        }
예제 #9
0
 /// <summary>
 /// Resigns the player from the match when that player is not the current player. This action does not end the match.
 /// Raises QuitMatchCompleted and QuitMatchFailed events for success and error completion.
 /// </summary>
 /// <param name="matchOutcome">The end outcome of the current player in the match.</param>
 public void QuitOutOfTurn(GKTurnBasedMatchOutcome matchOutcome)
 {
     gkTurnBasedMatch.ParticipantQuitOutOfTurn(
         matchOutcome,
         _CreateCompleteFunction(_quitMatchCompletedHandlers, _quitMatchFailedHandlers));
 }
예제 #10
0
 /// <summary>
 /// Resigns the current player from the match without ending the match.
 /// Raises QuitMatchCompleted and QuitMatchFailed events for success and error completion.
 /// On iOS 5.0, it only takes one next participant, and ignores the timeout.
 /// </summary>
 /// <param name="matchOutcome">The end outcome of the current player in the match.</param>
 /// <param name="matchData">A serialized string of data reflecting the game-specific state for the match.</param>
 /// <param name="aMessage">A message to display reflecting the state of the match.</param>
 /// <param name="nextParticipants">An array of TurnBasedParticipant objects reflecting the order in which the players should act next.
 /// Each object in the array must be one of the objects stored in the match’s participants property.
 /// If null or not specified, it would use the next player in the order of the participants property.</param>
 /// <param name="timeout">The length of time the next player has to complete their turn; in seconds.</param>
 public void QuitDuringTurn(GKTurnBasedMatchOutcome matchOutcome, string matchData, string aMessage = null, TurnBasedParticipant[] nextParticipants = null, double timeout = 0)
 {
     QuitDuringTurn(matchOutcome, matchData.ToStraightBytes(), aMessage, nextParticipants, timeout);
 }
예제 #11
0
 /// <summary>
 /// Resigns the player from the match when that player is not the current player. This action does not end the match.
 /// Raises QuitMatchCompleted and QuitMatchFailed events for success and error completion.
 /// </summary>
 /// <param name="matchOutcome">The end outcome of the current player in the match.</param>
 public void QuitOutOfTurn(GKTurnBasedMatchOutcome matchOutcome)
 {
     gkTurnBasedMatch.ParticipantQuitOutOfTurn(
         matchOutcome,
         _CreateCompleteFunction(_quitMatchCompletedHandlers, _quitMatchFailedHandlers));
 }
예제 #12
0
 /// <summary>
 /// Resigns the current player from the match without ending the match.
 /// Raises QuitMatchCompleted and QuitMatchFailed events for success and error completion.
 /// On iOS 5.0, it only takes one next participant, and ignores the timeout.
 /// </summary>
 /// <param name="matchOutcome">The end outcome of the current player in the match.</param>
 /// <param name="matchData">A serialized string of data reflecting the game-specific state for the match.</param>
 /// <param name="aMessage">A message to display reflecting the state of the match.</param>
 /// <param name="nextParticipants">An array of TurnBasedParticipant objects reflecting the order in which the players should act next.
 /// Each object in the array must be one of the objects stored in the match’s participants property.
 /// If null or not specified, it would use the next player in the order of the participants property.</param>
 /// <param name="timeout">The length of time the next player has to complete their turn; in seconds.</param>
 public void QuitDuringTurn(GKTurnBasedMatchOutcome matchOutcome, string matchData, string aMessage = null, TurnBasedParticipant[] nextParticipants = null, double timeout = 0)
 {
     QuitDuringTurn(matchOutcome, matchData.ToStraightBytes(), aMessage, nextParticipants, timeout);
 }
예제 #13
0
        /// <summary>
        /// Resigns the current player from the match without ending the match.
        /// Raises QuitMatchCompleted and QuitMatchFailed events for success and error completion.
        /// On iOS 5.0, it only takes one next participant, and ignores the timeout.
        /// </summary>
        /// <param name="matchOutcome">The end outcome of the current player in the match.</param>
        /// <param name="matchData">A serialized blob of data reflecting the game-specific state for the match.</param>
        /// <param name="aMessage">A message to display reflecting the state of the match.</param>
        /// <param name="nextParticipants">An array of TurnBasedParticipant objects reflecting the order in which the players should act next.
        /// Each object in the array must be one of the objects stored in the match’s participants property.
        /// If null or not specified, it would use the next player in the order of the participants property.</param>
        /// <param name="timeout">The length of time the next player has to complete their turn; in seconds.</param>
        public void QuitDuringTurn(GKTurnBasedMatchOutcome matchOutcome, byte[] matchData, string aMessage = null, TurnBasedParticipant[] nextParticipants = null, double timeout = 0)
        {
            if (aMessage != null)
                gkTurnBasedMatch.message = aMessage;

            if (nextParticipants == null)
                nextParticipants = _GetNextActiveParticipants();

            //hack: apple server doesn't work if it takes an array, so popping all except 1 now
            if (nextParticipants.Length > 1)
                nextParticipants = new TurnBasedParticipant[] { nextParticipants[0] };

            if (gkTurnBasedMatch.RespondsToSelector("participantQuitInTurnWithOutcome:nextParticipants:turnTimeout:matchData:completionHandler:")) {
                gkTurnBasedMatch.ParticipantQuitInTurn(
                    matchOutcome,
                    TurnBasedParticipant.ToGKParticipants(nextParticipants),
                    timeout, NSData.FromByteArray(matchData),
                    _CreateCompleteFunction(_quitMatchCompletedHandlers, _quitMatchFailedHandlers));
            } else {
                gkTurnBasedMatch.ParticipantQuitInTurn(
                    matchOutcome,
                    TurnBasedParticipant.ToGKParticipants(nextParticipants)[0],
                    NSData.FromByteArray(matchData),
                    _CreateCompleteFunction(_quitMatchCompletedHandlers, _quitMatchFailedHandlers));
            }
        }
예제 #14
0
 internal static extern void GKTurnBasedParticipant_setMatchOutcome(HandleRef self, ref GKTurnBasedMatchOutcome matchOutcome);