sprcl
Version:
Simple API client for Clash of Clans, Clash Royale, and Brawl Stars
56 lines (47 loc) • 1.63 kB
JavaScript
class Player {
constructor(data) {
this.tag = data.tag;
this.name = data.name;
this.nameColor = data.nameColor;
this.icon = data.icon;
this.trophies = data.trophies;
this.highestTrophies = data.highestTrophies;
this.expLevel = data.expLevel;
this.expPoints = data.expPoints;
this.isQualifiedFromChampionshipChallenge = data.isQualifiedFromChampionshipChallenge;
this.victories = {
'3vs3': data['3vs3Victories'],
solo: data.soloVictories,
duo: data.duoVictories
};
this.bestRoboRumbleTime = data.bestRoboRumbleTime;
this.bestTimeAsBigBrawler = data.bestTimeAsBigBrawler;
this.club = data.club;
this.brawlers = data.brawlers;
}
static fromJSON(json) {
return new Player(json);
}
getBrawlerByName(name) {
return this.brawlers.find(brawler => brawler.name === name);
}
getBrawlerById(id) {
return this.brawlers.find(brawler => brawler.id === id);
}
getHighestRankedBrawler() {
return [...this.brawlers].sort((a, b) => b.rank - a.rank)[0];
}
getHighestTrophyBrawler() {
return [...this.brawlers].sort((a, b) => b.trophies - a.trophies)[0];
}
getTotalBrawlers() {
return this.brawlers.length;
}
getTotalTrophiesFromBrawlers() {
return this.brawlers.reduce((sum, brawler) => sum + brawler.trophies, 0);
}
getBrawlersByPower(minPower) {
return this.brawlers.filter(brawler => brawler.power >= minPower);
}
}
module.exports = { Player };