mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-08 22:33:24 +00:00
Fix for engineered modules in SLEF imports from Inara.
This commit is contained in:
@@ -327,26 +327,43 @@ export function setPercent(ship, m, percent) {
|
||||
ship.clearModifications(m);
|
||||
// Pick given value as multiplier
|
||||
const mult = percent / 100;
|
||||
const features = m.blueprint.grades[m.blueprint.grade].features;
|
||||
setQualityCB(m.blueprint, mult, (featureName, value) => ship.setModification(m, featureName, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the blueprint quality and fires a callback for each property affected.
|
||||
* @param {Object} blueprint The ship for which to perform the modifications
|
||||
* @param {Number} quality The quality to apply - float number 0 to 1.
|
||||
* @param {Function} cb The Callback to run for each property. Function (featureName, value)
|
||||
*/
|
||||
export function setQualityCB(blueprint, quality, cb) {
|
||||
// Pick given value as multiplier
|
||||
const features = blueprint.grades[blueprint.grade].features;
|
||||
for (const featureName in features) {
|
||||
let value;
|
||||
if (Modifications.modifications[featureName].higherbetter) {
|
||||
// Higher is better, but is this making it better or worse?
|
||||
if (features[featureName][0] < 0 || (features[featureName][0] === 0 && features[featureName][1] < 0)) {
|
||||
value = features[featureName][1] + ((features[featureName][0] - features[featureName][1]) * mult);
|
||||
value = features[featureName][1] + ((features[featureName][0] - features[featureName][1]) * quality);
|
||||
} else {
|
||||
value = features[featureName][0] + ((features[featureName][1] - features[featureName][0]) * mult);
|
||||
value = features[featureName][0] + ((features[featureName][1] - features[featureName][0]) * quality);
|
||||
}
|
||||
} else {
|
||||
// Higher is worse, but is this making it better or worse?
|
||||
if (features[featureName][0] < 0 || (features[featureName][0] === 0 && features[featureName][1] < 0)) {
|
||||
value = features[featureName][0] + ((features[featureName][1] - features[featureName][0]) * mult);
|
||||
value = features[featureName][0] + ((features[featureName][1] - features[featureName][0]) * quality);
|
||||
} else {
|
||||
value = features[featureName][1] + ((features[featureName][0] - features[featureName][1]) * mult);
|
||||
value = features[featureName][1] + ((features[featureName][0] - features[featureName][1]) * quality);
|
||||
}
|
||||
}
|
||||
|
||||
_setValue(ship, m, featureName, value);
|
||||
if (Modifications.modifications[featureName].type == 'percentage') {
|
||||
value = value * 10000;
|
||||
} else if (Modifications.modifications[featureName].type == 'numeric') {
|
||||
value = value * 100;
|
||||
}
|
||||
|
||||
cb(featureName, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Ships } from 'coriolis-data/dist';
|
||||
import Module from '../shipyard/Module';
|
||||
import { Modules } from 'coriolis-data/dist';
|
||||
import { Modifications } from 'coriolis-data/dist';
|
||||
import { getBlueprint } from './BlueprintFunctions';
|
||||
import { getBlueprint, setQualityCB } from './BlueprintFunctions';
|
||||
|
||||
/**
|
||||
* Obtain a module given its FD Name
|
||||
@@ -168,8 +168,6 @@ export function shipFromLoadoutJSON(json) {
|
||||
const hardpointSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === hardpointName.toLowerCase());
|
||||
if (!hardpointSlot) {
|
||||
// This can happen with old imports that don't contain new hardpoints
|
||||
} else if (!hardpointSlot) {
|
||||
// No module
|
||||
} else {
|
||||
hardpoint = _moduleFromFdName(hardpointSlot.Item);
|
||||
ship.use(ship.hardpoints[hardpointArrayNum], hardpoint, true);
|
||||
@@ -303,20 +301,13 @@ function _addModifications(module, modifiers, quality, blueprint, grade, special
|
||||
}
|
||||
}
|
||||
} else if (quality) {
|
||||
if (module.blueprint.grades) {
|
||||
const features = module.blueprint.grades[Number(grade)].features;
|
||||
Object.keys(features).map(featureKey => {
|
||||
/*
|
||||
Here we compute the value to use for this feature based on the range and quality.
|
||||
We do this by finding the difference between the low and high ends of the range.
|
||||
This gives us the maximum increase at 100% quality. Then we multiply this number by
|
||||
the quality to determine the actual increase. Lastly we add the actual increase to
|
||||
the low end of the range back in to determine the final value.
|
||||
Value = ((High End of Range - Low End of Range) * Quality) + Low End of Range
|
||||
*/
|
||||
let value = (((features[featureKey][1] * 100) - (features[featureKey][0] * 100) * Number(quality)) + (features[featureKey][0] * 100)) * 100;
|
||||
module.setModValue(featureKey, value, true);
|
||||
});
|
||||
}
|
||||
setQualityCB(module.blueprint, quality, (featureName, value) => {
|
||||
// The resistance values of bulkheads need an extra adjustment.
|
||||
if (featureName === 'kinres' || featureName === 'thermres' || featureName === 'causres' || featureName === 'explres') {
|
||||
let baseValue = module.get(featureName, false);
|
||||
value = (1 - baseValue) * value;
|
||||
}
|
||||
module.setModValue(featureName, value, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user