added modifier list, added suggestion template (not started yet)
This commit is contained in:
+112
-12
@@ -36,7 +36,6 @@ function populateWeapons() {
|
||||
|
||||
// Function to display the selected weapon's stats in the UI
|
||||
function updateWeaponStats(weapon) {
|
||||
// Example: Display the stats in variables or in the HTML
|
||||
const statsElement = document.getElementById('weapon-stats');
|
||||
statsElement.innerHTML = `
|
||||
<p>Name: ${weapon.name}</p>
|
||||
@@ -46,22 +45,121 @@ function updateWeaponStats(weapon) {
|
||||
<p>Reload Time: ${weapon.reload_time}</p>
|
||||
`;
|
||||
|
||||
// You can store the values for further calculations:
|
||||
let damage = weapon.damage;
|
||||
let rpm = weapon.rpm;
|
||||
let magSize = weapon.mag_size;
|
||||
let reloadTime = weapon.reload_time;
|
||||
// Store values for further calculations
|
||||
const damage = weapon.damage;
|
||||
const rpm = weapon.rpm;
|
||||
const magSize = weapon.mag_size;
|
||||
const reloadTime = weapon.reload_time;
|
||||
|
||||
// Calculate DPS and DPM here or trigger a calculation function
|
||||
// Calculate DPS and DPM initially without modifiers
|
||||
calculateDPSAndDPM(damage, rpm, magSize, reloadTime);
|
||||
}
|
||||
|
||||
// Example DPS and DPM calculation function
|
||||
function calculateDPSAndDPM(damage, rpm, magSize, reloadTime) {
|
||||
// Function to fetch and populate modifiers from the JSON file
|
||||
function fetchModifiers() {
|
||||
fetch('static/modifiers.json') // Adjust the path to your JSON file
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
populateModifiers(data);
|
||||
})
|
||||
.catch(error => console.error('Error fetching modifiers:', error));
|
||||
}
|
||||
|
||||
// Function to dynamically populate modifiers into the HTML
|
||||
function populateModifiers(modifiers) {
|
||||
const modifiersContainer = document.getElementById('modifiers');
|
||||
|
||||
const createModifierSection = (title, modifierList) => {
|
||||
const section = document.createElement('div');
|
||||
const header = document.createElement('h3');
|
||||
header.textContent = title;
|
||||
section.appendChild(header);
|
||||
|
||||
modifierList.forEach(mod => {
|
||||
const label = document.createElement('label');
|
||||
const input = document.createElement('input');
|
||||
input.type = 'checkbox';
|
||||
input.id = mod.id;
|
||||
input.value = mod.value;
|
||||
input.dataset.type = mod.type; // Store if it's additive or multiplicative
|
||||
label.appendChild(input);
|
||||
label.appendChild(document.createTextNode(mod.label));
|
||||
section.appendChild(label);
|
||||
section.appendChild(document.createElement('br'));
|
||||
});
|
||||
|
||||
return section;
|
||||
};
|
||||
|
||||
// Clear any existing modifiers
|
||||
modifiersContainer.innerHTML = '';
|
||||
|
||||
// Add Item Buffs
|
||||
modifiersContainer.appendChild(createModifierSection('Item Buffs', modifiers.itemBuffs));
|
||||
|
||||
// Add Operative Perks
|
||||
modifiersContainer.appendChild(createModifierSection('Operative Perks', modifiers.operativePerks));
|
||||
|
||||
// Add Ability Perks
|
||||
modifiersContainer.appendChild(createModifierSection('Ability Perks', modifiers.abilityPerks));
|
||||
|
||||
// Add event listener to recalculate DPS/DPM when modifiers are toggled
|
||||
modifiersContainer.addEventListener('change', applyModifiers);
|
||||
}
|
||||
|
||||
// Function to apply the modifiers and recalculate DPS and DPM
|
||||
function applyModifiers() {
|
||||
if (!selectedWeapon) return;
|
||||
|
||||
const damage = selectedWeapon.damage;
|
||||
let rpm = selectedWeapon.rpm;
|
||||
const magSize = selectedWeapon.mag_size;
|
||||
const reloadTime = selectedWeapon.reload_time;
|
||||
|
||||
let dpsModifier = { additive: 0, multiplicative: 1 };
|
||||
let dpmModifier = { additive: 0, multiplicative: 1 };
|
||||
let rpmModifier = { additive: 0, multiplicative: 1 };
|
||||
|
||||
// Collect checked modifier values
|
||||
document.querySelectorAll('#modifiers input:checked').forEach(mod => {
|
||||
const modType = mod.dataset.type;
|
||||
const modValue = parseFloat(mod.value);
|
||||
|
||||
if (mod.id.includes('dps')) {
|
||||
if (modType === 'additive') dpsModifier.additive += modValue;
|
||||
else dpsModifier.multiplicative *= modValue;
|
||||
}
|
||||
if (mod.id.includes('dpm')) {
|
||||
if (modType === 'additive') dpmModifier.additive += modValue;
|
||||
else dpmModifier.multiplicative *= modValue;
|
||||
}
|
||||
if (mod.id.includes('rpm')) {
|
||||
if (modType === 'additive') rpmModifier.additive += modValue;
|
||||
else rpmModifier.multiplicative *= modValue;
|
||||
}
|
||||
});
|
||||
|
||||
// Apply RPM modifiers
|
||||
rpm = rpm + (rpm * rpmModifier.additive);
|
||||
rpm = rpm * rpmModifier.multiplicative;
|
||||
|
||||
// Recalculate DPS and DPM with modifiers
|
||||
calculateDPSAndDPM(damage, rpm, magSize, reloadTime, dpsModifier, dpmModifier);
|
||||
}
|
||||
|
||||
// Function to calculate DPS, DPM, and RPS with optional modifiers
|
||||
// Function to calculate DPS and DPM with optional modifiers
|
||||
function calculateDPSAndDPM(damage, rpm, magSize, reloadTime, dpsModifier = { additive: 0, multiplicative: 1 }, dpmModifier = { additive: 0, multiplicative: 1 }) {
|
||||
const rps = rpm / 60; // Rounds per second
|
||||
const dps = damage * rps;
|
||||
let dps = damage * rps;
|
||||
const reloadTimeMin = reloadTime / 60;
|
||||
const dpm = (magSize * damage) / (reloadTimeMin + (magSize / rpm));
|
||||
let dpm = (magSize * damage) / (reloadTimeMin + (magSize / rpm));
|
||||
|
||||
// Apply modifiers
|
||||
dps = dps + (dps * dpsModifier.additive);
|
||||
dps = dps * dpsModifier.multiplicative;
|
||||
dpm = dpm + (dpm * dpmModifier.additive);
|
||||
dpm = dpm * dpmModifier.multiplicative;
|
||||
|
||||
// Display the calculated stats
|
||||
const resultElement = document.getElementById('calculated-stats');
|
||||
@@ -71,5 +169,7 @@ function calculateDPSAndDPM(damage, rpm, magSize, reloadTime) {
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
// Call the fetch function to load the data and populate the dropdown on page load
|
||||
fetchWeaponsData();
|
||||
fetchWeaponsData();
|
||||
fetchModifiers();
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"itemBuffs": [
|
||||
{ "id": "dps-item-additive", "label": "DPS Additive (10%)", "value": 0.1, "type": "additive" },
|
||||
{ "id": "dps-item-multiplicative", "label": "DPS Multiplicative (20%)", "value": 1.2, "type": "multiplicative" },
|
||||
{ "id": "dpm-item-additive", "label": "DPM Additive (10%)", "value": 0.1, "type": "additive" },
|
||||
{ "id": "dpm-item-multiplicative", "label": "DPM Multiplicative (20%)", "value": 1.2, "type": "multiplicative" },
|
||||
{ "id": "rpm-item-additive", "label": "RPM Additive (5%)", "value": 0.05, "type": "additive" },
|
||||
{ "id": "rpm-item-multiplicative", "label": "RPM Multiplicative (10%)", "value": 1.1, "type": "multiplicative" }
|
||||
],
|
||||
"operativePerks": [
|
||||
{ "id": "dps-perk-additive", "label": "DPS Additive (15%)", "value": 0.15, "type": "additive" },
|
||||
{ "id": "dps-perk-multiplicative", "label": "DPS Multiplicative (30%)", "value": 1.3, "type": "multiplicative" },
|
||||
{ "id": "dpm-perk-additive", "label": "DPM Additive (15%)", "value": 0.15, "type": "additive" },
|
||||
{ "id": "dpm-perk-multiplicative", "label": "DPM Multiplicative (30%)", "value": 1.3, "type": "multiplicative" },
|
||||
{ "id": "rpm-perk-additive", "label": "RPM Additive (10%)", "value": 0.1, "type": "additive" },
|
||||
{ "id": "rpm-perk-multiplicative", "label": "RPM Multiplicative (20%)", "value": 1.2, "type": "multiplicative" }
|
||||
],
|
||||
"abilityPerks": [
|
||||
{ "id": "dps-ability-additive", "label": "DPS Additive (20%)", "value": 0.2, "type": "additive" },
|
||||
{ "id": "dps-ability-multiplicative", "label": "DPS Multiplicative (40%)", "value": 1.4, "type": "multiplicative" },
|
||||
{ "id": "dpm-ability-additive", "label": "DPM Additive (20%)", "value": 0.2, "type": "additive" },
|
||||
{ "id": "dpm-ability-multiplicative", "label": "DPM Multiplicative (40%)", "value": 1.4, "type": "multiplicative" },
|
||||
{ "id": "rpm-ability-additive", "label": "RPM Additive (10%)", "value": 0.1, "type": "additive" },
|
||||
{ "id": "rpm-ability-multiplicative", "label": "RPM Multiplicative (30%)", "value": 1.3, "type": "multiplicative" }
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user