-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUser.as
273 lines (237 loc) · 7.25 KB
/
User.as
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package
{
/**
* ...
* @author Hidetchi
*/
public class User
{
public static const STATE_CONNECTED:String = "connected";
public static const STATE_GAME_WAITING:String = "game_waiting";
public static const STATE_GAME:String = "game";
public static const STATE_POSTGAME:String = "post_game";
private static const IMAGE_DIRECTORY:String = "http://49.212.52.151/dojo/images/";
public var name:String;
public var rating:int;
public var country_code:int = 0;
public var wins:int;
public var losses:int;
public var streak:int;
public var streak_best:int;
public var status:String = STATE_CONNECTED;
public var opponent:String = "";
public var game_name:String = "*";
public var turn:String = "*";
public var monitor_game:String = "*";
public var moves:int = 0;
public var mark:String = "";
public var markWidth:int = 0;
public var idle:Boolean = false;
public var disconnected:Boolean = false;
public var cheater:Boolean = false;
public var favorite:String = "";
public var favoriteWidth:int = 0;
public var exist:Boolean;
public function User(name:String) {
this.name = name;
}
public function initialize():void {
status = STATE_CONNECTED;
opponent = "";
game_name = "*";
turn = "*";
monitor_game = "*";
moves = 0;
mark = "";
markWidth = 0;
idle = false;
disconnected = false;
cheater = false;
}
public function setFromWho(rating:int, country_code:int, wins:int, losses:int, streak:int, streak_best:int,
status:String, opponent:String, game_name:String, turn:String, monitor_game:String, moves:int, idle:Boolean):void {
this.rating = rating;
this.country_code = country_code;
this.wins = wins;
this.losses = losses;
this.streak = streak;
this.streak_best = streak_best;
this.status = status;
this.opponent = opponent;
this.game_name = game_name;
this.turn = turn;
this.monitor_game = monitor_game;
this.moves = moves;
this.idle = idle;
exist = true;
}
public function setFromLobbyIn(rating:int, country_code:int, wins:int, losses:int, streak:int, streak_best:int):void {
this.rating = rating;
this.country_code = country_code;
this.wins = wins;
this.losses = losses;
this.streak = streak;
this.streak_best = streak_best;
}
public function setFromList(rating:int, country_code:int):void {
this.rating = rating;
this.country_code = country_code;
}
public function setFromGame(game_name:String, turn:String):void {
this.game_name = game_name;
this.turn = turn;
if (game_name == "*") status = STATE_CONNECTED;
else status = STATE_GAME_WAITING;
}
public function setFromStart(game_name:String, turn:String):void {
this.game_name = game_name;
this.turn = turn;
this.status = STATE_GAME;
this.moves = 0;
this.idle = false;
}
public function setFromStudy():void {
rating = 0;
country_code = 0;
wins = 0;
losses = 0;
}
public function get country():String {
return InfoFetcher.country_names[country_code];
}
public function get country3():String {
return InfoFetcher.country_names3[country_code];
}
public function get flag_m():String {
return IMAGE_DIRECTORY + "flags_m/" + String(country_code + 1000).substring(1) + ".swf";
}
public function get flag_s():String {
return IMAGE_DIRECTORY + "flags_s/" + String(country_code + 1000).substring(1) + ".gif";
}
public function get flag_ss():String {
return IMAGE_DIRECTORY + "flags_ss/" + String(country_code + 1000).substring(1) + ".png";
}
public function get statusMark():String {
var str:String = "";
if (monitor_game != "*") str = "M ";
if(status == STATE_GAME_WAITING && !game_name.match(/_@/)){
str += "W";
} else if (status == STATE_POSTGAME) {
str = "P ";
} else if (status == STATE_GAME) {
str = "G " + InfoFetcher.textBar(moves);
}
if (disconnected) str = "D";
return str;
}
public function get titleName():String {
for (var i:int = 0; i < InfoFetcher.titleUser.length; i++) {
if (name.toLowerCase() == InfoFetcher.titleUser[i]) {
return InfoFetcher.titleName[i];
}
}
if (cheater) return "!!!";
return "";
}
public function get titleSubName():String {
for (var i:int = 0; i < InfoFetcher.titleUser.length; i++) {
if (name.toLowerCase() == InfoFetcher.titleUser[i]) {
return InfoFetcher.titleSubName[i];
}
}
return "";
}
public function get avatar():String {
var str:String = rank;
for (var i:int = 0; i < InfoFetcher.titleUser.length; i++) {
if (name.toLowerCase() == InfoFetcher.titleUser[i]) {
if (InfoFetcher.titleAvatar[i] != "*") str = InfoFetcher.titleAvatar[i];
break;
}
}
return IMAGE_DIRECTORY + "avatars/" + str + ".jpg";
}
public function get rank():String {
if (!isProvisional || titleName != "") {
return InfoFetcher.makeRankFromRating(rating);
} else {
return "-";
}
}
public function get rankColor():uint {
if (!isProvisional || titleName != "") {
return InfoFetcher.makeColorFromRating(rating);
} else {
return 0xCCCCCC;
}
}
public function get gameDescriptionRated():String {
if (game_name == "*") return "";
var game_info:Array = game_name.match(/^([0-9a-z]+?)_(.*)-([0-9]*)-([0-9]*)$/);
if (game_info[1] == "r") {
return "R";
} else {
return "NR";
}
}
public function get gameDescriptionTime():String {
if (game_name == "*") return "";
var game_info:Array = game_name.match(/^([0-9a-z]+?)_(.*)-([0-9]*)-([0-9]*)$/);
if (game_info[2].match(/\-\-..$/)) {
return InfoFetcher.fetchTournamentJp(game_info[2].substr(game_info[2].length - 2, 2));
} else {
return (parseInt(game_info[3]) / 60) + "-" + game_info[4];
}
}
public function get gameDescriptionTimeTip():String {
if (game_name == "*") return "";
var game_info:Array = game_name.match(/^([0-9a-z]+?)_(.*)-([0-9]*)-([0-9]*)$/);
if (game_info[2].match(/\-\-..$/)) {
return InfoFetcher.fetchTournamentEn(game_info[2].substr(game_info[2].length - 2, 2));
} else {
return "";
}
}
public function get gameDescriptionHandicap():String {
if (game_name == "*") return "";
var game_info:Array = game_name.match(/^([0-9a-z]+?)_(.*)-([0-9]*)-([0-9]*)$/);
return InfoFetcher.gameTypeShort(game_info[1]);
}
public function get rateStr():String {
if (isProvisional && rating < InfoFetcher.rank_thresholds[1]) return ("*" + String(rating));
else return String(rating);
}
public function get description():String {
var str:String = titleName;
return "R:" + rateStr + ", " + (str == "" ? rank : str);
}
public function get total():int {
return wins + losses;
}
public function get percentage():Number {
if (wins + losses == 0) {
return 0;
} else {
return (wins / (wins + losses) * 100);
}
}
public function get idleColor():uint {
return idle ? 0x0000FF : 0x000000;
}
public function markSelf():void {
mark = "◆";
markWidth = 11;
}
public function markFavorite():void {
mark = "★";
markWidth = 11;
}
public function unmark():void {
mark "";
markWidth = 0;
}
public function get isProvisional():Boolean {
return (total < 10);
}
}
}