<commit_before>function makeJewel(tier, shapeType, components, quality) {
    var componentsSum = 0;
    var componentBonuses = {};
    var jewelType = 0;
    for (var i = 0; i < 3; i++) {
        componentsSum += components[i];
    }
    var RGB = [0, 0, 0];
    var minActiveComponent = 1;
    var maxActiveComponent = 0;
    var totalActiveCompontent = 0;
    var numberOfActiveComponents = 0;
    for (var i = 0; i < 3; i++) {
        components[i] /= componentsSum;
        // A compontent is not activy if it is less than 30% of the jewel.
        if (components[i] < .3) continue;
        numberOfActiveComponents++;
        if (i == 0) componentBonuses['+strength'] = components[i];
        else if (i == 1) componentBonuses['+dexterity'] = components[i];
        else componentBonuses['+intelligence'] = components[i];
        totalActiveCompontent += components[i];
        minActiveComponent = Math.min(minActiveComponent, components[i]);
        maxActiveComponent = Math.max(maxActiveComponent, components[i]);
        jewelType += (1 << i);
    }
    var qualifierIndex = 3;
    var qualifierBonus = 1;
    if (jewelType === 7) {
        // Diamonds quality is based on how evenly components are
        if (maxActiveComponent - minActiveComponent <= .01) {
            qualifierIndex = 0;
        } else {
            qualifierIndex = Math.min(4, Math.ceil((maxActiveComponent - minActiveComponent) / .02));
        }
        qualifierBonus = [3, 2, 1.5, 1, .5][qualifierIndex];
    } else {
        // Other jewels are based on the total % of active components
        if (totalActiveCompontent >= .99) {
            qualifierIndex = 0;
        } else if (totalActiveCompontent >= .95) {
            qualifierIndex = 1;
        } else if (totalActiveCompontent >= .9) {
            qualifierIndex = 2;
        } else if (totalActiveCompontent >= .8) {
            qualifierIndex = 3;
        } else {
            qualifierIndex = 4;
        }
        qualifierBonus = [1.2, 1.1, 1.05, 1, .9][qualifierIndex];
    }
    for (var i = 0; i < 3; i++) {
        if (numberOfActiveComponents == 1) {
            RGB[i] = Math.round(200 * components[i]);
        } else if (numberOfActiveComponents == 2) {
            RGB[i] = Math.round(290 * components[i]);
        } else {
            RGB[i] = Math.round(500 * components[i]);
        }
        if (components[i] >= .3) {
            RGB[i] = Math.min(255, Math.max(0, RGB[i] + [50, 30, 10, -10, -20][qualifierIndex]));
        } else {
            RGB[i] = Math.min(255, Math.max(0, RGB[i] + [0, 10, 20, 40, 60][qualifierIndex]));
        }
    }
    var shapeDefinition = shapeDefinitions[shapeType][0];
    var area = shapeDefinition.area;
    var jewel = {
        'tier': tier,
        'shapeType': shapeType,
        'components': components,
        'componentBonuses': componentBonuses,
        'qualifierName': ['Perfect', 'Brilliant', 'Shining', '', 'Dull'][qualifierIndex],
        'qualifierBonus': qualifierBonus,
        'jewelType': jewelType,
        'quality': quality,
        'shape': makeShape(0, 0, 0, shapeDefinition).scale(30),
        'area': area,
        'price': Math.round(Math.pow(10, tier) * quality * quality * (5 - qualifierIndex) * area),
        'adjacentJewels': [],
        'adjacencyBonuses': {}
    };
    var typeIndex = 0;
    jewel.shape.color = arrayToCssRGB(RGB);
    jewel.canvas = createCanvas(68, 68);
    jewel.context = jewel.canvas.getContext("2d");
    // Jewels can be displayed in 3 different states:
    // Drawn directly inside of the canvas for a character's jewel board.
    // Drawn on the jewel.$canvas canvas while being dragged by the user.
    // Drawn on the jewel.$canvas canvas while it is inside jewel.$item and
    // being displayed in grid in the jewel-inventory panel.
    jewel.$canvas = $(jewel.canvas);
    jewel.$canvas.data('jewel', jewel);
    jewel.$item = $tag('div', 'js-jewel jewel').append(jewel.canvas);
    jewel.$item.data('jewel', jewel);
    jewel.character = null;
    updateJewel(jewel);
    return jewel;
}
function clearAdjacentJewels(jewel) {
    while (jewel.adjacentJewels.length) {
        var adjacentJewel = jewel.adjacentJewels.pop();
        var jewelIndex = adjacentJewel.adjacentJewels.indexOf(jewel);
        if (jewelIndex >= 0) {
            adjacentJewel.adjacentJewels.splice(jewelIndex, 1);
        }
        updateAdjacencyBonsues(adjacentJewel);
    }
}
function updateAdjacentJewels(jewel) {
    clearAdjacentJewels(jewel);
    if (!jewel.character) {
        return;
    }
    var jewels = jewel.character.board.jewels.concat(jewel.character.board.fixed);
    for (var i = 0; i < jewels.length; i++) {
        if (jewels[i] === jewel) continue;
        var count = 0;
        for (var j = 0; j < jewel.shape.points.length && count < 2; j++) {
            if (isPointInPoints(jewel.shape.points[j], jewels[i].shape.points)) {
                count++
            }
        }
        if (count < 2) {
            count = 0;
            for (var j = 0; j < jewels[i].shape.points.length && count < 2; j++) {
                if (isPointInPoints(jewels[i].shape.points[j], jewel.shape.points)) {
                    count++
                }
            }
        }
        if (count == 2) {
            jewel.adjacentJewels.push(jewels[i]);
            jewels[i].adjacentJewels.push(jewel);
            updateAdjacencyBonsues(jewels[i]);
        }
    }
    updateAdjacencyBonsues(jewel);
    removeToolTip();
}
function updateAdjacencyBonsues(jewel) {
    jewel.adjacencyBonuses = {};
    if (jewel.fixed) {
        return;
    }
    var matches = 0;
    var typesSeen = {};
    typesSeen[jewel.jewelType] = true;
    var uniqueTypes = 0;
    var shapeDefinition = shapeDefinitions[jewel.shapeType][0];
    var coefficient = jewel.quality * shapeDefinition.area;
    // Pure gems qualifier bonus is applied to their own adjacency bonuses
    if (jewel.jewelType === 1 || jewel.jewelType === 2 || jewel.jewelType === 4) {
        coefficient *= jewel.qualifierBonus;
    }
    var adjacentQualifierBonus = 1;
    for (var i = 0; i < jewel.adjacentJewels.length; i++) {
        var adjacent = jewel.adjacentJewels[i];
        if (adjacent.jewelType === jewel.jewelType) {
            matches++;
        }
        if (!typesSeen[adjacent.jewelType]) {
            typesSeen[adjacent.jewelType] = true;
            uniqueTypes++;
        }
        // Dual gems qualifier bonus is applied to adjacent gems' adjacency bonuses
        if (adjacent.jewelType === 3 || adjacent.jewelType === 5 || adjacent.jewelType === 6) {
            // These are additive, otherwise they could result in 3x multiplier on hexagons.
            adjacentQualifierBonus += (jewel.qualifierBonus - 1);
        }
    }
    coefficient *= adjacentQualifierBonus;
    var resonanceBonus = coefficient * [0, 1, 2, 3, 5, 8, 13, 21, 34][matches];
    var contrastBonus = coefficient * [0, 1, 2, 3, 5, 8, 13, 21, 34][uniqueTypes];
    switch(jewel.jewelType) {
        case 1:
            jewel.adjacencyBonuses['%maxHealth'] = resonanceBonus / 100;
            jewel.adjacencyBonuses['%damage'] = contrastBonus / 100;
            break;
        case 2:
            jewel.adjacencyBonuses['%evasion'] = resonanceBonus / 100;
            jewel.adjacencyBonuses['%attackSpeed'] = contrastBonus / 100;
            break;
        case 4:
            jewel.adjacencyBonuses['%block'] = resonanceBonus / 100;
            jewel.adjacencyBonuses['%accuracy'] = contrastBonus / 100;
            break;
        case 3:
            jewel.adjacencyBonuses['%critChance'] = resonanceBonus / 100;
            jewel.adjacencyBonuses['+critDamage'] = contrastBonus / 100;
            break;
        case 5:
            jewel.adjacencyBonuses['+healthRegen'] = resonanceBonus / 10;
            jewel.adjacencyBonuses['+healthGainOnHit'] = contrastBonus / 10;<commit_msg>Fix the wrong qualifier bonus was being used for dual gem adjacency bonuses.<commit_after>function makeJewel(tier, shapeType, components, quality) {
    var componentsSum = 0;
    var componentBonuses = {};
    var jewelType = 0;
    for (var i = 0; i < 3; i++) {
        componentsSum += components[i];
    }
    var RGB = [0, 0, 0];
    var minActiveComponent = 1;
    var maxActiveComponent = 0;
    var totalActiveCompontent = 0;
    var numberOfActiveComponents = 0;
    for (var i = 0; i < 3; i++) {
        components[i] /= componentsSum;
        // A compontent is not activy if it is less than 30% of the jewel.
        if (components[i] < .3) continue;
        numberOfActiveComponents++;
        if (i == 0) componentBonuses['+strength'] = components[i];
        else if (i == 1) componentBonuses['+dexterity'] = components[i];
        else componentBonuses['+intelligence'] = components[i];
        totalActiveCompontent += components[i];
        minActiveComponent = Math.min(minActiveComponent, components[i]);
        maxActiveComponent = Math.max(maxActiveComponent, components[i]);
        jewelType += (1 << i);
    }
    var qualifierIndex = 3;
    var qualifierBonus = 1;
    if (jewelType === 7) {
        // Diamonds quality is based on how evenly components are
        if (maxActiveComponent - minActiveComponent <= .01) {
            qualifierIndex = 0;
        } else {
            qualifierIndex = Math.min(4, Math.ceil((maxActiveComponent - minActiveComponent) / .02));
        }
        qualifierBonus = [3, 2, 1.5, 1, .5][qualifierIndex];
    } else {
        // Other jewels are based on the total % of active components
        if (totalActiveCompontent >= .99) {
            qualifierIndex = 0;
        } else if (totalActiveCompontent >= .95) {
            qualifierIndex = 1;
        } else if (totalActiveCompontent >= .9) {
            qualifierIndex = 2;
        } else if (totalActiveCompontent >= .8) {
            qualifierIndex = 3;
        } else {
            qualifierIndex = 4;
        }
        qualifierBonus = [1.2, 1.1, 1.05, 1, .9][qualifierIndex];
    }
    for (var i = 0; i < 3; i++) {
        if (numberOfActiveComponents == 1) {
            RGB[i] = Math.round(200 * components[i]);
        } else if (numberOfActiveComponents == 2) {
            RGB[i] = Math.round(290 * components[i]);
        } else {
            RGB[i] = Math.round(500 * components[i]);
        }
        if (components[i] >= .3) {
            RGB[i] = Math.min(255, Math.max(0, RGB[i] + [50, 30, 10, -10, -20][qualifierIndex]));
        } else {
            RGB[i] = Math.min(255, Math.max(0, RGB[i] + [0, 10, 20, 40, 60][qualifierIndex]));
        }
    }
    var shapeDefinition = shapeDefinitions[shapeType][0];
    var area = shapeDefinition.area;
    var jewel = {
        'tier': tier,
        'shapeType': shapeType,
        'components': components,
        'componentBonuses': componentBonuses,
        'qualifierName': ['Perfect', 'Brilliant', 'Shining', '', 'Dull'][qualifierIndex],
        'qualifierBonus': qualifierBonus,
        'jewelType': jewelType,
        'quality': quality,
        'shape': makeShape(0, 0, 0, shapeDefinition).scale(30),
        'area': area,
        'price': Math.round(Math.pow(10, tier) * quality * quality * (5 - qualifierIndex) * area),
        'adjacentJewels': [],
        'adjacencyBonuses': {}
    };
    var typeIndex = 0;
    jewel.shape.color = arrayToCssRGB(RGB);
    jewel.canvas = createCanvas(68, 68);
    jewel.context = jewel.canvas.getContext("2d");
    // Jewels can be displayed in 3 different states:
    // Drawn directly inside of the canvas for a character's jewel board.
    // Drawn on the jewel.$canvas canvas while being dragged by the user.
    // Drawn on the jewel.$canvas canvas while it is inside jewel.$item and
    // being displayed in grid in the jewel-inventory panel.
    jewel.$canvas = $(jewel.canvas);
    jewel.$canvas.data('jewel', jewel);
    jewel.$item = $tag('div', 'js-jewel jewel').append(jewel.canvas);
    jewel.$item.data('jewel', jewel);
    jewel.character = null;
    updateJewel(jewel);
    return jewel;
}
function clearAdjacentJewels(jewel) {
    while (jewel.adjacentJewels.length) {
        var adjacentJewel = jewel.adjacentJewels.pop();
        var jewelIndex = adjacentJewel.adjacentJewels.indexOf(jewel);
        if (jewelIndex >= 0) {
            adjacentJewel.adjacentJewels.splice(jewelIndex, 1);
        }
        updateAdjacencyBonsues(adjacentJewel);
    }
}
function updateAdjacentJewels(jewel) {
    clearAdjacentJewels(jewel);
    if (!jewel.character) {
        return;
    }
    var jewels = jewel.character.board.jewels.concat(jewel.character.board.fixed);
    for (var i = 0; i < jewels.length; i++) {
        if (jewels[i] === jewel) continue;
        var count = 0;
        for (var j = 0; j < jewel.shape.points.length && count < 2; j++) {
            if (isPointInPoints(jewel.shape.points[j], jewels[i].shape.points)) {
                count++
            }
        }
        if (count < 2) {
            count = 0;
            for (var j = 0; j < jewels[i].shape.points.length && count < 2; j++) {
                if (isPointInPoints(jewels[i].shape.points[j], jewel.shape.points)) {
                    count++
                }
            }
        }
        if (count == 2) {
            jewel.adjacentJewels.push(jewels[i]);
            jewels[i].adjacentJewels.push(jewel);
            updateAdjacencyBonsues(jewels[i]);
        }
    }
    updateAdjacencyBonsues(jewel);
    removeToolTip();
}
function updateAdjacencyBonsues(jewel) {
    jewel.adjacencyBonuses = {};
    if (jewel.fixed) {
        return;
    }
    var matches = 0;
    var typesSeen = {};
    typesSeen[jewel.jewelType] = true;
    var uniqueTypes = 0;
    var shapeDefinition = shapeDefinitions[jewel.shapeType][0];
    var coefficient = jewel.quality * shapeDefinition.area;
    // Pure gems qualifier bonus is applied to their own adjacency bonuses
    if (jewel.jewelType === 1 || jewel.jewelType === 2 || jewel.jewelType === 4) {
        coefficient *= jewel.qualifierBonus;
    }
    var adjacentQualifierBonus = 1;
    for (var i = 0; i < jewel.adjacentJewels.length; i++) {
        var adjacent = jewel.adjacentJewels[i];
        if (adjacent.jewelType === jewel.jewelType) {
            matches++;
        }
        if (!typesSeen[adjacent.jewelType]) {
            typesSeen[adjacent.jewelType] = true;
            uniqueTypes++;
        }
        // Dual gems qualifier bonus is applied to adjacent gems' adjacency bonuses
        if (adjacent.jewelType === 3 || adjacent.jewelType === 5 || adjacent.jewelType === 6) {
            // These are additive, otherwise they could result in 3x multiplier on hexagons.
            adjacentQualifierBonus += (adjacent.qualifierBonus - 1);
        }
    }
    coefficient *= adjacentQualifierBonus;
    var resonanceBonus = coefficient * [0, 1, 2, 3, 5, 8, 13, 21, 34][matches];
    var contrastBonus = coefficient * [0, 1, 2, 3, 5, 8, 13, 21, 34][uniqueTypes];
    switch(jewel.jewelType) {
        case 1:
            jewel.adjacencyBonuses['%maxHealth'] = resonanceBonus / 100;
            jewel.adjacencyBonuses['%damage'] = contrastBonus / 100;
            break;
        case 2:
            jewel.adjacencyBonuses['%evasion'] = resonanceBonus / 100;
            jewel.adjacencyBonuses['%attackSpeed'] = contrastBonus / 100;
            break;
        case 4:
            jewel.adjacencyBonuses['%block'] = resonanceBonus / 100;
            jewel.adjacencyBonuses['%accuracy'] = contrastBonus / 100;
            break;
        case 3:
            jewel.adjacencyBonuses['%critChance'] = resonanceBonus / 100;
            jewel.adjacencyBonuses['+critDamage'] = contrastBonus / 100;
            break;
        case 5:
            jewel.adjacencyBonuses['+healthRegen'] = resonanceBonus / 10;
            jewel.adjacencyBonuses['+healthGainOnHit'] = contrastBonus / 10;
{'fraction_non_alphanumeric': 0.1308546900643858, 'fraction_numerical': 0.024239363716702437, 'mean_word_length': 2.2978767693588678, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '438518', 'n_tokens_mistral': 5348, 'n_tokens_neox': 4984, 'n_words': 1175}