Advertisement
Guest User

Inheritance

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