-
Notifications
You must be signed in to change notification settings - Fork 1
/
tournament.js
152 lines (136 loc) · 4.46 KB
/
tournament.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const { ChallengeView, Price } = require('./challenge');
const TournamentType = {
OPEN: 'open',
PASSWORD_PROTECTED: 'passwordProtected',
UNKNOWN: 'unknown'
}
const TournamentStatus = {
IN_PREPARATION: 'inPreparation',
IN_PROGRESS: 'inProgress',
ENDED: 'ended',
UNKNOWN: 'unknown'
}
class TournamentPlayer {
constructor(tag, name, score, rank, clan) {
this.tag = tag;
this.name = name;
this.score = score;
this.rank = rank;
this.clan = clan;
}
static fromJSON(jsonObject) {
return new TournamentPlayer(
jsonObject.tag,
jsonObject.name,
jsonObject.score,
jsonObject.rank,
jsonObject.clan);
}
toString() {
return this.name;
}
}
class Tournament {
constructor(tag, type, status, creatorTag, name, description, levelCap, firstPlaceCardPrize, capacity, maxCapacity,
preparationDuration, duration, createdTime, startedTime, membersList, gameMode) {
this.tag = tag;
this.type = type;
this.status = status;
this.creatorTag = creatorTag;
this.name = name;
this.description = description;
this.levelCap = levelCap;
this.firstPlaceCardPrize = firstPlaceCardPrize;
this.capacity = capacity;
this.maxCapacity = maxCapacity;
this.preparationDuration = preparationDuration;
this.duration = duration;
this.createdTime = createdTime;
this.startedTime = startedTime;
this.membersList = membersList;
this.gameMode = gameMode;
}
static fromJSON(jsonObject) {
return new Tournament(
jsonObject.tag,
jsonObject.type,
jsonObject.status,
jsonObject.creatorTag,
jsonObject.name,
jsonObject.description || 'no description given',
jsonObject.levelCap,
jsonObject.firstPlaceCardPrize,
jsonObject.capacity,
jsonObject.maxCapacity,
jsonObject.preparationDuration,
jsonObject.duration,
ChallengeView.formatDate(jsonObject.createdTime),
jsonObject.startedTime
? ChallengeView.formatDate(jsonObject.startedTime)
: undefined,
jsonObject.membersList
? jsonObject.membersList.map(TournamentPlayer.fromJSON)
: [],
jsonObject.gameMode);
}
toString() {
return `${this.name}: ${this.description}`;
}
}
class TournamentPrice {
constructor(winsNeeded, price) {
this.winsNeeded = winsNeeded;
this.price = price;
}
static fromJSON(jsonObject) {
return new TournamentPrice(
jsonObject.wins,
Price.fromJSON(jsonObject)
)
}
toString() {
return this.price.toString();
}
}
class GlobalTournament {
constructor(tag, name, startTime, endTime, rewards, freeTierRewards, topRankReward, maxTopRewardRank, gameMode,
maxLosses, levelCap, tournamentLevel) {
this.tag = tag;
this.name = name;
this.startTime = startTime;
this.endTime = endTime;
this.rewards = rewards;
this.freeTierRewards = rewards;
this.topRankReward = topRankReward;
this.maxTopRewardRank = maxTopRewardRank;
this.gameMode = gameMode;
this.maxLosses = maxLosses;
this.levelCap = levelCap;
this.tournamentLevel = tournamentLevel;
}
static fromJSON(jsonObject) {
return new GlobalTournament(
jsonObject.tag,
jsonObject.title,
ChallengeView.formatDate(jsonObject.startTime),
ChallengeView.formatDate(jsonObject.endTime),
jsonObject.milestoneRewards
.filter(reward => reward.type !== null)
.map(TournamentPrice.fromJSON),
jsonObject.freeTierRewards
.filter(reward => reward.type !== null)
.map(TournamentPrice.fromJSON),
jsonObject.topRankReward
.filter(reward => reward.type !== null)
.map(TournamentPrice.fromJSON),
jsonObject.maxTopRewardRank,
jsonObject.gameMode,
jsonObject.maxLosses,
jsonObject.minExpLevel,
jsonObject.tournamentLevel);
}
toString() {
return this.name;
}
}
module.exports = {Tournament, TournamentStatus, TournamentType, GlobalTournament}