From fceb37d7c3506d7518ed0e880262180ed3fecee2 Mon Sep 17 00:00:00 2001 From: mv Date: Mon, 2 Sep 2024 00:38:39 +0300 Subject: [PATCH] Add enabling/disabling specific categories --- index.html | 16 +++++++++++++++- random.js | 10 +++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index bbd668d..67e94a7 100644 --- a/index.html +++ b/index.html @@ -1,4 +1,6 @@ +
+
-
+
+
+ Categories enabled:
+ +
+ +
+ +
+ +

+
+


diff --git a/random.js b/random.js index 695edb5..04419f9 100644 --- a/random.js +++ b/random.js @@ -66,6 +66,12 @@ function getSupportLvlLimit() { } } +function genFromWpnCategories(set) { + var str = ""; + document.querySelectorAll('#categories>[type="checkbox"]:checked').forEach(e=>{str+="|"+e.value}) + return set.filter((e)=>e.category.match(str.slice(1))); +} + function getRandomElement(array) { return array[Math.floor(Math.random() * array.length)]; } @@ -74,6 +80,7 @@ function getRandomWeapons(weaponset, howmany, perk) { var weightmax = (perk == "support" ? getSupportLvlLimit() : 16); var isfirebug = (perk == "firebug" ? true : false); var chosenweapons = []; + var newset = genFromWpnCategories(weaponset); var totalweight = 0; var totalprice = 0; var containsFireAxe = false; @@ -83,7 +90,8 @@ function getRandomWeapons(weaponset, howmany, perk) { i = i + 1; chosenweapons = []; totalweight = 0; - for (let i = 0; i < howmany; i++) { chosenweapons.push(getRandomElement(weaponset)) }; + console.log(newset); + for (let i = 0; i < howmany; i++) { chosenweapons.push(getRandomElement(newset)) }; chosenweapons.forEach(e => { totalweight += e.weight }); if (i < 75000) { if (isfirebug) containsFireAxe = chosenweapons.some(e=>e === vanillaWeapons[1]); -- 2.39.2