Anonymous
×
Create a new article
Write your page title here:
We currently have 895 articles on WIKI - Flat MMO. Type your article name above or click on one of the titles below and start writing!



WIKI - Flat MMO
895Articles

MediaWiki:XpCalculator.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
 1 const LEVELS = [
 2 0,0,108,177,265,380,527,717,956,1254,1622,2068,2605,3245,4000,4885,5913,7100,8464,10022,11794,13799,16060,18599,21442,24614,28145,32063,36400,41191,46470,52277,58652,65637,73279,81625,90728,100642,111424,123135,135841,149611,164516,180634,198047,216840,237105,258938,282440,307721,334893,364077,395399,428994,465003,503577,544871,589054,636300,686794,740732,798320,859775,925326,995213,1069691,1149027,1233503,1323417,1419081,1520824,1628993,1743952,1866086,1995798,2133515,2279683,2434772,2599278,2773721,2958649,3154637,3362289,3582243,3815166,4061762,4322767,4598959,4891153,5200203,5527011,5872521,6237725,6623665,7031436,7462185,7917120,8397507,8904674,9440017,10004999
 3 ];
 4 function init() {
 5     const parentDiv = document.getElementById("xpCalculator");
 6 
 7     const currentLabel = document.createElement("label");
 8     currentLabel.textContent = "Current XP:";
 9     const currentInput = document.createElement("input");
10     currentInput.type = "number";
11     currentInput.id = "currentXp"
12     currentInput.onchange = () => calcLevel();
13     currentLabel.htmlFor = "currentXp";
14     parentDiv.appendChild(currentLabel);
15     parentDiv.appendChild(currentInput);
16 
17     const targetLabel = document.createElement("label");
18     targetLabel.textContent = "Target Level:";
19     const targetInput = document.createElement("input");
20     targetInput.type = "number";
21     targetInput.id = "targetLevel";
22     targetInput.onchange = () => calcLevel();
23     targetLabel.htmlFor = "targetLevel";
24     parentDiv.appendChild(targetLabel);
25     parentDiv.appendChild(targetInput);
26 
27     const actionXpLabel = document.createElement("label");
28     actionXpLabel.textContent = "XP Per Action:";
29     const actionXpInput = document.createElement("input");
30     actionXpInput.type = "number";
31     actionXpInput.id = "xpPerAction";
32     actionXpInput.onchange = () => calcLevel();
33     actionXpLabel.htmlFor = "xpPerAction";
34     parentDiv.appendChild(actionXpLabel);
35     parentDiv.appendChild(actionXpInput);
36 
37     const remainingLabel = document.createElement("label");
38     remainingLabel.textContent = "Remaining XP:";
39     const remainingInput = document.createElement("input");
40     remainingInput.id = "remainingXp"
41     remainingInput.disabled = true;
42     remainingInput.value = 0;
43     remainingLabel.htmlFor = "remainingXp"
44     parentDiv.appendChild(remainingLabel);
45     parentDiv.appendChild(remainingInput);
46 
47     const actionsRequiredLabel = document.createElement("label");
48     actionsRequiredLabel.textContent = "Actions Required:";
49     const actionsRequiredInput = document.createElement("input");
50     actionsRequiredInput.id = "actionsRequired";
51     actionsRequiredInput.disabled = true;
52     actionsRequiredInput.value = 0;
53     actionsRequiredLabel.htmlFor = "actionsRequired";
54     parentDiv.appendChild(actionsRequiredLabel);
55     parentDiv.appendChild(actionsRequiredInput);
56 }
57 function calcLevel() {
58     const targetLevel = parseInt(document.getElementById("targetLevel").value) || 0;
59     const xp = parseInt(document.getElementById("currentXp").value) || 0;
60     const xpPerAction = parseInt(document.getElementById("xpPerAction").value) || 0;
61     const xpRequired = document.getElementById("remainingXp");
62     const actionsRequired = document.getElementById("actionsRequired");
63     let xpRequiredValue = 0;
64     let actionsRequiredValue = 0;
65 
66     const required = LEVELS[targetLevel] - xp;
67     if(required > 0) {
68         xpRequiredValue = required;
69         if (xpPerAction) {
70             actionsRequiredValue = Math.ceil(required / xpPerAction);
71         }
72     }
73 
74     xpRequired.value = xpRequiredValue.toLocaleString("en-US");
75     actionsRequired.value = actionsRequiredValue.toLocaleString("en-US");
76 }
77 
78 init()