WIP: Add enabling/disabling specific categories #1

Draft
mv wants to merge 1 commits from staging into master
2 changed files with 24 additions and 2 deletions
Showing only changes of commit fceb37d7c3 - Show all commits

View File

@ -1,4 +1,6 @@
<script type="text/javascript" src="./random.js"></script>
<div style="display: flex; flex-wrap: nowrap;">
<div style="margin-right: 12px;">
<select id="perk" style="width: 200px;">
<option class="selection" value="">No perk</option>
<option value="medic">Medic</option>
@ -22,9 +24,21 @@
<option value="kfs">KFS Weapons</option>
</select>
<input type="number" id="numofweapons" style="width: 108px;" placeholder="# of Weapons" min=1 max=3>
<div style="margin-bottom:10px;"></div>
<button style="font-size: 33px" id="random">ROCK AND ROLL<br>MCDONALDS</button>
</div>
<div id="categories">
Categories enabled:<br>
<input type="checkbox" id="melee" name="melee" value="Melee" checked>
<label for="melee"> Melee</label><br>
<input type="checkbox" id="power" name="power" value="Power" checked>
<label for="power"> Power</label><br>
<input type="checkbox" id="speed" name="speed" value="Speed" checked>
<label for="speed"> Speed</label><br>
<input type="checkbox" id="range" name="range" value="Range" checked>
<label for="range"> Range</label><br><br>
</div>
</div>
<br><br>
<table style="width:70%; border : 1px solid #f00;">
<tbody id="tbody">

View File

@ -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]);