/* * public void GetWinRankWeekly(int totalWinNo, bool enemyFlg) { * NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject>("pvpWeekly"); * query.WhereGreaterThan("totalWinNo", totalWinNo); * query.CountAsync((int count, NCMBException e) => { * if (e != null) { * //件数取得失敗 * }else { * //件数取得成功 * if (!enemyFlg) { * winRankWeekly = count + 1;// 自分よりスコアが上の人がn人いたら自分はn+1位 * }else { * pvpWinRankList.Add(count + 1); * } * } * }); * } */ public void GetPtRankWeekly(int totalPt, bool enemyFlg, int todayNCMB) { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("pvpTmp"); query.WhereGreaterThan("totalPt", totalPt); //date query.WhereGreaterThanOrEqualTo("endDate", todayNCMB); query.CountAsync((int count, NCMBException e) => { if (e != null) { //件数取得失敗 } else { //件数取得成功 if (!enemyFlg) { ptRankWeekly = count + 1;// 自分よりスコアが上の人がn人いたら自分はn+1位 } else { pvpPtRankList.Add(count + 1); } } }); }
public void UpdatePvPWeekly(string userId, string userName, int todayNCMB, int kuniLv, int soudaisyo, int jinkeiHeiryoku) { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("pvpTmp"); query.WhereEqualTo("userId", userId); query.WhereGreaterThanOrEqualTo("endDate", todayNCMB); query.OrderByDescending("endDate"); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { if (objList.Count != 0) { objList[0]["userName"] = userName; objList[0]["kuniLv"] = kuniLv; if (soudaisyo != 0) { objList[0]["soudaisyo"] = soudaisyo; } objList[0]["jinkeiHeiryoku"] = jinkeiHeiryoku; objList[0].SaveAsync(); } } }); }
/* Weekly Pt Start*/ public void GetTop10Pt(int todayNCMB) { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("pvpTmp"); query.WhereGreaterThanOrEqualTo("endDate", todayNCMB); query.OrderByDescending("totalPt"); query.AddDescendingOrder("totalWinNo"); query.Limit = 10; query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null) { } else { foreach (NCMBObject obj in objList) { //PvP Detail string userId = System.Convert.ToString(obj["userId"]); Top10PtWeeklyWinList.Add(System.Convert.ToInt32(obj["totalWinNo"])); int atkNo = System.Convert.ToInt32(obj["atkNo"]); int dfcNo = System.Convert.ToInt32(obj["dfcNo"]); Top10PtWeeklyBattleList.Add(atkNo + dfcNo); Top10PtWeeklyQtyList.Add(System.Convert.ToInt32(obj["totalPt"])); Top10PtWeeklyUserIdList.Add(userId); Top10PtWeeklyNameList.Add(System.Convert.ToString(obj["userName"])); Top10PtWeeklyRankList.Add(System.Convert.ToInt32(obj["kuniLv"])); Top10PtWeeklyBusyoList.Add(System.Convert.ToInt32(obj["soudaisyo"])); Top10PtWeeklyHeiList.Add(System.Convert.ToInt32(obj["jinkeiHeiryoku"])); } } }); }
//指定したレコードのランクを取得 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; }); }
public void GetMyPvPWeekly(int startDateNCMB, int endDateNCMB, int todayNCMB) { //Common Info. string myUserName = PlayerPrefs.GetString("PvPName"); int pvpHeiryoku = PlayerPrefs.GetInt("pvpHeiryoku"); if (pvpHeiryoku == 0) { pvpHeiryoku = PlayerPrefs.GetInt("jinkeiHeiryoku"); } int kuniLv = PlayerPrefs.GetInt("kuniLv"); int jinkei = PlayerPrefs.GetInt("jinkei"); string soudaisyoTmp = "soudaisyo" + jinkei.ToString(); int soudaisyo = PlayerPrefs.GetInt(soudaisyoTmp); NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("pvpTmp"); userId = PlayerPrefs.GetString("userId"); query.WhereEqualTo("userId", userId); //date query.WhereGreaterThanOrEqualTo("endDate", todayNCMB); query.OrderByDescending("endDate"); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { if (objList.Count == 0) { //never registered InsertPvPWeekly(userId, startDateNCMB, endDateNCMB, myUserName, kuniLv, soudaisyo, pvpHeiryoku); atkNoWeekly = 0; atkWinNoWeekly = 0; dfcNoWeekly = 0; dfcWinNoWeekly = 0; totalPtWeekly = 1000; } else { //registered //Update info. UpdatePvPWeekly(userId, myUserName, todayNCMB, kuniLv, soudaisyo, pvpHeiryoku); //Get info. foreach (NCMBObject obj in objList) { atkNoWeekly = System.Convert.ToInt32(obj["atkNo"]); atkWinNoWeekly = System.Convert.ToInt32(obj["atkWinNo"]); dfcNoWeekly = System.Convert.ToInt32(obj["dfcNo"]); dfcWinNoWeekly = System.Convert.ToInt32(obj["dfcWinNo"]); totalPtWeekly = System.Convert.ToInt32(obj["totalPt"]); } } } }); }
//PvP Dfcして勝利した回数の更新 > Total & Weekly public void UpdatePvPDfcWinNo(string userId, int todayNCMB) { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("pvp"); query.WhereEqualTo("userId", userId); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { if (objList.Count != 0) { int dfcWinNo = System.Convert.ToInt32(objList[0]["dfcWinNo"]); dfcWinNo = dfcWinNo + 1; objList[0]["dfcWinNo"] = dfcWinNo; int totalWinNo = System.Convert.ToInt32(objList[0]["totalWinNo"]); totalWinNo = totalWinNo + 1; objList[0]["totalWinNo"] = totalWinNo; objList[0].SaveAsync(); } } }); NCMBQuery <NCMBObject> queryWeekly = new NCMBQuery <NCMBObject>("pvpTmp"); queryWeekly.WhereEqualTo("userId", userId); queryWeekly.WhereGreaterThanOrEqualTo("endDate", todayNCMB); queryWeekly.OrderByDescending("endDate"); queryWeekly.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { if (objList.Count != 0) { int dfcWinNo = System.Convert.ToInt32(objList[0]["dfcWinNo"]); dfcWinNo = dfcWinNo + 1; objList[0]["dfcWinNo"] = dfcWinNo; int totalWinNo = System.Convert.ToInt32(objList[0]["totalWinNo"]); totalWinNo = totalWinNo + 1; objList[0]["totalWinNo"] = totalWinNo; objList[0].SaveAsync(); } } }); }
//Playerの前3位のユーザデータ取得 /* * public void GetNeighborsPt(int currentRank, int todayNCMB) { * * int numSkip = currentRank - 4; * if (numSkip < 0) numSkip = 0; * * NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject>("pvpTmp"); * query.WhereGreaterThanOrEqualTo("endDate", todayNCMB); * * query.OrderByDescending("totalPt"); * query.Skip = numSkip; * query.Limit = 5; * query.FindAsync((List<NCMBObject> objList, NCMBException e) => { * if (e != null) { * //検索失敗時の処理 * }else { * foreach (NCMBObject obj in objList) { * string userId = System.Convert.ToString(obj["userId"]); * * //PvP * NCMBQuery<NCMBObject> queryPvP = new NCMBQuery<NCMBObject>("pvp"); * queryPvP.WhereEqualTo("userId", userId); * * queryPvP.FindAsync((List<NCMBObject> objListPvP, NCMBException ePvP) => { * if (ePvP == null) { * if (objListPvP.Count != 0) { * NeighborsPtWeeklyNameList.Add(System.Convert.ToString(objListPvP[0]["userName"])); * NeighborsPtWeeklyRankList.Add(System.Convert.ToInt32(objListPvP[0]["kuniLv"])); * NeighborsPtWeeklyBusyoList.Add(System.Convert.ToInt32(objListPvP[0]["soudaisyo"])); * NeighborsPtWeeklyQtyList.Add(System.Convert.ToInt32(obj["totalPt"])); * } * } * }); * } * } * }); * } */ /* Weekly Pt End*/ //Point Up public void UpdatePvPPt(string userId, bool plusFlg, int getPt) //true + : false - { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("pvpTmp"); query.WhereEqualTo("userId", userId); query.WhereGreaterThanOrEqualTo("endDate", todayNCMB); query.OrderByDescending("endDate"); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { if (objList.Count != 0) { int totalPt = System.Convert.ToInt32(objList[0]["totalPt"]); if (plusFlg) { totalPt = totalPt + getPt; objList[0]["totalPt"] = totalPt; objList[0].SaveAsync(); donePlusUpdatePtFlg = true; } else { totalPt = totalPt - getPt; if (totalPt < 0) { totalPt = 0; } objList[0]["totalPt"] = totalPt; objList[0].SaveAsync(); doneMinusUpdatePtFlg = true; } } else { if (plusFlg) { donePlusUpdatePtFlg = true; } else { doneMinusUpdatePtFlg = true; } } } }); }
/* Total End */ /* Weekly Start */ public void GetPvPCountWeekly(int todayNCMB) { //PvPCount NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("pvpTmp"); //date query.WhereGreaterThanOrEqualTo("endDate", todayNCMB); query.CountAsync((int count, NCMBException e) => { if (e != null) { //件数取得失敗 Debug.Log("pvpTmp:" + count); } else { //件数取得成功 pvpCountWeekly = count; } }); }
/* 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; * } * }); * * } * } * }); * } * } * }); */ }