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



WIKI - Flat MMO
922Articles

MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
Line 55: Line 55:
if (document.querySelector('.hitChance')) {
if (document.querySelector('.hitChance')) {
     document.querySelectorAll(".hitChance").forEach(el => {
     document.querySelectorAll(".hitChance").forEach(el => {
         const [acc, def] = el.innerText.split(",")
         let [acc, def] = el.innerText.split(",")
         el.innerText = "";
         el.innerText = "";
         const accSpan = document.createElement("span");
         const accSpan = document.createElement("span");

Revision as of 07:07, 6 November 2025

 1 /* Any JavaScript here will be loaded for all users on every page load. */
 2 $(document).ready(function () {
 3 console.log("loaded")
 4 	if (document.getElementById("interactiveMap")) {
 5 console.log("map loaded")
 6 		$.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
 7             $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
 8                 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
 9                     $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap.js") + "?action=raw&ctype=text/javascript", function() {
10                     });
11                 });
12             });
13         });
14 	}
15 
16 	if (document.getElementById("wardrobe")) {
17 		$.getScript(mw.util.getUrl("MediaWiki:Wardrobe.js") + "?action=raw&ctype=text/javascript");
18 		console.log("wardrobe loaded")
19 	}
20 
21     if (document.getElementById("mapEditor")) {
22         $.getScript("https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js", function() {
23             $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
24                 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
25                     $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
26                         $.getScript(mw.util.getUrl("MediaWiki:MapEditor.js") + "?action=raw&ctype=text/javascript", function() {
27                         });
28                     });
29                 });
30             });
31         });
32     }
33 if (document.querySelector(".code")) {
34 	$.getScript("../custom/highlight.min.js", ()=>{
35 		document.querySelectorAll(".code").forEach(el=>hljs.highlightElement(el))
36 		console.log('Code highlighted');
37 	});
38 }
39 
40 if (document.getElementById("enemiesDB")) {
41 	$.getScript(mw.util.getUrl("MediaWiki:Update_DB.js") + "?action=raw&ctype=text/javascript");
42 	console.log("DB Updater Loaded")
43 }
44 function hitChance(accuracy, defence) {
45     accuracy = parseInt(accuracy);
46     defence = parseInt(defence);
47     let hitChance = 0;
48     if(accuracy >= defence) {
49         hitChance = 1;
50     } else {
51         hitChance = 1 / (1 + defence - accuracy)
52     }
53     return (hitChance * 100).toFixed(2);
54 }
55 if (document.querySelector('.hitChance')) {
56     document.querySelectorAll(".hitChance").forEach(el => {
57         let [acc, def] = el.innerText.split(",")
58         el.innerText = "";
59         const accSpan = document.createElement("span");
60         const defSpan = document.createElement("span");
61         const hitSpan = document.createElement("span");
62         const accInput = document.createElement("input");
63         const defInput = document.createElement("input");
64         const hitValueSpan = document.createElement("span");
65 
66         accSpan.innerText = "Accuracy:";
67         defSpan.innerText = "Defence:";
68         hitSpan.innerText = "Hit Chance:";
69 
70         accInput.type = "number";
71         defInput.type = "number";
72         accInput.min = 0;
73         defInput.min = 0;
74         if(def !== "0" || def === "-1") {
75             defInput.disabled = true
76             def = 0;
77         }
78         if(acc !== "0" || acc === "-1") {
79             accInput.disabled = true;
80             acc = 0;
81         }
82         accInput.defaultValue = acc;
83         defInput.defaultValue = def;
84         accInput.onchange = function(){
85             hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
86         }
87         defInput.onchange = function(){
88             hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
89         }
90         el.append(accSpan, accInput, defSpan, defInput, hitSpan, hitValueSpan);
91         hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
92     })
93 }
94 
95 });