|
||||||
|
|
|
||||||||||||||||||||||||
MediaWiki:Common.js/blessing.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
| Linha 1: | Linha 1: | ||
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)); | |||
}; | |||
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));
};