MediaWiki:WildCreatureStats.js

De ARK Wiki
Aller à la navigation Aller à la recherche

Dans d’autres langues: EnglishEspañolItaliano日本語PolskiPortuguês do BrasilРусский


Tous changements apportés au fichiers CSS et Javascript doivent être conforme aux règles de design du wiki.


Note : après avoir enregistré vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

  • Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ou Ctrl-R (⌘-R sur un Mac)
  • Google Chrome : appuyez sur Ctrl-Maj-R (⌘-Shift-R sur un Mac)
  • Internet Explorer : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5
  • Opera : allez dans Menu → Settings (Opera → Préférences sur un Mac) et ensuite à Confidentialité & sécurité → Effacer les données d’exploration → Images et fichiers en cache.
arkUsingArticles(['MediaWiki:DataFetch.js'], function() {
  var wildStatCalcDiv = null;
  var stats = null;
  var wildCreatureStats = null;
  var percentiles = null;
  var wildStatCalcStats = {
      'health': 'Santé',
      'stamina': 'Énergie',
      'oxygen': 'Oxygène',
      'food': 'Nourriture',
      'weight': 'Poids',
      'damage': 'Dégâts de mêlée'
  };

var CACHE_EXPIRY_TIME = 72 * 60 * 60;
  var DATA_PAGE_NAME = 'Donnée:Wild creature stat values';
  var DATA_CACHE_ID = 1; // bump if stat data changes and you need it refreshed within the next hour

  if (wildStatCalcDiv = document.getElementById('wildStatCalc')) {
      // if a stat has x levelups, the stat is in the top percentiles[x] %. For 33 or more level, the probability is less than 0.01 %
      percentiles = Array(100.00, 100.00, 100.00, 100.00, 99.99, 99.97, 99.89, 99.67, 99.17, 98.13, 96.23, 93.09, 88.39, 81.93,
                          73.78, 64.28, 53.98, 43.58, 33.76, 25.06, 17.81, 12.11, 7.88, 4.91, 2.92, 1.67, 0.91, 0.48, 0.24, 0.12,
                          0.05, 0.02, 0.01);
      
      // TODO: these notes apply to data, move it into docs when we get an extension with formatting capabilities
      // NOTE: the increase is always given as percentage of the base-stat
      // NOTE: in this tool damage1 is (in most cases) 100 to represent 100% (as it is seen ingame)
      // NOTE: if a creature don't have oxygen (aquatics etc.), just leave these parameter out

      arkLoadDataPages([ DATA_PAGE_NAME ], DATA_CACHE_ID, CACHE_EXPIRY_TIME).then(function (results) {
          wildCreatureStats = results[DATA_PAGE_NAME];
          changeCreature(wildStatCalcDiv.innerHTML);
      });
  }

  function changeCreature(creature) {
      if (wildCreatureStats[creature] == null)
          creature = Object.keys(wildCreatureStats)[0];

      stats = wildCreatureStats[creature];
      var tableRows = '';
      for (var id in wildStatCalcStats) {
          if (stats[id + '1']) {
              var unit = '';
              if (id === 'damage')
                  unit = ' [%]';
              tableRows += '<tr><td><a href="/' + wildStatCalcStats[id] + '">' + wildStatCalcStats[id] + unit + '</a></td><td><input type="number" min="' + stats[id + '1'] + '" max="100000" maxlength="6" step="0.1" value="' + stats[id + '1'] + '" id="wildStatCalc' + id + 'input" style="width:5em"></td><td id="wildStatCalc' + id + '"></td></tr>';
          }
      }
      tableRows += '<tr><td><a href="/fr/Vitesse de déplacement">Vitesse [%]</a></td><td title="Les créatures sauvages ont toujours et seulement 100% de Vitesse">100</td><td id="wildStatCalcSpeed"></td></tr>';
      var creatureSelect = '<select id="wildStatCalcSwitch">';
      //for (var c in wildCreatureStats) {
      //    creatureSelect += '<option' + (c === creature ? ' selected' : '') + '>' + c + '</option>';
      //}
      var list = Object.keys(wildCreatureStats).sort(function (a, b) {
        return a.localeCompare(b);
      })
      list.forEach(function (name) {
        creatureSelect += '<option' + (name === creature ? ' selected' : '') + '>' + name + '</option>';
      });
      creatureSelect += '</select>';
      wildStatCalcDiv.innerHTML = '<table class="wikitable">' +
      '<tr><th colspan="3">' + creatureSelect + ' Niveau <input type="number" min="1" max="100000" maxlength="6" value="1" id="wildStatCalcLevelInput" style="width:5em"></th></tr>' +
      '<tr><th>Attribut</th><th>Valeur</th><th>Niveaux</th></tr>' +
      tableRows +
      '</table>';

      for (var id in wildStatCalcStats) {
          if (stats[id + '1']) {
              document.getElementById('wildStatCalc' + id + 'input').addEventListener('input', calcNatStats);
          }
      }

      var selectElement = document.getElementById('wildStatCalcSwitch');
      selectElement.addEventListener('change', function() {
          changeCreature(selectElement.value);
      });
      document.getElementById('wildStatCalcLevelInput').addEventListener('input', calcNatStats);
      calcNatStats();
  }

  function calcNatStats() {
      // calculate according level
      if (stats) {
          var totallevel = 1; // 1 is first level
          var levels = [];
          var stat = 0;
          var levelEl = null;
          var percentile = '';
          var determinedStatsNr = 0;
          for (var id in wildStatCalcStats) {
              if (stats[id + '1']) {
                  stat = document.getElementById('wildStatCalc' + id + 'input').value;
                  if (stats[id + '1'] && stats[id + 'Inc'] && stat >= stats[id + '1']) {
                      var level = Math.round((stat - stats[id + '1']) / (stats[id + 'Inc'] * stats[id + '1']));
                      levels[id] = level;
                      levelEl = document.getElementById('wildStatCalc' + id);
                      levelEl.innerHTML = level;
                      if (level > 32)
                      percentile = 0.01;
                      else
                      percentile = percentiles[level];
                      levelEl.title = 'Ce niveau est le meilleur des ' + percentile + '% comparé aux créatures sauvages de niveau 120.';
                      totallevel += level;
                      determinedStatsNr++;
                  }
              }
          }
          var levelInput = document.getElementById('wildStatCalcLevelInput').value;
          var speedPrefix = '';
          if (determinedStatsNr < 6)
              speedPrefix = '~';
          if (determinedStatsNr !== 7)
              document.getElementById('wildStatCalcSpeed').innerHTML = speedPrefix + Math.round((levelInput - totallevel) / (7 - determinedStatsNr));
          var hue = 0;
          for (var id in wildStatCalcStats) {
              if (stats[id + '1']) {
                  hue = 0;
                  if (totallevel > 1) {
                      hue = Math.round(120 * levels[id] / 28);
                  }
                  if (hue > 120)
                  hue = 120;
                  document.getElementById('wildStatCalc' + id).parentElement.style.backgroundColor = 'hsl(' + hue + ', 100%, 85%)';
              }
          }
      }
  }
});