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
Lioks
Lioks (discussão | contribs) (Foram revertidas as edições de Lioks (disc) para a última versão por Karumo)
m
Linha 1: Linha 1:
/* Calculadoras - Blessings */
const BLESSINGS_HEADING = 'Blessings';
$(document).ready(function () {
const DISCOUNTS_HEADING = 'Descontos';
    $('#calc_blessing').bind("keyup change", function () {
const TOTALS_HEADING = 'Totais';
        var level = $('#level_blessing').val();
const ENHANCED = 'enhanced';
     
const REGULAR = 'regular';
if ( level >= 120) {
const TWIST_OF_FATE = 'twist';
        var blessing = 20000;
const ID = {
var blessing_new = 26000;
  cost: 'blessing-cost',
        }else if ( level <= 30){
  discount: 'blessing-discount',
        var blessing = 2000;
  levelInput: 'blessing-level-input',
var blessing_new = 2600;
  levelInputWrapper: 'level-input-wrapper',
        }else{
  results: 'blessing-results',
        var blessing = (2000 + 200 * (level - 30));
  total: 'blessing-total',
var blessing_new = (260 * (level - 20));
};
        }
const BLESSING = {
        var blessing_inqui = blessing * 5;
  regular: {
var blessing_total = blessing_inqui + (blessing_new * 2);
    amount: 5,
       
    baseValue: 2000,
          $('#blessing-normal-unitaria-result').text('* Você pagará ' + blessing + ' gps por cada blessings normal.');
    levelCeil: 120,
          $('#blessing-nova-unitaria-result').text('* Você pagará ' + blessing_new + ' gps por cada blessings aprimorada.');
    levelFloor: 30,
    scaleAboveCeil: 75,
    scaleAboveFloor: 200,
  },
  enhanced: {
    amount: 2,
    baseValue: 2600,
    levelCeil: 120,
    levelFloor: 30,
    scaleAboveCeil: 100,
    scaleAboveFloor: 260,
  },
  twist: {
    baseValue: 2000,
    levelCeil: 270,
    levelFloor: 30,
    scaleAboveFloor: 200,
  },
  inquisition: {
    baseValue: 88000,
    levelFloor: 100,
    scaleAboveFloor: 1.1,
  },
};
const DISCOUNT = {
  phoenixEgg: 0.1,
  pilgrimage: {
    amount: 5,
    baseValue: 1000,
  },
};


        if (level >= 100){
const calcNormalBlessingValue = (
          var blessing_inqui_com = blessing_inqui + 10000;
  level,
          var blessing_total_com = blessing_total + 10000;
  baseValue,
          $('#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).');
  levelCeil,
          $('#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.');
  levelFloor,
        } else {
  scaleAboveFloor,
          $('#blessing-inqui-result').text('* Você pagará ' + blessing_inqui + ' gps por todas blessings normais.');
  scaleAboveCeil,
          $('#blessing-total-result').text('* Caso compre todas blessings normais e aprimoradas você ira pagar '+ blessing_total + ' gps.');
  amount
        }
) => {
          $('#blessing-normal-unitaria-result').removeClass("hide");
  const maxValue = baseValue + scaleAboveFloor * (levelCeil - levelFloor);
          $('#blessing-nova-unitaria-result').removeClass("hide");
  return level > levelCeil
          $('#blessing-inqui-result').removeClass("hide");
    ? (maxValue + scaleAboveCeil * (level - levelCeil)) * amount
          $('#blessing-total-result').removeClass("hide");
    : level > levelFloor
     });
    ? (baseValue + scaleAboveFloor * (level - levelFloor)) * amount
});
     : baseValue * amount;
};


$(document).ready(function () {
const calcTwistBlessingValue = (
    $("#calc_blessing").keydown(function (event) {
  level,
        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)) {
  baseValue,
            return;
  levelCeil,
        } else {
  levelFloor,
            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
  scaleAboveFloor,
                event.preventDefault();
  amount
            }
) => {
        }
  const maxValue = baseValue + scaleAboveFloor * (levelCeil - levelFloor);
     });
  return level > levelCeil
});
    ? maxValue * amount
    : level > levelFloor
    ? (baseValue + scaleAboveFloor * (level - levelFloor)) * amount
     : baseValue * amount;
};


$("#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 calcBlessingValue = (level, type, amount = 1) => {
  const { baseValue, levelCeil, levelFloor, scaleAboveFloor, scaleAboveCeil } =
    BLESSING[type];
 
  switch (type) {
    case ENHANCED:
    case REGULAR:
      return calcNormalBlessingValue(
        level,
        baseValue,
        levelCeil,
        levelFloor,
        scaleAboveFloor,
        scaleAboveCeil,
        amount
      );
    case TWIST_OF_FATE:
      return calcTwistBlessingValue(
        level,
        baseValue,
        levelCeil,
        levelFloor,
        scaleAboveFloor,
        amount
      );
    default:
      return baseValue * amount;
  }
};
 
const calcInqBlessingValue = (level) => {
  const { amount } = BLESSING.regular;
  const { baseValue, levelFloor, scaleAboveFloor } = BLESSING.inquisition;
 
  if (level >= levelFloor) {
    return Math.round(calcBlessingValue(level, REGULAR, amount) * scaleAboveFloor);
  }
 
  return baseValue * amount;
};
 
const calcPhxEggDiscount = (level) => {
  return Math.round(calcBlessingValue(level, REGULAR) * DISCOUNT.phoenixEgg);
};
 
const renderLevelInput = () => {
  const levelInputWrapper = document.querySelector(`#${ID.levelInputWrapper}`);
 
  const input = document.createElement('input');
  input.id = 'blessing-level-input';
  input.type = 'text';
  input.name = 'level';
  input.min = '0';
  input.max = '9999';
  input.maxLength = '4';
  input.value = '0';
  input.addEventListener('click', () => (input.value = ''));
  input.addEventListener('blur', () => (input.value = !input.value ? '0' : input.value));
 
  levelInputWrapper.appendChild(input);
};
 
const setResultsVisibility = (level) => {
  const resultsOutput = document.querySelector(`#${ID.results}`);
 
  if (level === '' || level === 0) {
    resultsOutput.style.display = 'none';
    return;
  }
  resultsOutput.style.display = 'block';
};
 
const renderResults = (heading, messages, elementId) => {
  const resultsList = messages.map((message) => `<li>${message}</li>`);
  const resultsOutput = document.querySelector(`#${elementId}`);
  // <h3>${heading}</h3> commented out until we have a proper CSS for it
  resultsOutput.innerHTML = `<b>${heading}</b><ul>${resultsList.join('')}</ul>`;
};
 
const handleKeyDown = (event) => {
  const allowedKeys = [
    'Escape',
    'Tab',
    'ArrowLeft',
    'ArrowRight',
    'Home',
    'End',
    'Backspace',
    'Delete',
  ];
 
  if (!allowedKeys.includes(event.code) && isNaN(parseInt(event.key))) {
    event.preventDefault();
  }
};
 
const handleInput = (level) => {
  setResultsVisibility(level);
 
  const enhancedAll = calcBlessingValue(level, ENHANCED, BLESSING.enhanced.amount);
  const enhancedUnit = calcBlessingValue(level, ENHANCED);
  const inquisitionUnit = calcInqBlessingValue(level);
  const phoenixUnit = calcPhxEggDiscount(level);
  const pilgrimageAll = DISCOUNT.pilgrimage.baseValue * DISCOUNT.pilgrimage.amount;
  const pilgrimageUnit = DISCOUNT.pilgrimage.baseValue;
  const regularAll = calcBlessingValue(level, REGULAR, BLESSING.regular.amount);
  const regularUnit = calcBlessingValue(level, REGULAR);
  const twistUnit = calcBlessingValue(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 resultFor = {
    blessing: {
      regular: [
        // <a href="/wiki/Blessings#Bênçãos_Comuns"><b>Regulares</b></a>  commented out until we have a proper CSS for it
        `<b>Regulares</b> = `,
        `${regularUnit.toLocaleString()} gold coins (cada), `,
        `<b>${regularAll.toLocaleString()} gold coins</b> (total);`,
      ].join(''),
      enhanced: [
        // <a href="/wiki/Blessings#Bênçãos_Melhoradas"><b>Aprimoradas</b></a>  commented out until we have a proper CSS for it
        `<b>Aprimoradas</b> = `,
        `${enhancedUnit.toLocaleString()} gold coins (cada), `,
        `<b>${enhancedAll.toLocaleString()} gold coins</b> (total);`,
      ].join(''),
      twist: [
        // <a href="/wiki/Twist_of_Fate"><b>Twist of Fate</b></a>  commented out until we have a proper CSS for it
        `<b>Twist of Fate</b> <i>(protege as 5 regulares em caso de morte por PvP)</i> = `,
        `<b>${twistUnit.toLocaleString()} gold coins</b>;`,
      ].join(''),
    },
    discount: {
      // <a href="/wiki/Phoenix_Egg"><b>Phoenix Egg</b></a>  commented out until we have a proper CSS for it
      phoenixEgg: `<b>Phoenix Egg</b> = <b>${phoenixUnit.toLocaleString()} gold coins</b>;`,
      pilgrimage: [
        // <a href="/wiki/Pilgrimage_of_Ashes_Quest"><b>Pilgrimage of Ashes</b></a>  commented out until we have a proper CSS for it
        `<b>Pilgrimage of Ashes</b> <i>(apenas 1x)</i> = `,
        `${pilgrimageUnit.toLocaleString()} gold coins (cada), `,
        `<b>${pilgrimageAll.toLocaleString()} gold coins</b> (total);`,
      ].join(''),
    },
    total: {
      twistPlusEnhanced: [
        `<b>Twist of Fate</b> + <b>Aprimoradas</b> = `,
        `<b>${twistPlusEnhanced.toLocaleString()} gold coins</b>;`,
      ].join(''),
      normal: [
        `<b>Normais</b> <i>(regulares + aprimoradas)</i> = `,
        `<b>${allBlessings.toLocaleString()} gold coins</b>;`,
      ].join(''),
      normalMinusDiscounts: [
        `<b>Normais</b> - <b>Descontos</b> = `,
        `${allMinusPhoenix.toLocaleString()} gold coins (phoenix egg), `,
        `<b>${allMinusDiscounts.toLocaleString()} gold coins</b> (phoenix egg e pilgrimage);`,
      ].join(''),
    },
  };
 
  if (level >= BLESSING.inquisition.levelFloor) {
    resultFor.blessing.inquisition = [
      // <a href="/wiki/Blessing_of_the_Inquisition"><b>Inquisition</b></a>  commented out until we have a proper CSS for it
      `<b>Inquisition</b> <i>(vale pelas 5 regulares)</i> = `,
      `<b>${inquisitionUnit.toLocaleString()} gold coins</b>.`,
    ].join('');
    resultFor.total.inquisitionPlusEnhanced = [
      `<b>Inquisition</b> + <b>Aprimoradas</b> = `,
      `<b>${inquisitionPlusEnhanced.toLocaleString()} gold coins</b>.`,
    ].join('');
  }
 
  const resultsForBlessings = Object.values(resultFor.blessing);
  renderResults(BLESSINGS_HEADING, resultsForBlessings, ID.cost);
 
  const resultsForDiscounts = Object.values(resultFor.discount);
  renderResults(DISCOUNTS_HEADING, resultsForDiscounts, ID.discount);
 
  const resultsForTotals = Object.values(resultFor.total);
  renderResults(TOTALS_HEADING, resultsForTotals, ID.total);
};
 
window.onload = () => {
  renderLevelInput();
  const levelInput = document.querySelector(`#${ID.levelInput}`);
  levelInput.addEventListener('keydown', (event) => handleKeyDown(event));
  levelInput.addEventListener('input', ({ target: { value } }) => handleInput(value));
};

Edição das 14h22min de 5 de junho de 2023

const BLESSINGS_HEADING = 'Blessings';
const DISCOUNTS_HEADING = 'Descontos';
const TOTALS_HEADING = 'Totais';
const ENHANCED = 'enhanced';
const REGULAR = 'regular';
const TWIST_OF_FATE = 'twist';
const ID = {
  cost: 'blessing-cost',
  discount: 'blessing-discount',
  levelInput: 'blessing-level-input',
  levelInputWrapper: 'level-input-wrapper',
  results: 'blessing-results',
  total: 'blessing-total',
};
const BLESSING = {
  regular: {
    amount: 5,
    baseValue: 2000,
    levelCeil: 120,
    levelFloor: 30,
    scaleAboveCeil: 75,
    scaleAboveFloor: 200,
  },
  enhanced: {
    amount: 2,
    baseValue: 2600,
    levelCeil: 120,
    levelFloor: 30,
    scaleAboveCeil: 100,
    scaleAboveFloor: 260,
  },
  twist: {
    baseValue: 2000,
    levelCeil: 270,
    levelFloor: 30,
    scaleAboveFloor: 200,
  },
  inquisition: {
    baseValue: 88000,
    levelFloor: 100,
    scaleAboveFloor: 1.1,
  },
};
const DISCOUNT = {
  phoenixEgg: 0.1,
  pilgrimage: {
    amount: 5,
    baseValue: 1000,
  },
};

const calcNormalBlessingValue = (
  level,
  baseValue,
  levelCeil,
  levelFloor,
  scaleAboveFloor,
  scaleAboveCeil,
  amount
) => {
  const maxValue = baseValue + scaleAboveFloor * (levelCeil - levelFloor);
  return level > levelCeil
    ? (maxValue + scaleAboveCeil * (level - levelCeil)) * amount
    : level > levelFloor
    ? (baseValue + scaleAboveFloor * (level - levelFloor)) * amount
    : baseValue * amount;
};

const calcTwistBlessingValue = (
  level,
  baseValue,
  levelCeil,
  levelFloor,
  scaleAboveFloor,
  amount
) => {
  const maxValue = baseValue + scaleAboveFloor * (levelCeil - levelFloor);
  return level > levelCeil
    ? maxValue * amount
    : level > levelFloor
    ? (baseValue + scaleAboveFloor * (level - levelFloor)) * amount
    : baseValue * amount;
};

const calcBlessingValue = (level, type, amount = 1) => {
  const { baseValue, levelCeil, levelFloor, scaleAboveFloor, scaleAboveCeil } =
    BLESSING[type];

  switch (type) {
    case ENHANCED:
    case REGULAR:
      return calcNormalBlessingValue(
        level,
        baseValue,
        levelCeil,
        levelFloor,
        scaleAboveFloor,
        scaleAboveCeil,
        amount
      );
    case TWIST_OF_FATE:
      return calcTwistBlessingValue(
        level,
        baseValue,
        levelCeil,
        levelFloor,
        scaleAboveFloor,
        amount
      );
    default:
      return baseValue * amount;
  }
};

const calcInqBlessingValue = (level) => {
  const { amount } = BLESSING.regular;
  const { baseValue, levelFloor, scaleAboveFloor } = BLESSING.inquisition;

  if (level >= levelFloor) {
    return Math.round(calcBlessingValue(level, REGULAR, amount) * scaleAboveFloor);
  }

  return baseValue * amount;
};

const calcPhxEggDiscount = (level) => {
  return Math.round(calcBlessingValue(level, REGULAR) * DISCOUNT.phoenixEgg);
};

const renderLevelInput = () => {
  const levelInputWrapper = document.querySelector(`#${ID.levelInputWrapper}`);

  const input = document.createElement('input');
  input.id = 'blessing-level-input';
  input.type = 'text';
  input.name = 'level';
  input.min = '0';
  input.max = '9999';
  input.maxLength = '4';
  input.value = '0';
  input.addEventListener('click', () => (input.value = ''));
  input.addEventListener('blur', () => (input.value = !input.value ? '0' : input.value));

  levelInputWrapper.appendChild(input);
};

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

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

const renderResults = (heading, messages, elementId) => {
  const resultsList = messages.map((message) => `<li>${message}</li>`);
  const resultsOutput = document.querySelector(`#${elementId}`);
  // <h3>${heading}</h3> commented out until we have a proper CSS for it
  resultsOutput.innerHTML = `<b>${heading}</b><ul>${resultsList.join('')}</ul>`;
};

const handleKeyDown = (event) => {
  const allowedKeys = [
    'Escape',
    'Tab',
    'ArrowLeft',
    'ArrowRight',
    'Home',
    'End',
    'Backspace',
    'Delete',
  ];

  if (!allowedKeys.includes(event.code) && isNaN(parseInt(event.key))) {
    event.preventDefault();
  }
};

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

  const enhancedAll = calcBlessingValue(level, ENHANCED, BLESSING.enhanced.amount);
  const enhancedUnit = calcBlessingValue(level, ENHANCED);
  const inquisitionUnit = calcInqBlessingValue(level);
  const phoenixUnit = calcPhxEggDiscount(level);
  const pilgrimageAll = DISCOUNT.pilgrimage.baseValue * DISCOUNT.pilgrimage.amount;
  const pilgrimageUnit = DISCOUNT.pilgrimage.baseValue;
  const regularAll = calcBlessingValue(level, REGULAR, BLESSING.regular.amount);
  const regularUnit = calcBlessingValue(level, REGULAR);
  const twistUnit = calcBlessingValue(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 resultFor = {
    blessing: {
      regular: [
        // <a href="/wiki/Blessings#Bênçãos_Comuns"><b>Regulares</b></a>  commented out until we have a proper CSS for it
        `<b>Regulares</b> = `,
        `${regularUnit.toLocaleString()} gold coins (cada), `,
        `<b>${regularAll.toLocaleString()} gold coins</b> (total);`,
      ].join(''),
      enhanced: [
        // <a href="/wiki/Blessings#Bênçãos_Melhoradas"><b>Aprimoradas</b></a>  commented out until we have a proper CSS for it
        `<b>Aprimoradas</b> = `,
        `${enhancedUnit.toLocaleString()} gold coins (cada), `,
        `<b>${enhancedAll.toLocaleString()} gold coins</b> (total);`,
      ].join(''),
      twist: [
        // <a href="/wiki/Twist_of_Fate"><b>Twist of Fate</b></a>  commented out until we have a proper CSS for it
        `<b>Twist of Fate</b> <i>(protege as 5 regulares em caso de morte por PvP)</i> = `,
        `<b>${twistUnit.toLocaleString()} gold coins</b>;`,
      ].join(''),
    },
    discount: {
      // <a href="/wiki/Phoenix_Egg"><b>Phoenix Egg</b></a>  commented out until we have a proper CSS for it
      phoenixEgg: `<b>Phoenix Egg</b> = <b>${phoenixUnit.toLocaleString()} gold coins</b>;`,
      pilgrimage: [
        // <a href="/wiki/Pilgrimage_of_Ashes_Quest"><b>Pilgrimage of Ashes</b></a>  commented out until we have a proper CSS for it
        `<b>Pilgrimage of Ashes</b> <i>(apenas 1x)</i> = `,
        `${pilgrimageUnit.toLocaleString()} gold coins (cada), `,
        `<b>${pilgrimageAll.toLocaleString()} gold coins</b> (total);`,
      ].join(''),
    },
    total: {
      twistPlusEnhanced: [
        `<b>Twist of Fate</b> + <b>Aprimoradas</b> = `,
        `<b>${twistPlusEnhanced.toLocaleString()} gold coins</b>;`,
      ].join(''),
      normal: [
        `<b>Normais</b> <i>(regulares + aprimoradas)</i> = `,
        `<b>${allBlessings.toLocaleString()} gold coins</b>;`,
      ].join(''),
      normalMinusDiscounts: [
        `<b>Normais</b> - <b>Descontos</b> = `,
        `${allMinusPhoenix.toLocaleString()} gold coins (phoenix egg), `,
        `<b>${allMinusDiscounts.toLocaleString()} gold coins</b> (phoenix egg e pilgrimage);`,
      ].join(''),
    },
  };

  if (level >= BLESSING.inquisition.levelFloor) {
    resultFor.blessing.inquisition = [
      // <a href="/wiki/Blessing_of_the_Inquisition"><b>Inquisition</b></a>  commented out until we have a proper CSS for it
      `<b>Inquisition</b> <i>(vale pelas 5 regulares)</i> = `,
      `<b>${inquisitionUnit.toLocaleString()} gold coins</b>.`,
    ].join('');
    resultFor.total.inquisitionPlusEnhanced = [
      `<b>Inquisition</b> + <b>Aprimoradas</b> = `,
      `<b>${inquisitionPlusEnhanced.toLocaleString()} gold coins</b>.`,
    ].join('');
  }

  const resultsForBlessings = Object.values(resultFor.blessing);
  renderResults(BLESSINGS_HEADING, resultsForBlessings, ID.cost);

  const resultsForDiscounts = Object.values(resultFor.discount);
  renderResults(DISCOUNTS_HEADING, resultsForDiscounts, ID.discount);

  const resultsForTotals = Object.values(resultFor.total);
  renderResults(TOTALS_HEADING, resultsForTotals, ID.total);
};

window.onload = () => {
  renderLevelInput();
  const levelInput = document.querySelector(`#${ID.levelInput}`);
  levelInput.addEventListener('keydown', (event) => handleKeyDown(event));
  levelInput.addEventListener('input', ({ target: { value } }) => handleInput(value));
};