MediaWiki:Gadget-stat-calc.js
跳转到导航
跳转到搜索
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
mw.hook('wikipage.content').add(function ($content) {
const tag = $content.find('stat-calc, p:has(stat-calc), .stat-calc').first();
if (!tag.length) return;
// 从页面加载模板 HTML
$.get('/index.php?title=MediaWiki:StatCalcTemplate&action=raw', function (html) {
tag.replaceWith(html);
initStatCalc(); // 计算逻辑
});
});
function initStatCalc() {
function getNatureModifiers(nature) {
const map = {
adamant: [1.1, 1.0, 1.0, 0.9, 1.0],
modest: [0.9, 1.0, 1.0, 1.1, 1.0],
jolly: [1.0, 1.0, 1.0, 0.9, 1.1],
bold: [0.9, 1.1, 1.0, 1.0, 1.0],
calm: [0.9, 1.0, 1.0, 1.0, 1.1],
neutral: [1.0, 1.0, 1.0, 1.0, 1.0]
};
return map[nature] || map.neutral;
}
document.getElementById("calc-btn").addEventListener("click", function () {
const level = parseInt(document.getElementsByName("level2")[0].value);
const iv = parseInt(document.getElementsByName("geti")[0].value);
const evs = document.getElementsByName("ev");
const bases = document.querySelectorAll("._race2");
const results = document.querySelectorAll(".result");
const nature = document.getElementsByName("character")[0].value;
const modifiers = getNatureModifiers(nature);
let totalEV = 0;
for (let i = 0; i < 6; i++) {
const base = parseInt(bases[i].textContent || "0");
const ev = parseInt(evs[i].value || "0");
totalEV += ev;
let stat = 0;
if (i === 0) {
stat = Math.floor(((base * 2 + iv + Math.floor(ev / 4)) * level) / 100 + level + 10);
} else {
stat = Math.floor(((((base * 2 + iv + Math.floor(ev / 4)) * level) / 100) + 5) * modifiers[i - 1]);
}
results[i].textContent = stat;
}
document.getElementById("ev-remaining").textContent = Math.max(510 - totalEV, 0);
});
}
👥 当前在线人数:67