|
@@ -95,10 +95,10 @@ public class RankComp {
|
|
|
});
|
|
});
|
|
|
socketResponse.send(rankList, myRank);
|
|
socketResponse.send(rankList, myRank);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- List<Integer> pkGameTypes = Arrays.asList(new Integer[]{9, 10, 11, 12});
|
|
|
|
|
|
|
+ //pk 游戏
|
|
|
|
|
+ public static List<Integer> pkGameTypes = Arrays.asList(new Integer[]{9, 10, 11, 12});
|
|
|
//PK游戏结果,0:玩家1胜利;1:玩家2胜利;2:双方平局
|
|
//PK游戏结果,0:玩家1胜利;1:玩家2胜利;2:双方平局
|
|
|
- List<Integer> pkGameResults = Arrays.asList(new Integer[]{0, 1, 2});
|
|
|
|
|
|
|
+ public static List<Integer> pkGameResults = Arrays.asList(new Integer[]{0, 1, 2});
|
|
|
@SocketMethod(async = true)
|
|
@SocketMethod(async = true)
|
|
|
public void uploadPKGameRes(String roomKey, int gameType,
|
|
public void uploadPKGameRes(String roomKey, int gameType,
|
|
|
int p1ID, int p2ID, int gameRes
|
|
int p1ID, int p2ID, int gameRes
|
|
@@ -138,8 +138,8 @@ public class RankComp {
|
|
|
RankService.ins.updateGameScore(gameType, p1ID, (int)Ra);
|
|
RankService.ins.updateGameScore(gameType, p1ID, (int)Ra);
|
|
|
RankService.ins.updateGameScore(gameType, p2ID, (int)Rb);
|
|
RankService.ins.updateGameScore(gameType, p2ID, (int)Rb);
|
|
|
}
|
|
}
|
|
|
- //FruitMaster:15,WildAttack:14,DuckHunter:13
|
|
|
|
|
- List<Integer> singleGameTypes = Arrays.asList(new Integer[]{15, 14, 13});
|
|
|
|
|
|
|
+ //单机游戏 FruitMaster:15,WildAttack:14,DuckHunter:13
|
|
|
|
|
+ public static List<Integer> singleGameTypes = Arrays.asList(new Integer[]{15, 14, 13});
|
|
|
|
|
|
|
|
//上传用户单机游戏分数
|
|
//上传用户单机游戏分数
|
|
|
@SocketMethod(async = true)
|
|
@SocketMethod(async = true)
|
|
@@ -201,12 +201,64 @@ public class RankComp {
|
|
|
public void uploadSeasonPKGameRes(String roomKey, int gameType,
|
|
public void uploadSeasonPKGameRes(String roomKey, int gameType,
|
|
|
int p1ID, int p2ID, int gameRes
|
|
int p1ID, int p2ID, int gameRes
|
|
|
) {
|
|
) {
|
|
|
- if (roomKey == null || roomKey.length() != 32) return;
|
|
|
|
|
- if (!pkGameTypes.contains(gameType)) return;
|
|
|
|
|
- if (!pkGameResults.contains(gameRes)) return;
|
|
|
|
|
|
|
+ seasonPKGameRes(roomKey, gameType, p1ID, p2ID, gameRes);
|
|
|
|
|
+ //if (roomKey == null || roomKey.length() != 32) return;
|
|
|
|
|
+ //if (!pkGameTypes.contains(gameType)) return;
|
|
|
|
|
+ //if (!pkGameResults.contains(gameRes)) return;
|
|
|
|
|
+ //boolean res = RankService.ins.insertRoomGameRecord(roomKey, gameType, p1ID, p2ID, gameRes);
|
|
|
|
|
+ //if (!res) return;
|
|
|
|
|
+ //if (!RankService.ins.isRoomNeedCalculatePKScore(roomKey)) return;
|
|
|
|
|
+ //
|
|
|
|
|
+ ////获取时间
|
|
|
|
|
+ //String[] dates = getCurrentDates();
|
|
|
|
|
+ //String startDateStr = dates[0];
|
|
|
|
|
+ //String endDateStr = dates[1];
|
|
|
|
|
+ //
|
|
|
|
|
+ //Map map1 = RankService.ins.getSeasonGameScore(gameType, p1ID, startDateStr, endDateStr);
|
|
|
|
|
+ //Map map2 = RankService.ins.getSeasonGameScore(gameType, p2ID, startDateStr, endDateStr);
|
|
|
|
|
+ //int id1 = (int)map1.get("id");
|
|
|
|
|
+ //int id2 = (int)map2.get("id");
|
|
|
|
|
+ //
|
|
|
|
|
+ //double Ra = (int)map1.get("score"); //RankService.ins.getSeasonGameScore(gameType, p1ID, startDateStr, endDateStr);
|
|
|
|
|
+ //double Rb = (int)map2.get("score");// RankService.ins.getSeasonGameScore(gameType, p2ID, startDateStr, endDateStr);
|
|
|
|
|
+ //
|
|
|
|
|
+ //double Ea = 1 / ( 1 + Math.pow(10, (Rb-Ra)/400d) );
|
|
|
|
|
+ //double Eb = 1 / ( 1 + Math.pow(10, (Ra-Rb)/400d) );
|
|
|
|
|
+ //double Sa;
|
|
|
|
|
+ //double Sb;
|
|
|
|
|
+ //double Ka;
|
|
|
|
|
+ //double Kb;
|
|
|
|
|
+ //if (gameRes == 0) {
|
|
|
|
|
+ // Sa = 1;
|
|
|
|
|
+ // Sb = 0;
|
|
|
|
|
+ // Ka = 32;
|
|
|
|
|
+ // Kb = Rb < 1100 ? 12 : 32;
|
|
|
|
|
+ //} else if (gameRes == 1) {
|
|
|
|
|
+ // Sa = 0;
|
|
|
|
|
+ // Sb = 1;
|
|
|
|
|
+ // Ka = Ra < 1100 ? 12 : 32;
|
|
|
|
|
+ // Kb = 32;
|
|
|
|
|
+ //} else {
|
|
|
|
|
+ // Sa = 0.5;
|
|
|
|
|
+ // Sb = 0.5;
|
|
|
|
|
+ // Ka = 22;
|
|
|
|
|
+ // Kb = 22;
|
|
|
|
|
+ //}
|
|
|
|
|
+ //Ra += Ka * (Sa - Ea);
|
|
|
|
|
+ //Rb += Kb * (Sb - Eb);
|
|
|
|
|
+ //RankService.ins.updateSeasonGameScore(gameType,id1, p1ID, (int)Ra);
|
|
|
|
|
+ //RankService.ins.updateSeasonGameScore(gameType,id2, p2ID, (int)Rb);
|
|
|
|
|
+ }
|
|
|
|
|
+ //处理赛季分数
|
|
|
|
|
+ public String seasonPKGameRes(String roomKey, int gameType,
|
|
|
|
|
+ int p1ID, int p2ID, int gameRes
|
|
|
|
|
+ ) {
|
|
|
|
|
+ if (roomKey == null || roomKey.length() != 32) return "roomKey error!";
|
|
|
|
|
+ if (!pkGameTypes.contains(gameType)) return "gameType error!";
|
|
|
|
|
+ if (!pkGameResults.contains(gameRes)) return "gameRes error!";
|
|
|
boolean res = RankService.ins.insertRoomGameRecord(roomKey, gameType, p1ID, p2ID, gameRes);
|
|
boolean res = RankService.ins.insertRoomGameRecord(roomKey, gameType, p1ID, p2ID, gameRes);
|
|
|
- if (!res) return;
|
|
|
|
|
- if (!RankService.ins.isRoomNeedCalculatePKScore(roomKey)) return;
|
|
|
|
|
|
|
+ if (!res) return "room error!";
|
|
|
|
|
+ if (!RankService.ins.isRoomNeedCalculatePKScore(roomKey)) return "calculate pk score error";
|
|
|
|
|
|
|
|
//获取时间
|
|
//获取时间
|
|
|
String[] dates = getCurrentDates();
|
|
String[] dates = getCurrentDates();
|
|
@@ -247,28 +299,49 @@ public class RankComp {
|
|
|
Rb += Kb * (Sb - Eb);
|
|
Rb += Kb * (Sb - Eb);
|
|
|
RankService.ins.updateSeasonGameScore(gameType,id1, p1ID, (int)Ra);
|
|
RankService.ins.updateSeasonGameScore(gameType,id1, p1ID, (int)Ra);
|
|
|
RankService.ins.updateSeasonGameScore(gameType,id2, p2ID, (int)Rb);
|
|
RankService.ins.updateSeasonGameScore(gameType,id2, p2ID, (int)Rb);
|
|
|
|
|
+
|
|
|
|
|
+ return "上传成功!";
|
|
|
}
|
|
}
|
|
|
//上传用户单机游戏分数
|
|
//上传用户单机游戏分数
|
|
|
@SocketMethod(async = true)
|
|
@SocketMethod(async = true)
|
|
|
public void uploadSeasonSinglePlayerGameRes(
|
|
public void uploadSeasonSinglePlayerGameRes(
|
|
|
Player player, int gameType,int score
|
|
Player player, int gameType,int score
|
|
|
) {
|
|
) {
|
|
|
|
|
+ seasonSinglePlayerGameRes(player.userID,gameType,score);
|
|
|
|
|
+ //if (!singleGameTypes.contains(gameType)) return;
|
|
|
|
|
+ ////只加一个分数
|
|
|
|
|
+ ////获取时间
|
|
|
|
|
+ //String[] dates = getCurrentDates();
|
|
|
|
|
+ //String startDateStr = dates[0];
|
|
|
|
|
+ //String endDateStr = dates[1];
|
|
|
|
|
+ //Map map1 = RankService.ins.getSingleSeasonGameScore(gameType, player.userID, startDateStr, endDateStr);
|
|
|
|
|
+ //int id1 = (int)map1.get("id");
|
|
|
|
|
+ //int Ra = (int)map1.get("score"); //RankService.ins.getGameScore(gameType, player.userID);
|
|
|
|
|
+ ////Ra += score ;
|
|
|
|
|
+ ////记录一个最高分数
|
|
|
|
|
+ //if(score > Ra) Ra = score;
|
|
|
|
|
+ //RankService.ins.updateSeasonGameScore(gameType, id1 , player.userID, Ra);
|
|
|
|
|
+ }
|
|
|
|
|
+ //上传单机分数,目前只处理单机部分
|
|
|
|
|
+ public boolean seasonSinglePlayerGameRes(
|
|
|
|
|
+ int userId, int gameType,int score
|
|
|
|
|
+ ) {
|
|
|
|
|
|
|
|
- if (!singleGameTypes.contains(gameType)) return;
|
|
|
|
|
|
|
+ if (!singleGameTypes.contains(gameType)) return false;
|
|
|
//只加一个分数
|
|
//只加一个分数
|
|
|
//获取时间
|
|
//获取时间
|
|
|
String[] dates = getCurrentDates();
|
|
String[] dates = getCurrentDates();
|
|
|
String startDateStr = dates[0];
|
|
String startDateStr = dates[0];
|
|
|
String endDateStr = dates[1];
|
|
String endDateStr = dates[1];
|
|
|
- Map map1 = RankService.ins.getSingleSeasonGameScore(gameType, player.userID, startDateStr, endDateStr);
|
|
|
|
|
|
|
+ Map map1 = RankService.ins.getSingleSeasonGameScore(gameType, userId, startDateStr, endDateStr);
|
|
|
int id1 = (int)map1.get("id");
|
|
int id1 = (int)map1.get("id");
|
|
|
int Ra = (int)map1.get("score"); //RankService.ins.getGameScore(gameType, player.userID);
|
|
int Ra = (int)map1.get("score"); //RankService.ins.getGameScore(gameType, player.userID);
|
|
|
//Ra += score ;
|
|
//Ra += score ;
|
|
|
//记录一个最高分数
|
|
//记录一个最高分数
|
|
|
if(score > Ra) Ra = score;
|
|
if(score > Ra) Ra = score;
|
|
|
- RankService.ins.updateSeasonGameScore(gameType, id1 , player.userID, Ra);
|
|
|
|
|
|
|
+ RankService.ins.updateSeasonGameScore(gameType, id1 , userId, Ra);
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
List<Integer> allGameTypes = Arrays.asList(new Integer[]{9, 10, 11, 12,13,14,15});
|
|
List<Integer> allGameTypes = Arrays.asList(new Integer[]{9, 10, 11, 12,13,14,15});
|
|
|
//获取赛季排行版
|
|
//获取赛季排行版
|
|
|
@SocketMethod(async = true)
|
|
@SocketMethod(async = true)
|
|
@@ -276,7 +349,67 @@ public class RankComp {
|
|
|
Player player, SocketResponse socketResponse, int rankArea, int rankGameType,
|
|
Player player, SocketResponse socketResponse, int rankArea, int rankGameType,
|
|
|
String countryCode, String stateCode, String cityCode
|
|
String countryCode, String stateCode, String cityCode
|
|
|
) {
|
|
) {
|
|
|
- if (!allGameTypes.contains(rankGameType)) return;
|
|
|
|
|
|
|
+ Object[] results = seasonRankListByGameType(player.userID, rankArea, rankGameType, countryCode, stateCode, cityCode);
|
|
|
|
|
+ //不符合条件的直接return
|
|
|
|
|
+ if (results.length > 0) {
|
|
|
|
|
+ socketResponse.send(results);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ //if (!allGameTypes.contains(rankGameType)) return;
|
|
|
|
|
+ ////获取时间
|
|
|
|
|
+ //String[] dates = getCurrentDates();
|
|
|
|
|
+ //String startDateStr = dates[0];
|
|
|
|
|
+ //String endDateStr = dates[1];
|
|
|
|
|
+ //
|
|
|
|
|
+ //SQL sqlUtil = new SQL();
|
|
|
|
|
+ ////singleGameTypes.contains(rankGameType) ? 0 :
|
|
|
|
|
+ ////int _score = RankService.ins.getDefaultPkScore();
|
|
|
|
|
+ //int _score = singleGameTypes.contains(rankGameType) ? RankService.ins.getDefaultSingleScore() : RankService.ins.getDefaultPkScore();
|
|
|
|
|
+ //String formatScoreSQL = "IFNULL(score," + _score + ") as score";
|
|
|
|
|
+ //String sqlRankList = "SELECT user_info.id, " + formatScoreSQL
|
|
|
|
|
+ // + ", avatarID, avatarUrl, nickname, country FROM user_info LEFT JOIN game_season_"
|
|
|
|
|
+ // + rankGameType + " ON userID = user_info.id";
|
|
|
|
|
+ //
|
|
|
|
|
+ //if (rankArea == 3) { //国排行
|
|
|
|
|
+ // sqlRankList += " WHERE country = " + sqlUtil.PARAM(countryCode);
|
|
|
|
|
+ // sqlRankList += " AND create_time >= '"+startDateStr+"' AND create_time <= '" + endDateStr + "'";
|
|
|
|
|
+ //} else if (rankArea == 1) { //省排行
|
|
|
|
|
+ // sqlRankList += " WHERE country = " + sqlUtil.PARAM(countryCode);
|
|
|
|
|
+ // sqlRankList += " AND state = " + sqlUtil.PARAM(stateCode);
|
|
|
|
|
+ // sqlRankList += " AND create_time >= '"+startDateStr+"' AND create_time <= '" + endDateStr + "'";
|
|
|
|
|
+ //} else if (rankArea == 2) { //市排行
|
|
|
|
|
+ // sqlRankList += " WHERE country = " + sqlUtil.PARAM(countryCode);
|
|
|
|
|
+ // sqlRankList += " AND state = " + sqlUtil.PARAM(stateCode);
|
|
|
|
|
+ // sqlRankList += " AND city = " + sqlUtil.PARAM(cityCode);
|
|
|
|
|
+ // sqlRankList += " AND create_time >= '"+startDateStr+"' AND create_time <= '" + endDateStr + "'";
|
|
|
|
|
+ //} else {
|
|
|
|
|
+ // //否则为全球排行
|
|
|
|
|
+ // sqlRankList += " WHERE create_time >= '"+startDateStr+"' AND create_time <= '" + endDateStr + "'";
|
|
|
|
|
+ //}
|
|
|
|
|
+ //
|
|
|
|
|
+ //sqlRankList += " ORDER BY score DESC, update_time ASC, id ASC";
|
|
|
|
|
+ //List<JSONObject> rankList = GlobalRoot.db.select(sqlRankList + " Limit 20");
|
|
|
|
|
+ //for (int i = 0; i < rankList.size(); i++) {
|
|
|
|
|
+ // rankList.get(i).put("rankNum", i + 1);
|
|
|
|
|
+ //}
|
|
|
|
|
+ //String sqlMyRank = "SELECT id, score, avatarID, avatarUrl, nickname, country, rankNum FROM\n" +
|
|
|
|
|
+ // " (SELECT id, score, avatarID, avatarUrl, nickname, country, @rankNum:=@rankNum+1 AS rankNum\n" +
|
|
|
|
|
+ // " FROM (" + sqlRankList + ") a, (SELECT @rankNum:=0) b) c" +
|
|
|
|
|
+ // " WHERE id = " + sqlUtil.PARAM(player.userID);
|
|
|
|
|
+ //List<JSONObject> myRank = GlobalRoot.db.select(sqlMyRank);
|
|
|
|
|
+ //myRank.forEach((a) -> {
|
|
|
|
|
+ // a.put("userID", a.get("id"));
|
|
|
|
|
+ //});
|
|
|
|
|
+ //String seasonName = "S";
|
|
|
|
|
+ //socketResponse.send(rankList, myRank, seasonName,new String[]{startDateStr,endDateStr});
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Object[] seasonRankListByGameType(
|
|
|
|
|
+ int userId, int rankArea, int rankGameType,
|
|
|
|
|
+ String countryCode, String stateCode, String cityCode
|
|
|
|
|
+ ) {
|
|
|
|
|
+ if (!allGameTypes.contains(rankGameType)) return new Object[]{};
|
|
|
//获取时间
|
|
//获取时间
|
|
|
String[] dates = getCurrentDates();
|
|
String[] dates = getCurrentDates();
|
|
|
String startDateStr = dates[0];
|
|
String startDateStr = dates[0];
|
|
@@ -316,17 +449,18 @@ public class RankComp {
|
|
|
String sqlMyRank = "SELECT id, score, avatarID, avatarUrl, nickname, country, rankNum FROM\n" +
|
|
String sqlMyRank = "SELECT id, score, avatarID, avatarUrl, nickname, country, rankNum FROM\n" +
|
|
|
" (SELECT id, score, avatarID, avatarUrl, nickname, country, @rankNum:=@rankNum+1 AS rankNum\n" +
|
|
" (SELECT id, score, avatarID, avatarUrl, nickname, country, @rankNum:=@rankNum+1 AS rankNum\n" +
|
|
|
" FROM (" + sqlRankList + ") a, (SELECT @rankNum:=0) b) c" +
|
|
" FROM (" + sqlRankList + ") a, (SELECT @rankNum:=0) b) c" +
|
|
|
- " WHERE id = " + sqlUtil.PARAM(player.userID);
|
|
|
|
|
|
|
+ " WHERE id = " + sqlUtil.PARAM(userId);
|
|
|
List<JSONObject> myRank = GlobalRoot.db.select(sqlMyRank);
|
|
List<JSONObject> myRank = GlobalRoot.db.select(sqlMyRank);
|
|
|
myRank.forEach((a) -> {
|
|
myRank.forEach((a) -> {
|
|
|
a.put("userID", a.get("id"));
|
|
a.put("userID", a.get("id"));
|
|
|
});
|
|
});
|
|
|
String seasonName = "S";
|
|
String seasonName = "S";
|
|
|
- socketResponse.send(rankList, myRank, seasonName,new String[]{startDateStr,endDateStr});
|
|
|
|
|
|
|
+ //socketResponse.send(rankList, myRank, seasonName,new String[]{startDateStr,endDateStr});
|
|
|
|
|
+ //返回 Object... args
|
|
|
|
|
+ return new Object[]{ rankList, myRank, seasonName,new String[]{startDateStr,endDateStr}};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
////上传分数测试用,限制特定账号
|
|
////上传分数测试用,限制特定账号
|
|
|
//@SocketMethod(async = true)
|
|
//@SocketMethod(async = true)
|
|
|
//public void uploadSeasonPKGameResTest( int gameType,int p1ID, int p2ID, int gameRes
|
|
//public void uploadSeasonPKGameResTest( int gameType,int p1ID, int p2ID, int gameRes
|