{"size": 3507, "ext": "js", "max_stars_repo_path": "Knight/pug/js/rolls/pj/berserk.js", "max_stars_repo_name": "Zorghts/roll20-character-sheets", "max_stars_repo_stars_event_min_datetime": "2015-01-02T17:02:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T19:32:41.000Z", "max_issues_repo_path": "Knight/pug/js/rolls/pj/berserk.js", "max_issues_repo_name": "9thLevel/roll20-character-sheets", "max_issues_repo_issues_event_min_datetime": "2015-01-04T22:17:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:29:56.000Z", "max_forks_repo_path": "Knight/pug/js/rolls/pj/berserk.js", "max_forks_repo_name": "9thLevel/roll20-character-sheets", "max_forks_repo_forks_event_min_datetime": "2015-01-01T16:21:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T12:50:54.000Z"}
{"max_stars_count": 1104, "max_issues_count": 4560, "max_forks_count": 5009, "avg_line_length": 28.9834710744, "max_line_length": 120, "alphanum_fraction": 0.627031651}
/* eslint-disable camelcase */
/* eslint-disable no-undef */
const berserkIlluminationRoll = ['berserkIlluminationBlaze', 'berserkIlluminationLantern'];

berserkIlluminationRoll.forEach((button) => {
  on(`clicked:${button}`, async (info) => {
    const roll = info.htmlAttributes.value;

    const attributs = [
      'devasterAnatheme',
      'bourreauTenebres',
      'equilibreBalance',
    ];

    if (button === 'berserkIlluminationBlaze') {
      attributs.push(`${button}Dgts`);
      attributs.push(`${button}Violence`);
      attributs.push(`${button}Portee`);
    }

    if (button === 'berserkIlluminationLantern') {
      attributs.push(`${button}Dgts`);
      attributs.push(`${button}Portee`);
    }

    const attrs = await getAttrsAsync(attributs);
    const exec = [];
    exec.push(roll);

    const dgts = attrs[`${button}Dgts`];
    let violence = 0;
    const portee = attrs[`${button}Portee`];
    const devaste = +attrs.devasterAnatheme;
    const bourreau = +attrs.bourreauTenebres;
    const equilibre = +attrs.equilibreBalance;

    if (button === 'berserkIlluminationBlaze') {
      violence = attrs[`${button}Violence`];
      exec.push(`{{violence=[[${violence}]]}}`);
    }

    if (button === 'berserkIlluminationLantern') {
      exec.push(`{{esperance=${i18n_esperance}}}`);
      exec.push(`{{esperanceConditionD=${i18n_esperanceConditionD}}}`);
      exec.push('{{degatsConditionnel=true}}');
    }

    exec.push(`{{degats=[[${dgts}]]}}`);
    exec.push(`{{portee=${i18n_portee} ${portee}}}`);

    if (devaste || bourreau || equilibre) {
      const herauts = [];

      if (devaste) { herauts.push(i18n_devasterAnatheme); }
      if (bourreau) { herauts.push(i18n_bourreauTenebres); }
      if (equilibre) { herauts.push(i18n_equilibrerBalance); }

      exec.push(`{{herauts=${herauts.join(' / ')}}}`);
    }

    // ROLL
    const finalRoll = await startRoll(exec.join(' '));

    const rDegats = finalRoll.results.degats.rolls[0].results;

    let tDegats = finalRoll.results.degats.result;
    let tViolence = 0;

    if (bourreau || equilibre) {
      tDegats = rDegats.reduce((accumulateur, valeurCourante) => {
        let newV = valeurCourante;
        if (newV <= 3) { newV = 4; }

        return accumulateur + newV;
      }, 0);
    }

    if (finalRoll.results.violence !== undefined) {
      const rViolence = finalRoll.results.violence.rolls[0].results;

      tViolence = finalRoll.results.violence.result;

      if (devaste || equilibre) {
        tViolence = rViolence.reduce((accumulateur, valeurCourante) => {
          let newV = valeurCourante;
          if (newV <= 3) { newV = 4; }

          return accumulateur + newV;
        }, 0);
      }
    }

    const computed = {
      degats: tDegats,
      violence: tViolence,
    };

    finishRoll(finalRoll.rollId, computed);
  });
});

const berserkIlluminationRollSimple = ['berserkIlluminationCandle', 'berserkRageSacrificeEspoir', 'berserkRageN3Dgts',
  'berserkRageHostileHumain', 'berserkRageSalopardHumain', 'berserkRagePatronHumain', 'berserkRageBandeHumain',
  'berserkRageHostileAnathème', 'berserkRageSalopardAnathème', 'berserkRagePatronAnathème', 'berserkRageBandeAnathème'];

berserkIlluminationRollSimple.forEach((button) => {
  on(`clicked:${button}`, (info) => {
    const roll = info.htmlAttributes.value;

    const exec = [];
    exec.push(roll);

    startRoll(exec.join(' '), (results) => {
      finishRoll(
        results.rollId,
        {},
      );
    });
  });
});
