增加天梯排行榜
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const UserTool = require('../users/users.tool');
|
||||
const config = require('../config.js');
|
||||
|
||||
const ladderService = require('../ladder/ladder.service');
|
||||
const ladderModel = require('../ladder/ladder.model');
|
||||
|
||||
var MatchTool = {};
|
||||
|
||||
@@ -26,6 +27,10 @@ MatchTool.GetPlayerData = (player) =>
|
||||
var data = {};
|
||||
data.username = player.username;
|
||||
data.elo = player.elo;
|
||||
// Add ladder info to player data
|
||||
data.rankId = player.rankId;
|
||||
data.stars = player.stars;
|
||||
data.rankScore = player.rankScore;
|
||||
data.reward = {};
|
||||
return data;
|
||||
}
|
||||
@@ -52,17 +57,37 @@ MatchTool.GainMatchReward = async(player, opponent, winner_username) => {
|
||||
else if (lost)
|
||||
player.defeats += 1;
|
||||
|
||||
// Handle ladder system
|
||||
if (won) {
|
||||
await ladderService.handleWin(player, opponent);
|
||||
} else if (lost) {
|
||||
await ladderService.handleLoss(player, opponent);
|
||||
}
|
||||
|
||||
// Save last win deck for leaderboard
|
||||
if (won && player.decks && player.decks.length > 0) {
|
||||
// For simplicity, we'll use the first deck as the last win deck
|
||||
// In a real implementation, this would be the actual deck used in the match
|
||||
player.lastWinDeck = player.decks[0];
|
||||
}
|
||||
|
||||
//Calculate elo
|
||||
var match_count = player.matches || 0;
|
||||
var match_progress = Math.min(Math.max(match_count / config.elo_ini_match, 0.0), 1.0);
|
||||
var new_elo = MatchTool.calculateELO(player_elo, opponent_elo, match_progress, won, lost);
|
||||
player.elo = new_elo;
|
||||
player.save();
|
||||
|
||||
// Save player changes
|
||||
await player.save();
|
||||
|
||||
var reward = {
|
||||
elo: player.elo,
|
||||
xp: xp,
|
||||
coins: coins
|
||||
coins: coins,
|
||||
// Add ladder info to reward
|
||||
rankId: player.rankId,
|
||||
stars: player.stars,
|
||||
rankScore: player.rankScore
|
||||
};
|
||||
|
||||
return reward;
|
||||
|
||||
Reference in New Issue
Block a user