Changed the behavior of /challenge

/challenge now opens the challenge window instead of the user window (like /user does)

/challenge also accepts multiple parameters now: user, format, team
user is the name(id) of the user you want to challenge
format is the format you want. It gets changed to an id, so you can enter it in any way you want. For example: ou, ou no stealth rock, etc.
team is the name of the team you wish to use. It also gets changed to an id and stops at the first match (problem: multiple teams with the same name?)
Both the format and team parameters are optional
This commit is contained in:
Quinella 2013-10-08 23:34:47 +02:00
parent 627f587c81
commit d73f97d8f9
2 changed files with 44 additions and 4 deletions

View File

@ -393,6 +393,15 @@
switch (cmd.toLowerCase()) {
case 'challenge':
var targets = target.split(',').map($.trim);
if (!targets[0]) targets[0] = prompt('Who?');
target = toId(targets[0]);
this.challengeData = { userid: target, format: targets[1] || '', team: targets[2] || '' };
app.on('response:userdetails', this.challengeUserdetails, this);
app.send('/cmd userdetails '+target);
return false;
case 'user':
case 'open':
if (!target) target = prompt('Who?');
@ -601,6 +610,24 @@
}
return text;
},
challengeData: {},
challengeUserdetails: function (data) {
app.off('response:userdetails', this.challengeUserdetails);
if (!data || this.challengeData.userid !== data.userid) return;
if (data.rooms === false) {
this.add('This player does not exist or is not online.');
return;
}
app.rooms[''].requestNotifications();
app.focusRoom('');
var name = data.name || this.challengeData.userid;
if (/^[a-z0-9]/i.test(name)) name = ' ' + name;
app.rooms[''].challenge(name, this.challengeData.format, this.challengeData.team);
}
});

View File

@ -253,7 +253,7 @@
},
clickUsername: function(e) {
e.stopPropagation();
var name = $(e.currentTarget).data('name');
var name = $(e.currentTarget).data('name');console.log("HAHAHAHAHA", name);
app.addPopup(UserPopup, {name: name, sourceEl: e.currentTarget});
},
clickPMBackground: function(e) {
@ -420,16 +420,29 @@
},
// challenge buttons
challenge: function(name) {
challenge: function(name, format, team) {
var userid = toId(name);
var $challenge = this.$('.pm-window-'+userid+' .challenge');
if ($challenge.length && !$challenge.find('button[name=dismissChallenge]').length) {
return;
}
if (format) format = toId(format);
var teamIndex = undefined;
if (Storage.teams && team) {
var team = toId(team);
for (var i = 0; i < Storage.teams.length; i++) {
if (team === toId(Storage.teams[i].name || '')) {
teamIndex = i;
break;
}
}
}
$challenge = this.openChallenge(name);
var buf = '<form class="battleform"><p>Challenge '+Tools.escapeHTML(name)+'?</p>';
buf += '<p><label class="label">Format:</label>'+this.renderFormats()+'</p>';
buf += '<p><label class="label">Team:</label>'+this.renderTeams()+'</p>';
buf += '<p><label class="label">Format:</label>'+this.renderFormats(format)+'</p>';
buf += '<p><label class="label">Team:</label>'+this.renderTeams(format, teamIndex)+'</p>';
buf += '<p class="buttonbar"><button name="makeChallenge"><strong>Challenge</strong></button> <button name="dismissChallenge">Cancel</button></p></form>';
$challenge.html(buf);
},