some new features + json adjustments

This commit is contained in:
IM23a-spirgif
2024-11-06 18:58:09 +01:00
parent cbb00b060c
commit 9287c98635
4 changed files with 85 additions and 25 deletions
+50 -16
View File
@@ -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;
}
+24 -4
View File
@@ -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"]
},
+9 -3
View File
@@ -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": ""
+2 -2
View File
@@ -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": ""