Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. onTournamentEnd() {
  2. this.room.add('|tournament|end|' + JSON.stringify({
  3. results: this.generator.getResults().map(usersToNames),
  4. format: this.format,
  5. generator: this.generator.name,
  6. bracketData: this.getBracketData(),
  7. }));
  8. this.isEnded = true;
  9. if (this.autoDisqualifyTimer) clearTimeout(this.autoDisqualifyTimer);
  10.  
  11. //
  12. // Tournament Winnings
  13. //
  14.  
  15. let color = '#088cc7';
  16. let sizeRequiredToEarn = 4;
  17. let currencyName = function (amount) {
  18. let name = " buck";
  19. return amount === 1 ? name : name + "s";
  20. };
  21. let tourCard = function () {
  22. let name = " card";
  23. return amount === 1 ? name : name + "s";
  24. };
  25. let data = this.generator.getResults().map(usersToNames).toString();
  26. let winner, runnerUp;
  27.  
  28. if (data.indexOf(',') >= 0) {
  29. data = data.split(',');
  30. winner = data[0];
  31. if (data[1]) runnerUp = data[1];
  32. } else {
  33. winner = data;
  34. }
  35.  
  36. let wid = toId(winner);
  37. let rid = toId(runnerUp);
  38. let tourSize = this.generator.users.size;
  39.  
  40. if (this.room.isOfficial && tourSize >= sizeRequiredToEarn) {
  41. let firstMoney = Math.round(tourSize / 4);
  42. let secondMoney = Math.round(firstMoney / 2);
  43.  
  44. Db('money').set(wid, Db('money').get(wid, 0) + firstMoney);
  45. this.room.addRaw("<b><font color='" + color + "'>" + Tools.escapeHTML(winner) + "</font> has won " + "<font color='" + color + "'>" + firstMoney + "</font>" + currencyName(firstMoney) + " for winning the tournament!</b>");
  46.  
  47. if (runnerUp) {
  48. Db('money').set(rid, Db('money').get(rid, 0) + secondMoney);
  49. this.room.addRaw("<b><font color='" + color + "'>" + Tools.escapeHTML(runnerUp) + "</font> has won " + "<font color='" + color + "'>" + secondMoney + "</font>" + currencyName(secondMoney) + " for winning the tournament!</b>");
  50. }
  51. }
  52. delete exports.tournaments[this.room.id];
  53. delete this.room.game;
  54. for (let i in this.players) {
  55. this.players[i].destroy();
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement