예제 #1
0
파일: Match.cs 프로젝트: StudioJD/unity-sdk
        /// <summary>Posts a move to other players.</summary>
        /// <returns>Promise resolved when the operation has completed.</returns>
        /// <param name="moveData">A freeform object indicating the move data to be posted and transfered to other players. This
        ///     move data will be kept in the events, and new players should be able to use it to reproduce the local game
        ///     state.</param>
        /// <param name="updatedGameState">A freeform object replacing the global game state, to be used by players who join from
        ///     now on. Passing a non null value clears the pending events in the match.</param>
        /// <param name="notification">A push notification that can be sent to all players except you.</param>
        public Promise<Done> PostMove(Bundle moveData, Bundle updatedGameState = null, PushNotification notification = null)
        {
            UrlBuilder url = new UrlBuilder("/v1/gamer/matches").Path(MatchId).Path("move").QueryParam("lastEventId", LastEventId);
            Bundle config = Bundle.CreateObject();
            config["move"] = moveData;
            config["globalState"] = updatedGameState;
            if (notification != null) config["osn"] = notification.Data;

            HttpRequest req = Gamer.MakeHttpRequest(url);
            req.BodyJson = config;
            return Common.RunInTask<Done>(req, (response, task) => {
                UpdateWithServerData(response.BodyJson["match"]);
                // Record event
                if (updatedGameState != null) {
                    Moves.Clear();
                    GlobalState = updatedGameState;
                }
                Moves.Add(new MatchMove(Gamer.GamerId, moveData));
                task.PostResult(new Done(true, response.BodyJson));
            });
        }
예제 #2
0
 /// <summary>Call this to attribute a godfather to the currently logged in user.</summary>
 /// <returns>Promise resolved when the operation has completed.</returns>
 /// <param name="code">Is a string as generated by #GenerateCode.</param>
 /// <param name="rewardTx">A transaction Json rewarding the godfather formed as follows:
 ///     { transaction : { "unit" : amount},
 ///     description : "reward transaction",
 ///     domain : "com.clanoftcloud.text.DOMAIN" }
 ///     where description and domain are optional.</param>
 /// <param name="notification">Optional OS notification to be sent to the godfather who generated the code.
 ///     The godfather will reveive an event of type 'godchildren' containing the id of the godchildren
 ///     and the balance/achievements field if rewarded.</param>
 public Promise<Done> UseCode(string code, Bundle rewardTx = null, PushNotification notification = null)
 {
     UrlBuilder url = new UrlBuilder("/v2.6/gamer/godfather").Path(domain);
     HttpRequest req = Gamer.MakeHttpRequest(url);
     Bundle config = Bundle.CreateObject();
     config["godfather"] = code;
     config["osn"] = notification != null ? notification.Data : null;
     config["reward"] = rewardTx;
     req.BodyJson = config;
     return Common.RunInTask<Done>(req, (response, task) => {
         task.PostResult(new Done(response.BodyJson));
     });
 }
예제 #3
0
파일: Match.cs 프로젝트: StudioJD/unity-sdk
 /// <summary>Terminates the match. You need to be the creator of the match to perform this operation.</summary>
 /// <returns>Promise resolved when the operation has completed.</returns>
 /// <param name="deleteToo">If true, deletes the match if it finishes successfully or is already finished.</param>
 /// <param name="notification">A notification that can be sent to all players currently playing the match (except you).</param>
 public Promise<Done> Finish(bool deleteToo = false, PushNotification notification = null)
 {
     UrlBuilder url = new UrlBuilder("/v1/gamer/matches").Path(MatchId).Path("finish");
     url.QueryParam("lastEventId", LastEventId);
     HttpRequest req = Gamer.MakeHttpRequest(url);
     req.BodyJson = Bundle.CreateObject("osn", notification != null ? notification.Data : null);
     return Common.RunInTask<Done>(req, (response, task) => {
         UpdateWithServerData(response.BodyJson["match"]);
         // Affect match
         Status = MatchStatus.Finished;
         // Also delete match
         if (deleteToo) {
             Gamer.Matches.Delete(MatchId).ForwardTo(task);
         }
         else {
             task.PostResult(new Done(true, response.BodyJson));
         }
     });
 }
예제 #4
0
파일: Match.cs 프로젝트: StudioJD/unity-sdk
 /// <summary>Leaves the match.</summary>
 /// <returns>Promise resolved when the operation has completed.</returns>
 /// <param name="notification">A push notification that can be sent to all players except you.</param>
 public Promise<Done> Leave(PushNotification notification = null)
 {
     UrlBuilder url = new UrlBuilder("/v1/gamer/matches").Path(MatchId).Path("leave");
     HttpRequest req = Gamer.MakeHttpRequest(url);
     req.BodyJson = Bundle.CreateObject("osn", notification != null ? notification.Data : null);
     return Common.RunInTask<Done>(req, (response, task) => {
         UpdateWithServerData(response.BodyJson["match"]);
         task.PostResult(new Done(true, response.BodyJson));
     });
 }
예제 #5
0
파일: Match.cs 프로젝트: StudioJD/unity-sdk
 /// <summary>Draws an item from the shoe.</summary>
 /// <returns>Promise resolved when the operation has completed. The attached bundle contains an array of items drawn
 ///     from the shoe. You may do `(int)result.Value[0]` to fetch the first value as integer.</returns>
 /// <param name="count">The number of items to draw from the shoe.</param>
 /// <param name="notification">A notification that can be sent to all players currently playing the match (except you).</param>
 public Promise<DrawnItemsResult> DrawFromShoe(int count = 1, PushNotification notification = null)
 {
     UrlBuilder url = new UrlBuilder("/v1/gamer/matches").Path(MatchId).Path("shoe").Path("draw");
     url.QueryParam("count", count).QueryParam("lastEventId", LastEventId);
     HttpRequest req = Gamer.MakeHttpRequest(url);
     req.BodyJson = Bundle.CreateObject("osn", notification != null ? notification.Data : null);
     return Common.RunInTask<DrawnItemsResult>(req, (response, task) => {
         UpdateWithServerData(response.BodyJson["match"]);
         task.PostResult(new DrawnItemsResult(response.BodyJson));
     });
 }
예제 #6
0
 /// <summary>Allows to change the relation of a friendship inside the application.</summary>
 /// <returns>Promise resolved when the operation has completed.</returns>
 /// <param name="gamerId">ID of the gamer to change the relationship (fetched using ListFriends for instance).</param>
 /// <param name="state">The new state to set.</param>
 /// <param name="notification">Optional OS notification to be sent to indicate the player that the status has changed.</param>
 public Promise<Done> ChangeRelationshipStatus(string gamerId, FriendRelationshipStatus state, PushNotification notification = null)
 {
     UrlBuilder url = new UrlBuilder("/v2.6/gamer/friends").Path(domain).Path(gamerId).QueryParam("status", state.ToString().ToLower());
     HttpRequest req = Gamer.MakeHttpRequest(url);
     req.BodyJson = Bundle.CreateObject("osn", notification != null ? notification.Data : null);
     return Common.RunInTask<Done>(req, (response, task) => {
         task.PostResult(new Done(response.BodyJson));
     });
 }
예제 #7
0
 /// <summary>Easy way to add a friend knowing his gamer ID inside the CotC community.</summary>
 /// <returns>Promise resolved when the operation has completed.</returns>
 /// <param name="gamerId">ID of the gamer to add as a friend (fetched using ListFriends for instance).</param>
 /// <param name="notification">Optional OS notification to be sent to indicate the player that the status has changed.</param>
 public Promise<Done> AddFriend(string gamerId, PushNotification notification = null)
 {
     return ChangeRelationshipStatus(gamerId, FriendRelationshipStatus.Add, notification);
 }
예제 #8
0
        /// <summary>
        /// Use this method to send a message to another user from your game.
        /// 
        /// Messages are sent to a specific user, in a specific domain. You can use domains to send messages
        /// across games (or use private for messages sent to your game only).
        ///
        /// </summary>
        /// <returns>Promise resolved when the operation has completed.</returns>
        /// <param name="gamerId">ID of the recipient gamer.</param>
        /// <param name="eventData">JSON object representing the event to be sent. The recipient will receive it as is
        ///     when subscribed to a #CotcSdk.DomainEventLoop (ReceivedEvent property). If the application is not active,
        ///     the message will be queued and transmitted the next time the domain event loop is started.</param>
        /// <param name="notification">Push notification to send to the recipient player if not currently active.</param>
        public Promise<Done> SendEvent(string gamerId, Bundle eventData, PushNotification notification = null)
        {
            UrlBuilder url = new UrlBuilder("/v1/gamer/event").Path(domain).Path(gamerId);
            HttpRequest req = Gamer.MakeHttpRequest(url);
            Bundle config = Bundle.CreateObject();
            config["type"] = "user";
            config["event"] = eventData;
            config["from"] = Gamer.GamerId;
            config["to"] = gamerId;
            config["name"] = Gamer["profile"]["displayname"];
            if (notification != null) config["osn"] = notification.Data;

            req.BodyJson = config;
            return Common.RunInTask<Done>(req, (response, task) => {
                task.PostResult(new Done(true, response.BodyJson));
            });
        }
예제 #9
0
 /// <summary>
 /// Asks to join the match with a given ID. Do not use this if you are already part of the match.
 /// This call is not scoped by domain (it uses the Match ID directly).
 /// </summary>
 /// <returns>Promise resolved when the operation has completed. In case of success, you get the exact same
 ///     match object that would be returned by a call to Create or Fetch. It can be used to interact with
 ///     the match as the user who just joined.</returns>
 /// <param name="matchId">The ID of an existing match to join. It can be fetched from the Match object (MatchId).</param>
 /// <param name="notification">Optional push notification to be sent to inactive players (see class definition).</param>
 public Promise<Match> Join(string matchId, PushNotification notification = null)
 {
     UrlBuilder url = new UrlBuilder("/v1/gamer/matches").Path(matchId).Path("join");
     HttpRequest req = Gamer.MakeHttpRequest(url);
     req.BodyJson = Bundle.CreateObject("osn", notification != null ? notification.Data : null);
     return Common.RunInTask<Match>(req, (response, task) => {
         task.PostResult(new Match(Gamer, response.BodyJson["match"]));
     });
 }