gistfile1.txt
· 1.4 KiB · Text
Originalformat
function buildEntries(nation: Nation, week: WRankWeek): LeaderboardEntry[] {
const wRankEntries = WRank.entriesForNation(nation, week);
return wRankEntries.map((wr): LeaderboardEntry => {
const char = wr.character;
// Aggregate K/D and stats from all active slots this week
let totalKills = 0;
let totalDeaths = 0;
let totalAtk = 0;
let totalDef = 0;
let totalHeal = 0;
for (const historyKey of (WRank.currentWeek().scoreIndex[char.name] ?? [])) {
const score = Score.get({
character: char,
slot: TGKey.parse(historyKey as TGKey).slot,
historyKey: historyKey as TGKey,
});
if (!score) continue;
totalKills += score.k ?? 0;
totalDeaths += score.d ?? 0;
totalAtk += score.atk ?? 0;
totalDef += score.def ?? 0;
totalHeal += score.heal ?? 0;
}
return {
character: char,
weeklyPts: wr.weeklyPoints,
tgCount: wr.tgCount,
totalKills,
totalDeaths,
stats: {
atk: totalAtk || undefined,
def: totalDef || undefined,
heal: totalHeal || undefined,
},
currentRank: wr.currentRank,
previousRank: wr.previousRank,
leavesCount: Leaves.countForChar({ characterName: char.name }),
};
});
}
| 1 | function buildEntries(nation: Nation, week: WRankWeek): LeaderboardEntry[] { |
| 2 | const wRankEntries = WRank.entriesForNation(nation, week); |
| 3 | |
| 4 | return wRankEntries.map((wr): LeaderboardEntry => { |
| 5 | const char = wr.character; |
| 6 | |
| 7 | // Aggregate K/D and stats from all active slots this week |
| 8 | let totalKills = 0; |
| 9 | let totalDeaths = 0; |
| 10 | let totalAtk = 0; |
| 11 | let totalDef = 0; |
| 12 | let totalHeal = 0; |
| 13 | |
| 14 | for (const historyKey of (WRank.currentWeek().scoreIndex[char.name] ?? [])) { |
| 15 | const score = Score.get({ |
| 16 | character: char, |
| 17 | slot: TGKey.parse(historyKey as TGKey).slot, |
| 18 | historyKey: historyKey as TGKey, |
| 19 | }); |
| 20 | if (!score) continue; |
| 21 | totalKills += score.k ?? 0; |
| 22 | totalDeaths += score.d ?? 0; |
| 23 | totalAtk += score.atk ?? 0; |
| 24 | totalDef += score.def ?? 0; |
| 25 | totalHeal += score.heal ?? 0; |
| 26 | } |
| 27 | |
| 28 | return { |
| 29 | character: char, |
| 30 | weeklyPts: wr.weeklyPoints, |
| 31 | tgCount: wr.tgCount, |
| 32 | totalKills, |
| 33 | totalDeaths, |
| 34 | stats: { |
| 35 | atk: totalAtk || undefined, |
| 36 | def: totalDef || undefined, |
| 37 | heal: totalHeal || undefined, |
| 38 | }, |
| 39 | currentRank: wr.currentRank, |
| 40 | previousRank: wr.previousRank, |
| 41 | leavesCount: Leaves.countForChar({ characterName: char.name }), |
| 42 | }; |
| 43 | }); |
| 44 | } |