Advertisement
Guest User

Inheritance

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