everything is done, now we need to add all operatives

This commit is contained in:
IM23a-spirgif
2024-09-18 22:31:50 +02:00
parent 96622eae77
commit a120cd7e37
2 changed files with 119 additions and 30 deletions
+67 -17
View File
@@ -51,9 +51,10 @@ function updateOperativeBuffs(operative) {
input.id = mod.id;
input.value = mod.value;
input.dataset.type = mod.type;
input.dataset.buffs = mod.buffs ? JSON.stringify(mod.buffs) : ''; // Store buffs if available
// Automatically check the box if you want it enabled by default
input.checked = true;
// Set checkbox to be unchecked by default
input.checked = false;
label.appendChild(input);
label.appendChild(document.createTextNode(mod.label));
@@ -200,45 +201,95 @@ function applyModifiers() {
let rpmModifier = {additive: 0, multiplicative: 1};
let reloadTimeModifier = {additive: 0, multiplicative: 1};
// Function to process individual modifiers
// Function to process global modifiers
const processModifier = (mod) => {
const modType = mod.dataset.type;
const modValue = parseFloat(mod.value);
if (mod.appliesNotTo && mod.appliesNotTo === selectedWeapon.guntype) {
return; // Skip this modifier
}
if (mod.appliesTo && mod.appliesTo !== selectedWeapon.guntype) {
return; // Skip this modifier
}
// Handle modifiers with multiple 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 => {
// Apply each buff
applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier);
});
} else {
const modType = mod.dataset.type;
const modValue = parseFloat(mod.value);
const singleBuff = {
type: modType === 'multiplicative' ? 'multiplicative' : 'additive', // Use the proper modifier type
type: modType === 'multiplicative' ? 'multiplicative' : 'additive',
buffType: modType,
value: modValue
};
if (mod.id.includes('damage')) {
singleBuff.type = 'damage'; // This mod applies to damage
singleBuff.type = 'damage';
} else if (mod.id.includes('rpm')) {
singleBuff.type = 'rpm'; // This mod applies to RPM
singleBuff.type = 'rpm';
} else if (mod.id.includes('reload')) {
singleBuff.type = 'reloadTime'; // This mod applies to reload time
singleBuff.type = 'reloadTime';
}
applyBuff(singleBuff, rpmModifier, reloadTimeModifier, damageModifier);
}
};
// Function to process operative-based modifiers
const processOperativeModifier = (mod) => {
if (mod.appliesNotTo && mod.appliesNotTo === selectedWeapon.guntype) {
return; // Skip this modifier for this weapon type
}
if (mod.appliesTo && mod.appliesTo !== selectedWeapon.guntype) {
return; // Skip if the modifier does not apply to this weapon type
}
// Handle operative modifiers with multiple buffs
if (mod.buffs) {
mod.buffs.forEach(buff => {
applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier);
});
} else {
const modValue = parseFloat(mod.value);
const modType = mod.type || 'additive';
const singleBuff = {
type: mod.id.includes('damage') ? 'damage' : mod.id.includes('rpm') ? 'rpm' : 'reloadTime',
buffType: modType === 'multiplicative' ? 'multiplicative' : 'additive',
value: modValue
};
applyBuff(singleBuff, rpmModifier, reloadTimeModifier, damageModifier);
}
};
// Clear out listeners and avoid re-adding
const modifiersContainer = document.getElementById('modifiers');
modifiersContainer.removeEventListener('change', applyModifiers);
// Process global modifiers
document.querySelectorAll('#modifiers input:checked').forEach(mod => {
processModifier(mod);
});
// Re-apply listener after change
modifiersContainer.addEventListener('change', applyModifiers);
// Process operative-specific modifiers
if (selectedOperative) {
document.querySelectorAll('#operative-modifiers input:checked').forEach(mod => {
processModifier(mod);
});
// Process operative-specific modifiers that are checked
const operativeSection = document.getElementById('operative-modifiers');
operativeSection.querySelectorAll('input:checked').forEach(mod => {
if (selectedOperative && selectedOperative.modifiers) {
const modObj = selectedOperative.modifiers.find(m => m.id === mod.id);
if (modObj) {
processOperativeModifier(modObj);
}
}
});
// Recalculate with applied modifiers
let damage = baseDamage * damageModifier.multiplicative;
@@ -254,8 +305,7 @@ function applyModifiers() {
updateModifiedWeaponStats(damage, rpm, reloadTime);
}
// Helper function to apply individual buffs
// Function to apply individual buffs (simplified to avoid mistakes)
function applyBuff(buff, rpmModifier, reloadTimeModifier, damageModifier = null) {
const {type, buffType, value} = buff;
+46 -7
View File
@@ -55,7 +55,16 @@
{
"id": "Classic-ISD",
"name": "ISD",
"category": "Classic"
"category": "Classic",
"modifiers": [
{
"id": "chaos-insurgency-damage-perk",
"label": "Chaos Insurgency (+50% Damage)",
"value": 1.50,
"type": "multiplicative",
"appliesTo": ""
}
]
},
{
"id": "Classic-TRU",
@@ -94,7 +103,7 @@
"label": "LMG User (+35% Damage)",
"value": 1.35,
"type": "multiplicative",
"appliesNotTo": "LMG"
"appliesTo": "LMG"
}
]
},
@@ -125,13 +134,23 @@
{
"id": "all-upgrades-damage-perk",
"label": "All Upgrades (+25% Damage, +15% Reload Speed)",
"buffs": [
{
"type": "damage",
"value": 1.25,
"type": "multiplicative",
"buffType": "multiplicative"
},
{
"type": "reloadTime",
"value": 0.85,
"buffType": "multiplicative"
}
],
"appliesTo": ""
},
{
"id": "mcd-sandevistan-damage-perk",
"label": "All Upgrades (+75% Damage)",
"label": "MCD Sandevistan (+75% Damage)",
"value": 1.75,
"type": "multiplicative",
"appliesTo": ""
@@ -213,8 +232,18 @@
{
"id": "rrt-mastery-damage-rpm-perk",
"label": "Mastery (+25% Firerate, +25% Damage)",
"buffs": [
{
"type": "damage",
"value": 1.25,
"type": "multiplicative",
"buffType": "multiplicative"
},
{
"type": "rpm",
"value": 1.25,
"buffType": "multiplicative"
}
],
"appliesTo": ""
}
]
@@ -234,8 +263,18 @@
{
"id": "adrenaline-damage-reload-perk",
"label": "Adrenaline (+30% Damage, +40% Reload Speed)",
"value": 1.3,
"type": "multiplicative",
"buffs": [
{
"type": "damage",
"value": 1.30,
"buffType": "multiplicative"
},
{
"type": "reloadTime",
"value": 0.6,
"buffType": "multiplicative"
}
],
"appliesTo": ""
},
{