From 9287c98635d800ef5da3355cb27be8c7a3f379df Mon Sep 17 00:00:00 2001 From: IM23a-spirgif Date: Wed, 6 Nov 2024 18:58:09 +0100 Subject: [PATCH] some new features + json adjustments --- static/filterWeapons.js | 66 +++++++++++++++++++++++++++++--------- static/json/data.json | 28 +++++++++++++--- static/json/modifiers.json | 12 +++++-- static/json/operative.json | 4 +-- 4 files changed, 85 insertions(+), 25 deletions(-) diff --git a/static/filterWeapons.js b/static/filterWeapons.js index 9d16b96..490254f 100644 --- a/static/filterWeapons.js +++ b/static/filterWeapons.js @@ -3,6 +3,9 @@ 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 +let headshotMultiplier = 0; +let headshotBaseApplied = false; + // Function to fetch operatives data from JSON function fetchOperativesData() { @@ -300,6 +303,9 @@ function applyModifiers() { let damageModifier = {additive: 0, multiplicative: 1}; let rpmModifier = {additive: 0, multiplicative: 1}; let reloadTimeModifier = {additive: 0, multiplicative: 1}; + headshotMultiplier = 0; // Reset headshot multiplier + headshotBaseApplied = false; + // Function to process global modifiers const processModifier = (mod) => { @@ -316,6 +322,28 @@ function applyModifiers() { return; // Skip this modifier if it does not apply to the selected weapon type } + + if (mod.dataset.type === 'multiplicative-headshot') { + if (!headshotBaseApplied) { + // Automatically check and apply headshot base + const baseHeadshotModifier = document.querySelector("#modifiers input[data-type='multiplicative-headshot-base']"); + if (baseHeadshotModifier && !baseHeadshotModifier.checked) { + baseHeadshotModifier.checked = true; + headshotMultiplier += parseFloat(baseHeadshotModifier.value) - 1; + headshotBaseApplied = true; + } + } + headshotMultiplier += parseFloat(mod.value) - 1; + } else if (mod.dataset.type === 'multiplicative-headshot-base') { + if (!headshotBaseApplied) { + headshotMultiplier += parseFloat(mod.value) - 1; + headshotBaseApplied = true; + } + } else { + // Process other modifiers + applyBuff(mod, rpmModifier, reloadTimeModifier, damageModifier); + } + // Handle modifiers with multiple buffs if (mod.dataset.buffs) { const buffs = JSON.parse(mod.dataset.buffs); @@ -407,12 +435,16 @@ function applyModifiers() { } }); - // Step 1: Calculate final damage + // Step 1: Calculate final damage let damage = baseDamage; // Reset to base damage // Step 2: Apply multiplicative damage modifiers damage *= damageModifier.multiplicative; + if (headshotMultiplier > 0) { + damage *= (1 + headshotMultiplier); + } + // Step 3: Apply additive damage modifiers damage += damageModifier.additive; @@ -433,27 +465,29 @@ function applyModifiers() { updateModifiedWeaponStats(damage, rpm, reloadTime); } -// Function to apply individual buffs (simplified to avoid mistakes) -function applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier = null) { +// Function to apply individual buffs, with headshot handling +function applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier) { const {type, buffType, value} = buff; + // Handle headshot multipliers + if (buffType === 'multiplicative-headshot-base' && !headshotBaseApplied) { + headshotMultiplier = value - 1; + headshotBaseApplied = true; + return; + } + if (buffType === 'multiplicative-headshot') { + headshotMultiplier += value - 1; + return; + } + // Apply buffs based on the stat being modified if (type === 'rpm') { if (buffType === 'multiplicative') rpmModifier.multiplicative *= value; else if (buffType === 'additive') rpmModifier.additive += value; - } - - if (type === 'reloadTime') { - if (buffType === 'multiplicative') { - reloadTimeModifier.multiplicative *= value; - } else if (buffType === 'additive') { - // Subtract value for additive reload time modifiers (like Weapon Expert) - reloadTimeModifier.additive += value; - } - } - - // Apply damage buffs - if (type === 'damage' && damageModifier) { + } else if (type === 'reloadTime') { + if (buffType === 'multiplicative') reloadTimeModifier.multiplicative *= value; + else if (buffType === 'additive') reloadTimeModifier.additive += value; + } else if (type === 'damage' && damageModifier) { if (buffType === 'multiplicative') damageModifier.multiplicative *= value; else if (buffType === 'additive') damageModifier.additive += value; } diff --git a/static/json/data.json b/static/json/data.json index 1cb5301..039512d 100644 --- a/static/json/data.json +++ b/static/json/data.json @@ -136,7 +136,7 @@ "damage_multiplier": 4, "rpm": 300, "mag_size": 7, - "reload_time": 4, + "reload_time": 4.5, "guntype": ["SHOTGUN", "PRIMARY"] }, { @@ -402,13 +402,23 @@ { "id": 44, "name": "Improved G18", - "damage": 38, + "damage": 46, "damage_multiplier": 1, "rpm": 650, "mag_size": 18, "reload_time": 2, "guntype": ["PISTOL"] }, + { + "id": 89, + "name": "Improved G18 (150+ Kills)", + "damage": 51, + "damage_multiplier": 1, + "rpm": 650, + "mag_size": 23, + "reload_time": 2, + "guntype": ["PISTOL"] + }, { "id": 45, "name": "Silenced G18", @@ -592,10 +602,20 @@ { "id": 64, "name": "Improved Vector", - "damage": 36, + "damage": 34, "damage_multiplier": 1, "rpm": 1050, - "mag_size": 30, + "mag_size": 33, + "reload_time": 2, + "guntype": ["SMG", "PRIMARY"] + }, + { + "id": 88, + "name": "Improved Vector (150+ Kills)", + "damage": 39, + "damage_multiplier": 1, + "rpm": 1050, + "mag_size": 33, "reload_time": 2, "guntype": ["SMG", "PRIMARY"] }, diff --git a/static/json/modifiers.json b/static/json/modifiers.json index 5b1b193..f0b9029 100644 --- a/static/json/modifiers.json +++ b/static/json/modifiers.json @@ -85,8 +85,14 @@ { "id": "damage-perk-multiplicative-precise-shots", "label": "Precise Shots (+15% Damage)", - "value": 1.15, - "type": "multiplicative", + "buffs": [ + { + "type": "damage", + "value": 1.15, + "buffType": "multiplicative-headshot" + } + ], + "appliesTo": "", "operatives": "" }, { @@ -115,7 +121,7 @@ { "type": "damage", "value": 1.25, - "buffType": "multiplicative" + "buffType": "multiplicative-headshot-base" } ], "appliesTo": "" diff --git a/static/json/operative.json b/static/json/operative.json index ce4801d..d0ae08c 100644 --- a/static/json/operative.json +++ b/static/json/operative.json @@ -694,7 +694,7 @@ { "type": "damage", "value": 1.2, - "buffType": "multiplicative" + "buffType": "multiplicative-headshot" } ], "appliesTo": "" @@ -749,7 +749,7 @@ { "type": "damage", "value": 1.2, - "buffType": "multiplicative" + "buffType": "multiplicative-headshot" } ], "appliesTo": ""