diff --git a/static/filterWeapons.js b/static/filterWeapons.js index cc3311f..66fb089 100644 --- a/static/filterWeapons.js +++ b/static/filterWeapons.js @@ -1,6 +1,7 @@ let selectedWeapon = null; // Store the selected weapon's data let weapons = []; // This will be populated by the fetched JSON data let selectedOperative = null; // Store the selected operative's data +let globalModifiers = []; // Function to fetch operatives data from JSON function fetchOperativesData() { @@ -34,6 +35,41 @@ function populateOperatives(operatives) { }); } +function updateOperativeBuffs(operative) { + const operativeModifiers = operative.modifiers || []; + + // Remove previously added operative-specific modifiers + const operativeSection = document.getElementById('operative-modifiers'); + operativeSection.innerHTML = ''; // Clear existing operative modifiers + + // If the operative has specific modifiers, show them + if (operativeModifiers.length > 0) { + operativeModifiers.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; + + // Automatically check the box if you want it enabled by default + input.checked = true; + + label.appendChild(input); + label.appendChild(document.createTextNode(mod.label)); + operativeSection.appendChild(label); + operativeSection.appendChild(document.createElement('br')); + }); + } + + // Make sure that each operative-specific modifier checkbox triggers recalculation when changed + operativeSection.addEventListener('change', applyModifiers); + + // Trigger recalculation once the operative buffs are displayed + applyModifiers(); +} + + // Function to fetch weapons data from JSON function fetchWeaponsData() { fetch('static/json/data.json') // Adjust the path to the actual location of your JSON file @@ -93,7 +129,8 @@ function fetchModifiers() { fetch('static/json/modifiers.json') // Adjust the path to your JSON file .then(response => response.json()) .then(data => { - populateModifiers(data); + globalModifiers = data; // Save global modifiers for future use + populateModifiers(data); // Populate the modifiers in the UI }) .catch(error => console.error('Error fetching modifiers:', error)); } @@ -154,88 +191,85 @@ function populateModifiers(modifiers) { function applyModifiers() { if (!selectedWeapon) return; - // Get the base stats from the selected weapon + // Base stats let baseDamage = selectedWeapon.damage * selectedWeapon.damage_multiplier; let baseRpm = selectedWeapon.rpm; let baseReloadTime = selectedWeapon.reload_time; - // Initialize the modifier objects - let damageModifier = {additive: 0, multiplicative: 1}; - let rpmModifier = {additive: 0, multiplicative: 1}; - let reloadTimeModifier = {additive: 0, multiplicative: 1}; + // Modifiers initialization + let damageModifier = { additive: 0, multiplicative: 1 }; + let rpmModifier = { additive: 0, multiplicative: 1 }; + let reloadTimeModifier = { 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); - - // Handle multi-buff modifiers (like Bloxy Cola or Firefight) + // Function to process individual modifiers + const processModifier = (mod, rpmModifier, reloadTimeModifier, damageModifier) => { + // Handle multi-buff modifiers if (mod.dataset.buffs) { - const buffs = JSON.parse(mod.dataset.buffs); // Parse buffs data from the data-buffs attribute + const buffs = JSON.parse(mod.dataset.buffs); buffs.forEach(buff => { - // Apply each buff applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier); }); } else { - // Handle single-buff modifiers + // Single buff modifier const singleBuff = { - type: modType === 'multiplicative' ? 'multiplicative' : 'additive', // Use the proper modifier type - buffType: modType, - value: modValue + type: mod.dataset.type === 'multiplicative' ? 'multiplicative' : 'additive', + value: parseFloat(mod.value) }; - if (mod.id.includes('damage')) { - singleBuff.type = 'damage'; // This mod applies to damage - } else if (mod.id.includes('rpm')) { - singleBuff.type = 'rpm'; // This mod applies to RPM - } else if (mod.id.includes('reload')) { - singleBuff.type = 'reloadTime'; // This mod applies to reload time - } - - // Apply the single buff - applyBuff(singleBuff, rpmModifier, reloadTimeModifier, damageModifier); + // Apply the single buff depending on its stat + if (mod.id.includes('damage')) applyBuff({ stat: 'damage', ...singleBuff }, rpmModifier, reloadTimeModifier, damageModifier); + if (mod.id.includes('rpm')) applyBuff({ stat: 'rpm', ...singleBuff }, rpmModifier, reloadTimeModifier, damageModifier); + if (mod.id.includes('reload')) applyBuff({ stat: 'reloadTime', ...singleBuff }, rpmModifier, reloadTimeModifier, damageModifier); } + }; + + // Process global modifiers + document.querySelectorAll('#modifiers input:checked').forEach(mod => { + processModifier(mod, rpmModifier, reloadTimeModifier, damageModifier); }); - // Apply the damage modifiers - let damage = baseDamage * damageModifier.multiplicative; // First apply multiplicative modifiers - damage += damageModifier.additive; // Then apply percentage-based additive modifiers + // Process operative-specific modifiers + if (selectedOperative) { + document.querySelectorAll('#operative-modifiers input:checked').forEach(mod => { + processModifier(mod, rpmModifier, reloadTimeModifier, damageModifier); + }); + } + + // Recalculate with applied modifiers + let damage = baseDamage * damageModifier.multiplicative; + damage += damageModifier.additive; - // Apply the RPM modifiers let rpm = baseRpm * rpmModifier.multiplicative; - rpm = rpm + (rpm * rpmModifier.additive); + rpm += rpm * rpmModifier.additive; - // Apply the reload time modifiers let reloadTime = baseReloadTime * reloadTimeModifier.multiplicative; - reloadTime = reloadTime + (reloadTime * reloadTimeModifier.additive); + reloadTime += reloadTime * reloadTimeModifier.additive; - // Recalculate DPS and DPM with the modified stats calculateDPSAndDPM(damage, rpm, selectedWeapon.mag_size, reloadTime); - - // Update the displayed weapon stats with the modified values updateModifiedWeaponStats(damage, rpm, reloadTime); } + // Helper function to apply individual buffs function applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier = null) { - const {type, buffType, value} = buff; + const {stat, type, value} = buff; - // Apply buffs based on type - if (type === 'rpm') { - if (buffType === 'multiplicative') rpmModifier.multiplicative *= value; - else if (buffType === 'additive') rpmModifier.additive += value; + // Apply buffs based on the stat being modified + if (stat === 'rpm') { + if (type === 'multiplicative') rpmModifier.multiplicative *= value; + else if (type === 'additive') rpmModifier.additive += value; } - if (type === 'reloadTime') { - if (buffType === 'multiplicative') reloadTimeModifier.multiplicative *= value; - else if (buffType === 'additive') reloadTimeModifier.additive += value; + if (stat === 'reloadTime') { + if (type === 'multiplicative') reloadTimeModifier.multiplicative *= value; + else if (type === 'additive') reloadTimeModifier.additive += value; } // Apply damage buffs - if (type === 'damage' && damageModifier) { - if (buffType === 'multiplicative') damageModifier.multiplicative *= value; - else if (buffType === 'additive') damageModifier.additive += value; + if (stat === 'damage' && damageModifier) { + if (type === 'multiplicative') damageModifier.multiplicative *= value; + else if (type === 'additive') damageModifier.additive += value; } } diff --git a/static/json/modifiers.json b/static/json/modifiers.json index 95c290c..140b8a9 100644 --- a/static/json/modifiers.json +++ b/static/json/modifiers.json @@ -4,25 +4,29 @@ "id": "damage-item-additive-elite-he-rounds", "label": "Elite HE Rounds (+14 damage)", "value": 14, - "type": "additive" + "type": "additive", + "operatives": [] }, { "id": "damage-item-additive-he-rounds", "label": "HE Rounds (+8 damage)", "value": 8, - "type": "additive" + "type": "additive", + "operatives": [] }, { "id": "damage-item-multiplicative-strength-mixture", "label": "Strength Mixture (+20% damage)", "value": 1.2, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] }, { "id": "damage-item-multiplicative-fortunos-necklace", "label": "Fortunos Necklace (+15% damage)", "value": 1.15, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] }, { "id": "multiple-buffs-bloxy-cola", @@ -38,19 +42,22 @@ "value": 0, "buffType": "multiplicative" } - ] + ], + "operatives": [] }, { "id": "damage-item-multiplicative-enhancer", "label": "Enhancer (+10% damage)", "value": 1.1, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] }, { "id": "damage-item-multiplicative-teleport-device", "label": "Teleport Device (+25% damage)", "value": 1.25, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] } ], "operativePerks": [ @@ -58,25 +65,29 @@ "id": "damage-perk-multiplicative-fbi-badge", "label": "FBI Badge (+10% Damage)", "value": 1.1, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] }, { "id": "damage-perk-multiplicative-anatomy-book", "label": "Anatomy Book (+5% Damage)", "value": 1.05, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] }, { "id": "damage-perk-multiplicative-silly-soldier", "label": "Silly Soldier (+10% Damage)", "value": 1.10, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] }, { "id": "damage-perk-multiplicative-precise-shots", "label": "Precise Shots (+15% Damage)", - "value": 1.15, - "type": "multiplicative" + "value": 1.40, + "type": "multiplicative", + "operatives": [] }, { "id": "damage-perk-multiplicative-goc-insignia", @@ -92,7 +103,8 @@ "value": 0.85, "buffType": "multiplicative" } - ] + ], + "operatives": [] } ], "abilityPerks": [ @@ -110,17 +122,20 @@ "value": 0.6, "buffType": "multiplicative" } - ] + ], + "operatives": [] }, { "id": "damage-ability-multiplicative-heath-spawn", "label": "[All Operatives] Heath Spawn (+30% Damage)", "value": 1.3, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] }, { "id": "multiple-buffs-warcry", "label": "[All Operatives] War Cry(+25% Damage, +?% Reload Speed)", + "operatives": [], "buffs": [ { "type": "damage", @@ -138,31 +153,36 @@ "id": "damage-ability-multiplicative-blackout", "label": "[All Operatives] Blackout (+30% Damage)", "value": 1.3, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] }, { "id": "damage-ability-multiplicative-red-scan", "label": "[All Operatives] Red Scan (+30% Damage)", "value": 1.3, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] }, { "id": "damage-ability-multiplicative-red-scan", "label": "[All Operatives] Green Scan (+50% Damage)", "value": 1.5, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] }, { "id": "damage-ability-multiplicative-point-out", "label": "[All Operatives] Point Out (+50% Damage)", "value": 1.5, - "type": "multiplicative" + "type": "multiplicative", + "operatives": [] }, { "id": "damage-item-additive-5-uiu-elite", "label": "[All Operatives] 5 UIU Elite nearby (+25 damage)", "value": 25, - "type": "additive" + "type": "additive", + "operatives": [] } ] } diff --git a/static/json/operative.json b/static/json/operative.json index 45f5482..d8f0a15 100644 --- a/static/json/operative.json +++ b/static/json/operative.json @@ -3,7 +3,16 @@ { "id": "Classic-Guard", "name": "Guard", - "category": "Classic" + "category": "Classic", + "modifiers": [ + { + "id": "smg-user-damage-perk", + "label": "SMG User (+15% Damage)", + "value": 1.15, + "type": "multiplicative", + "appliesTo": "SMG" + } + ] }, { "id": "Classic-Scout", @@ -13,7 +22,16 @@ { "id": "Classic-RCU", "name": "RCU", - "category": "Classic" + "category": "Classic", + "modifiers": [ + { + "id": "shotgun-expert-damage-perk", + "label": "Shotgun Expert (+25% Damage)", + "value": 1.25, + "type": "multiplicative", + "appliesTo": "SHOTGUN" + } + ] }, { "id": "Classic-Viper", @@ -23,7 +41,16 @@ { "id": "Classic-SD-Sergeant", "name": "SD Sergeant", - "category": "Classic" + "category": "Classic", + "modifiers": [ + { + "id": "max-corruption-damage-perk", + "label": "Max Corruption (+30% Damage)", + "value": 1.30, + "type": "multiplicative", + "appliesTo": "" + } + ] }, { "id": "Classic-ISD", @@ -43,17 +70,73 @@ { "id": "Classic-Vanguard", "name": "Vanguard", - "category": "Classic" + "category": "Classic", + "modifiers": [ + { + "id": "bad-experience-damage-perk", + "label": "Bad Experience (+25% Damage, +25% Reload Speed)", + "buffs": [ + { + "type": "damage", + "value": 1.25, + "buffType": "multiplicative" + }, + { + "type": "reloadTime", + "value": 0.75, + "buffType": "multiplicative" + } + ], + "appliesNotTo": "LMG" + }, + { + "id": "lmg-user-damage-perk", + "label": "LMG User (+35% Damage)", + "value": 1.35, + "type": "multiplicative", + "appliesNotTo": "LMG" + } + ] }, { "id": "Classic-Demolitionist", "name": "Demolitionist", "category": "Classic" }, + { + "id": "Classic-Juggernaut", + "name": "Juggernaut", + "category": "Classic", + "modifiers": [ + { + "id": "hold-the-line-damage-perk", + "label": "Hold The Line (+90% Damage)", + "value": 1.90, + "type": "multiplicative", + "appliesTo": "" + } + ] + }, { "id": "Classic-Mercenary", "name": "Mercenary", - "category": "Classic" + "category": "Classic", + "modifiers": [ + { + "id": "all-upgrades-damage-perk", + "label": "All Upgrades (+25% Damage, +15% Reload Speed)", + "value": 1.25, + "type": "multiplicative", + "appliesTo": "" + }, + { + "id": "mcd-sandevistan-damage-perk", + "label": "All Upgrades (+75% Damage)", + "value": 1.75, + "type": "multiplicative", + "appliesTo": "" + } + ] }, { "id": "Classic-CRT", @@ -63,7 +146,99 @@ { "id": "Classic-Anarchist", "name": "Anarchist", - "category": "Classic" + "category": "Classic", + "modifiers": [ + { + "id": "last-stand-damage-perk", + "label": "Last Stand (+150% Damage)", + "value": 2.5, + "type": "multiplicative", + "appliesTo": "" + }, + { + "id": "world-on-fire-damage-perk", + "label": "World on fire (+150% Damage)", + "value": 2.5, + "type": "multiplicative", + "appliesTo": "" + }, + { + "id": "adrenaline-damage-perk", + "label": "All Upgrades (+30% Damage)", + "value": 1.3, + "type": "multiplicative", + "appliesTo": "" + } + ] + }, + { + "id": "Special-Squid-Guard", + "name": "Squid Guard", + "category": "Special", + "modifiers": [ + { + "id": "smg-user-damage-perk", + "label": "SMG User (+15% Damage)", + "value": 1.15, + "type": "multiplicative", + "appliesTo": "SMG" + } + ] + }, + { + "id": "Special-Researcher", + "name": "Researcher", + "category": "Special", + "modifiers": [] + }, + { + "id": "Special-RRT", + "name": "RRT", + "category": "Special", + "modifiers": [ + { + "id": "smg-user-damage-perk", + "label": "SMG User (+15% Damage)", + "value": 1.15, + "type": "multiplicative", + "appliesTo": "SMG" + }, + { + "id": "weapon-expert-reload-perk", + "label": "Weapon Expert (-1s Reload Time)", + "value": -1, + "type": "additive", + "appliesTo": "" + }, + { + "id": "rrt-mastery-damage-rpm-perk", + "label": "Mastery (+25% Firerate, +25% Damage)", + "value": 1.25, + "type": "multiplicative", + "appliesTo": "" + } + ] + }, + { + "id": "Special-Private", + "name": "Private", + "category": "Special", + "modifiers": [ + { + "id": "nostalgia-reload-perk", + "label": "Nostalgia (+10% Reload Speed)", + "value": 0.9, + "type": "multiplicative", + "appliesTo": "" + }, + { + "id": "adrenaline-damage-reload-perk", + "label": "Adrenaline (+30% Damage, +40% Reload Speed)", + "value": 1.3, + "type": "multiplicative", + "appliesTo": "" + } + ] } ] -} +} \ No newline at end of file diff --git a/templates/calculator.html b/templates/calculator.html index 29c543f..034a2c0 100644 --- a/templates/calculator.html +++ b/templates/calculator.html @@ -72,7 +72,8 @@
- +

Operative Specific Modifiers

+