2024-08-11 11:14:21 -04:00
|
|
|
var perks = ["medic", "support", "sharpshooter", "commando", "berserker", "firebug"];
|
|
|
|
|
|
|
|
var vanillaWeapons = [
|
|
|
|
{name: "Broken Pipe", weight: 3, price: 133, category: "Melee"},
|
|
|
|
{name: "Fire Axe", weight: 5, price: 200, category: "Melee"},
|
|
|
|
{name: "Chainsaw", weight: 8, price: 666, category: "Melee"},
|
|
|
|
{name: "Drawf Axe", weight: 6, price: 1337, category: "Melee"},
|
|
|
|
|
|
|
|
{name: "Handcannon", weight: 5, price: 266, category: "Power"},
|
|
|
|
{name: "Shotgun", weight: 8, price: 400, category: "Power"},
|
|
|
|
{name: "A Landmine", weight: 10, price: 560, category: "Power"},
|
|
|
|
{name: "Hunting Shotgun", weight: 10, price: 600, category: "Power"},
|
|
|
|
{name: "LAW", weight: 15, price: 800, category: "Power"},
|
|
|
|
|
|
|
|
{name: "Dual 9mms", weight: 4, price: 200, category: "Speed"},
|
|
|
|
{name: "Bullpup", weight: 6, price: 400, category: "Speed"},
|
|
|
|
{name: "FlameThrower", weight: 10, price: 533, category: "Speed"},
|
|
|
|
{name: "Machine Pistol", weight: 4, price: 533, category: "Speed"},
|
|
|
|
|
|
|
|
{name: "Winchester", weight: 6, price: 400, category: "Range"},
|
|
|
|
{name: "Crossbow", weight: 10, price: 533, category: "Range"},
|
|
|
|
]
|
|
|
|
|
|
|
|
var KFSWeapons = [
|
|
|
|
{name: "Hammer", weight: 1, price: 133, category: "Melee"},
|
|
|
|
{name: "Sword", weight: 5, price: 533, category: "Melee"},
|
|
|
|
|
|
|
|
{name: "Taurus Revolver", weight: 5, price: 400, category: "Power"},
|
|
|
|
{name: "Blunderbuss", weight: 10, price: 560, category: "Power"},
|
|
|
|
{name: "A Landmine", weight: 10, price: 560, category: "Power"},
|
|
|
|
{name: "RPG-7", weight: 15, price: 800, category: "Power"},
|
|
|
|
{name: "M202A1", weight: 16, price: 1200, category: "Power"},
|
|
|
|
{name: "Ultimax 100 MK2", weight: 8, price: 1733, category: "Power"},
|
|
|
|
|
|
|
|
{name: "Dual Glock 17s", weight: 4, price: 200, category: "Speed"},
|
|
|
|
{name: "BD3008", weight: 6, price: 400, category: "Speed"},
|
|
|
|
{name: "Molotov", weight: 6, price: 400, category: "Speed"},
|
|
|
|
{name: "MAC M10", weight: 3, price: 600, category: "Speed"},
|
|
|
|
{name: "MP5A", weight: 6, price: 653, category: "Speed"},
|
|
|
|
{name: "Dual MAC M10s", weight: 4, price: 1200, category: "Speed"},
|
|
|
|
|
|
|
|
{name: "Winchester 1873", weight: 6, price: 400, category: "Range"},
|
2024-09-01 17:35:40 -04:00
|
|
|
{name: "Pepper Spray", weight: 6, price: 400, category: "Range"},
|
2024-08-11 11:14:21 -04:00
|
|
|
{name: "MSG-90", weight: 6, price: 1266, category: "Range"},
|
|
|
|
]
|
|
|
|
|
|
|
|
function areDistinct(arr) {
|
|
|
|
let n = arr.length;
|
|
|
|
let s = new Set();
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
s.add(arr[i]);
|
|
|
|
}
|
|
|
|
return (s.size == n);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSupportLvlLimit() {
|
2024-08-11 11:16:54 -04:00
|
|
|
switch (localStorage.getItem("supportlvl")) {
|
|
|
|
case '1':
|
|
|
|
return 21;
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
return 23;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 25;
|
|
|
|
}
|
2024-08-11 11:14:21 -04:00
|
|
|
}
|
|
|
|
|
2024-09-01 17:38:39 -04:00
|
|
|
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)));
|
|
|
|
}
|
|
|
|
|
2024-08-11 11:14:21 -04:00
|
|
|
function getRandomElement(array) {
|
|
|
|
return array[Math.floor(Math.random() * array.length)];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getRandomWeapons(weaponset, howmany, perk) {
|
|
|
|
var weightmax = (perk == "support" ? getSupportLvlLimit() : 16);
|
2024-08-11 11:16:54 -04:00
|
|
|
var isfirebug = (perk == "firebug" ? true : false);
|
2024-08-11 11:14:21 -04:00
|
|
|
var chosenweapons = [];
|
2024-09-01 17:38:39 -04:00
|
|
|
var newset = genFromWpnCategories(weaponset);
|
2024-08-11 11:14:21 -04:00
|
|
|
var totalweight = 0;
|
|
|
|
var totalprice = 0;
|
2024-08-11 11:19:09 -04:00
|
|
|
var containsFireAxe = false;
|
2024-08-11 11:14:21 -04:00
|
|
|
var i = 0;
|
|
|
|
do {
|
2024-08-11 11:19:09 -04:00
|
|
|
containsFireAxe = false;
|
2024-08-11 11:14:21 -04:00
|
|
|
i = i + 1;
|
|
|
|
chosenweapons = [];
|
|
|
|
totalweight = 0;
|
2024-09-01 17:38:39 -04:00
|
|
|
console.log(newset);
|
|
|
|
for (let i = 0; i < howmany; i++) { chosenweapons.push(getRandomElement(newset)) };
|
2024-08-11 11:14:21 -04:00
|
|
|
chosenweapons.forEach(e => { totalweight += e.weight });
|
|
|
|
if (i < 75000) {
|
2024-08-11 11:16:54 -04:00
|
|
|
if (isfirebug) containsFireAxe = chosenweapons.some(e=>e === vanillaWeapons[1]);
|
|
|
|
totalling = !(areDistinct(chosenweapons) && totalweight < weightmax && !containsFireAxe);
|
2024-08-11 11:14:21 -04:00
|
|
|
} else {
|
|
|
|
totalling = false;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
} while (totalling);
|
|
|
|
chosenweapons.forEach(e => { totalprice += e.price });
|
|
|
|
return {chosenweapons, totalweight, totalprice};
|
|
|
|
}
|
|
|
|
|
|
|
|
// webui functions
|
|
|
|
window.onload = function() {///////////////////////////////////////////
|
|
|
|
var selperk = document.getElementById("perk");
|
|
|
|
var selset = document.getElementById("set");
|
|
|
|
var selnum = document.getElementById("numofweapons");
|
2024-08-11 11:16:54 -04:00
|
|
|
var selsuplvl = document.getElementById("supportlvl");
|
|
|
|
var supportlvl = localStorage.getItem("supportlvl");
|
|
|
|
|
|
|
|
if (supportlvl != null) selsuplvl.value = supportlvl;
|
2024-08-11 11:14:21 -04:00
|
|
|
|
|
|
|
document.getElementById("rollperk").addEventListener("click", () => {
|
|
|
|
document.getElementById("perk").value = getRandomElement(perks);
|
|
|
|
changePerkAndOrSetFunction();
|
|
|
|
});
|
|
|
|
|
|
|
|
function changePerkAndOrSetFunction() {
|
|
|
|
if (selperk.value == "support") {
|
2024-08-11 11:16:54 -04:00
|
|
|
if (selset.value == "kfs" && getSupportLvlLimit() == 25) selnum.max = 7;
|
|
|
|
else if (selset.value == "kfs" && getSupportLvlLimit() < 25) selnum.max = 6;
|
|
|
|
else if (getSupportLvlLimit() < 23) selnum.max = 4;
|
2024-08-11 11:14:21 -04:00
|
|
|
else selnum.max = 5;
|
2024-08-11 11:16:54 -04:00
|
|
|
selsuplvl.style.display = "";
|
2024-08-11 11:14:21 -04:00
|
|
|
} else {
|
|
|
|
if (selset.value == "kfs") selnum.max = 5;
|
|
|
|
else selnum.max = 3;
|
2024-08-11 11:16:54 -04:00
|
|
|
selsuplvl.style.display = "none";
|
2024-08-11 11:14:21 -04:00
|
|
|
}
|
|
|
|
if (selnum.value > selnum.max) selnum.value = selnum.max;
|
|
|
|
}
|
|
|
|
|
|
|
|
selperk.addEventListener("change", changePerkAndOrSetFunction);
|
|
|
|
selset.addEventListener("change", changePerkAndOrSetFunction);
|
2024-08-11 11:16:54 -04:00
|
|
|
selsuplvl.addEventListener("change", () => {
|
|
|
|
localStorage.setItem("supportlvl", selsuplvl.value);
|
2024-08-11 11:19:09 -04:00
|
|
|
changePerkAndOrSetFunction();
|
|
|
|
});
|
|
|
|
|
|
|
|
selnum.addEventListener("keyup", () => {
|
|
|
|
if (selnum.value != "") {
|
|
|
|
if (parseInt(selnum.value) < parseInt(selnum.min)) {
|
|
|
|
selnum.value = selnum.min;
|
|
|
|
}
|
|
|
|
if (parseInt(selnum.value) > parseInt(selnum.max)) {
|
|
|
|
selnum.value = selnum.max;
|
|
|
|
}
|
|
|
|
}
|
2024-08-11 11:16:54 -04:00
|
|
|
});
|
2024-08-11 11:14:21 -04:00
|
|
|
|
|
|
|
document.getElementById("random").addEventListener("click", () => {
|
|
|
|
document.querySelectorAll(".row").forEach(e=>{e.remove()});
|
|
|
|
var set = (selset.value == "kfs" ? KFSWeapons : vanillaWeapons)
|
|
|
|
if (selnum.value == 0) selnum.value = 2;
|
|
|
|
var randomWeapon = getRandomWeapons(set, selnum.value, selperk.value)
|
|
|
|
if (Object.keys(randomWeapon) != 0) {
|
|
|
|
randomWeapon.chosenweapons.forEach(e=>{
|
|
|
|
document.getElementById("tbody").insertAdjacentHTML('beforeend', `<tr class="row">
|
|
|
|
<td>${e.name}</td>
|
|
|
|
<td>${e.price}</td>
|
|
|
|
<td>${e.weight}</td>
|
|
|
|
<td>${e.category}</td>
|
|
|
|
</tr>`);
|
|
|
|
})
|
2024-08-11 11:19:09 -04:00
|
|
|
document.getElementById("tbody").insertAdjacentHTML('beforeend',
|
|
|
|
`<tr class="row"><th colspan="4">Total price: ${randomWeapon.totalprice} | Total weight: <b>${randomWeapon.totalweight}</th></tr>`);
|
|
|
|
} else { alert("shit failed, hit the button again or try lowering the number of weapons") }
|
2024-08-11 11:14:21 -04:00
|
|
|
})
|
|
|
|
|
2024-08-11 11:19:09 -04:00
|
|
|
}//////////////////////////////////////////////////////////////////////
|