Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bestTrophies and threeCrownWins #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ client.getPlayerRanks('2023-03')

> Get a list of all locations in the game

* **getClan**(tag)

> Get all information about a specific clan

* **getClanRanks**(locationId, clanWars = false, limit = undefined)

> Get a ranking of all clans in a certain location, either by clan ranking or by clan-war ranking
Expand Down
41 changes: 41 additions & 0 deletions clan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Clan {
constructor(tag, name, type, description, badgeId, clanScore, clanWarTrophies, location, requiredTrophies, donationsPerWeek, members, memberList) {
this.tag = tag;
this.name = name;
this.type = type;
this.description = description;
this.badgeId = badgeId;
this.clanScore = clanScore;
this.clanWarTrophies = clanWarTrophies;
this.location = location;
this.requiredTrophies = requiredTrophies;
this.donationsPerWeek = donationsPerWeek;
this.members = members;
this.memberList = memberList;
}

static fromJSON(jsonObject) {
return new Clan(
jsonObject.tag,
jsonObject.name,
jsonObject.type,
jsonObject.description,
jsonObject.badgeId,
jsonObject.clanScore,
jsonObject.clanWarTrophies,
jsonObject.location,
jsonObject.requiredTrophies,
jsonObject.donationsPerWeek,
jsonObject.members,
jsonObject.memberList
);
}

toString() {
return this.name;
}

}


module.exports = {Clan};
8 changes: 8 additions & 0 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { Connector} = require('./connector');
const { Card } = require('./card');
const { ChallengeView } = require('./challenge');
const { Player } = require('./player');
const { Clan } = require('./clan');
const { BattleLog } = require('./battle');
const { Location, ClanRanking } = require('./location');
const { PlayerRanking } = require('./season');
Expand Down Expand Up @@ -65,6 +66,13 @@ class Client {
.map(Location.fromJSON);
}

async getClan(tag) {
// Allow getClan to be called on a tagged object
tag = this.argumentToString(`getClan(${tag})`, tag, 'tag');
const clan = await this.connector.request(['clans', tag]);
return Clan.fromJSON(clan);
}

async getClanRanks(locationId, clanWars = false, limit = undefined) {
// Allow getClanRanks to be called on an identified object
locationId = this.argumentToString(`getClanRanks(${location}, ${clanWars}, ${limit})`, locationId, 'id');
Expand Down
15 changes: 8 additions & 7 deletions player.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class LeagueStats {
}

class Player {
constructor(tag, name, expLevel, expPoints, totalExpPoints, starPoints, trophies, trophyRecord,
battleCount, wins, threeCrowns, losses, challengeCardsWon, challengeBattleCount,
constructor(tag, name, expLevel, expPoints, totalExpPoints, starPoints, trophies, bestTrophies,
battleCount, wins, threeCrownWins, losses, challengeCardsWon, challengeBattleCount,
tournamentCardsWon, tournamentBattleCount, role, donations, donationsReceived,
totalDonations, warDayWins, clanCardsCollected, clan, arena, leagueStats,
badges, achievements, cards, favouriteCard) {
Expand All @@ -123,11 +123,12 @@ class Player {
this.totalExpPoints = totalExpPoints;
this.starPoints = starPoints;
this.trophies = trophies;
this.trophyRecord = trophyRecord;
this.bestTrophies = bestTrophies;
this.battleCount = battleCount;
this.wins = wins;
this.threeCrowns = threeCrowns;
this.threeCrownWins = threeCrownWins;
this.losses = losses;
this.draws = battleCount - (wins + losses);
this.challengeCardsWon = challengeCardsWon;
this.challengeBattleCount = challengeBattleCount;
this.tournamentCardsWon = tournamentCardsWon;
Expand Down Expand Up @@ -156,10 +157,10 @@ class Player {
jsonObject.totalExpPoints,
jsonObject.starPoints,
jsonObject.trophies,
jsonObject.trophyRecord,
jsonObject.bestTrophies,
jsonObject.battleCount,
jsonObject.wins,
jsonObject.threeCrowns,
jsonObject.threeCrownWins,
jsonObject.losses,
jsonObject.challengeCardsWon,
jsonObject.challengeBattleCount,
Expand All @@ -171,7 +172,7 @@ class Player {
jsonObject.totalDonations,
jsonObject.warDayWins,
jsonObject.clanCardsCollected,
jsonObject.clan ? jsonObject.clan.name : 'not in a clan',
jsonObject.clan ? jsonObject.clan.name : 'Sin clan',
jsonObject.arena.name,
LeagueStats.fromJSON(jsonObject.leagueStatistics),
jsonObject.badges.map(Badge.fromJSON),
Expand Down