1
This commit is contained in:
@@ -11,6 +11,7 @@ const leaderboardSchema = new Schema({
|
||||
stars: { type: Number, default: 0 },
|
||||
totalWins: { type: Number, default: 0 },
|
||||
position: { type: Number, required: true },
|
||||
lastWinDeck: { type: Object, default: null }, // 添加最后获胜牌组信息
|
||||
lastUpdated: { type: Date, default: Date.now }
|
||||
});
|
||||
|
||||
@@ -28,7 +29,7 @@ exports.generateLeaderboard = async () => {
|
||||
|
||||
// Sort users based on ranking criteria:
|
||||
// 1. Rank level (higher is better)
|
||||
// 2. Rank score (for王者分数 mechanism)
|
||||
// 2. Rank score (for King rank mechanism)
|
||||
// 3. Stars
|
||||
// 4. Total wins
|
||||
const sortedUsers = users.sort((a, b) => {
|
||||
@@ -40,7 +41,7 @@ exports.generateLeaderboard = async () => {
|
||||
return configB.Level - configA.Level;
|
||||
}
|
||||
|
||||
// For players with rank score mechanism
|
||||
// For players with rank score mechanism (King rank)
|
||||
if (configA.RankScore === 1 && configB.RankScore === 1) {
|
||||
if (a.rankScore !== b.rankScore) {
|
||||
return b.rankScore - a.rankScore;
|
||||
@@ -71,6 +72,7 @@ exports.generateLeaderboard = async () => {
|
||||
rankScore: player.rankScore,
|
||||
stars: player.stars,
|
||||
totalWins: player.totalWins,
|
||||
lastWinDeck: player.lastWinDeck, // 包含最后获胜牌组
|
||||
position: i + 1
|
||||
});
|
||||
leaderboardEntries.push(entry);
|
||||
@@ -115,5 +117,6 @@ exports.initializePlayerLadder = (player) => {
|
||||
player.rankScore = 0;
|
||||
player.winStreak = 0;
|
||||
player.totalWins = 0;
|
||||
player.lastWinDeck = null; // 初始化最后获胜牌组
|
||||
return player;
|
||||
};
|
||||
@@ -31,7 +31,7 @@ class LadderService {
|
||||
const config = this.getRankConfig(player.rankId);
|
||||
|
||||
if (config.RankScore === 1) {
|
||||
// 王者分数 mechanism
|
||||
// King rank score mechanism
|
||||
this.updateRankScore(player, opponent, true);
|
||||
} else {
|
||||
// Star-based mechanism
|
||||
@@ -49,7 +49,7 @@ class LadderService {
|
||||
const config = this.getRankConfig(player.rankId);
|
||||
|
||||
if (config.RankScore === 1) {
|
||||
// 王者分数 mechanism
|
||||
// King rank score mechanism
|
||||
this.updateRankScore(player, opponent, false);
|
||||
} else {
|
||||
// Star-based mechanism
|
||||
@@ -64,8 +64,8 @@ class LadderService {
|
||||
updateStars(player, config, isWin) {
|
||||
if (isWin) {
|
||||
let starsToAdd = config.WinGetStar;
|
||||
// Add extra stars for win streak
|
||||
if (player.winStreak >= 3) {
|
||||
// Add extra stars for win streak (3+ wins)
|
||||
if (player.winStreak >= 2) { // Streak starts at 2 (after 2 wins)
|
||||
starsToAdd += config.ExtraGetStar;
|
||||
}
|
||||
player.stars += starsToAdd;
|
||||
@@ -79,7 +79,7 @@ class LadderService {
|
||||
player.stars = Math.max(0, player.stars - 1);
|
||||
|
||||
// Level down check
|
||||
if (player.stars === 0) {
|
||||
if (player.stars === 0 && config.LoseRankDown === 1) {
|
||||
this.levelDown(player, config);
|
||||
}
|
||||
}
|
||||
@@ -87,18 +87,35 @@ class LadderService {
|
||||
}
|
||||
|
||||
updateRankScore(player, opponent, isWin) {
|
||||
const config = this.getRankConfig(player.rankId);
|
||||
|
||||
if (isWin) {
|
||||
let scoreToAdd = 20;
|
||||
// Initialize rank score if not already set
|
||||
if (player.rankScore === 0) {
|
||||
player.rankScore = config.InitialRankScore || 1100;
|
||||
}
|
||||
|
||||
// Calculate score to add based on opponent's rank
|
||||
let scoreToAdd = config.WinScoreMin || 80;
|
||||
|
||||
// If opponent has a higher rank score, calculate bonus
|
||||
if (opponent.rankScore > player.rankScore) {
|
||||
const ratio = Math.min(opponent.rankScore / player.rankScore, 3);
|
||||
scoreToAdd = Math.round(ratio * 20);
|
||||
// Calculate bonus based on rank difference (simplified)
|
||||
const ratio = Math.min((opponent.rankScore - player.rankScore) / 100, 1);
|
||||
scoreToAdd = Math.round(config.WinScoreMin + ratio * (config.WinScoreMax - config.WinScoreMin));
|
||||
}
|
||||
|
||||
player.rankScore += scoreToAdd;
|
||||
} else {
|
||||
// Deduct points on loss
|
||||
const scoreToDeduct = config.LoseScore || 20;
|
||||
if (player.rankScore > 0) {
|
||||
player.rankScore = Math.max(0, player.rankScore - 20);
|
||||
player.rankScore = Math.max(0, player.rankScore - scoreToDeduct);
|
||||
}
|
||||
|
||||
// Check for level down if score is too low
|
||||
if (player.rankScore < 1000 && config.LoseRankDown === 1) {
|
||||
this.levelDown(player, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,6 +125,11 @@ class LadderService {
|
||||
if (nextConfig) {
|
||||
player.rankId++;
|
||||
player.stars = nextConfig.BeginStar;
|
||||
|
||||
// Initialize rank score for King rank
|
||||
if (nextConfig.RankScore === 1) {
|
||||
player.rankScore = nextConfig.InitialRankScore || 1100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +137,14 @@ class LadderService {
|
||||
if (currentConfig.LoseRankDown === 1 && player.rankId > 1) {
|
||||
player.rankId--;
|
||||
const prevConfig = this.getRankConfig(player.rankId);
|
||||
player.stars = prevConfig.RankDownStar;
|
||||
if (prevConfig.RankScore === 1) {
|
||||
// Stay in rank score system
|
||||
player.rankScore = Math.max(prevConfig.InitialRankScore || 1100, player.rankScore - (prevConfig.LoseScore || 20));
|
||||
} else {
|
||||
// Back to star system
|
||||
player.stars = prevConfig.RankDownStar;
|
||||
player.rankScore = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user