コード例 #1
0
    //指定したレコードのランクを取得
    public void fetchRank(string name, int gameModeId, Save_ranking_item save_Ranking_Item, CallbackInt callback)
    {
        currentRank = 0;
        RankingRecord myRecord = null;
        // データスコアの「HighScore」から検索
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>(rankingClassName);

        query.WhereEqualTo("name", name);
        query.WhereEqualTo("gameModeId", gameModeId);
        query.WhereEqualTo("type", (int)save_Ranking_Item);
        query.FindAsync((List <NCMBObject> objList, NCMBException e) =>
        {
            if (e == null && objList.Count > 0)
            {                                                                      //検索成功したら
                string _name    = System.Convert.ToString(objList[0]["name"]);     // 名前を取得
                float _distance = System.Convert.ToSingle(objList[0]["distance"]); // スコアを取得
                float _timeSpan = System.Convert.ToSingle(objList[0]["timeSpan"]);
                myRecord        = new RankingRecord(0, _name, _distance, _timeSpan, save_Ranking_Item);

                var query2 = new NCMBQuery <NCMBObject>(rankingClassName);
                query2.WhereEqualTo("gameModeId", gameModeId);
                query2.WhereEqualTo("type", (int)save_Ranking_Item);
                switch (save_Ranking_Item)
                {
                case Save_ranking_item.SAVE_RANKING_HIGH:
                    query2.WhereGreaterThanOrEqualTo("distance", myRecord.distance);
                    break;

                case Save_ranking_item.SAVE_RANKING_LOW:
                    query2.WhereLessThanOrEqualTo("distance", myRecord.distance);
                    break;

                default:
                    break;
                }

                query2.CountAsync((int count, NCMBException e2) =>
                {
                    if (e2 != null)
                    {
                        //件数取得失敗
                        callback(currentRank);
                    }
                    else
                    {
                        //件数取得成功
                        currentRank = count + 1; // 自分よりスコアが上の人がn人いたら自分はn+1位
                    }
                    callback(currentRank);
                });
            }
            else
            {
                callback(currentRank);
            }

            return;
        });
    }
コード例 #2
0
    /* Weekly End */



    /* Matching Start */
    public void GetRandomEnemy(string myUserId, int HpBase, int startDateNCMB, int endDateNCMB, int todayNCMB, int myTotalPt)
    {
        //Test
        //myTotalPt = 1000000;

        NCMBQuery <NCMBObject> queryPvPTmp = new NCMBQuery <NCMBObject>("pvpTmp");

        queryPvPTmp.WhereNotEqualTo("userId", myUserId);
        queryPvPTmp.WhereGreaterThanOrEqualTo("endDate", todayNCMB);
        queryPvPTmp.WhereLessThanOrEqualTo("totalPt", myTotalPt * 2);
        queryPvPTmp.WhereGreaterThanOrEqualTo("totalPt", myTotalPt);
        //queryPvPTmp.WhereLessThanOrEqualTo("jinkeiHeiryoku", HpBase * 2);
        //queryPvPTmp.WhereGreaterThanOrEqualTo("jinkeiHeiryoku", HpBase / 2);

        queryPvPTmp.CountAsync((int count, NCMBException eCount) => {
            if (eCount == null)
            {
                matchCount  = count;
                int rdmSkip = UnityEngine.Random.Range(0, matchCount) - 3;
                if (rdmSkip < 0)
                {
                    rdmSkip = 0;
                }

                /*From PvP*/

                if (matchCount == 0)
                {
                    NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("pvp");
                    query.WhereNotEqualTo("userId", myUserId);
                    query.WhereLessThanOrEqualTo("jinkeiHeiryoku", Mathf.CeilToInt((float)HpBase * 1.5f));
                    query.WhereGreaterThanOrEqualTo("jinkeiHeiryoku", Mathf.CeilToInt((float)HpBase / 1.5f));
                    query.WhereNotEqualTo("atkNo", 0);

                    query.CountAsync((int pvpCount, NCMBException PvPexpection) => {
                        if (PvPexpection == null)
                        {
                            matchCount = pvpCount;

                            if (matchCount == 0)
                            {
                                matchedFlg = true;
                            }
                            else
                            {
                                //Random Id
                                query.Skip  = rdmSkip;
                                query.Limit = 3;

                                query.FindAsync((List <NCMBObject> objList, NCMBException e) => {
                                    if (e != null)
                                    {
                                        Debug.Log("Ther is no user : exception");
                                    }
                                    else
                                    {
                                        int jinkeiJudgeCount = 0;
                                        for (int i = 0; i < objList.Count; i++)
                                        {
                                            int index     = i;
                                            string userId = System.Convert.ToString(objList[index]["userId"]);

                                            // userIdに対応するpvpjinkeiが存在するか
                                            NCMBQuery <NCMBObject> jinkeiQuery = new NCMBQuery <NCMBObject>("pvpJinkei");
                                            jinkeiQuery.WhereEqualTo("userId", userId);
                                            jinkeiQuery.CountAsync((int jinkeiCount, NCMBException exception) => {
                                                if (exception == null)
                                                {
                                                    // pvpjinkeiが存在するもののみ追加
                                                    if (jinkeiCount > 0)
                                                    {
                                                        string userName = System.Convert.ToString(objList[index]["userName"]);
                                                        int soudaisyo   = System.Convert.ToInt32(objList[index]["soudaisyo"]);
                                                        int kuniLv      = System.Convert.ToInt32(objList[index]["kuniLv"]);
                                                        int hp          = System.Convert.ToInt32(objList[index]["jinkeiHeiryoku"]);

                                                        if (soudaisyo != 0)
                                                        {
                                                            pvpUserIdList.Add(userId);
                                                            pvpUserNameList.Add(userName);
                                                            pvpSoudaisyoList.Add(soudaisyo);
                                                            pvpKuniLvList.Add(kuniLv);
                                                            pvpHpList.Add(hp);

                                                            //Enemy Pt & Rank
                                                            //InsertPvPWeekly(userId, startDateNCMB, endDateNCMB, userName, kuniLv, soudaisyo, hp);
                                                            pvpPtList.Add(1000);
                                                        }
                                                    }
                                                }

                                                jinkeiJudgeCount++;
                                                if (jinkeiJudgeCount == objList.Count)
                                                {
                                                    matchedFlg = true;
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });

                    /*From PvP Tmp(Weekly)*/
                }
                else
                {
                    queryPvPTmp.Skip  = rdmSkip;
                    queryPvPTmp.Limit = 3;
                    queryPvPTmp.FindAsync((List <NCMBObject> objList, NCMBException e) => {
                        if (e != null)
                        {
                            Debug.Log("Ther is no user : exception");
                        }
                        else
                        {
                            int jinkeiJudgeCount = 0;
                            for (int i = 0; i < objList.Count; i++)
                            {
                                int index     = i;
                                string userId = System.Convert.ToString(objList[index]["userId"]);

                                // userIdに対応するpvpjinkeiが存在するか
                                NCMBQuery <NCMBObject> jinkeiQuery = new NCMBQuery <NCMBObject>("pvpJinkei");
                                jinkeiQuery.WhereEqualTo("userId", userId);
                                jinkeiQuery.CountAsync((int jinkeiCount, NCMBException exception) => {
                                    if (exception == null)
                                    {
                                        // pvpjinkeiが存在するもののみ追加
                                        if (jinkeiCount > 0)
                                        {
                                            string userName = System.Convert.ToString(objList[index]["userName"]);
                                            int soudaisyo   = System.Convert.ToInt32(objList[index]["soudaisyo"]);
                                            int kuniLv      = System.Convert.ToInt32(objList[index]["kuniLv"]);
                                            int hp          = System.Convert.ToInt32(objList[index]["jinkeiHeiryoku"]);
                                            int pt          = System.Convert.ToInt32(objList[index]["totalPt"]);

                                            if (soudaisyo != 0)
                                            {
                                                pvpUserIdList.Add(userId);
                                                pvpUserNameList.Add(userName);
                                                pvpSoudaisyoList.Add(soudaisyo);
                                                pvpKuniLvList.Add(kuniLv);
                                                pvpHpList.Add(hp);
                                                pvpPtList.Add(pt);
                                            }
                                        }
                                    }

                                    jinkeiJudgeCount++;
                                    if (jinkeiJudgeCount == objList.Count)
                                    {
                                        matchedFlg = true;
                                    }
                                });
                            }
                        }
                    });
                }
            }
        });



        /*
         * NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject>("pvp");
         * query.WhereNotEqualTo("userId", myUserId);
         * query.WhereLessThanOrEqualTo("jinkeiHeiryoku", Mathf.CeilToInt((float)HpBase * 1.5f));
         * query.WhereGreaterThanOrEqualTo("jinkeiHeiryoku", Mathf.CeilToInt((float)HpBase/1.5f));
         * query.WhereNotEqualTo("atkNo",0);
         *
         * int rdmSkip = 0;
         * query.CountAsync((int count, NCMBException eCount) => {
         *  if (eCount == null) {
         *      matchCount = count;
         *      rdmSkip = UnityEngine.Random.Range(0, matchCount) - 3;
         *      if (rdmSkip < 0) rdmSkip = 0;
         *
         *      if (matchCount == 0) {
         *          matchedFlg = true;
         *      }else {
         *          //Random Id
         *          query.Skip = rdmSkip;
         *          query.Limit = 3;
         *
         *          query.FindAsync((List<NCMBObject> objList, NCMBException e) => {
         *              if (e != null) {
         *                  Debug.Log("Ther is no user : exception");
         *              }
         *              else {
         *                  int jinkeiJudgeCount = 0;
         *                  for (int i = 0; i < objList.Count; i++) {
         *
         *                      if (pvpUserIdList.Count == 3) {
         *                          matchedFlg = true;
         *                          break;
         *                      }
         *
         *                      int index = UnityEngine.Random.Range(0, objList.Count);
         *                      string userId = System.Convert.ToString(objList[index]["userId"]);
         *
         *                      // userIdに対応するpvpjinkeiが存在するか
         *                      NCMBQuery<NCMBObject> jinkeiQuery = new NCMBQuery<NCMBObject>("pvpJinkei");
         *                      jinkeiQuery.WhereEqualTo("userId", userId);
         *                      jinkeiQuery.CountAsync((int jinkeiCount, NCMBException exception) => {
         *                          if (exception == null) {
         *                              // pvpjinkeiが存在するもののみ追加
         *                              if (jinkeiCount > 0) {
         *                                  string userName = System.Convert.ToString(objList[index]["userName"]);
         *                                  int soudaisyo = System.Convert.ToInt32(objList[index]["soudaisyo"]);
         *                                  int kuniLv = System.Convert.ToInt32(objList[index]["kuniLv"]);
         *                                  int hp = System.Convert.ToInt32(objList[index]["jinkeiHeiryoku"]);
         *
         *                                  pvpUserIdList.Add(userId);
         *                                  pvpUserNameList.Add(userName);
         *                                  pvpSoudaisyoList.Add(soudaisyo);
         *                                  pvpKuniLvList.Add(kuniLv);
         *                                  pvpHpList.Add(hp);
         *
         *                                  //Enemy Pt & Rank
         *                                  NCMBQuery<NCMBObject> queryPvPTmp = new NCMBQuery<NCMBObject>("pvpTmp");
         *                                  queryPvPTmp.WhereEqualTo("userId", userId);
         *                                  queryPvPTmp.WhereGreaterThanOrEqualTo("endDate", todayNCMB);
         *                                  queryPvPTmp.FindAsync((List<NCMBObject> objPvPList, NCMBException ePvP) => {
         *                                      if (ePvP == null) {
         *                                          if (objPvPList.Count == 0) { //never registered
         *                                              InsertPvPWeekly(userId, startDateNCMB, endDateNCMB, userName, kuniLv, soudaisyo, hp);
         *                                              pvpPtList.Add(1000);
         *                                          }
         *                                          else { //Get Data
         *                                              foreach (NCMBObject objPvP in objPvPList) {
         *                                                  int pt = System.Convert.ToInt32(objPvP["totalPt"]);
         *                                                  pvpPtList.Add(pt);
         *                                              }
         *                                          }
         *                                      }
         *                                  });
         *                              }
         *                          }
         *
         *                          jinkeiJudgeCount++;
         *                          if (jinkeiJudgeCount == 3) {
         *                              matchedFlg = true;
         *                          }
         *                      });
         *
         *                  }
         *              }
         *          });
         *      }
         *  }
         * });
         */
    }