Widget:Cooking Calculator

RLQ.push(function {  var maxIngredients = 8;  var statsMultiplier = 5;

// [0]: health, [1]: stamina, [2]:food, [3]: water, [4]: weight // for new entries: use the original values from the devkit // Ingredient * Increase Per Quantity in PrimalItemConsumable_Something var cookingStats = { 'Raw Meat/Fish': [0.11, 0.01, 0.15, 0.01, 0.02], 'Raw Prime Meat/Fish/Mutton': [0.24, 0.01, 0.2, 0.01, 0.02], 'Cooked Meat/Jerky/Fish': [0.11, 0.01, 0.2, 0.01, 0.02], 'Cooked Prime Meat/Jerky/Fish/Lamb Chop': [0.33, 0.01, 0.29, 0.01, 0.02], 'Amar/Azul/Tintoberry': [0.01, 0.01, 0.0375, 0.025, 0.01], 'Cactus Sap': [0.01, 0.01, 0.0375, 0.025, 0.01], 'Mejoberry': [0.01, 0.01, 0.0525, 0.035, 0.01], 'Narcoberry': [0.01, -0.1, 0.1, 0.01, 0.01], 'Stimberry': [0.01, 0.125, 0.0375, -0.25, 0.01], 'Seed': [0.01, 0.01, 0.01, 0.01, 0.01], 'Advanced Crops': [0.055, 0.01, 0.06, 0.5, 0.02], 'Rare Mushroom': [0.01, 1, 0.01, 0.01, 0.01], 'Rare Flower': [0.01, 0.01, 0.01, 0.01, 1], 'Egg': [0.8, 0.8, 0.8, 0.01, 0.3], 'Kibble': [0.01, 3, 2.25, -1, 0.05], 'Sweet Vegetable Cake': [0.1, 0.01, 0.1, 0.01, 0.02], 'Spoiled Meat': [-0.5, -0.3, 0.0625, 0.01, 0.02], 'Human Feces': [-0.125, -0.125, 0.1, -0.125, 0.01], 'Small Feces': [-0.05, -0.05, 0, -0.05, 0.01], 'Medium Feces': [-0.1, -0.1, 0.1, -0.1, 0.01], 'Large/Massive Feces': [-0.15, -0.15, 0.1, -0.15, 0.01], 'Soap': [-0.05, -0.05, 0.1, -0.05, 0.01], 'Organic Polymer': [-0.5, -0.5, 0.1, -0.5, 0.01] };

$('.cookingCalc').each(function {     var $cookingCalcIngredient = $(this).find('.cookingCalcIngredient');

if ($cookingCalcIngredient.length == 1) { var $select = $cookingCalcIngredient.find('select'); for (var ingredient in cookingStats) { if (cookingStats.hasOwnProperty(ingredient)) { $select.append($(' ').text(ingredient)); }       }

for (var i = 1; i < maxIngredients; i++) { $cookingCalcIngredient.clone.insertAfter($cookingCalcIngredient); }

$(this).find('.cookingCalcIngredient').each(function(index) {           $(this).find('select')[0].selectedIndex = index;            $(this).find('input').val(0);          }); }   });

$('.cookingCalcInput').on('change', 'input,select', cookingCalc); $('.cookingCalcOutput').on('change', 'input', cookingCalcChangeKind);

function cookingCalcChangeKind { var kind = this.value; $('#cookingCalcFood').css('text-decoration', kind === 'food' ? '' : 'line-through'); $('#cookingCalcWater').css('text-decoration', kind === 'drink' ? '' : 'line-through'); }

function cookingCalc { var results = { health: 1, stamina: 1, food: 1, water: 1, weight: 0.1 };

var craftingSpeed = $('#cookingCalcCraftingSpeed').val / 100;

$('.cookingCalcIngredient').each(function {      var $this = $(this);      var ingredient = $this.find('select').val;      var amount = parseInt($this.find('input').val) || 0;

if (cookingStats[ingredient] && amount) { results.health += amount * cookingStats[ingredient][0] * statsMultiplier * (craftingSpeed * 1.5625 - 0.3125); results.stamina += amount * cookingStats[ingredient][1] * statsMultiplier * (craftingSpeed * 1.5625 - 0.3125); results.food += amount * cookingStats[ingredient][2] * statsMultiplier * (craftingSpeed * 1.5625 - 0.3125); results.water += amount * cookingStats[ingredient][3] * statsMultiplier * (craftingSpeed * 1.5625 - 0.3125); results.weight += amount * cookingStats[ingredient][4]; }   });    $('#cookingCalcHealth').text(results.health.toFixed(2));    $('#cookingCalcStamina').text(results.stamina.toFixed(2));    $('#cookingCalcFood').text(results.food.toFixed(2));    $('#cookingCalcWater').text(results.water.toFixed(2));    $('#cookingCalcWeight').text(results.weight.toFixed(2));  } });