minor change

This commit is contained in:
IM23a-spirgif
2024-09-17 14:25:31 +02:00
parent 11518ceee9
commit 40a1c628f8
4 changed files with 307 additions and 77 deletions
+82 -48
View File
@@ -1,6 +1,7 @@
let selectedWeapon = null; // Store the selected weapon's data let selectedWeapon = null; // Store the selected weapon's data
let weapons = []; // This will be populated by the fetched JSON data let weapons = []; // This will be populated by the fetched JSON data
let selectedOperative = null; // Store the selected operative's data let selectedOperative = null; // Store the selected operative's data
let globalModifiers = [];
// Function to fetch operatives data from JSON // Function to fetch operatives data from JSON
function fetchOperativesData() { 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 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
@@ -93,7 +129,8 @@ 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
.then(response => response.json()) .then(response => response.json())
.then(data => { .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)); .catch(error => console.error('Error fetching modifiers:', error));
} }
@@ -154,88 +191,85 @@ function populateModifiers(modifiers) {
function applyModifiers() { function applyModifiers() {
if (!selectedWeapon) return; if (!selectedWeapon) return;
// Get the base stats from the selected weapon // Base stats
let baseDamage = selectedWeapon.damage * selectedWeapon.damage_multiplier; let baseDamage = selectedWeapon.damage * selectedWeapon.damage_multiplier;
let baseRpm = selectedWeapon.rpm; let baseRpm = selectedWeapon.rpm;
let baseReloadTime = selectedWeapon.reload_time; let baseReloadTime = selectedWeapon.reload_time;
// Initialize the modifier objects // 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 };
let reloadTimeModifier = {additive: 0, multiplicative: 1}; let reloadTimeModifier = { additive: 0, multiplicative: 1 };
// Collect checked modifier values // Function to process individual modifiers
document.querySelectorAll('#modifiers input:checked').forEach(mod => { const processModifier = (mod, rpmModifier, reloadTimeModifier, damageModifier) => {
const modType = mod.dataset.type; // Handle multi-buff modifiers
const modValue = parseFloat(mod.value);
// Handle multi-buff modifiers (like Bloxy Cola or Firefight)
if (mod.dataset.buffs) { 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 => { buffs.forEach(buff => {
// Apply each buff
applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier); applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier);
}); });
} else { } else {
// Handle single-buff modifiers // Single buff modifier
const singleBuff = { const singleBuff = {
type: modType === 'multiplicative' ? 'multiplicative' : 'additive', // Use the proper modifier type type: mod.dataset.type === 'multiplicative' ? 'multiplicative' : 'additive',
buffType: modType, value: parseFloat(mod.value)
value: modValue
}; };
if (mod.id.includes('damage')) { // Apply the single buff depending on its stat
singleBuff.type = 'damage'; // This mod applies to damage if (mod.id.includes('damage')) applyBuff({ stat: 'damage', ...singleBuff }, rpmModifier, reloadTimeModifier, damageModifier);
} else if (mod.id.includes('rpm')) { if (mod.id.includes('rpm')) applyBuff({ stat: 'rpm', ...singleBuff }, rpmModifier, reloadTimeModifier, damageModifier);
singleBuff.type = 'rpm'; // This mod applies to RPM if (mod.id.includes('reload')) applyBuff({ stat: 'reloadTime', ...singleBuff }, rpmModifier, reloadTimeModifier, damageModifier);
} else if (mod.id.includes('reload')) {
singleBuff.type = 'reloadTime'; // This mod applies to reload time
} }
};
// Apply the single buff // Process global modifiers
applyBuff(singleBuff, rpmModifier, reloadTimeModifier, damageModifier); document.querySelectorAll('#modifiers input:checked').forEach(mod => {
} processModifier(mod, rpmModifier, reloadTimeModifier, damageModifier);
}); });
// Apply the damage modifiers // Process operative-specific modifiers
let damage = baseDamage * damageModifier.multiplicative; // First apply multiplicative modifiers if (selectedOperative) {
damage += damageModifier.additive; // Then apply percentage-based additive modifiers 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; let rpm = baseRpm * rpmModifier.multiplicative;
rpm = rpm + (rpm * rpmModifier.additive); rpm += rpm * rpmModifier.additive;
// Apply the reload time modifiers
let reloadTime = baseReloadTime * reloadTimeModifier.multiplicative; 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); calculateDPSAndDPM(damage, rpm, selectedWeapon.mag_size, reloadTime);
// Update the displayed weapon stats with the modified values
updateModifiedWeaponStats(damage, rpm, reloadTime); updateModifiedWeaponStats(damage, rpm, reloadTime);
} }
// Helper function to apply individual buffs // Helper function to apply individual buffs
function applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier = null) { function applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier = null) {
const {type, buffType, value} = buff; const {stat, type, value} = buff;
// Apply buffs based on type // Apply buffs based on the stat being modified
if (type === 'rpm') { if (stat === 'rpm') {
if (buffType === 'multiplicative') rpmModifier.multiplicative *= value; if (type === 'multiplicative') rpmModifier.multiplicative *= value;
else if (buffType === 'additive') rpmModifier.additive += value; else if (type === 'additive') rpmModifier.additive += value;
} }
if (type === 'reloadTime') { if (stat === 'reloadTime') {
if (buffType === 'multiplicative') reloadTimeModifier.multiplicative *= value; if (type === 'multiplicative') reloadTimeModifier.multiplicative *= value;
else if (buffType === 'additive') reloadTimeModifier.additive += value; else if (type === 'additive') reloadTimeModifier.additive += value;
} }
// Apply damage buffs // Apply damage buffs
if (type === 'damage' && damageModifier) { if (stat === 'damage' && damageModifier) {
if (buffType === 'multiplicative') damageModifier.multiplicative *= value; if (type === 'multiplicative') damageModifier.multiplicative *= value;
else if (buffType === 'additive') damageModifier.additive += value; else if (type === 'additive') damageModifier.additive += value;
} }
} }
+40 -20
View File
@@ -4,25 +4,29 @@
"id": "damage-item-additive-elite-he-rounds", "id": "damage-item-additive-elite-he-rounds",
"label": "Elite HE Rounds (+14 damage)", "label": "Elite HE Rounds (+14 damage)",
"value": 14, "value": 14,
"type": "additive" "type": "additive",
"operatives": []
}, },
{ {
"id": "damage-item-additive-he-rounds", "id": "damage-item-additive-he-rounds",
"label": "HE Rounds (+8 damage)", "label": "HE Rounds (+8 damage)",
"value": 8, "value": 8,
"type": "additive" "type": "additive",
"operatives": []
}, },
{ {
"id": "damage-item-multiplicative-strength-mixture", "id": "damage-item-multiplicative-strength-mixture",
"label": "Strength Mixture (+20% damage)", "label": "Strength Mixture (+20% damage)",
"value": 1.2, "value": 1.2,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "damage-item-multiplicative-fortunos-necklace", "id": "damage-item-multiplicative-fortunos-necklace",
"label": "Fortunos Necklace (+15% damage)", "label": "Fortunos Necklace (+15% damage)",
"value": 1.15, "value": 1.15,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "multiple-buffs-bloxy-cola", "id": "multiple-buffs-bloxy-cola",
@@ -38,19 +42,22 @@
"value": 0, "value": 0,
"buffType": "multiplicative" "buffType": "multiplicative"
} }
] ],
"operatives": []
}, },
{ {
"id": "damage-item-multiplicative-enhancer", "id": "damage-item-multiplicative-enhancer",
"label": "Enhancer (+10% damage)", "label": "Enhancer (+10% damage)",
"value": 1.1, "value": 1.1,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "damage-item-multiplicative-teleport-device", "id": "damage-item-multiplicative-teleport-device",
"label": "Teleport Device (+25% damage)", "label": "Teleport Device (+25% damage)",
"value": 1.25, "value": 1.25,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
} }
], ],
"operativePerks": [ "operativePerks": [
@@ -58,25 +65,29 @@
"id": "damage-perk-multiplicative-fbi-badge", "id": "damage-perk-multiplicative-fbi-badge",
"label": "FBI Badge (+10% Damage)", "label": "FBI Badge (+10% Damage)",
"value": 1.1, "value": 1.1,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "damage-perk-multiplicative-anatomy-book", "id": "damage-perk-multiplicative-anatomy-book",
"label": "Anatomy Book (+5% Damage)", "label": "Anatomy Book (+5% Damage)",
"value": 1.05, "value": 1.05,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "damage-perk-multiplicative-silly-soldier", "id": "damage-perk-multiplicative-silly-soldier",
"label": "Silly Soldier (+10% Damage)", "label": "Silly Soldier (+10% Damage)",
"value": 1.10, "value": 1.10,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "damage-perk-multiplicative-precise-shots", "id": "damage-perk-multiplicative-precise-shots",
"label": "Precise Shots (+15% Damage)", "label": "Precise Shots (+15% Damage)",
"value": 1.15, "value": 1.40,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "damage-perk-multiplicative-goc-insignia", "id": "damage-perk-multiplicative-goc-insignia",
@@ -92,7 +103,8 @@
"value": 0.85, "value": 0.85,
"buffType": "multiplicative" "buffType": "multiplicative"
} }
] ],
"operatives": []
} }
], ],
"abilityPerks": [ "abilityPerks": [
@@ -110,17 +122,20 @@
"value": 0.6, "value": 0.6,
"buffType": "multiplicative" "buffType": "multiplicative"
} }
] ],
"operatives": []
}, },
{ {
"id": "damage-ability-multiplicative-heath-spawn", "id": "damage-ability-multiplicative-heath-spawn",
"label": "[All Operatives] Heath Spawn (+30% Damage)", "label": "[All Operatives] Heath Spawn (+30% Damage)",
"value": 1.3, "value": 1.3,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "multiple-buffs-warcry", "id": "multiple-buffs-warcry",
"label": "[All Operatives] War Cry(+25% Damage, +?% Reload Speed)", "label": "[All Operatives] War Cry(+25% Damage, +?% Reload Speed)",
"operatives": [],
"buffs": [ "buffs": [
{ {
"type": "damage", "type": "damage",
@@ -138,31 +153,36 @@
"id": "damage-ability-multiplicative-blackout", "id": "damage-ability-multiplicative-blackout",
"label": "[All Operatives] Blackout (+30% Damage)", "label": "[All Operatives] Blackout (+30% Damage)",
"value": 1.3, "value": 1.3,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "damage-ability-multiplicative-red-scan", "id": "damage-ability-multiplicative-red-scan",
"label": "[All Operatives] Red Scan (+30% Damage)", "label": "[All Operatives] Red Scan (+30% Damage)",
"value": 1.3, "value": 1.3,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "damage-ability-multiplicative-red-scan", "id": "damage-ability-multiplicative-red-scan",
"label": "[All Operatives] Green Scan (+50% Damage)", "label": "[All Operatives] Green Scan (+50% Damage)",
"value": 1.5, "value": 1.5,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "damage-ability-multiplicative-point-out", "id": "damage-ability-multiplicative-point-out",
"label": "[All Operatives] Point Out (+50% Damage)", "label": "[All Operatives] Point Out (+50% Damage)",
"value": 1.5, "value": 1.5,
"type": "multiplicative" "type": "multiplicative",
"operatives": []
}, },
{ {
"id": "damage-item-additive-5-uiu-elite", "id": "damage-item-additive-5-uiu-elite",
"label": "[All Operatives] 5 UIU Elite nearby (+25 damage)", "label": "[All Operatives] 5 UIU Elite nearby (+25 damage)",
"value": 25, "value": 25,
"type": "additive" "type": "additive",
"operatives": []
} }
] ]
} }
+181 -6
View File
@@ -3,7 +3,16 @@
{ {
"id": "Classic-Guard", "id": "Classic-Guard",
"name": "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", "id": "Classic-Scout",
@@ -13,7 +22,16 @@
{ {
"id": "Classic-RCU", "id": "Classic-RCU",
"name": "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", "id": "Classic-Viper",
@@ -23,7 +41,16 @@
{ {
"id": "Classic-SD-Sergeant", "id": "Classic-SD-Sergeant",
"name": "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", "id": "Classic-ISD",
@@ -43,17 +70,73 @@
{ {
"id": "Classic-Vanguard", "id": "Classic-Vanguard",
"name": "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", "id": "Classic-Demolitionist",
"name": "Demolitionist", "name": "Demolitionist",
"category": "Classic" "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", "id": "Classic-Mercenary",
"name": "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", "id": "Classic-CRT",
@@ -63,7 +146,99 @@
{ {
"id": "Classic-Anarchist", "id": "Classic-Anarchist",
"name": "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": ""
}
]
} }
] ]
} }
+2 -1
View File
@@ -72,7 +72,8 @@
<!-- Modifiers Display --> <!-- Modifiers Display -->
<div id="modifiers"></div> <div id="modifiers"></div>
<h3>Operative Specific Modifiers</h3>
<div id="operative-modifiers"></div>
<script src="{{ url_for('static', filename='filterWeapons.js') }}"></script> <script src="{{ url_for('static', filename='filterWeapons.js') }}"></script>
</main> </main>