Added some more comments and updated code arrangement
This commit is contained in:
+4
-64
@@ -21,30 +21,25 @@ function fetchOperativesData() {
|
|||||||
function populateOperatives(operatives) {
|
function populateOperatives(operatives) {
|
||||||
const select = document.getElementById('operative-select');
|
const select = document.getElementById('operative-select');
|
||||||
select.innerHTML = ""; // Clear any existing options
|
select.innerHTML = ""; // Clear any existing options
|
||||||
|
|
||||||
// Add the placeholder option
|
// Add the placeholder option
|
||||||
const placeholderOption = document.createElement('option');
|
const placeholderOption = document.createElement('option');
|
||||||
placeholderOption.value = ""; // Empty value for the placeholder
|
placeholderOption.value = ""; // Empty value for the placeholder
|
||||||
placeholderOption.text = "Select an operative";
|
placeholderOption.text = "Select an operative";
|
||||||
select.appendChild(placeholderOption); // Add the placeholder option
|
select.appendChild(placeholderOption); // Add the placeholder option
|
||||||
|
|
||||||
operatives.forEach(operative => {
|
operatives.forEach(operative => {
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = operative.id;
|
option.value = operative.id;
|
||||||
option.text = operative.name;
|
option.text = operative.name;
|
||||||
select.appendChild(option);
|
select.appendChild(option);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Attach event listener to detect when an operative is selected
|
// Attach event listener to detect when an operative is selected
|
||||||
select.addEventListener('change', (event) => {
|
select.addEventListener('change', (event) => {
|
||||||
const selectedOperativeId = event.target.value;
|
const selectedOperativeId = event.target.value;
|
||||||
|
|
||||||
// If placeholder is selected, don't proceed
|
// If placeholder is selected, don't proceed
|
||||||
if (!selectedOperativeId) {
|
if (!selectedOperativeId) {
|
||||||
document.getElementById('operative-modifiers').innerHTML = '';
|
document.getElementById('operative-modifiers').innerHTML = '';
|
||||||
return; // Do nothing when the placeholder is selected
|
return; // Do nothing when the placeholder is selected
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedOperative = operatives.find(op => op.id === selectedOperativeId);
|
selectedOperative = operatives.find(op => op.id === selectedOperativeId);
|
||||||
if (selectedOperative) {
|
if (selectedOperative) {
|
||||||
updateOperativeBuffs(selectedOperative); // Update operative modifiers on valid selection
|
updateOperativeBuffs(selectedOperative); // Update operative modifiers on valid selection
|
||||||
@@ -54,11 +49,9 @@ function populateOperatives(operatives) {
|
|||||||
|
|
||||||
function updateOperativeBuffs(operative) {
|
function updateOperativeBuffs(operative) {
|
||||||
const operativeModifiers = operative.modifiers || [];
|
const operativeModifiers = operative.modifiers || [];
|
||||||
|
|
||||||
// Remove previously added operative-specific modifiers
|
// Remove previously added operative-specific modifiers
|
||||||
const operativeSection = document.getElementById('operative-modifiers');
|
const operativeSection = document.getElementById('operative-modifiers');
|
||||||
operativeSection.innerHTML = ''; // Clear existing operative modifiers
|
operativeSection.innerHTML = ''; // Clear existing operative modifiers
|
||||||
|
|
||||||
// If the operative has specific modifiers, show them
|
// If the operative has specific modifiers, show them
|
||||||
if (operativeModifiers.length > 0) {
|
if (operativeModifiers.length > 0) {
|
||||||
operativeModifiers.forEach(mod => {
|
operativeModifiers.forEach(mod => {
|
||||||
@@ -69,25 +62,20 @@ function updateOperativeBuffs(operative) {
|
|||||||
input.value = mod.value;
|
input.value = mod.value;
|
||||||
input.dataset.type = mod.type;
|
input.dataset.type = mod.type;
|
||||||
input.dataset.buffs = mod.buffs ? JSON.stringify(mod.buffs) : ''; // Store buffs if available
|
input.dataset.buffs = mod.buffs ? JSON.stringify(mod.buffs) : ''; // Store buffs if available
|
||||||
|
|
||||||
// Set checkbox to be unchecked by default
|
// Set checkbox to be unchecked by default
|
||||||
input.checked = false;
|
input.checked = false;
|
||||||
|
|
||||||
label.appendChild(input);
|
label.appendChild(input);
|
||||||
label.appendChild(document.createTextNode(mod.label));
|
label.appendChild(document.createTextNode(mod.label));
|
||||||
operativeSection.appendChild(label);
|
operativeSection.appendChild(label);
|
||||||
operativeSection.appendChild(document.createElement('br'));
|
operativeSection.appendChild(document.createElement('br'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that each operative-specific modifier checkbox triggers recalculation when changed
|
// Make sure that each operative-specific modifier checkbox triggers recalculation when changed
|
||||||
operativeSection.addEventListener('change', applyModifiers);
|
operativeSection.addEventListener('change', applyModifiers);
|
||||||
|
|
||||||
// Trigger recalculation once the operative buffs are displayed
|
// Trigger recalculation once the operative buffs are displayed
|
||||||
applyModifiers();
|
applyModifiers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Function to fetch weapons data from JSON
|
// Function to fetch weapons data from JSON
|
||||||
function fetchWeaponsData() {
|
function fetchWeaponsData() {
|
||||||
fetch('static/json/data.json') // Adjust the path to the actual location of your JSON file
|
fetch('static/json/data.json') // Adjust the path to the actual location of your JSON file
|
||||||
@@ -104,13 +92,11 @@ function fetchWeaponsData() {
|
|||||||
function populateWeapons() {
|
function populateWeapons() {
|
||||||
const select = document.getElementById('weapon-select');
|
const select = document.getElementById('weapon-select');
|
||||||
select.innerHTML = ""; // Clear any existing options
|
select.innerHTML = ""; // Clear any existing options
|
||||||
|
|
||||||
// Add the placeholder option
|
// Add the placeholder option
|
||||||
const placeholderOption = document.createElement('option');
|
const placeholderOption = document.createElement('option');
|
||||||
placeholderOption.value = ""; // Empty value for the placeholder
|
placeholderOption.value = ""; // Empty value for the placeholder
|
||||||
placeholderOption.text = "Select a Weapon";
|
placeholderOption.text = "Select a Weapon";
|
||||||
select.appendChild(placeholderOption); // Add the placeholder option
|
select.appendChild(placeholderOption); // Add the placeholder option
|
||||||
|
|
||||||
// Populate with actual weapons
|
// Populate with actual weapons
|
||||||
weapons.forEach(weapon => {
|
weapons.forEach(weapon => {
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
@@ -118,17 +104,14 @@ function populateWeapons() {
|
|||||||
option.text = weapon.name;
|
option.text = weapon.name;
|
||||||
select.appendChild(option);
|
select.appendChild(option);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Attach event listener to detect when a weapon is selected
|
// Attach event listener to detect when a weapon is selected
|
||||||
select.addEventListener('change', (event) => {
|
select.addEventListener('change', (event) => {
|
||||||
const selectedWeaponId = parseInt(event.target.value);
|
const selectedWeaponId = parseInt(event.target.value);
|
||||||
|
|
||||||
// If placeholder is selected, don't proceed
|
// If placeholder is selected, don't proceed
|
||||||
if (!selectedWeaponId) {
|
if (!selectedWeaponId) {
|
||||||
document.getElementById('weapon-stats').innerHTML = '';
|
document.getElementById('weapon-stats').innerHTML = '';
|
||||||
return; // Do nothing when the placeholder is selected
|
return; // Do nothing when the placeholder is selected
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedWeapon = weapons.find(weapon => weapon.id === selectedWeaponId);
|
selectedWeapon = weapons.find(weapon => weapon.id === selectedWeaponId);
|
||||||
if (selectedWeapon) {
|
if (selectedWeapon) {
|
||||||
updateWeaponStats(selectedWeapon); // Update stats on valid selection
|
updateWeaponStats(selectedWeapon); // Update stats on valid selection
|
||||||
@@ -164,13 +147,11 @@ function updateWeaponStats(weapon) {
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Store values for further calculations
|
// Store values for further calculations
|
||||||
const damage = weapon.damage * weapon.damage_multiplier;
|
const damage = weapon.damage * weapon.damage_multiplier;
|
||||||
const rpm = weapon.rpm;
|
const rpm = weapon.rpm;
|
||||||
const magSize = weapon.mag_size;
|
const magSize = weapon.mag_size;
|
||||||
const reloadTime = weapon.reload_time;
|
const reloadTime = weapon.reload_time;
|
||||||
|
|
||||||
// Calculate DPS, DPM, and Average DPS
|
// Calculate DPS, DPM, and Average DPS
|
||||||
calculateDPSAndDPM(damage, rpm, magSize, reloadTime);
|
calculateDPSAndDPM(damage, rpm, magSize, reloadTime);
|
||||||
}
|
}
|
||||||
@@ -202,7 +183,6 @@ function updateModifiedWeaponStats(damage, rpm, reloadTime) {
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Recalculate and update DPS, DPM, and Average DPS
|
// Recalculate and update DPS, DPM, and Average DPS
|
||||||
calculateDPSAndDPM(damage, rpm, selectedWeapon.mag_size, reloadTime);
|
calculateDPSAndDPM(damage, rpm, selectedWeapon.mag_size, reloadTime);
|
||||||
}
|
}
|
||||||
@@ -214,14 +194,12 @@ function calculateDPSAndDPM(damage, rpm, magSize, reloadTime) {
|
|||||||
const reloadTimeMin = reloadTime / 60;
|
const reloadTimeMin = reloadTime / 60;
|
||||||
let dpm = (magSize * damage) / (reloadTimeMin + (magSize / rpm));
|
let dpm = (magSize * damage) / (reloadTimeMin + (magSize / rpm));
|
||||||
let averageDPS = dpm / 60; // New Average DPS Calculation
|
let averageDPS = dpm / 60; // New Average DPS Calculation
|
||||||
|
|
||||||
// Update DPS, DPM, and Average DPS values in the table
|
// Update DPS, DPM, and Average DPS values in the table
|
||||||
document.getElementById('dps-value').innerText = dps.toFixed(2);
|
document.getElementById('dps-value').innerText = dps.toFixed(2);
|
||||||
document.getElementById('dpm-value').innerText = dpm.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
|
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 to fetch and populate modifiers from the JSON file
|
||||||
function fetchModifiers() {
|
function fetchModifiers() {
|
||||||
fetch('static/json/modifiers.json') // Adjust the path to your JSON file
|
fetch('static/json/modifiers.json') // Adjust the path to your JSON file
|
||||||
@@ -237,22 +215,18 @@ function fetchModifiers() {
|
|||||||
function populateModifiers(modifiers) {
|
function populateModifiers(modifiers) {
|
||||||
const modifiersContainer = document.getElementById('modifiers-container');
|
const modifiersContainer = document.getElementById('modifiers-container');
|
||||||
modifiersContainer.innerHTML = ''; // Clear existing modifiers
|
modifiersContainer.innerHTML = ''; // Clear existing modifiers
|
||||||
|
|
||||||
const createModifierSection = (title, modifierList, sectionId) => {
|
const createModifierSection = (title, modifierList, sectionId) => {
|
||||||
const section = document.createElement('div');
|
const section = document.createElement('div');
|
||||||
section.id = sectionId; // Set an ID for the section
|
section.id = sectionId; // Set an ID for the section
|
||||||
section.className = sectionId === 'abilities' ? 'abilities' : ''; // Only for abilities
|
section.className = sectionId === 'abilities' ? 'abilities' : ''; // Only for abilities
|
||||||
|
|
||||||
const header = document.createElement('h3');
|
const header = document.createElement('h3');
|
||||||
header.textContent = title;
|
header.textContent = title;
|
||||||
section.appendChild(header);
|
section.appendChild(header);
|
||||||
|
|
||||||
modifierList.forEach(mod => {
|
modifierList.forEach(mod => {
|
||||||
const label = document.createElement('label');
|
const label = document.createElement('label');
|
||||||
const input = document.createElement('input');
|
const input = document.createElement('input');
|
||||||
input.type = 'checkbox';
|
input.type = 'checkbox';
|
||||||
input.id = mod.id;
|
input.id = mod.id;
|
||||||
|
|
||||||
// Check if the modifier has multiple buffs
|
// Check if the modifier has multiple buffs
|
||||||
if (mod.buffs) {
|
if (mod.buffs) {
|
||||||
input.dataset.buffs = JSON.stringify(mod.buffs);
|
input.dataset.buffs = JSON.stringify(mod.buffs);
|
||||||
@@ -260,33 +234,26 @@ function populateModifiers(modifiers) {
|
|||||||
input.value = mod.value;
|
input.value = mod.value;
|
||||||
input.dataset.type = mod.type;
|
input.dataset.type = mod.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
label.appendChild(input);
|
label.appendChild(input);
|
||||||
label.appendChild(document.createTextNode(mod.label));
|
label.appendChild(document.createTextNode(mod.label));
|
||||||
|
|
||||||
// Create a container for each modifier item
|
// Create a container for each modifier item
|
||||||
const modifierItem = document.createElement('div');
|
const modifierItem = document.createElement('div');
|
||||||
modifierItem.className = 'modifier-item'; // Add the class for styling
|
modifierItem.className = 'modifier-item'; // Add the class for styling
|
||||||
modifierItem.appendChild(label);
|
modifierItem.appendChild(label);
|
||||||
section.appendChild(modifierItem); // Append the modifier item to the section
|
section.appendChild(modifierItem); // Append the modifier item to the section
|
||||||
});
|
});
|
||||||
|
|
||||||
return section;
|
return section;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a container for all modifiers
|
// Create a container for all modifiers
|
||||||
const container = document.createElement('div');
|
const container = document.createElement('div');
|
||||||
container.id = 'modifiers';
|
container.id = 'modifiers';
|
||||||
|
|
||||||
// Populate sections
|
// Populate sections
|
||||||
container.appendChild(createModifierSection('Item Buffs', modifiers.itemBuffs, 'items'));
|
container.appendChild(createModifierSection('Item Buffs', modifiers.itemBuffs, 'items'));
|
||||||
container.appendChild(createModifierSection('Perks', modifiers.operativePerks, 'perks'));
|
container.appendChild(createModifierSection('Perks', modifiers.operativePerks, 'perks'));
|
||||||
modifiersContainer.appendChild(container); // Append item and perks container
|
modifiersContainer.appendChild(container); // Append item and perks container
|
||||||
|
|
||||||
// Create and append abilities section
|
// Create and append abilities section
|
||||||
const abilitiesSection = createModifierSection('Abilities', modifiers.abilityPerks, 'abilities');
|
const abilitiesSection = createModifierSection('Abilities', modifiers.abilityPerks, 'abilities');
|
||||||
modifiersContainer.appendChild(abilitiesSection); // Append abilities section
|
modifiersContainer.appendChild(abilitiesSection); // Append abilities section
|
||||||
|
|
||||||
// Add event listener to recalculate DPS/DPM when modifiers are toggled
|
// Add event listener to recalculate DPS/DPM when modifiers are toggled
|
||||||
modifiersContainer.addEventListener('change', applyModifiers);
|
modifiersContainer.addEventListener('change', applyModifiers);
|
||||||
}
|
}
|
||||||
@@ -294,12 +261,10 @@ function populateModifiers(modifiers) {
|
|||||||
// Function to apply the modifiers and recalculate damage, RPM, and reloadTime
|
// Function to apply the modifiers and recalculate damage, RPM, and reloadTime
|
||||||
function applyModifiers() {
|
function applyModifiers() {
|
||||||
if (!selectedWeapon) return;
|
if (!selectedWeapon) return;
|
||||||
|
|
||||||
// Base stats
|
// Base stats
|
||||||
let baseDamage = selectedWeapon.damage;
|
let baseDamage = selectedWeapon.damage;
|
||||||
let baseRpm = selectedWeapon.rpm;
|
let baseRpm = selectedWeapon.rpm;
|
||||||
let baseReloadTime = selectedWeapon.reload_time;
|
let baseReloadTime = selectedWeapon.reload_time;
|
||||||
|
|
||||||
// Modifiers initialization
|
// Modifiers initialization
|
||||||
let damageModifier = {additive: 0, multiplicative: 1};
|
let damageModifier = {additive: 0, multiplicative: 1};
|
||||||
let rpmModifier = {additive: 0, multiplicative: 1};
|
let rpmModifier = {additive: 0, multiplicative: 1};
|
||||||
@@ -311,19 +276,15 @@ function applyModifiers() {
|
|||||||
// Function to process global modifiers
|
// Function to process global modifiers
|
||||||
const processModifier = (mod) => {
|
const processModifier = (mod) => {
|
||||||
// Ensure guntype is now an array of tags
|
// Ensure guntype is now an array of tags
|
||||||
const weaponTags = selectedWeapon.guntype; // This is now an array like ["PISTOL", "WW2", "SECONDARY"]
|
const weaponTags = selectedWeapon.guntype; // This is now an array like ["PISTOL", "WW2", "SECONDARY"] -> Do not write "guntype": "PISTOL", write "guntype": ["PISTOL"]
|
||||||
|
|
||||||
// Skip the modifier if it should not apply to any of the current weapon's tags
|
// Skip the modifier if it should not apply to any of the current weapon's tags
|
||||||
if (mod.appliesNotTo && weaponTags.includes(mod.appliesNotTo)) {
|
if (mod.appliesNotTo && weaponTags.includes(mod.appliesNotTo)) {
|
||||||
return; // Skip this modifier
|
return; // Skip this modifier
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the modifier applies to any of the current weapon's tags
|
// Check if the modifier applies to any of the current weapon's tags
|
||||||
if (mod.appliesTo && !weaponTags.includes(mod.appliesTo)) {
|
if (mod.appliesTo && !weaponTags.includes(mod.appliesTo)) {
|
||||||
return; // Skip this modifier if it does not apply to the selected weapon type
|
return; // Skip this modifier if it does not apply to the selected weapon type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (mod.dataset.type === 'multiplicative-headshot') {
|
if (mod.dataset.type === 'multiplicative-headshot') {
|
||||||
if (!headshotBaseApplied) {
|
if (!headshotBaseApplied) {
|
||||||
// Automatically check and apply headshot base
|
// Automatically check and apply headshot base
|
||||||
@@ -344,7 +305,6 @@ function applyModifiers() {
|
|||||||
// Process other modifiers
|
// Process other modifiers
|
||||||
applyBuff(mod, rpmModifier, reloadTimeModifier, damageModifier);
|
applyBuff(mod, rpmModifier, reloadTimeModifier, damageModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle modifiers with multiple buffs
|
// Handle modifiers with multiple buffs
|
||||||
if (mod.dataset.buffs) {
|
if (mod.dataset.buffs) {
|
||||||
const buffs = JSON.parse(mod.dataset.buffs);
|
const buffs = JSON.parse(mod.dataset.buffs);
|
||||||
@@ -354,13 +314,11 @@ function applyModifiers() {
|
|||||||
} else {
|
} else {
|
||||||
const modType = mod.dataset.type;
|
const modType = mod.dataset.type;
|
||||||
const modValue = parseFloat(mod.value);
|
const modValue = parseFloat(mod.value);
|
||||||
|
|
||||||
const singleBuff = {
|
const singleBuff = {
|
||||||
type: modType === 'multiplicative' ? 'multiplicative' : 'additive',
|
type: modType === 'multiplicative' ? 'multiplicative' : 'additive',
|
||||||
buffType: modType,
|
buffType: modType,
|
||||||
value: modValue
|
value: modValue
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mod.id.includes('damage')) {
|
if (mod.id.includes('damage')) {
|
||||||
singleBuff.type = 'damage';
|
singleBuff.type = 'damage';
|
||||||
} else if (mod.id.includes('rpm')) {
|
} else if (mod.id.includes('rpm')) {
|
||||||
@@ -376,17 +334,14 @@ function applyModifiers() {
|
|||||||
const processOperativeModifier = (mod) => {
|
const processOperativeModifier = (mod) => {
|
||||||
// Ensure guntype is now an array of tags
|
// Ensure guntype is now an array of tags
|
||||||
const weaponTags = selectedWeapon.guntype; // This is now an array like ["PISTOL", "WW2", "SECONDARY"]
|
const weaponTags = selectedWeapon.guntype; // This is now an array like ["PISTOL", "WW2", "SECONDARY"]
|
||||||
|
|
||||||
// Skip the modifier if it should not apply to any of the current weapon's tags
|
// Skip the modifier if it should not apply to any of the current weapon's tags
|
||||||
if (mod.appliesNotTo && weaponTags.includes(mod.appliesNotTo)) {
|
if (mod.appliesNotTo && weaponTags.includes(mod.appliesNotTo)) {
|
||||||
return; // Skip this modifier
|
return; // Skip this modifier
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the modifier applies to any of the current weapon's tags
|
// Check if the modifier applies to any of the current weapon's tags
|
||||||
if (mod.appliesTo && !weaponTags.includes(mod.appliesTo)) {
|
if (mod.appliesTo && !weaponTags.includes(mod.appliesTo)) {
|
||||||
return; // Skip this modifier if it does not apply to the selected weapon type
|
return; // Skip this modifier if it does not apply to the selected weapon type
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle operative modifiers with multiple buffs
|
// Handle operative modifiers with multiple buffs
|
||||||
if (mod.buffs) {
|
if (mod.buffs) {
|
||||||
mod.buffs.forEach(buff => {
|
mod.buffs.forEach(buff => {
|
||||||
@@ -405,26 +360,19 @@ function applyModifiers() {
|
|||||||
applyBuff(singleBuff, rpmModifier, reloadTimeModifier, damageModifier);
|
applyBuff(singleBuff, rpmModifier, reloadTimeModifier, damageModifier);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Clear out listeners and avoid re-adding
|
|
||||||
// Process ability modifiers
|
// Process ability modifiers
|
||||||
const abilitiesSection = document.getElementById('abilities');
|
const abilitiesSection = document.getElementById('abilities');
|
||||||
abilitiesSection.querySelectorAll('input:checked').forEach(mod => {
|
abilitiesSection.querySelectorAll('input:checked').forEach(mod => {
|
||||||
processModifier(mod); // Process the ability modifier the same way as global modifiers
|
processModifier(mod); // Process the ability modifier the same way as global modifiers
|
||||||
});
|
});
|
||||||
|
|
||||||
const modifiersContainer = document.getElementById('modifiers');
|
const modifiersContainer = document.getElementById('modifiers');
|
||||||
modifiersContainer.removeEventListener('change', applyModifiers);
|
modifiersContainer.removeEventListener('change', applyModifiers);
|
||||||
|
|
||||||
// Process global modifiers
|
// Process global modifiers
|
||||||
document.querySelectorAll('#modifiers input:checked').forEach(mod => {
|
document.querySelectorAll('#modifiers input:checked').forEach(mod => {
|
||||||
processModifier(mod);
|
processModifier(mod);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Re-apply listener after change
|
// Re-apply listener after change
|
||||||
modifiersContainer.addEventListener('change', applyModifiers);
|
modifiersContainer.addEventListener('change', applyModifiers);
|
||||||
|
|
||||||
// Process operative-specific modifiers that are checked
|
// Process operative-specific modifiers that are checked
|
||||||
const operativeSection = document.getElementById('operative-modifiers');
|
const operativeSection = document.getElementById('operative-modifiers');
|
||||||
operativeSection.querySelectorAll('input:checked').forEach(mod => {
|
operativeSection.querySelectorAll('input:checked').forEach(mod => {
|
||||||
@@ -442,14 +390,15 @@ function applyModifiers() {
|
|||||||
// Step 2: Apply multiplicative damage modifiers
|
// Step 2: Apply multiplicative damage modifiers
|
||||||
damage *= damageModifier.multiplicative;
|
damage *= damageModifier.multiplicative;
|
||||||
|
|
||||||
|
// Step 3: Apply headshot multiplicative damage modifiers
|
||||||
if (headshotMultiplier > 0) {
|
if (headshotMultiplier > 0) {
|
||||||
damage *= (1 + headshotMultiplier);
|
damage *= (1 + headshotMultiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3: Apply additive damage modifiers
|
// Step 4: Apply additive damage modifiers
|
||||||
damage += damageModifier.additive;
|
damage += damageModifier.additive;
|
||||||
|
|
||||||
// Apply the weapon's damage multiplier (if applicable) last
|
// Step 5: Apply the weapon's damage multiplier
|
||||||
damage *= selectedWeapon.damage_multiplier;
|
damage *= selectedWeapon.damage_multiplier;
|
||||||
|
|
||||||
// Calculate other modified stats
|
// Calculate other modified stats
|
||||||
@@ -469,7 +418,6 @@ function applyModifiers() {
|
|||||||
// Function to apply individual buffs, with headshot handling
|
// Function to apply individual buffs, with headshot handling
|
||||||
function applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier) {
|
function applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier) {
|
||||||
const {type, buffType, value} = buff;
|
const {type, buffType, value} = buff;
|
||||||
|
|
||||||
// Handle headshot multipliers
|
// Handle headshot multipliers
|
||||||
if (buffType === 'multiplicative-headshot-base' && !headshotBaseApplied) {
|
if (buffType === 'multiplicative-headshot-base' && !headshotBaseApplied) {
|
||||||
headshotMultiplier = value - 1;
|
headshotMultiplier = value - 1;
|
||||||
@@ -480,7 +428,6 @@ function applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier) {
|
|||||||
headshotMultiplier += value - 1;
|
headshotMultiplier += value - 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply buffs based on the stat being modified
|
// Apply buffs based on the stat being modified
|
||||||
if (type === 'rpm') {
|
if (type === 'rpm') {
|
||||||
if (buffType === 'multiplicative') rpmModifier.multiplicative *= value;
|
if (buffType === 'multiplicative') rpmModifier.multiplicative *= value;
|
||||||
@@ -499,24 +446,18 @@ function filterWeapons() {
|
|||||||
const input = document.getElementById('weapon-search').value.toLowerCase();
|
const input = document.getElementById('weapon-search').value.toLowerCase();
|
||||||
const weaponSelect = document.getElementById('weapon-select');
|
const weaponSelect = document.getElementById('weapon-select');
|
||||||
const options = weaponSelect.getElementsByTagName('option');
|
const options = weaponSelect.getElementsByTagName('option');
|
||||||
|
|
||||||
// Get selected guntype filters
|
// Get selected guntype filters
|
||||||
const selectedGuntypes = Array.from(document.querySelectorAll('#guntype-filters input:checked'))
|
const selectedGuntypes = Array.from(document.querySelectorAll('#guntype-filters input:checked'))
|
||||||
.map(checkbox => checkbox.value);
|
.map(checkbox => checkbox.value);
|
||||||
|
|
||||||
let firstVisibleOption = null; // Variable to track the first matching option
|
let firstVisibleOption = null; // Variable to track the first matching option
|
||||||
|
|
||||||
for (let i = 0; i < options.length; i++) {
|
for (let i = 0; i < options.length; i++) {
|
||||||
const optionText = options[i].textContent || options[i].innerText;
|
const optionText = options[i].textContent || options[i].innerText;
|
||||||
const weaponId = parseInt(options[i].value); // Get the weapon ID
|
const weaponId = parseInt(options[i].value); // Get the weapon ID
|
||||||
const weapon = weapons.find(w => w.id === weaponId); // Find the corresponding weapon
|
const weapon = weapons.find(w => w.id === weaponId); // Find the corresponding weapon
|
||||||
|
|
||||||
if (!weapon) continue; // Skip if the weapon is not found (for safety)
|
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
|
// Check if the option matches the search query and the selected guntype filters
|
||||||
const matchesSearch = optionText.toLowerCase().indexOf(input) > -1;
|
const matchesSearch = optionText.toLowerCase().indexOf(input) > -1;
|
||||||
const matchesGuntypes = selectedGuntypes.length === 0 || selectedGuntypes.every(type => weapon.guntype.includes(type));
|
const matchesGuntypes = selectedGuntypes.length === 0 || selectedGuntypes.every(type => weapon.guntype.includes(type));
|
||||||
|
|
||||||
// Show or hide options based on both search and guntype filters
|
// Show or hide options based on both search and guntype filters
|
||||||
if (matchesSearch && matchesGuntypes) {
|
if (matchesSearch && matchesGuntypes) {
|
||||||
options[i].style.display = ''; // Show matching option
|
options[i].style.display = ''; // Show matching option
|
||||||
@@ -527,7 +468,6 @@ function filterWeapons() {
|
|||||||
options[i].style.display = 'none'; // Hide non-matching option
|
options[i].style.display = 'none'; // Hide non-matching option
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Automatically select the first visible matching option
|
// Automatically select the first visible matching option
|
||||||
if (firstVisibleOption) {
|
if (firstVisibleOption) {
|
||||||
weaponSelect.value = firstVisibleOption.value;
|
weaponSelect.value = firstVisibleOption.value;
|
||||||
|
|||||||
Reference in New Issue
Block a user