User:Cadaei/tamingCalc.js

function prepareTC { // get array of possible and reasonable foods from creatureData.js   importScript('creaturesData.js'); if (creaturesData !== null) { var creatureData = {}, creatureName = ''; // looking for div with class 'taming-calculator var tcContainers = document.getElementsByClassName('taming-calculator'); for (var c = 0, clen = tcContainers.length; c < clen; c++) { // get creature name creatureName = tcContainer.firstChild.firstChild.firstChild.firstChild.getAttribute('creature'); if (creatureName === '') creatureName = document.getElementById('firstHeading').firstChild.innerHMTL; if (creatureName !== null && creaturesData[creatureName] !== null) { creatureData = creaturesData[creatureName]; // create rows for food that this creatures does eat var rowEl = , className = , tableEl = document; for (var i = 0, len = creatureData.eats.length; i < len; i++) { className = 'tc-' + (creatureName + '-' + creatureData.eats[i]).replace(/\W/g, '-').toLowerCase; rowEl = '  ' + ' ' + ' ' + ' '; tcContainers[c].firstChild.innerHTML += rowEl; }           }        }    } }

function tamingCalculation(level, tableEl, creatureName) { // get array of possible and reasonable foods from creatureData.js   importScript('creaturesData.js'); importScript('foodData.js'); if (creaturesData !== null && creatureName == null && creaturesData[creatureName] !== null && foodData !== null) { var creatureData = creaturesData[creatureName]; // how much affinity is needed var affinityNeeded = creatureData.affinityNeeded0 + creatureData.affinityIncrease * level; // how much food/resources of the different kinds that this creature eats is needed var resNeeded = {}, foodValue = 0, className = '', rowEls = []; for (var i = 0, len = creatureData.eats.length; i < len; i++) { resNeeded[creatureData.eats[i]] = {}; // how much of the current food is needed resNeeded[creatureData.eats[i]]['foodNr'] = Math.ceil(affinityNeeded / foodData[creatureData.eats[i]].affinity); // what foodValue does this amount yield foodValue = resNeeded[creatureData.eats[i]]['foodNr'] * foodData[creatureData.eats[i]].foodValue; // what time in s does the creature take to eat this foodValue resNeeded[creatureData.eats[i]]['time'] = foodValue / creatureData.foodDepletionPS;

// print values of needed food in table className = 'tc-' + (creatureName + '-' + creatureData.eats[i]).replace(/\W/g, '-').toLowerCase; // food amount rowEls = tableEl.getElementsByClassName(className); for (var row = 0, rowLen = rowEls.length; row < rowLen; row++) { rowEls[row].innerHTML = creatureData.eats[i] + ': ' + resNeeded[creatureData.eats[i]]['foodNr']; }           // TODO narcoberries and narcotics // print needed time for this food rowEls = tableEl.getElementsByClassName(className + '-time'); for (var row = 0, rowLen = rowEls.length; row < rowLen; row++) { rowEls[row].innerHTML = resNeeded[creatureData.eats[i]]['time']; }       }    } }