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



WIKI - Idle Pixel

MediaWiki:Common.js: Difference between revisions

m (Fixed typo)
m (Added some console.log to debug)
Line 72: Line 72:
if (document.getElementById('compareSelect2')) {
if (document.getElementById('compareSelect2')) {
document.getElementById('compareSelect2').innerHTML = addSelects(2)
document.getElementById('compareSelect2').innerHTML = addSelects(2)
console.log('Compare Select loaded');
}
}
if (document.getElementById('updateLogs')) {
if (document.getElementById('updateLogs')) {
Line 81: Line 82:
).then( function () {
).then( function () {
     hljs.highlightAll();
     hljs.highlightAll();
console.log('Code highlighted');
});
});
mw.loader.getScript(
mw.loader.getScript(
Line 103: Line 105:
})
})
}
}
console.log('Tabby loaded')
});
});
window.addEventListener("load", function() {
window.addEventListener("load", function() {
Line 118: Line 121:
});
});
})
})
console.log('hitChange listeners added')
}
}
console.log('Page loaded')
});
});



Revision as of 18:07, 2 August 2024

var weaponDPS = {
    WithoutWeapon: [0,0.125,0.375,0.750,1.250,1.875,2.625,3.125],
    WoodenSword: [0.125,0.250,0.500,0.875,1.375,2.000,2.750,3.250],
    Stinger: [0.250,0.375,0.625,1.000,1.500,2.125,2.875,3.375],
    PoisonStinger: [0.333,0.458,0.708,1.083,1.583,2.208,2.958,3.458],
    IronDagger: [0.333,0.500,0.833,1.333,2.000,2.833,3.833,4.500],
    SkeletonSword: [0.625,0.750,1.000,1.375,1.875,2.500,3.250,3.750],
    Club: [0.667,0.750,0.917,1.167,1.500,1.917,2.417,2.750],
    SpikedClub: [1.000,1.083,1.250,1.500,1.833,2.250,2.750,3.083],
    Scythe: [1.000,1.125,1.375,1.750,2.250,2.875,3.625,4.125],
    ScythePlus: [1.000,1.125,1.375,1.750,2.250,2.875,3.625,4.125],
    StingerDagger: [0.375,0.563,0.938,1.500,2.250,3.188,4.313,5.063],
    PoisonStingerDagger: [0.708,0.896,1.271,1.833,2.583,3.521,4.646,5.396],
	BattleAxe: [0.875,1.000,1.250,1.625,2.125,2.750,3.500,4.000],
	LongSpear: [0.583,0.667,0.833,1.083,1.417,1.833,2.333,2.667],
	Trident: [0.875,1.000,1.250,1.625,2.125,2.750,3.500,4.000],
	LongTrident: [0.875,1.000,1.250,1.625,2.125,2.750,3.500,4.000],
    Rapier: [1.500,1.625,1.875,2.250,2.750,3.375,4.125,4.625],
    PoisonRapier: [1.917,2.042,2.292,2.667,3.167,3.792,4.542,5.042],
    DenseClub: [1.667,1.750,1.917,2.167,2.500,2.917,3.417,3.750],
    SpikedDenseClub: [2.500,2.583,2.750,3.000,3.333,3.750,4.250,4.583],
    GoldenRapier: [2.000,2.167,2.500,3.000,3.667,4.500,5.500,6.167],
    PoisonGoldenRapier: [2.778,2.944,3.278,3.778,4.444,5.278,6.278,6.944],
    Ballista: [1.167,1.333,1.667,2.167,2.833,3.667,4.667,5.333],
    HauntedBow: [0.875,1.000,1.250,1.625,2.125,2.750,3.500,4.000]
}

function compareDPS(value,id) {
	document.getElementById('compareDPST0Row'+id).innerText = Math.round(weaponDPS[value][0] * 100) / 100;
	document.getElementById('compareDPST1Row'+id).innerText = Math.round(weaponDPS[value][1] * 100) / 100;
	document.getElementById('compareDPST2Row'+id).innerText = Math.round(weaponDPS[value][2] * 100) / 100;
	document.getElementById('compareDPST3Row'+id).innerText = Math.round(weaponDPS[value][3] * 100) / 100;
	document.getElementById('compareDPST4Row'+id).innerText = Math.round(weaponDPS[value][4] * 100) / 100;
	document.getElementById('compareDPST5Row'+id).innerText = Math.round(weaponDPS[value][5] * 100) / 100;
	document.getElementById('compareDPST6Row'+id).innerText = Math.round(weaponDPS[value][6] * 100) / 100;
	document.getElementById('compareDPST7Row'+id).innerText = Math.round(weaponDPS[value][7] * 100) / 100;
}

function addSelects(id) {
	return '<select onchange="compareDPS(this.value,'+id+')">\
		<option value="" disabled selected>Weapon '+id+'</option>\
		<option value="WithoutWeapon">Without Weapon</option>\
		<option value="WoodenSword">Wooden Sword</option>\
		<option value="Stinger">Stinger</option>\
		<option value="PoisonStinger">Poison Stinger</option>\
		<option value="IronDagger">Iron Dagger</option>\
		<option value="SkeletonSword">Skeleton Sword</option>\
		<option value="Club">Club</option>\
		<option value="SpikedClub">Spiked Club</option>\
		<option value="Scythe">Scythe</option>\
		<option value="ScythePlus">Scythe+</option>\
		<option value="StingerDagger">Stinger Dagger</option>\
		<option value="PoisonStingerDagger">Poison Stinger Dagger</option>\
		<option value="BattleAxe">Battle Axe</option>\
		<option value="LongSpear">Long Spear</option>\
		<option value="Trident">Trident</option>\
		<option value="LongTrident">Long Trident</option>\
		<option value="Rapier">Rapier</option>\
		<option value="PoisonRapier">Poison Rapier</option>\
		<option value="DenseClub">Dense Club</option>\
		<option value="SpikedDenseClub">Spiked Dense Club</option>\
		<option value="GoldenRapier">Golden Rapier</option>\
		<option value="PoisonGoldenRapier">Poison Golden Rapier</option>\
		<option value="Ballista">Ballista</option>\
		<option value="HauntedBow">Haunted Bow</option>\
	</select>'
}

if (document.getElementById('compareSelect1')) {
	document.getElementById('compareSelect1').innerHTML = addSelects(1)
}
if (document.getElementById('compareSelect2')) {
	document.getElementById('compareSelect2').innerHTML = addSelects(2)
	console.log('Compare Select loaded');
}
if (document.getElementById('updateLogs')) {
	document.getElementById('updateLogs').innerHTML = '<iframe src="https://idle-pixel.com/updatelog/" width="100%" height="600px"></iframe>'
}

mw.loader.getScript(
    'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@latest/build/highlight.min.js'
).then( function () {
    hljs.highlightAll();
	console.log('Code highlighted');
});
mw.loader.getScript(
    'https://cdn.jsdelivr.net/gh/cferdinandi/tabby@12/dist/js/tabby.polyfills.min.js'
).then( function () {
    if (document.querySelector('[id^="dtab"]')) {
		document.querySelectorAll('[id^="dtab"]').forEach(function (data) {
			var ulContent = data.innerText;
			var tabsArray = ulContent.split(',');
			var ulElement = data;
			ulElement.innerHTML = '';
			tabsArray.forEach(function(tab,index) {
				var liElement = document.createElement('li');
				var aElement = document.createElement('a');
				aElement.href = '#' + tab.toLowerCase().replace(/\s+/g, '');
				aElement.textContent = tab;
				if (index == 0) {aElement.setAttribute("data-tabby-default", "")}
				liElement.appendChild(aElement);
				ulElement.appendChild(liElement);
			});
			var tabs = new Tabby('#'+data.id)
		})
	}
	console.log('Tabby loaded')
});
window.addEventListener("load", function() {
	if (document.querySelector('[class="hitChance"]')) {
		Array.prototype.forEach.call(document.getElementsByClassName('hitChance'), function(el) {
			var attacker = el.getAttribute('data-hit') || ''
			document.getElementById('accuracy'+attacker).addEventListener("input", function() {
				hitRateCalc(attacker)
			});
			document.getElementById('defense'+attacker).addEventListener("input", function() {
				hitRateCalc(attacker)
			});
			document.getElementById('darkness'+attacker).addEventListener("change", function() {
				hitRateCalc(attacker)
			});
		})
		console.log('hitChange listeners added')
	}
	console.log('Page loaded')
});

function hitRateCalc(attacker) {
	var defense = document.getElementById("defense" + attacker).value;
	var accuracy = document.getElementById("accuracy" + attacker).value;
	var darkness = document.getElementById("darkness" + attacker).checked;

	var hitChance = 0;

	if (((defense / 2) - accuracy) > 4) {
		hitChance = 1 / (Math.max(1, ((defense / 2) - accuracy)) + 1);
	} else if (((defense / 2) - accuracy) <= 0) {
		hitChance = 1;
	} else {
		hitChance = 1 - (((defense / 2) - accuracy) * 2 / 10);
	}

	var hitChancePercentage = (hitChance * 100).toFixed(2);
	hitChancePercentage = darkness == true ? '50.00' : hitChancePercentage;
	document.getElementById("hitRate" + attacker).innerText = hitChancePercentage;
};