Initial revision, sent in DMs at 14:26 GMT+3
This commit is contained in:
commit
9a23b922d4
|
@ -0,0 +1,32 @@
|
||||||
|
<script type="text/javascript" src="./random.js"></script>
|
||||||
|
<select id="perk" style="width: 200px;">
|
||||||
|
<option class="selection" value="">Perk select</option>
|
||||||
|
<option value="medic">Medic</option>
|
||||||
|
<option value="support">Support</option>
|
||||||
|
<option value="sharpshooter">Sharpshooter</option>
|
||||||
|
<option value="commando">Commando</option>
|
||||||
|
<option value="berserker">Berserker</option>
|
||||||
|
<option value="firebug">Firebug</option>
|
||||||
|
</select>
|
||||||
|
<button id="rollperk">Roll a perk</button>
|
||||||
|
<div style="margin-bottom:4px;"></div>
|
||||||
|
<select id="set" style="width: 170px;">
|
||||||
|
<option value="vanilla">Vanilla Weapons</option>
|
||||||
|
<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>
|
||||||
|
<br><br>
|
||||||
|
<table style="width:70%; border : 1px solid #f00;">
|
||||||
|
<tbody id="tbody">
|
||||||
|
<tr>
|
||||||
|
<th>Weapon</th>
|
||||||
|
<th>Price</th>
|
||||||
|
<th>Weight</th>
|
||||||
|
<th>Category</th>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
|
@ -0,0 +1,131 @@
|
||||||
|
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"},
|
||||||
|
{name: "Pepper Spray", weight: 1, price: 400, category: "Range"},
|
||||||
|
{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() {
|
||||||
|
return 25; // i wanted to implement support for support lv1 and lv2 but idk what the max weight for those levels are
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRandomElement(array) {
|
||||||
|
return array[Math.floor(Math.random() * array.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRandomWeapons(weaponset, howmany, perk) {
|
||||||
|
var weightmax = (perk == "support" ? getSupportLvlLimit() : 16);
|
||||||
|
var chosenweapons = [];
|
||||||
|
var totalweight = 0;
|
||||||
|
var totalprice = 0;
|
||||||
|
var i = 0;
|
||||||
|
do {
|
||||||
|
i = i + 1;
|
||||||
|
chosenweapons = [];
|
||||||
|
totalweight = 0;
|
||||||
|
for (let i = 0; i < howmany; i++) { chosenweapons.push(getRandomElement(weaponset)) };
|
||||||
|
chosenweapons.forEach(e => { totalweight += e.weight });
|
||||||
|
if (i < 75000) {
|
||||||
|
totalling = !(areDistinct(chosenweapons) && totalweight < weightmax);
|
||||||
|
} 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");
|
||||||
|
|
||||||
|
document.getElementById("rollperk").addEventListener("click", () => {
|
||||||
|
document.getElementById("perk").value = getRandomElement(perks);
|
||||||
|
changePerkAndOrSetFunction();
|
||||||
|
});
|
||||||
|
|
||||||
|
function changePerkAndOrSetFunction() {
|
||||||
|
if (selperk.value == "support") {
|
||||||
|
if (selset.value == "kfs") selnum.max = 7;
|
||||||
|
else selnum.max = 5;
|
||||||
|
} else {
|
||||||
|
if (selset.value == "kfs") selnum.max = 5;
|
||||||
|
else selnum.max = 3;
|
||||||
|
}
|
||||||
|
if (selnum.value > selnum.max) selnum.value = selnum.max;
|
||||||
|
}
|
||||||
|
|
||||||
|
selperk.addEventListener("change", changePerkAndOrSetFunction);
|
||||||
|
selset.addEventListener("change", changePerkAndOrSetFunction);
|
||||||
|
|
||||||
|
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) {
|
||||||
|
document.getElementById("tbody").insertAdjacentHTML('afterend',
|
||||||
|
`<tr class="row"><th colspan="4">Total price: ${randomWeapon.totalprice} | Total weight: ${randomWeapon.totalweight}</td></tr>`);
|
||||||
|
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>`);
|
||||||
|
})
|
||||||
|
} else { alert("shit failed, hit the button again") }
|
||||||
|
})
|
||||||
|
|
||||||
|
}//////////////////////////////////////////////////////////////////////
|
Loading…
Reference in New Issue