Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- name: "1v1 Reversed",
- desc: [
- "Bring three Pokémon to Team Preview and choose one to battle. You are able to command your foe's Pokémon",
- "• <a href=\"https://www.smogon.com/forums/threads/3496773/\">1v1</a>",
- ],
- section: 'Other Metagames',
- debug: true,
- teamLength: {
- validate: [1, 3],
- battle: 1,
- },
- ruleset: ['Pokemon', 'Moody Clause', 'OHKO Clause', 'Evasion Moves Clause', 'Swagger Clause', 'Endless Battle Clause', 'HP Percentage Mod', 'Cancel Mod', 'Team Preview'],
- banlist: ['Illegal', 'Unreleased', 'Arceus', 'Blaziken', 'Darkrai', 'Deoxys', 'Deoxys-Attack', 'Dialga',
- 'Giratina', 'Giratina-Origin', 'Groudon', 'Ho-Oh', 'Kyogre', 'Kyurem-White', 'Lugia', 'Mewtwo',
- 'Palkia', 'Rayquaza', 'Reshiram', 'Shaymin-Sky', 'Xerneas', 'Yveltal', 'Zekrom',
- 'Focus Sash', 'Kangaskhanite', 'Salamencite', 'Soul Dew', 'Perish Song',
- ],
- makeRequest: function (type, requestDetails) {
- if (type) {
- this.currentRequest = type;
- this.currentRequestDetails = requestDetails || '';
- this.rqid++;
- this.p1.decision = null;
- this.p2.decision = null;
- } else {
- type = this.currentRequest;
- requestDetails = this.currentRequestDetails;
- }
- // default to no request
- let p1request = null;
- let p2request = null;
- this.p1.currentRequest = '';
- this.p2.currentRequest = '';
- switch (type) {
- case 'teampreview':
- this.add('teampreview' + (requestDetails ? '|' + requestDetails : ''));
- this.p1.currentRequest = 'teampreview';
- p1request = {teamPreview: true, side: this.p1.getData(), rqid: this.rqid};
- this.p2.currentRequest = 'teampreview';
- p2request = {teamPreview: true, side: this.p2.getData(), rqid: this.rqid};
- break;
- default: {
- this.p1.currentRequest = 'move';
- let activeData = this.p2.active.map(pokemon => pokemon && pokemon.getRequestData());
- p1request = {active: activeData, side: this.p1.getData(), rqid: this.rqid};
- this.p2.currentRequest = 'move';
- activeData = this.p1.active.map(pokemon => pokemon && pokemon.getRequestData());
- p2request = {active: activeData, side: this.p2.getData(), rqid: this.rqid};
- break;
- }
- }
- if (this.p1 && this.p2) {
- let inactiveSide = -1;
- if (p1request && !p2request) {
- inactiveSide = 0;
- } else if (!p1request && p2request) {
- inactiveSide = 1;
- }
- if (inactiveSide !== this.inactiveSide) {
- this.send('inactiveside', inactiveSide);
- this.inactiveSide = inactiveSide;
- }
- }
- if (p1request) {
- if (!this.supportCancel || !p2request) p1request.noCancel = true;
- this.p1.emitRequest(p1request);
- } else {
- this.p1.decision = true;
- this.p1.emitRequest({wait: true, side: this.p1.getData()});
- }
- if (p2request) {
- if (!this.supportCancel || !p1request) p2request.noCancel = true;
- this.p2.emitRequest(p2request);
- } else {
- this.p2.decision = true;
- this.p2.emitRequest({wait: true, side: this.p2.getData()});
- }
- if (this.p2.decision && this.p1.decision) {
- if (this.p2.decision === true && this.p1.decision === true) {
- if (type !== 'move') {
- // TODO: investigate this race condition; should be fixed
- // properly later
- return this.makeRequest('move');
- }
- this.add('html', '<div class="broadcast-red"><b>The battle crashed</b></div>');
- this.win();
- } else {
- // some kind of weird race condition?
- this.commitDecisions();
- }
- return;
- }
- },
- choose: function (sideid, choice, rqid) {
- let side = null;
- if (sideid === 'p1' || sideid === 'p2') side = this[sideid];
- // This condition should be impossible because the sideid comes
- // from our forked process and if the player id were invalid, we would
- // not have even got to this function.
- if (!side) return; // wtf
- const targetSide = choice.startsWith('move ') ? side.foe : side;
- // This condition can occur if the client sends a decision at the
- // wrong time.
- if (!targetSide.currentRequest) return;
- // Make sure the decision is for the right request.
- if ((rqid !== undefined) && (parseInt(rqid) !== this.rqid)) {
- return;
- }
- if (targetSide.decision && targetSide.decision.finalDecision) {
- this.debug("Can't override decision: the last pokemon could have been trapped or disabled");
- return;
- }
- targetSide.decision = this.parseChoice(choice.split(','), targetSide);
- targetSide.choice = choice;
- if (this.p1.decision && this.p2.decision) {
- this.commitDecisions();
- }
- },
- emitCallback: function () {
- const parts = new Array(arguments.length);
- for (let i = 0; i < arguments.length; i++) {
- if (!arguments[i]) {
- parts.push(arguments[i]);
- continue;
- }
- if (arguments[i].pokemon) { // BattleSide
- parts.push(arguments[i].foe);
- } else if (arguments[i].getStatus) { // BattlePokemon
- parts.push(arguments[i].side.foe.active[0]);
- } else {
- parts.push(arguments[i]);
- }
- }
- this.battle.send('sideupdate', this.id + "\n|callback|" + parts.join('|'));
- },
- onBegin: function () {
- const format = this.getFormat();
- this.choose = format.choose;
- this.makeRequest = format.makeRequest;
- this.p1.emitCallback = format.emitCallback;
- this.p2.emitCallback = format.emitCallback;
- },
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement