diff --git a/static/filterWeapons.js b/static/filterWeapons.js
index 64710e1..58cc41f 100644
--- a/static/filterWeapons.js
+++ b/static/filterWeapons.js
@@ -2,6 +2,7 @@ let selectedWeapon = null; // Store the selected weapon's data
let selectedOperative = null; // Store the selected operative's data
let weapons = []; // This will be populated by the fetched JSON data
let globalModifiers = []; // This will be populated by the fetched JSON data
+let selectedGunTypes = []; // Track selected gun types for filtering
// Function to fetch operatives data from JSON
function fetchOperativesData() {
@@ -91,6 +92,7 @@ function fetchWeaponsData() {
.then(data => {
weapons = data; // Store the fetched data in the global 'weapons' variable
populateWeapons(); // Populate the weapon dropdown once data is loaded
+ createGunTypeCheckboxes(); // Create the gun type checkboxes after loading the weapons
})
.catch(error => console.error('Error fetching weapons data:', error));
}
@@ -144,6 +146,7 @@ function updateWeaponStats(weapon) {
Reload Time
DPS
DPM
+ Average DPS
${weapon.name}
@@ -153,6 +156,7 @@ function updateWeaponStats(weapon) {
${weapon.reload_time.toFixed(2)} seconds
+
`;
@@ -163,22 +167,10 @@ function updateWeaponStats(weapon) {
const magSize = weapon.mag_size;
const reloadTime = weapon.reload_time;
- // Calculate DPS and DPM initially without modifiers
+ // Calculate DPS, DPM, and Average DPS
calculateDPSAndDPM(damage, rpm, magSize, reloadTime);
}
-// Function to calculate DPS and DPM and update the values in the table
-function calculateDPSAndDPM(damage, rpm, magSize, reloadTime) {
- const rps = rpm / 60; // Rounds per second
- let dps = damage * rps;
- const reloadTimeMin = reloadTime / 60;
- let dpm = (magSize * damage) / (reloadTimeMin + (magSize / rpm));
-
- // Update DPS and DPM values in the table
- document.getElementById('dps-value').innerText = dps.toFixed(2);
- document.getElementById('dpm-value').innerText = dpm.toFixed(2);
-}
-
// Function to display the modified weapon's stats in the table format
function updateModifiedWeaponStats(damage, rpm, reloadTime) {
const statsElement = document.getElementById('weapon-stats');
@@ -192,6 +184,7 @@ function updateModifiedWeaponStats(damage, rpm, reloadTime) {
Modified Reload Time
DPS
DPM
+ Average DPS
${selectedWeapon.name}
@@ -201,14 +194,30 @@ function updateModifiedWeaponStats(damage, rpm, reloadTime) {
${reloadTime.toFixed(2)} seconds
+
`;
- // Recalculate and update DPS and DPM values with modifiers applied
+ // Recalculate and update DPS, DPM, and Average DPS
calculateDPSAndDPM(damage, rpm, selectedWeapon.mag_size, reloadTime);
}
+// Function to calculate DPS, DPM, and Average DPS, and update the values in the table
+function calculateDPSAndDPM(damage, rpm, magSize, reloadTime) {
+ const rps = rpm / 60; // Rounds per second
+ let dps = damage * rps;
+ const reloadTimeMin = reloadTime / 60;
+ let dpm = (magSize * damage) / (reloadTimeMin + (magSize / rpm));
+ let averageDPS = dpm / 60; // New Average DPS Calculation
+
+ // Update DPS, DPM, and Average DPS values in the table
+ document.getElementById('dps-value').innerText = dps.toFixed(2);
+ document.getElementById('dpm-value').innerText = dpm.toFixed(2);
+ document.getElementById('average-dps-value').innerText = averageDPS.toFixed(2); // Update the Average DPS in the table
+}
+
+
// Function to fetch and populate modifiers from the JSON file
function fetchModifiers() {
fetch('static/json/modifiers.json') // Adjust the path to your JSON file
@@ -283,7 +292,7 @@ function applyModifiers() {
if (!selectedWeapon) return;
// Base stats
- let baseDamage = selectedWeapon.damage * selectedWeapon.damage_multiplier;
+ let baseDamage = selectedWeapon.damage;
let baseRpm = selectedWeapon.rpm;
let baseReloadTime = selectedWeapon.reload_time;
@@ -398,24 +407,30 @@ function applyModifiers() {
}
});
- // Recalculate with applied modifiers
- let damage = baseDamage * damageModifier.multiplicative;
+ // Step 1: Calculate final damage
+ let damage = baseDamage; // Reset to base damage
+
+ // Step 2: Apply multiplicative damage modifiers
+ damage *= damageModifier.multiplicative;
+
+ // Step 3: Apply additive damage modifiers
damage += damageModifier.additive;
- let rpm = baseRpm * rpmModifier.multiplicative;
- rpm += rpmModifier.additive;
+ // Apply the weapon's damage multiplier (if applicable) last
+ damage *= selectedWeapon.damage_multiplier;
- let reloadTime = baseReloadTime * reloadTimeModifier.multiplicative;
- reloadTime += reloadTimeModifier.additive;
+ // Calculate other modified stats
+ let rpm = baseRpm * rpmModifier.multiplicative + rpmModifier.additive;
+ let reloadTime = baseReloadTime * reloadTimeModifier.multiplicative + reloadTimeModifier.additive;
-// Safeguard: Reload time can not go below 0.1 seconds
+ // Safeguard: Reload time cannot go below 0.1 seconds
if (reloadTime < 0.1) {
reloadTime = 0.1;
}
+ // Calculate and update DPS, DPM, and average DPS
calculateDPSAndDPM(damage, rpm, selectedWeapon.mag_size, reloadTime);
updateModifiedWeaponStats(damage, rpm, reloadTime);
-
}
// Function to apply individual buffs (simplified to avoid mistakes)
@@ -444,18 +459,31 @@ function applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier = null)
}
}
+// Modify the existing filterWeapons function to consider gun type checkboxes
function filterWeapons() {
const input = document.getElementById('weapon-search').value.toLowerCase();
const weaponSelect = document.getElementById('weapon-select');
const options = weaponSelect.getElementsByTagName('option');
+ // Get selected guntype filters
+ const selectedGuntypes = Array.from(document.querySelectorAll('#guntype-filters input:checked'))
+ .map(checkbox => checkbox.value);
+
let firstVisibleOption = null; // Variable to track the first matching option
for (let i = 0; i < options.length; i++) {
const optionText = options[i].textContent || options[i].innerText;
+ const weaponId = parseInt(options[i].value); // Get the weapon ID
+ const weapon = weapons.find(w => w.id === weaponId); // Find the corresponding weapon
- // Check if the option matches the search query
- if (optionText.toLowerCase().indexOf(input) > -1) {
+ if (!weapon) continue; // Skip if the weapon is not found (for safety)
+
+ // Check if the option matches the search query and the selected guntype filters
+ const matchesSearch = optionText.toLowerCase().indexOf(input) > -1;
+ const matchesGuntypes = selectedGuntypes.length === 0 || selectedGuntypes.every(type => weapon.guntype.includes(type));
+
+ // Show or hide options based on both search and guntype filters
+ if (matchesSearch && matchesGuntypes) {
options[i].style.display = ''; // Show matching option
if (!firstVisibleOption) {
firstVisibleOption = options[i]; // Save the first visible option
@@ -503,9 +531,48 @@ function filterOperatives() {
}
}
+// Function to dynamically create gun type checkboxes based on available gun types in the weapon data
+function createGunTypeCheckboxes() {
+ const gunTypeFiltersContainer = document.getElementById('gun-type-filters');
+ gunTypeFiltersContainer.innerHTML = ''; // Clear existing checkboxes
+
+ const gunTypesSet = new Set(); // Use a Set to store unique gun types from the weapon data
+
+ // Extract unique gun types from the weapon data
+ weapons.forEach(weapon => {
+ weapon.guntype.forEach(type => gunTypesSet.add(type)); // Add each gun type to the Set
+ });
+
+ // Create checkboxes for each unique gun type
+ gunTypesSet.forEach(gunType => {
+ const label = document.createElement('label');
+ const input = document.createElement('input');
+ input.type = 'checkbox';
+ input.value = gunType;
+ input.className = 'gun-type-checkbox';
+
+ // Add event listener to filter weapons when checkbox is checked/unchecked
+ input.addEventListener('change', () => {
+ const selectedCheckboxes = Array.from(document.querySelectorAll('.gun-type-checkbox:checked'));
+ selectedGunTypes = selectedCheckboxes.map(checkbox => checkbox.value);
+ filterWeapons(); // Re-filter weapons based on the selected gun types
+ });
+
+ label.appendChild(input);
+ label.appendChild(document.createTextNode(gunType));
+ gunTypeFiltersContainer.appendChild(label);
+ gunTypeFiltersContainer.appendChild(document.createElement('br'));
+ });
+}
+
// Attach event listeners to the search inputs
document.getElementById('weapon-search').addEventListener('keyup', filterWeapons);
document.getElementById('operative-search').addEventListener('keyup', filterOperatives);
+// Add event listeners to the guntype checkboxes
+document.querySelectorAll('#guntype-filters input').forEach(checkbox => {
+ checkbox.addEventListener('change', filterWeapons);
+});
+
// Call the fetch function to load the data and populate the dropdown on page load
fetchWeaponsData();
diff --git a/static/json/data.json b/static/json/data.json
index 87f7165..4fa563a 100644
--- a/static/json/data.json
+++ b/static/json/data.json
@@ -57,7 +57,7 @@
"rpm": 600,
"mag_size": 30,
"reload_time": 2.1,
- "guntype": ["RIFLE", "SOVIET"]
+ "guntype": ["RIFLE", "PRIMARY","SOVIET"]
},
{
"id": 7,
@@ -67,7 +67,7 @@
"rpm": 700,
"mag_size": 30,
"reload_time": 2.4,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 8,
@@ -77,7 +77,7 @@
"rpm": 400,
"mag_size": 24,
"reload_time": 2.6,
- "guntype": "SEMI-AUTO"
+ "guntype": ["RIFLE", "SEMI-AUTO", "PRIMARY"]
},
{
"id": 9,
@@ -87,7 +87,7 @@
"rpm": 670,
"mag_size": 30,
"reload_time": 3.25,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 10,
@@ -97,7 +97,7 @@
"rpm": 700,
"mag_size": 30,
"reload_time": 2.35,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 11,
@@ -107,7 +107,7 @@
"rpm": 60,
"mag_size": 8,
"reload_time": 2.8,
- "guntype": ["SEMI-AUTO", "WW2"]
+ "guntype": ["RIFLE", "SEMI-AUTO", "PRIMARY"]
},
{
"id": 12,
@@ -117,7 +117,7 @@
"rpm": 70,
"mag_size": 12,
"reload_time": 12,
- "guntype": "SHOTGUN"
+ "guntype": ["SHOTGUN", "PRIMARY"]
},
{
"id": 87,
@@ -127,7 +127,7 @@
"rpm": 70,
"mag_size": 12,
"reload_time": 12,
- "guntype": "R870-B"
+ "guntype": ["SHOTGUN", "PRIMARY"]
},
{
"id": 14,
@@ -137,7 +137,7 @@
"rpm": 300,
"mag_size": 7,
"reload_time": 4,
- "guntype": "SHOTGUN"
+ "guntype": ["SHOTGUN", "PRIMARY"]
},
{
"id": 16,
@@ -147,7 +147,7 @@
"rpm": 185,
"mag_size": 8,
"reload_time": 3.5,
- "guntype": "SHOTGUN"
+ "guntype": ["SHOTGUN", "SECONDARY"]
},
{
"id": 18,
@@ -157,7 +157,7 @@
"rpm": 300,
"mag_size": 20,
"reload_time": 2.2,
- "guntype": "SHOTGUN"
+ "guntype": ["SHOTGUN", "PRIMARY"]
},
{
"id": 20,
@@ -167,7 +167,7 @@
"rpm": 900,
"mag_size": 50,
"reload_time": 3,
- "guntype": "SMG"
+ "guntype": ["SMG", "PRIMARY"]
},
{
"id": 21,
@@ -177,7 +177,7 @@
"rpm": 750,
"mag_size": 50,
"reload_time": 2.5,
- "guntype": ["RIFLE", "WW2"]
+ "guntype": ["SMG", "PRIMARY", "WW2"]
},
{
"id": 22,
@@ -197,7 +197,7 @@
"rpm": 1050,
"mag_size": 33,
"reload_time": 2,
- "guntype": "SMG"
+ "guntype": ["SMG", "PRIMARY"]
},
{
"id": 24,
@@ -207,7 +207,7 @@
"rpm": 800,
"mag_size": 30,
"reload_time": 2.1,
- "guntype": "SMG"
+ "guntype": ["SMG", "SECONDARY"]
},
{
"id": 25,
@@ -237,7 +237,7 @@
"rpm": 600,
"mag_size": 25,
"reload_time": 2,
- "guntype": "SMG"
+ "guntype": ["SMG", "SECONDARY"]
},
{
"id": 28,
@@ -267,7 +267,7 @@
"rpm": 550,
"mag_size": 32,
"reload_time": 3,
- "guntype": ["SMG", "WW2"]
+ "guntype": ["SMG", "PRIMARY", "WW2"]
},
{
"id": 31,
@@ -277,7 +277,7 @@
"rpm": 750,
"mag_size": 100,
"reload_time": 5.5,
- "guntype": ["LMG", "SOVIET"]
+ "guntype": ["LMG", "PRIMARY","SOVIET"]
},
{
"id": 32,
@@ -287,7 +287,7 @@
"rpm": 850,
"mag_size": 100,
"reload_time": 6,
- "guntype": "LMG"
+ "guntype": ["LMG", "PRIMARY"]
},
{
"id": 33,
@@ -297,7 +297,7 @@
"rpm": 780,
"mag_size": 125,
"reload_time": 5.5,
- "guntype": "LMG"
+ "guntype": ["LMG", "PRIMARY"]
},
{
"id": 34,
@@ -307,7 +307,7 @@
"rpm": 700,
"mag_size": 50,
"reload_time": 3.25,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 35,
@@ -317,7 +317,7 @@
"rpm": 850,
"mag_size": 125,
"reload_time": 5.5,
- "guntype": "LMG"
+ "guntype": ["LMG", "PRIMARY"]
},
{
"id": 36,
@@ -327,7 +327,7 @@
"rpm": 750,
"mag_size": 50,
"reload_time": 3.25,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 37,
@@ -337,7 +337,7 @@
"rpm": 30,
"mag_size": 5,
"reload_time": 3.5,
- "guntype": "SEMI-AUTO"
+ "guntype": ["RIFLE", "SEMI-AUTO", "PRIMARY"]
},
{
"id": 38,
@@ -347,7 +347,7 @@
"rpm": 800,
"mag_size": 50,
"reload_time": 2.5,
- "guntype": "SMG"
+ "guntype": ["SMG", "PRIMARY"]
},
{
"id": 39,
@@ -357,7 +357,7 @@
"rpm": 900,
"mag_size": 64,
"reload_time": 4,
- "guntype": "SMG"
+ "guntype": ["SMG", "PRIMARY"]
},
{
"id": 40,
@@ -367,7 +367,7 @@
"rpm": 1000,
"mag_size": 50,
"reload_time": 2.45,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 41,
@@ -377,7 +377,7 @@
"rpm": 3000,
"mag_size": 10000000000000000000,
"reload_time": 0,
- "guntype": "SPECIAL"
+ "guntype": ["SPECIAL"]
},
{
"id": 42,
@@ -387,7 +387,7 @@
"rpm": 500,
"mag_size": 650,
"reload_time": 0,
- "guntype": "SPECIAL"
+ "guntype": ["SPECIAL"]
},
{
"id": 43,
@@ -397,7 +397,7 @@
"rpm": 300,
"mag_size": 650,
"reload_time": 0,
- "guntype": "SPECIAL"
+ "guntype": ["SPECIAL"]
},
{
"id": 44,
@@ -407,7 +407,7 @@
"rpm": 650,
"mag_size": 18,
"reload_time": 2,
- "guntype": "PISTOL"
+ "guntype": ["PISTOL"]
},
{
"id": 45,
@@ -417,7 +417,7 @@
"rpm": 550,
"mag_size": 18,
"reload_time": 2,
- "guntype": "PISTOL"
+ "guntype": ["PISTOL"]
},
{
"id": 46,
@@ -427,7 +427,7 @@
"rpm": 225,
"mag_size": 10,
"reload_time": 5,
- "guntype": "SHOTGUN"
+ "guntype": ["SHOTGUN", "PRIMARY"]
},
{
"id": 48,
@@ -437,7 +437,7 @@
"rpm": 550,
"mag_size": 30,
"reload_time": 2.35,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 49,
@@ -447,7 +447,7 @@
"rpm": 600,
"mag_size": 30,
"reload_time": 2.35,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 50,
@@ -457,7 +457,7 @@
"rpm": 600,
"mag_size": 32,
"reload_time": 2.45,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 51,
@@ -467,7 +467,7 @@
"rpm": 650,
"mag_size": 32,
"reload_time": 2.45,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 52,
@@ -477,7 +477,7 @@
"rpm": 625,
"mag_size": 100,
"reload_time": 4.5,
- "guntype": "LMG"
+ "guntype": ["LMG", "PRIMARY"]
},
{
"id": 53,
@@ -487,7 +487,7 @@
"rpm": 700,
"mag_size": 100,
"reload_time": 4.5,
- "guntype": "LMG"
+ "guntype": ["LMG", "PRIMARY"]
},
{
"id": 54,
@@ -497,7 +497,7 @@
"rpm": 800,
"mag_size": 50,
"reload_time": 2.6,
- "guntype": "SMG"
+ "guntype": ["SMG", "PRIMARY"]
},
{
"id": 55,
@@ -507,7 +507,7 @@
"rpm": 550,
"mag_size": 32,
"reload_time": 2.5,
- "guntype": "SMG"
+ "guntype": ["SMG", "PRIMARY", "WW2"]
},
{
"id": 56,
@@ -527,7 +527,7 @@
"rpm": 440,
"mag_size": 18,
"reload_time": 3.5,
- "guntype": "SEMI-AUTO"
+ "guntype": ["RIFLE", "SEMI-AUTO", "PRIMARY"]
},
{
"id": 58,
@@ -537,7 +537,7 @@
"rpm": 540,
"mag_size": 18,
"reload_time": 3.5,
- "guntype": "SEMI-AUTO"
+ "guntype": ["RIFLE", "SEMI-AUTO", "PRIMARY"]
},
{
"id": 59,
@@ -547,7 +547,7 @@
"rpm": 780,
"mag_size": 30,
"reload_time": 2.25,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 60,
@@ -577,7 +577,7 @@
"rpm": 800,
"mag_size": 30,
"reload_time": 1.5,
- "guntype": "SMG"
+ "guntype": ["SMG", "PRIMARY"]
},
{
"id": 63,
@@ -597,7 +597,7 @@
"rpm": 1050,
"mag_size": 30,
"reload_time": 2,
- "guntype": "SMG"
+ "guntype": ["SMG", "PRIMARY"]
},
{
"id": 65,
@@ -607,7 +607,7 @@
"rpm": 850,
"mag_size": 30,
"reload_time": 2,
- "guntype": "SMG"
+ "guntype": ["SMG", "PRIMARY"]
},
{
"id": 66,
@@ -617,7 +617,7 @@
"rpm": 850,
"mag_size": 30,
"reload_time": 2,
- "guntype": "SMG"
+ "guntype": ["SMG", "PRIMARY"]
},
{
"id": 67,
@@ -647,7 +647,7 @@
"rpm": 830,
"mag_size": 30,
"reload_time": 2.5,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 70,
@@ -657,7 +657,7 @@
"rpm": 900,
"mag_size": 30,
"reload_time": 2.5,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 71,
@@ -677,7 +677,7 @@
"rpm": 700,
"mag_size": 30,
"reload_time": 3.25,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 73,
@@ -707,7 +707,7 @@
"rpm": 300,
"mag_size": 10,
"reload_time": 3,
- "guntype": "SEMI-AUTO"
+ "guntype": ["RIFLE", "PRIMARY", "SEMI-AUTO"]
},
{
"id": 76,
@@ -727,7 +727,7 @@
"rpm": 1000,
"mag_size": 71,
"reload_time": 2.5,
- "guntype": ["SMG", "SOVIET"]
+ "guntype": ["SMG", "PRIMARY", "SOVIET"]
},
{
"id": 78,
@@ -737,7 +737,7 @@
"rpm": 690,
"mag_size": 30,
"reload_time": 2.5,
- "guntype": ["RIFLE", "SOVIET"]
+ "guntype": ["RIFLE", "PRIMARY", "SOVIET"]
},
{
"id": 79,
@@ -747,7 +747,7 @@
"rpm": 800,
"mag_size": 64,
"reload_time": 4,
- "guntype": "SMG"
+ "guntype": ["SMG"]
},
{
"id": 80,
@@ -757,7 +757,7 @@
"rpm": 800,
"mag_size": 60,
"reload_time": 4,
- "guntype": "SMG"
+ "guntype": ["SMG"]
},
{
"id": 81,
@@ -767,7 +767,7 @@
"rpm": 800,
"mag_size": 50,
"reload_time": 2.5,
- "guntype": "SMG"
+ "guntype": ["SMG", "PRIMARY"]
},
{
"id": 82,
@@ -777,7 +777,7 @@
"rpm": 400,
"mag_size": 12,
"reload_time": 2.6,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE"]
},
{
"id": 83,
@@ -787,7 +787,7 @@
"rpm": 150,
"mag_size": 8,
"reload_time": 2.2,
- "guntype": "SHOTGUN"
+ "guntype": ["SHOTGUN", "PRIMARY"]
},
{
"id": 84,
@@ -797,7 +797,7 @@
"rpm": 200,
"mag_size": 1000000000000000000000000000000000000000000000000000000000000000,
"reload_time": 0,
- "guntype": "SHOTGUN"
+ "guntype": ["SHOTGUN", "PRIMARY"]
},
{
"id": 85,
@@ -807,7 +807,7 @@
"rpm": 900,
"mag_size": 30,
"reload_time": 4,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
},
{
"id": 86,
@@ -817,6 +817,6 @@
"rpm": 9999,
"mag_size": 999,
"reload_time": 1,
- "guntype": "RIFLE"
+ "guntype": ["RIFLE", "PRIMARY"]
}
]
\ No newline at end of file
diff --git a/templates/calculator.html b/templates/calculator.html
index 74518f2..a148b0d 100644
--- a/templates/calculator.html
+++ b/templates/calculator.html
@@ -77,6 +77,20 @@
Select a Weapon
+
+
+ Primary
+ Secondary
+ WW2
+ Soviet
+ Rifle
+ SMG
+ Shotgun
+ LMG
+ Pistol
+ Special
+
+