Advertisement
Guest User

1v1 Reversed

a guest
May 30th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.         name: "1v1 Reversed",
  3.         desc: [
  4.             "Bring three Pokémon to Team Preview and choose one to battle. You are able to command your foe's Pokémon",
  5.             "&bullet; <a href=\"https://www.smogon.com/forums/threads/3496773/\">1v1</a>",
  6.         ],
  7.         section: 'Other Metagames',
  8.  
  9.         debug: true,
  10.         teamLength: {
  11.             validate: [1, 3],
  12.             battle: 1,
  13.         },
  14.         ruleset: ['Pokemon', 'Moody Clause', 'OHKO Clause', 'Evasion Moves Clause', 'Swagger Clause', 'Endless Battle Clause', 'HP Percentage Mod', 'Cancel Mod', 'Team Preview'],
  15.         banlist: ['Illegal', 'Unreleased', 'Arceus', 'Blaziken', 'Darkrai', 'Deoxys', 'Deoxys-Attack', 'Dialga',
  16.             'Giratina', 'Giratina-Origin', 'Groudon', 'Ho-Oh', 'Kyogre', 'Kyurem-White', 'Lugia', 'Mewtwo',
  17.             'Palkia', 'Rayquaza', 'Reshiram', 'Shaymin-Sky', 'Xerneas', 'Yveltal', 'Zekrom',
  18.             'Focus Sash', 'Kangaskhanite', 'Salamencite', 'Soul Dew', 'Perish Song',
  19.         ],
  20.         makeRequest: function (type, requestDetails) {
  21.             if (type) {
  22.                 this.currentRequest = type;
  23.                 this.currentRequestDetails = requestDetails || '';
  24.                 this.rqid++;
  25.                 this.p1.decision = null;
  26.                 this.p2.decision = null;
  27.             } else {
  28.                 type = this.currentRequest;
  29.                 requestDetails = this.currentRequestDetails;
  30.             }
  31.  
  32.             // default to no request
  33.             let p1request = null;
  34.             let p2request = null;
  35.             this.p1.currentRequest = '';
  36.             this.p2.currentRequest = '';
  37.  
  38.             switch (type) {
  39.             case 'teampreview':
  40.                 this.add('teampreview' + (requestDetails ? '|' + requestDetails : ''));
  41.                 this.p1.currentRequest = 'teampreview';
  42.                 p1request = {teamPreview: true, side: this.p1.getData(), rqid: this.rqid};
  43.                 this.p2.currentRequest = 'teampreview';
  44.                 p2request = {teamPreview: true, side: this.p2.getData(), rqid: this.rqid};
  45.                 break;
  46.  
  47.             default: {
  48.                 this.p1.currentRequest = 'move';
  49.                 let activeData = this.p2.active.map(pokemon => pokemon && pokemon.getRequestData());
  50.                 p1request = {active: activeData, side: this.p1.getData(), rqid: this.rqid};
  51.  
  52.                 this.p2.currentRequest = 'move';
  53.                 activeData = this.p1.active.map(pokemon => pokemon && pokemon.getRequestData());
  54.                 p2request = {active: activeData, side: this.p2.getData(), rqid: this.rqid};
  55.                 break;
  56.             }
  57.  
  58.             }
  59.  
  60.             if (this.p1 && this.p2) {
  61.                 let inactiveSide = -1;
  62.                 if (p1request && !p2request) {
  63.                     inactiveSide = 0;
  64.                 } else if (!p1request && p2request) {
  65.                     inactiveSide = 1;
  66.                 }
  67.                 if (inactiveSide !== this.inactiveSide) {
  68.                     this.send('inactiveside', inactiveSide);
  69.                     this.inactiveSide = inactiveSide;
  70.                 }
  71.             }
  72.  
  73.             if (p1request) {
  74.                 if (!this.supportCancel || !p2request) p1request.noCancel = true;
  75.                 this.p1.emitRequest(p1request);
  76.             } else {
  77.                 this.p1.decision = true;
  78.                 this.p1.emitRequest({wait: true, side: this.p1.getData()});
  79.             }
  80.  
  81.             if (p2request) {
  82.                 if (!this.supportCancel || !p1request) p2request.noCancel = true;
  83.                 this.p2.emitRequest(p2request);
  84.             } else {
  85.                 this.p2.decision = true;
  86.                 this.p2.emitRequest({wait: true, side: this.p2.getData()});
  87.             }
  88.  
  89.             if (this.p2.decision && this.p1.decision) {
  90.                 if (this.p2.decision === true && this.p1.decision === true) {
  91.                     if (type !== 'move') {
  92.                         // TODO: investigate this race condition; should be fixed
  93.                         // properly later
  94.                         return this.makeRequest('move');
  95.                     }
  96.                     this.add('html', '<div class="broadcast-red"><b>The battle crashed</b></div>');
  97.                     this.win();
  98.                 } else {
  99.                     // some kind of weird race condition?
  100.                     this.commitDecisions();
  101.                 }
  102.                 return;
  103.             }
  104.         },
  105.         choose: function (sideid, choice, rqid) {
  106.             let side = null;
  107.             if (sideid === 'p1' || sideid === 'p2') side = this[sideid];
  108.             // This condition should be impossible because the sideid comes
  109.             // from our forked process and if the player id were invalid, we would
  110.             // not have even got to this function.
  111.             if (!side) return; // wtf
  112.  
  113.             const targetSide = choice.startsWith('move ') ? side.foe : side;
  114.  
  115.             // This condition can occur if the client sends a decision at the
  116.             // wrong time.
  117.             if (!targetSide.currentRequest) return;
  118.  
  119.             // Make sure the decision is for the right request.
  120.             if ((rqid !== undefined) && (parseInt(rqid) !== this.rqid)) {
  121.                 return;
  122.             }
  123.  
  124.             if (targetSide.decision && targetSide.decision.finalDecision) {
  125.                 this.debug("Can't override decision: the last pokemon could have been trapped or disabled");
  126.                 return;
  127.             }
  128.  
  129.             targetSide.decision = this.parseChoice(choice.split(','), targetSide);
  130.             targetSide.choice = choice;
  131.  
  132.             if (this.p1.decision && this.p2.decision) {
  133.                 this.commitDecisions();
  134.             }
  135.         },
  136.         emitCallback: function () {
  137.             const parts = new Array(arguments.length);
  138.             for (let i = 0; i < arguments.length; i++) {
  139.                 if (!arguments[i]) {
  140.                     parts.push(arguments[i]);
  141.                     continue;
  142.                 }
  143.                 if (arguments[i].pokemon) { // BattleSide
  144.                     parts.push(arguments[i].foe);
  145.                 } else if (arguments[i].getStatus) { // BattlePokemon
  146.                     parts.push(arguments[i].side.foe.active[0]);
  147.                 } else {
  148.                     parts.push(arguments[i]);
  149.                 }
  150.             }
  151.             this.battle.send('sideupdate', this.id + "\n|callback|" + parts.join('|'));
  152.         },
  153.         onBegin: function () {
  154.             const format = this.getFormat();
  155.             this.choose = format.choose;
  156.             this.makeRequest = format.makeRequest;
  157.             this.p1.emitCallback = format.emitCallback;
  158.             this.p2.emitCallback = format.emitCallback;
  159.         },
  160.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement