Advertisement
Guest User

Inheritance

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