Doublexp doubleskill.png Double Exp & Skill: Matar monstros rende o dobro de pontos de experiência. O progresso de skills é duas vezes mais rápido! Doublexp doubleskill.png
Bone Overlord.gif The Roost of the Graveborn Quest Spoiler!
Domine Graveborn: todos os bosses e mecânicas ilustradas!
Saiba mais ➔
Winter Tree.png Winter Update 2025
Acompanhe tudo sobre o Winter Update 2025!
Saiba mais ➔
Stag.gif The Order of the Stag Quest Spoiler!
Conheça Isle of Ada: sua quest, missões secundárias e todos os bosses!
Saiba mais ➔

MediaWiki:Common.js/blessing.js: mudanças entre as edições

De Tibia Wiki - A Enciclopédia do Tibia
Ir para navegação Ir para pesquisar
Karumo
Karumo (discussão | contribs) (Calculadora Blessings by Karumo version 2.6)
Linha 1: Linha 1:
/* Calculadoras - Blessings */
const BLESSINGS = 'Blessings';
$(document).ready(function () {
const BLOCK = 'block';
    $('#calc_blessing').bind("keyup change", function () {
const DESCONTOS = 'Descontos';
        var level = $('#level_blessing').val();
const ENHANCED = 'enhanced';
     
const INPUT = 'input';
if ( level >= 120) {
const INQUISITION = 'inquisition';
        var blessing = 20000;
const KEYDOWN = 'keydown';
var blessing_new = 26000;
const NONE = 'none';
        }else if ( level <= 30){
const PHOENIX_EGG = 'phoenixEgg';
        var blessing = 2000;
const PILGRIMAGE = 'pilgrimage';
var blessing_new = 2600;
const REGULAR = 'regular';
        }else{
const TOTAIS = 'Totais';
        var blessing = (2000 + 200 * (level - 30));
const TWIST_OF_FATE = 'twist';
var blessing_new = (260 * (level - 20));
const ID_BLESSING = {
        }
  cost: 'blessing-cost',
        var blessing_inqui = blessing * 5;
  discount: 'blessing-discount',
var blessing_total = blessing_inqui + (blessing_new * 2);
  levelInput: 'blessing-level-input',
       
  results: 'blessing-results',
          $('#blessing-normal-unitaria-result').text('* Você pagará ' + blessing + ' gps por cada blessings normal.');
  total: 'blessing-total',
          $('#blessing-nova-unitaria-result').text('* Você pagará ' + blessing_new + ' gps por cada blessings aprimorada.');
}


        if (level >= 100){
const BLESSING = {
          var blessing_inqui_com = blessing_inqui + 10000;
  regular: {
          var blessing_total_com = blessing_total + 10000;
    maxLevel: 120,
          $('#blessing-inqui-result').text('* Você pagará ' + blessing_inqui + ' gps por todas blessings normais ou ' + blessing_inqui_com + ' gps caso compre no NPC Henricus (Necessário ter feito a The Inquisition Quest).');
    maxLevelScalingValue: 75,
          $('#blessing-total-result').text('* Caso compre todas blessings normais e aprimoradas você ira pagar '+ blessing_total + ' gps ou pagara ' + blessing_total_com + ' gps caso compre as blessings normais no NPC Henricus como citado anteriormente.');
    maxUnit: 5,
        } else {
    minLevel: 30,
          $('#blessing-inqui-result').text('* Você pagará ' + blessing_inqui + ' gps por todas blessings normais.');
    minLevelScalingValue: 200,
          $('#blessing-total-result').text('* Caso compre todas blessings normais e aprimoradas você ira pagar '+ blessing_total + ' gps.');
    minValue: 2000,
        }
  },
          $('#blessing-normal-unitaria-result').removeClass("hide");
  enhanced: {
          $('#blessing-nova-unitaria-result').removeClass("hide");
    maxLevel: 120,
          $('#blessing-inqui-result').removeClass("hide");
    maxLevelScalingValue: 100,
          $('#blessing-total-result').removeClass("hide");
    maxUnit: 2,
    });
    minLevel: 30,
});
    minLevelScalingValue: 260,
    minValue: 2600,
  },
  twist: {
    maxLevel: 270,
    minLevel: 30,
    minLevelScalingValue: 200,
    minValue: 2000,
  },
  inquisition: {
    minLevel: 100,
    minValue: 88000,
    scalingFactor: 1.1,
  },
};


$(document).ready(function () {
const DISCOUNT = {
    $("#calc_blessing").keydown(function (event) {
  phoenixEgg: 0.1,
        if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || (event.keyCode == 65 && event.ctrlKey === true) || (event.keyCode >= 35 && event.keyCode <= 39)) {
  pilgrimage: {
            return;
    maxUnit: 5,
        } else {
    minValue: 1000,
            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
  },
                event.preventDefault();
};
            }
        }
    });
});


$("#get_level").append('<input name="level_blessing" maxlength="4" id="level_blessing" type="text" size="10" align="center" value="0" onclick="this.value=&#39;&#39;;" onblur="this.value=!this.value?&#39;0&#39;:this.value;" />');
const calcBlessing = (level, type, maxUnit = 1) => {
  const { maxLevel, maxLevelScalingValue, minLevel, minLevelScalingValue, minValue } =
    BLESSING[type];
  const maxValue = minValue + minLevelScalingValue * (maxLevel - minLevel);
 
  switch (type) {
    case ENHANCED:
    case REGULAR:
      switch (true) {
        case level > maxLevel:
          return (maxValue + maxLevelScalingValue * (level - maxLevel)) * maxUnit;
        case level > minLevel:
          return (minValue + minLevelScalingValue * (level - minLevel)) * maxUnit;
      }
    case TWIST_OF_FATE:
      switch (true) {
        case level > maxLevel:
          return maxValue * maxUnit;
        case level > minLevel:
          return (minValue + minLevelScalingValue * (level - minLevel)) * maxUnit;
      }
    default:
      return minValue * maxUnit;
  }
};
 
const calcInquisitionBlessing = (level) => {
  const { maxUnit } = BLESSING.regular;
  const { minLevel, minValue, scalingFactor } = BLESSING.inquisition;
 
  if (level >= minLevel) {
    return Math.round(calcBlessing(level, REGULAR, maxUnit) * scalingFactor);
  }
 
  return minValue * maxUnit;
};
 
const calcDiscountPhoenixEgg = (level) =>
  Math.round(calcBlessing(level, REGULAR) * DISCOUNT.phoenixEgg);
 
const toggleResultsDisplay = (level) => {
  const resultsOutput = document.querySelector(`#${ID_BLESSING.results}`);
 
  if (level === '' || level === 0) {
    resultsOutput.style.display = NONE;
    return;
  }
  resultsOutput.style.display = BLOCK;
};
 
const handleResultsDisplay = (heading, messages, elementId) => {
  const resultsList = messages.map((message) => `<li>${message}</li>`);
  const resultsOutput = document.querySelector(`#${elementId}`);
  resultsOutput.innerHTML = `<p>${heading}:</p><ul>${resultsList.join('')}</ul>`;
};
 
const handleKeyDown = (event) => {
  if (
    event.keyCode === 8 ||
    event.keyCode === 9 ||
    event.keyCode === 13 ||
    event.keyCode === 27 ||
    event.keyCode === 46 ||
    (event.keyCode >= 35 && event.keyCode <= 39) ||
    (event.keyCode === 65 && event.ctrlKey === true)
  ) {
    return;
  }
  if (
    event.shiftKey ||
    ((event.keyCode < 48 || event.keyCode > 57) &&
      (event.keyCode < 96 || event.keyCode > 105))
  ) {
    event.preventDefault();
  }
};
 
const handleInput = (level) => {
  toggleResultsDisplay(level);
 
  const enhancedAll = calcBlessing(level, ENHANCED, BLESSING.enhanced.maxUnit);
  const enhancedUnit = calcBlessing(level, ENHANCED);
  const inquisitionUnit = calcInquisitionBlessing(level);
  const phoenixUnit = calcDiscountPhoenixEgg(level);
  const pilgrimageAll = DISCOUNT.pilgrimage.minValue * DISCOUNT.pilgrimage.maxUnit;
  const pilgrimageUnit = DISCOUNT.pilgrimage.minValue;
  const regularAll = calcBlessing(level, REGULAR, BLESSING.regular.maxUnit);
  const regularUnit = calcBlessing(level, REGULAR);
  const twistUnit = calcBlessing(level, TWIST_OF_FATE);
  const twistPlusEnhanced = twistUnit + enhancedAll;
  const inquisitionPlusEnhanced = inquisitionUnit + enhancedAll;
  const allBlessings = regularAll + enhancedAll;
  const allMinusPhoenix = allBlessings - phoenixUnit;
  const allMinusDiscounts = allMinusPhoenix - pilgrimageAll;
 
  const messageFor = {
    blessing: {
      regular: `Regulares: ${regularUnit.toLocaleString()} gold coins (cada), <b>${regularAll.toLocaleString()} gold coins</b> (total);`,
      enhanced: `Aprimoradas: ${enhancedUnit.toLocaleString()} gold coins (cada), <b>${enhancedAll.toLocaleString()} gold coins</b> (total);`,
      twist: `Twist of Fate (protege as 5 regulares em caso de morte por PvP): <b>${twistUnit.toLocaleString()} gold coins</b>;`,
    },
    discount: {
      phoenixEgg: `Phoenix Egg: <b>${phoenixUnit.toLocaleString()} gold coins</b>;`,
      pilgrimage: `Pilgrimage of Ashes (apenas 1x): ${pilgrimageUnit.toLocaleString()} gold coins (cada), <b>${pilgrimageAll.toLocaleString()} gold coins</b> (total);`,
    },
    total: {
      twistPlusEnhanced: `Twist of Fate + Aprimoradas: <b>${twistPlusEnhanced.toLocaleString()} gold coins</b>;`,
      normal: `Normais (Regulares + Aprimoradas): <b>${allBlessings.toLocaleString()} gold coins</b>;`,
      normalMinusDiscounts: `Normais - descontos: <b>${allMinusPhoenix.toLocaleString()} gold coins</b> (Phoenix Egg), <b>${allMinusDiscounts.toLocaleString()} gold coins</b> (Phoenix Egg + Pilgrimage);`,
    },
  };
 
  if (level >= BLESSING.inquisition.minLevel) {
    messageFor.blessing.inquisition = `Inquisition: (vale pelas 5 regulares): <b>${inquisitionUnit.toLocaleString()} gold coins</b>.`;
    messageFor.total.inquisitionPlusEnhanced = `Inquisition + Aprimoradas: <b>${inquisitionPlusEnhanced.toLocaleString()} gold coins</b>.`;
  }
 
  const messagesForBlessings = Object.values(messageFor.blessing);
  handleResultsDisplay(BLESSINGS, messagesForBlessings, ID_BLESSING.cost);
 
  const messagesForDiscounts = Object.values(messageFor.discount);
  handleResultsDisplay(DESCONTOS, messagesForDiscounts, ID_BLESSING.discount);
 
  const messagesForTotals = Object.values(messageFor.total);
  handleResultsDisplay(TOTAIS, messagesForTotals, ID_BLESSING.total);
};
 
window.onload = () => {
  const levelInput = document.querySelector(`#${ID_BLESSING.levelInput}`);
  toggleResultsDisplay(levelInput.value);
  levelInput.addEventListener(KEYDOWN, (event) => handleKeyDown(event));
  levelInput.addEventListener(INPUT, ({ target: { value } }) => handleInput(value));
};

Edição das 12h36min de 30 de março de 2023

const BLESSINGS = 'Blessings';
const BLOCK = 'block';
const DESCONTOS = 'Descontos';
const ENHANCED = 'enhanced';
const INPUT = 'input';
const INQUISITION = 'inquisition';
const KEYDOWN = 'keydown';
const NONE = 'none';
const PHOENIX_EGG = 'phoenixEgg';
const PILGRIMAGE = 'pilgrimage';
const REGULAR = 'regular';
const TOTAIS = 'Totais';
const TWIST_OF_FATE = 'twist';
const ID_BLESSING = {
  cost: 'blessing-cost',
  discount: 'blessing-discount',
  levelInput: 'blessing-level-input',
  results: 'blessing-results',
  total: 'blessing-total',
}

const BLESSING = {
  regular: {
    maxLevel: 120,
    maxLevelScalingValue: 75,
    maxUnit: 5,
    minLevel: 30,
    minLevelScalingValue: 200,
    minValue: 2000,
  },
  enhanced: {
    maxLevel: 120,
    maxLevelScalingValue: 100,
    maxUnit: 2,
    minLevel: 30,
    minLevelScalingValue: 260,
    minValue: 2600,
  },
  twist: {
    maxLevel: 270,
    minLevel: 30,
    minLevelScalingValue: 200,
    minValue: 2000,
  },
  inquisition: {
    minLevel: 100,
    minValue: 88000,
    scalingFactor: 1.1,
  },
};

const DISCOUNT = {
  phoenixEgg: 0.1,
  pilgrimage: {
    maxUnit: 5,
    minValue: 1000,
  },
};

const calcBlessing = (level, type, maxUnit = 1) => {
  const { maxLevel, maxLevelScalingValue, minLevel, minLevelScalingValue, minValue } =
    BLESSING[type];
  const maxValue = minValue + minLevelScalingValue * (maxLevel - minLevel);

  switch (type) {
    case ENHANCED:
    case REGULAR:
      switch (true) {
        case level > maxLevel:
          return (maxValue + maxLevelScalingValue * (level - maxLevel)) * maxUnit;
        case level > minLevel:
          return (minValue + minLevelScalingValue * (level - minLevel)) * maxUnit;
      }
    case TWIST_OF_FATE:
      switch (true) {
        case level > maxLevel:
          return maxValue * maxUnit;
        case level > minLevel:
          return (minValue + minLevelScalingValue * (level - minLevel)) * maxUnit;
      }
    default:
      return minValue * maxUnit;
  }
};

const calcInquisitionBlessing = (level) => {
  const { maxUnit } = BLESSING.regular;
  const { minLevel, minValue, scalingFactor } = BLESSING.inquisition;

  if (level >= minLevel) {
    return Math.round(calcBlessing(level, REGULAR, maxUnit) * scalingFactor);
  }

  return minValue * maxUnit;
};

const calcDiscountPhoenixEgg = (level) =>
  Math.round(calcBlessing(level, REGULAR) * DISCOUNT.phoenixEgg);

const toggleResultsDisplay = (level) => {
  const resultsOutput = document.querySelector(`#${ID_BLESSING.results}`);

  if (level === '' || level === 0) {
    resultsOutput.style.display = NONE;
    return;
  }
  resultsOutput.style.display = BLOCK;
};

const handleResultsDisplay = (heading, messages, elementId) => {
  const resultsList = messages.map((message) => `<li>${message}</li>`);
  const resultsOutput = document.querySelector(`#${elementId}`);
  resultsOutput.innerHTML = `<p>${heading}:</p><ul>${resultsList.join('')}</ul>`;
};

const handleKeyDown = (event) => {
  if (
    event.keyCode === 8 ||
    event.keyCode === 9 ||
    event.keyCode === 13 ||
    event.keyCode === 27 ||
    event.keyCode === 46 ||
    (event.keyCode >= 35 && event.keyCode <= 39) ||
    (event.keyCode === 65 && event.ctrlKey === true)
  ) {
    return;
  }
  if (
    event.shiftKey ||
    ((event.keyCode < 48 || event.keyCode > 57) &&
      (event.keyCode < 96 || event.keyCode > 105))
  ) {
    event.preventDefault();
  }
};

const handleInput = (level) => {
  toggleResultsDisplay(level);

  const enhancedAll = calcBlessing(level, ENHANCED, BLESSING.enhanced.maxUnit);
  const enhancedUnit = calcBlessing(level, ENHANCED);
  const inquisitionUnit = calcInquisitionBlessing(level);
  const phoenixUnit = calcDiscountPhoenixEgg(level);
  const pilgrimageAll = DISCOUNT.pilgrimage.minValue * DISCOUNT.pilgrimage.maxUnit;
  const pilgrimageUnit = DISCOUNT.pilgrimage.minValue;
  const regularAll = calcBlessing(level, REGULAR, BLESSING.regular.maxUnit);
  const regularUnit = calcBlessing(level, REGULAR);
  const twistUnit = calcBlessing(level, TWIST_OF_FATE);
  const twistPlusEnhanced = twistUnit + enhancedAll;
  const inquisitionPlusEnhanced = inquisitionUnit + enhancedAll;
  const allBlessings = regularAll + enhancedAll;
  const allMinusPhoenix = allBlessings - phoenixUnit;
  const allMinusDiscounts = allMinusPhoenix - pilgrimageAll;

  const messageFor = {
    blessing: {
      regular: `Regulares: ${regularUnit.toLocaleString()} gold coins (cada), <b>${regularAll.toLocaleString()} gold coins</b> (total);`,
      enhanced: `Aprimoradas: ${enhancedUnit.toLocaleString()} gold coins (cada), <b>${enhancedAll.toLocaleString()} gold coins</b> (total);`,
      twist: `Twist of Fate (protege as 5 regulares em caso de morte por PvP): <b>${twistUnit.toLocaleString()} gold coins</b>;`,
    },
    discount: {
      phoenixEgg: `Phoenix Egg: <b>${phoenixUnit.toLocaleString()} gold coins</b>;`,
      pilgrimage: `Pilgrimage of Ashes (apenas 1x): ${pilgrimageUnit.toLocaleString()} gold coins (cada), <b>${pilgrimageAll.toLocaleString()} gold coins</b> (total);`,
    },
    total: {
      twistPlusEnhanced: `Twist of Fate + Aprimoradas: <b>${twistPlusEnhanced.toLocaleString()} gold coins</b>;`,
      normal: `Normais (Regulares + Aprimoradas): <b>${allBlessings.toLocaleString()} gold coins</b>;`,
      normalMinusDiscounts: `Normais - descontos: <b>${allMinusPhoenix.toLocaleString()} gold coins</b> (Phoenix Egg), <b>${allMinusDiscounts.toLocaleString()} gold coins</b> (Phoenix Egg + Pilgrimage);`,
    },
  };

  if (level >= BLESSING.inquisition.minLevel) {
    messageFor.blessing.inquisition = `Inquisition: (vale pelas 5 regulares): <b>${inquisitionUnit.toLocaleString()} gold coins</b>.`;
    messageFor.total.inquisitionPlusEnhanced = `Inquisition + Aprimoradas: <b>${inquisitionPlusEnhanced.toLocaleString()} gold coins</b>.`;
  }

  const messagesForBlessings = Object.values(messageFor.blessing);
  handleResultsDisplay(BLESSINGS, messagesForBlessings, ID_BLESSING.cost);

  const messagesForDiscounts = Object.values(messageFor.discount);
  handleResultsDisplay(DESCONTOS, messagesForDiscounts, ID_BLESSING.discount);

  const messagesForTotals = Object.values(messageFor.total);
  handleResultsDisplay(TOTAIS, messagesForTotals, ID_BLESSING.total);
};

window.onload = () => {
  const levelInput = document.querySelector(`#${ID_BLESSING.levelInput}`);
  toggleResultsDisplay(levelInput.value);
  levelInput.addEventListener(KEYDOWN, (event) => handleKeyDown(event));
  levelInput.addEventListener(INPUT, ({ target: { value } }) => handleInput(value));
};