Advertisement
Slayer95

TYPEmons

Jan 27th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Copyright (c) 2011-2014 Guangcong Luo and other contributors
  3.  * http://pokemonshowdown.com/
  4.  *
  5.  * Permission is hereby granted, free of charge, to any person obtaining
  6.  * a copy of this software and associated documentation files (the
  7.  * "Software"), to deal in the Software without restriction, including
  8.  * without limitation the rights to use, copy, modify, merge, publish,
  9.  * distribute, sublicense, and/or sell copies of the Software, and to
  10.  * permit persons to whom the Software is furnished to do so, subject to
  11.  * the following conditions:
  12.  
  13.  * The above copyright notice and this permission notice shall be
  14.  * included in all copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17.  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19.  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20.  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21.  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22.  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23.  *
  24.  **/
  25.  
  26.  /* config/formats.js */
  27.  
  28. {
  29.     name: "TYPEmons",
  30.  
  31.     ruleset: ['Pokemon', 'Species Clause', 'OHKO Clause', 'Moody Clause', 'Evasion Moves Clause', 'Endless Battle Clause', 'HP Percentage Mod', 'Team Preview', 'Swagger Clause', 'Baton Pass Clause', 'Sleep Clause Mod'],
  32.     banlist: ['Unreleased', 'Uber', 'Soul Dew', 'Gengarite', 'Kangaskhanite', 'Lucarionite', 'Mawilite', 'Salamencite',
  33.         'Gengar-Mega', 'Kangaskhan-Mega', 'Mewtwo', 'Lugia', 'Ho-Oh', 'Blaziken', 'Mawile-Mega', 'Salamence-Mega',
  34.         'Kyogre', 'Groudon', 'Rayquaza', 'Deoxys', 'Deoxys-Attack', 'Deoxys-Defense', 'Deoxys-Speed', 'Lucario-Mega',
  35.         'Dialga', 'Palkia', 'Giratina', 'Giratina-Origin', 'Darkrai', 'Shaymin-Sky', 'Arceus', 'Reshiram', 'Zekrom',
  36.         'Kyurem-White', 'Genesect', 'Greninja', 'Aegislash', 'Xerneas', 'Yveltal'
  37.     ],
  38.     validateTeam: function (team, format) {
  39.         for (var type in this.data.TypeChart) {
  40.             var problems = [];
  41.             var teamHas = {formatType: type};
  42.  
  43.             for (var i = 0; i < team.length; i++) {
  44.                 var setProblems = format.customValidateSet.call(this, team[i], teamHas);
  45.                 if (setProblems) {
  46.                     problems = problems.concat(setProblems);
  47.                 }
  48.             }
  49.  
  50.             for (var i = 0; i < format.teamBanTable.length; i++) {
  51.                 var bannedCombo = true;
  52.                 for (var j = 0; j < format.teamBanTable[i].length; j++) {
  53.                     if (!teamHas[format.teamBanTable[i][j]]) {
  54.                         bannedCombo = false;
  55.                         break;
  56.                     }
  57.                 }
  58.                 if (bannedCombo) {
  59.                     var clause = format.name ? " by " + format.name : '';
  60.                     problems.push("Your team has the combination of " + format.teamBanTable[i].join(' + ') + ", which is banned" + clause + ".");
  61.                 }
  62.             }
  63.  
  64.             if (format.ruleset) {
  65.                 for (var i = 0; i < format.ruleset.length; i++) {
  66.                     var subformat = this.getFormat(format.ruleset[i]);
  67.                     if (subformat.validateTeam) {
  68.                         problems = problems.concat(subformat.validateTeam.call(this, team, format, teamHas) || []);
  69.                     }
  70.                 }
  71.             }
  72.  
  73.             if (!problems.length) return false;
  74.         }
  75.         return problems;
  76.     },
  77.     customValidateSet: function (set, teamHas) {
  78.         var format = this.getFormat('typemons');
  79.         var problems = [];
  80.         var isHidden = false;
  81.         var lsetData = {set:set, format:format};
  82.         var name = set.name || set.species;
  83.  
  84.         var setHas = {};
  85.  
  86.         if (format.ruleset) {
  87.             for (var i = 0; i < format.ruleset.length; i++) {
  88.                 var subformat = this.getFormat(format.ruleset[i]);
  89.                 if (subformat.validateSet) {
  90.                     problems = problems.concat(subformat.validateSet.call(this, set, format) || []);
  91.                 }
  92.             }
  93.         }
  94.         template = this.getTemplate(set.species);
  95.         item = this.getItem(set.item);
  96.         ability = this.getAbility(set.ability);
  97.  
  98.         var banlistTable = this.getBanlistTable(format);
  99.  
  100.         var check = template.id;
  101.         var clause = '';
  102.         setHas[check] = true;
  103.         if (banlistTable[check]) {
  104.             clause = typeof banlistTable[check] === 'string' ? " by " + banlistTable[check] : '';
  105.             problems.push(set.species + ' is banned' + clause + '.');
  106.         } else if (!this.data.FormatsData[check] || !this.data.FormatsData[check].tier) {
  107.             check = toId(template.baseSpecies);
  108.             if (banlistTable[check]) {
  109.                 clause = typeof banlistTable[check] === 'string' ? " by " + banlistTable[check] : '';
  110.                 problems.push(template.baseSpecies + ' is banned' + clause + '.');
  111.             }
  112.         }
  113.  
  114.         check = toId(set.ability);
  115.         setHas[check] = true;
  116.         if (banlistTable[check]) {
  117.             clause = typeof banlistTable[check] === 'string' ? " by " + banlistTable[check] : '';
  118.             problems.push(name + "'s ability " + set.ability + " is banned" + clause + ".");
  119.         }
  120.         check = toId(set.item);
  121.         setHas[check] = true;
  122.         if (banlistTable[check]) {
  123.             clause = typeof banlistTable[check] === 'string' ? " by " + banlistTable[check] : '';
  124.             problems.push(name + "'s item " + set.item + " is banned" + clause + ".");
  125.         }
  126.         if (banlistTable['Unreleased'] && item.isUnreleased) {
  127.             problems.push(name + "'s item " + set.item + " is unreleased.");
  128.         }
  129.         if (banlistTable['Unreleased'] && template.isUnreleased) {
  130.             if (!format.requirePentagon || (template.eggGroups[0] === 'Undiscovered' && !template.evos)) {
  131.                 problems.push(name + " (" + template.species + ") is unreleased.");
  132.             }
  133.         }
  134.         setHas[toId(set.ability)] = true;
  135.  
  136.         // Don't check abilities for metagames with All Abilities
  137.         if (this.gen <= 2) {
  138.             set.ability = 'None';
  139.         } else if (!banlistTable['ignoreillegalabilities']) {
  140.             if (!ability.name) {
  141.                 problems.push(name + " needs to have an ability.");
  142.             } else if (ability.name !== template.abilities['0'] &&
  143.                 ability.name !== template.abilities['1'] &&
  144.                 ability.name !== template.abilities['H']) {
  145.                 problems.push(name + " can't have " + set.ability + ".");
  146.             }
  147.             if (ability.name === template.abilities['H']) {
  148.                 isHidden = true;
  149.  
  150.                 if (template.unreleasedHidden && banlistTable['illegal']) {
  151.                     problems.push(name + "'s hidden ability is unreleased.");
  152.                 } else if (this.gen === 5 && set.level < 10 && (template.maleOnlyHidden || template.gender === 'N')) {
  153.                     problems.push(name + " must be at least level 10 with its hidden ability.");
  154.                 }
  155.                 if (template.maleOnlyHidden) {
  156.                     set.gender = 'M';
  157.                     lsetData.sources = ['5D'];
  158.                 }
  159.             }
  160.         }
  161.  
  162.         for (var i = 0; i < set.moves.length; i++) {
  163.             var move = this.getMove(string(set.moves[i]));
  164.             set.moves[i] = move.name;
  165.             check = move.id;
  166.             setHas[check] = true;
  167.             if (banlistTable[check]) {
  168.                 clause = typeof banlistTable[check] === 'string' ? " by " + banlistTable[check] : '';
  169.                 problems.push(name + "'s move " + set.moves[i] + " is banned" + clause + ".");
  170.             }
  171.  
  172.             if (banlistTable['Unreleased']) {
  173.                 if (move.isUnreleased) problems.push(name + "'s move " + set.moves[i] + " is unreleased.");
  174.             }
  175.  
  176.             lsetData['ignoreMoveType'] = teamHas['formatType'];
  177.             var problem = format.checkLearnset.call(this, move, template, lsetData);
  178.             if (problem) {
  179.                 var problemString = name + " can't learn " + move.name;
  180.                 if (problem.type === 'incompatible') {
  181.                     if (isHidden) {
  182.                         problemString = problemString.concat(" because it's incompatible with its ability or another move.");
  183.                     } else {
  184.                         problemString = problemString.concat(" because it's incompatible with another move.");
  185.                     }
  186.                 } else if (problem.type === 'oversketched') {
  187.                     problemString = problemString.concat(" because it can only sketch " + problem.maxSketches + " move" + (problem.maxSketches > 1 ? "s" : "") + ".");
  188.                 } else if (problem.type === 'pokebank') {
  189.                     problemString = problemString.concat(" because it's only obtainable from a previous generation.");
  190.                 } else {
  191.                     problemString = problemString.concat(".");
  192.                 }
  193.                 problems.push(problemString);
  194.             }
  195.         }
  196.  
  197.         if (lsetData.sources && lsetData.sources.length === 1 && !lsetData.sourcesBefore) {
  198.             // we're restricted to a single source
  199.             var source = lsetData.sources[0];
  200.             if (source.substr(1, 1) === 'S') {
  201.                 // it's an event
  202.                 var eventData = null;
  203.                 var splitSource = source.substr(2).split(' ');
  204.                 var eventTemplate = this.getTemplate(splitSource[1]);
  205.                 if (eventTemplate.eventPokemon) eventData = eventTemplate.eventPokemon[parseInt(splitSource[0], 10)];
  206.                 if (eventData) {
  207.                     if (eventData.nature && eventData.nature !== set.nature) {
  208.                         problems.push(name + " must have a " + eventData.nature + " nature because it has a move only available from a specific event.");
  209.                     }
  210.                     if (eventData.shiny) {
  211.                         set.shiny = true;
  212.                     }
  213.                     if (eventData.generation < 5) eventData.isHidden = false;
  214.                     if (eventData.isHidden !== undefined && eventData.isHidden !== isHidden) {
  215.                         problems.push(name + (isHidden ? " can't have" : " must have") + " its hidden ability because it has a move only available from a specific event.");
  216.                     }
  217.                     if (this.gen <= 5 && eventData.abilities && eventData.abilities.indexOf(ability.id) < 0) {
  218.                         problems.push(name + " must have " + eventData.abilities.join(" or ") + " because it has a move only available from a specific event.");
  219.                     }
  220.                     if (eventData.gender) {
  221.                         set.gender = eventData.gender;
  222.                     }
  223.                     if (eventData.level && set.level < eventData.level) {
  224.                         problems.push(name + " must be at least level " + eventData.level + " because it has a move only available from a specific event.");
  225.                     }
  226.                 }
  227.                 isHidden = false;
  228.             }
  229.         }
  230.         if (isHidden && lsetData.sourcesBefore) {
  231.             if (!lsetData.sources && lsetData.sourcesBefore < 5) {
  232.                 problems.push(name + " has a hidden ability - it can't have moves only learned before gen 5.");
  233.             } else if (lsetData.sources && template.gender && template.gender !== 'F' && !{'Nidoran-M':1, 'Nidorino':1, 'Nidoking':1, 'Volbeat':1}[template.species]) {
  234.                 var compatibleSource = false;
  235.                 for (var i = 0, len = lsetData.sources.length; i < len; i++) {
  236.                     if (lsetData.sources[i].charAt(1) === 'E' || (lsetData.sources[i].substr(0, 2) === '5D' && set.level >= 10)) {
  237.                         compatibleSource = true;
  238.                         break;
  239.                     }
  240.                 }
  241.                 if (!compatibleSource) {
  242.                     problems.push(name + " has moves incompatible with its hidden ability.");
  243.                 }
  244.             }
  245.         }
  246.         if (set.level < template.evoLevel) {
  247.             // FIXME: Event pokemon given at a level under what it normally can be attained at gives a false positive
  248.             problems.push(name + " must be at least level " + template.evoLevel + " to be evolved.");
  249.         }
  250.         if (!lsetData.sources && lsetData.sourcesBefore <= 3 && this.getAbility(set.ability).gen === 4 && !template.prevo && this.gen <= 5) {
  251.             problems.push(name + " has a gen 4 ability and isn't evolved - it can't use anything from gen 3.");
  252.         }
  253.         if (!lsetData.sources && lsetData.sourcesBefore >= 3 && (isHidden || this.gen <= 5) && template.gen <= lsetData.sourcesBefore) {
  254.             var oldAbilities = this.mod('gen' + lsetData.sourcesBefore).getTemplate(set.species).abilities;
  255.             if (ability.name !== oldAbilities['0'] && ability.name !== oldAbilities['1'] && !oldAbilities['H']) {
  256.                 problems.push(name + " has moves incompatible with its ability.");
  257.             }
  258.         }
  259.  
  260.         setHas[toId(template.tier)] = true;
  261.         if (banlistTable[template.tier]) {
  262.             problems.push(name + " is in " + template.tier + ", which is banned.");
  263.         }
  264.  
  265.         if (teamHas) {
  266.             for (var i in setHas) {
  267.                 teamHas[i] = true;
  268.             }
  269.         }
  270.         for (var i = 0; i < format.setBanTable.length; i++) {
  271.             var bannedCombo = true;
  272.             for (var j = 0; j < format.setBanTable[i].length; j++) {
  273.                 if (!setHas[format.setBanTable[i][j]]) {
  274.                     bannedCombo = false;
  275.                     break;
  276.                 }
  277.             }
  278.             if (bannedCombo) {
  279.                 clause = format.name ? " by " + format.name : '';
  280.                 problems.push(name + " has the combination of " + format.setBanTable[i].join(' + ') + ", which is banned" + clause + ".");
  281.             }
  282.         }
  283.  
  284.         if (!problems.length) {
  285.             if (set.forcedLevel) set.level = set.forcedLevel;
  286.             return false;
  287.         }
  288.  
  289.         return problems;
  290.     },
  291.     checkLearnset: function (move, template, lsetData) {
  292.         move = toId(move);
  293.         template = this.getTemplate(template);
  294.  
  295.         lsetData = lsetData || {};
  296.         var set = (lsetData.set || (lsetData.set = {}));
  297.         var format = (lsetData.format || (lsetData.format = {}));
  298.         var alreadyChecked = {};
  299.         var level = set.level || 100;
  300.  
  301.         var isHidden = false;
  302.         if (set.ability && this.getAbility(set.ability).name === template.abilities['H']) isHidden = true;
  303.         var incompatibleHidden = false;
  304.  
  305.         var limit1 = true;
  306.         var sketch = false;
  307.  
  308.         var sometimesPossible = false; // is this move in the learnset at all?
  309.  
  310.         // This is a pretty complicated algorithm
  311.  
  312.         // Abstractly, what it does is construct the union of sets of all
  313.         // possible ways this pokemon could be obtained, and then intersect
  314.         // it with a the pokemon's existing set of all possible ways it could
  315.         // be obtained. If this intersection is non-empty, the move is legal.
  316.  
  317.         // We apply several optimizations to this algorithm. The most
  318.         // important is that with, for instance, a TM move, that Pokemon
  319.         // could have been obtained from any gen at or before that TM's gen.
  320.         // Instead of adding every possible source before or during that gen,
  321.         // we keep track of a maximum gen variable, intended to mean "any
  322.         // source at or before this gen is possible."
  323.  
  324.         // set of possible sources of a pokemon with this move, represented as an array
  325.         var sources = [];
  326.         // the equivalent of adding "every source at or before this gen" to sources
  327.         var sourcesBefore = 0;
  328.         var noPastGen = !!format.requirePentagon;
  329.         // since Gen 3, Pokemon cannot be traded to past generations
  330.         var noFutureGen = this.gen >= 3 ? true : !!(format.banlistTable && format.banlistTable['tradeback']);
  331.  
  332.         do {
  333.             alreadyChecked[template.speciesid] = true;
  334.             if (lsetData.ignoreMoveType && this.getMove(move).type === lsetData.ignoreMoveType) return false;
  335.             if (template.learnset) {
  336.                 if (template.learnset[move] || template.learnset['sketch']) {
  337.                     sometimesPossible = true;
  338.                     var lset = template.learnset[move];
  339.                     if (!lset || template.speciesid === 'smeargle') {
  340.                         lset = template.learnset['sketch'];
  341.                         sketch = true;
  342.                         // Chatter, Struggle and Magikarp's Revenge cannot be sketched
  343.                         if (move in {'chatter':1, 'struggle':1, 'magikarpsrevenge':1}) return true;
  344.                     }
  345.                     if (typeof lset === 'string') lset = [lset];
  346.  
  347.                     for (var i = 0, len = lset.length; i < len; i++) {
  348.                         var learned = lset[i];
  349.                         if (noPastGen && learned.charAt(0) !== '6') continue;
  350.                         if (noFutureGen && parseInt(learned.charAt(0), 10) > this.gen) continue;
  351.                         if (learned.charAt(0) !== '6' && isHidden && !this.mod('gen' + learned.charAt(0)).getTemplate(template.species).abilities['H']) {
  352.                             // check if the Pokemon's hidden ability was available
  353.                             incompatibleHidden = true;
  354.                             continue;
  355.                         }
  356.                         if (!template.isNonstandard) {
  357.                             // HMs can't be transferred
  358.                             if (this.gen >= 4 && learned.charAt(0) <= 3 && move in {'cut':1, 'fly':1, 'surf':1, 'strength':1, 'flash':1, 'rocksmash':1, 'waterfall':1, 'dive':1}) continue;
  359.                             if (this.gen >= 5 && learned.charAt(0) <= 4 && move in {'cut':1, 'fly':1, 'surf':1, 'strength':1, 'rocksmash':1, 'waterfall':1, 'rockclimb':1}) continue;
  360.                         }
  361.                         if (learned.substr(0, 2) in {'4L':1, '5L':1, '6L':1}) {
  362.                             // gen 4-6 level-up moves
  363.                             if (level >= parseInt(learned.substr(2), 10)) {
  364.                                 // we're past the required level to learn it
  365.                                 return false;
  366.                             }
  367.                             if (!template.gender || template.gender === 'F') {
  368.                                 // available as egg move
  369.                                 learned = learned.charAt(0) + 'Eany';
  370.                             } else {
  371.                                 // this move is unavailable, skip it
  372.                                 continue;
  373.                             }
  374.                         }
  375.                         if (learned.charAt(1) in {L:1, M:1, T:1}) {
  376.                             if (learned.charAt(0) === '6') {
  377.                                 // current-gen TM or tutor moves:
  378.                                 //   always available
  379.                                 return false;
  380.                             }
  381.                             // past-gen level-up, TM, or tutor moves:
  382.                             //   available as long as the source gen was or was before this gen
  383.                             limit1 = false;
  384.                             sourcesBefore = Math.max(sourcesBefore, parseInt(learned.charAt(0), 10));
  385.                         } else if (learned.charAt(1) in {E:1, S:1, D:1}) {
  386.                             // egg, event, or DW moves:
  387.                             //   only if that was the source
  388.                             if (learned.charAt(1) === 'E') {
  389.                                 // it's an egg move, so we add each pokemon that can be bred with to its sources
  390.                                 if (learned.charAt(0) === '6') {
  391.                                     // gen 6 doesn't have egg move incompatibilities except for certain cases with baby Pokemon
  392.                                     learned = '6E' + (template.prevo ? template.id : '');
  393.                                     sources.push(learned);
  394.                                     continue;
  395.                                 }
  396.                                 var eggGroups = template.eggGroups;
  397.                                 if (!eggGroups) continue;
  398.                                 if (eggGroups[0] === 'Undiscovered') eggGroups = this.getTemplate(template.evos[0]).eggGroups;
  399.                                 var atLeastOne = false;
  400.                                 var fromSelf = (learned.substr(1) === 'Eany');
  401.                                 learned = learned.substr(0, 2);
  402.                                 for (var templateid in this.data.Pokedex) {
  403.                                     var dexEntry = this.getTemplate(templateid);
  404.                                     if (
  405.                                         // CAP pokemon can't breed
  406.                                         !dexEntry.isNonstandard &&
  407.                                         // can't breed mons from future gens
  408.                                         dexEntry.gen <= parseInt(learned.charAt(0), 10) &&
  409.                                         // genderless pokemon can't pass egg moves
  410.                                         (dexEntry.gender !== 'N' || this.gen <= 1 && dexEntry.gen <= 1)) {
  411.                                         if (
  412.                                             // chainbreeding
  413.                                             fromSelf ||
  414.                                             // otherwise parent must be able to learn the move
  415.                                             !alreadyChecked[dexEntry.speciesid] && dexEntry.learnset && (dexEntry.learnset[move] || dexEntry.learnset['sketch'])) {
  416.                                             if (dexEntry.eggGroups.intersect(eggGroups).length) {
  417.                                                 // we can breed with it
  418.                                                 atLeastOne = true;
  419.                                                 sources.push(learned + dexEntry.id);
  420.                                             }
  421.                                         }
  422.                                     }
  423.                                 }
  424.                                 // chainbreeding with itself from earlier gen
  425.                                 if (!atLeastOne) sources.push(learned + template.id);
  426.                                 // Egg move tradeback for gens 1 and 2.
  427.                                 if (!noFutureGen) sourcesBefore = Math.max(sourcesBefore, parseInt(learned.charAt(0), 10));
  428.                             } else if (learned.charAt(1) === 'S') {
  429.                                 // Event Pokémon:
  430.                                 //  Available as long as the past gen can get the Pokémon and then trade it back.
  431.                                 sources.push(learned + ' ' + template.id);
  432.                                 if (!noFutureGen) sourcesBefore = Math.max(sourcesBefore, parseInt(learned.charAt(0), 10));
  433.                             } else {
  434.                                 // DW Pokemon are at level 10 or at the evolution level
  435.                                 var minLevel = (template.evoLevel && template.evoLevel > 10) ? template.evoLevel : 10;
  436.                                 if (set.level < minLevel) continue;
  437.                                 sources.push(learned);
  438.                             }
  439.                         }
  440.                     }
  441.                 }
  442.                 if (format.mimicGlitch && template.gen < 5) {
  443.                     // include the Mimic Glitch when checking this mon's learnset
  444.                     var glitchMoves = {metronome:1, copycat:1, transform:1, mimic:1, assist:1};
  445.                     var getGlitch = false;
  446.                     for (var i in glitchMoves) {
  447.                         if (template.learnset[i]) {
  448.                             if (!(i === 'mimic' && this.getAbility(set.ability).gen === 4 && !template.prevo)) {
  449.                                 getGlitch = true;
  450.                                 break;
  451.                             }
  452.                         }
  453.                     }
  454.                     if (getGlitch) {
  455.                         sourcesBefore = Math.max(sourcesBefore, 4);
  456.                         if (this.getMove(move).gen < 5) {
  457.                             limit1 = false;
  458.                         }
  459.                     }
  460.                 }
  461.             }
  462.             // also check to see if the mon's prevo or freely switchable formes can learn this move
  463.             if (!template.learnset && template.baseSpecies !== template.species) {
  464.                 // forme takes precedence over prevo only if forme has no learnset
  465.                 template = this.getTemplate(template.baseSpecies);
  466.             } else if (template.prevo) {
  467.                 template = this.getTemplate(template.prevo);
  468.                 if (template.gen > Math.max(2, this.gen)) template = null;
  469.             } else if (template.baseSpecies !== template.species && template.baseSpecies !== 'Kyurem' && template.baseSpecies !== 'Pikachu') {
  470.                 template = this.getTemplate(template.baseSpecies);
  471.             } else {
  472.                 template = null;
  473.             }
  474.         } while (template && template.species && !alreadyChecked[template.speciesid]);
  475.  
  476.         if (limit1 && sketch) {
  477.             // limit 1 sketch move
  478.             if (lsetData.sketchMove) {
  479.                 return {type:'oversketched', maxSketches: 1};
  480.             }
  481.             lsetData.sketchMove = move;
  482.         }
  483.  
  484.         // Now that we have our list of possible sources, intersect it with the current list
  485.         if (!sourcesBefore && !sources.length) {
  486.             if (noPastGen && sometimesPossible) return {type:'pokebank'};
  487.             if (incompatibleHidden) return {type:'incompatible'};
  488.             return true;
  489.         }
  490.         if (!sources.length) sources = null;
  491.         if (sourcesBefore || lsetData.sourcesBefore) {
  492.             // having sourcesBefore is the equivalent of having everything before that gen
  493.             // in sources, so we fill the other array in preparation for intersection
  494.             var learned;
  495.             if (sourcesBefore && lsetData.sources) {
  496.                 if (!sources) sources = [];
  497.                 for (var i = 0, len = lsetData.sources.length; i < len; i++) {
  498.                     learned = lsetData.sources[i];
  499.                     if (parseInt(learned.substr(0, 1), 10) <= sourcesBefore) {
  500.                         sources.push(learned);
  501.                     }
  502.                 }
  503.                 if (!lsetData.sourcesBefore) sourcesBefore = 0;
  504.             }
  505.             if (lsetData.sourcesBefore && sources) {
  506.                 if (!lsetData.sources) lsetData.sources = [];
  507.                 for (var i = 0, len = sources.length; i < len; i++) {
  508.                     learned = sources[i];
  509.                     if (parseInt(learned.substr(0, 1), 10) <= lsetData.sourcesBefore) {
  510.                         lsetData.sources.push(learned);
  511.                     }
  512.                 }
  513.                 if (!sourcesBefore) delete lsetData.sourcesBefore;
  514.             }
  515.         }
  516.         if (sources) {
  517.             if (lsetData.sources) {
  518.                 var intersectSources = lsetData.sources.intersect(sources);
  519.                 if (!intersectSources.length && !(sourcesBefore && lsetData.sourcesBefore)) {
  520.                     return {type:'incompatible'};
  521.                 }
  522.                 lsetData.sources = intersectSources;
  523.             } else {
  524.                 lsetData.sources = sources.unique();
  525.             }
  526.         }
  527.  
  528.         if (sourcesBefore) {
  529.             lsetData.sourcesBefore = Math.min(sourcesBefore, lsetData.sourcesBefore || 6);
  530.         }
  531.  
  532.         return false;
  533.     }
  534. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement