Advertisement
Guest User

Inheritance

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