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
+71 -21
View File
@@ -51,9 +51,10 @@ function updateOperativeBuffs(operative) {
input.id = mod.id; input.id = mod.id;
input.value = mod.value; input.value = mod.value;
input.dataset.type = mod.type; 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 // Set checkbox to be unchecked by default
input.checked = true; input.checked = false;
label.appendChild(input); label.appendChild(input);
label.appendChild(document.createTextNode(mod.label)); label.appendChild(document.createTextNode(mod.label));
@@ -200,47 +201,97 @@ function applyModifiers() {
let rpmModifier = {additive: 0, multiplicative: 1}; let rpmModifier = {additive: 0, multiplicative: 1};
let reloadTimeModifier = {additive: 0, multiplicative: 1}; let reloadTimeModifier = {additive: 0, multiplicative: 1};
// Function to process individual modifiers // Function to process global modifiers
const processModifier = (mod) => { const processModifier = (mod) => {
const modType = mod.dataset.type; if (mod.appliesNotTo && mod.appliesNotTo === selectedWeapon.guntype) {
const modValue = parseFloat(mod.value); return; // Skip this modifier
}
if (mod.appliesTo && mod.appliesTo !== selectedWeapon.guntype) {
return; // Skip this modifier
}
// Handle modifiers with multiple buffs
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 {
const modType = mod.dataset.type;
const modValue = parseFloat(mod.value);
const singleBuff = { const singleBuff = {
type: modType === 'multiplicative' ? 'multiplicative' : 'additive', // Use the proper modifier type type: modType === 'multiplicative' ? 'multiplicative' : 'additive',
buffType: modType, buffType: modType,
value: modValue value: modValue
}; };
if (mod.id.includes('damage')) { if (mod.id.includes('damage')) {
singleBuff.type = 'damage'; // This mod applies to damage singleBuff.type = 'damage';
} else if (mod.id.includes('rpm')) { } else if (mod.id.includes('rpm')) {
singleBuff.type = 'rpm'; // This mod applies to RPM singleBuff.type = 'rpm';
} else if (mod.id.includes('reload')) { } else if (mod.id.includes('reload')) {
singleBuff.type = 'reloadTime'; // This mod applies to reload time singleBuff.type = 'reloadTime';
} }
applyBuff(singleBuff, rpmModifier, reloadTimeModifier, damageModifier); applyBuff(singleBuff, rpmModifier, reloadTimeModifier, damageModifier);
} }
}; };
// Process global modifiers // 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 => { document.querySelectorAll('#modifiers input:checked').forEach(mod => {
processModifier(mod); processModifier(mod);
}); });
// Process operative-specific modifiers
if (selectedOperative) {
document.querySelectorAll('#operative-modifiers input:checked').forEach(mod => {
processModifier(mod);
});
}
// Recalculate with applied modifiers // Re-apply listener after change
modifiersContainer.addEventListener('change', applyModifiers);
// Process operative-specific modifiers
// 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; let damage = baseDamage * damageModifier.multiplicative;
damage += damageModifier.additive; damage += damageModifier.additive;
@@ -254,8 +305,7 @@ function applyModifiers() {
updateModifiedWeaponStats(damage, rpm, reloadTime); updateModifiedWeaponStats(damage, rpm, reloadTime);
} }
// Function to apply individual buffs (simplified to avoid mistakes)
// 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 {type, buffType, value} = buff;
+46 -7
View File
@@ -55,7 +55,16 @@
{ {
"id": "Classic-ISD", "id": "Classic-ISD",
"name": "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", "id": "Classic-TRU",
@@ -94,7 +103,7 @@
"label": "LMG User (+35% Damage)", "label": "LMG User (+35% Damage)",
"value": 1.35, "value": 1.35,
"type": "multiplicative", "type": "multiplicative",
"appliesNotTo": "LMG" "appliesTo": "LMG"
} }
] ]
}, },
@@ -125,13 +134,23 @@
{ {
"id": "all-upgrades-damage-perk", "id": "all-upgrades-damage-perk",
"label": "All Upgrades (+25% Damage, +15% Reload Speed)", "label": "All Upgrades (+25% Damage, +15% Reload Speed)",
"buffs": [
{
"type": "damage",
"value": 1.25, "value": 1.25,
"type": "multiplicative", "buffType": "multiplicative"
},
{
"type": "reloadTime",
"value": 0.85,
"buffType": "multiplicative"
}
],
"appliesTo": "" "appliesTo": ""
}, },
{ {
"id": "mcd-sandevistan-damage-perk", "id": "mcd-sandevistan-damage-perk",
"label": "All Upgrades (+75% Damage)", "label": "MCD Sandevistan (+75% Damage)",
"value": 1.75, "value": 1.75,
"type": "multiplicative", "type": "multiplicative",
"appliesTo": "" "appliesTo": ""
@@ -213,8 +232,18 @@
{ {
"id": "rrt-mastery-damage-rpm-perk", "id": "rrt-mastery-damage-rpm-perk",
"label": "Mastery (+25% Firerate, +25% Damage)", "label": "Mastery (+25% Firerate, +25% Damage)",
"buffs": [
{
"type": "damage",
"value": 1.25, "value": 1.25,
"type": "multiplicative", "buffType": "multiplicative"
},
{
"type": "rpm",
"value": 1.25,
"buffType": "multiplicative"
}
],
"appliesTo": "" "appliesTo": ""
} }
] ]
@@ -234,8 +263,18 @@
{ {
"id": "adrenaline-damage-reload-perk", "id": "adrenaline-damage-reload-perk",
"label": "Adrenaline (+30% Damage, +40% Reload Speed)", "label": "Adrenaline (+30% Damage, +40% Reload Speed)",
"value": 1.3, "buffs": [
"type": "multiplicative", {
"type": "damage",
"value": 1.30,
"buffType": "multiplicative"
},
{
"type": "reloadTime",
"value": 0.6,
"buffType": "multiplicative"
}
],
"appliesTo": "" "appliesTo": ""
}, },
{ {