Compare commits

...

8 Commits

Author SHA1 Message Date
Felix Linker
7050356bce Merge pull request #675 from alexeygorb/feature/fix-inara-slef-import
Fix for engineered modules in SLEF imports from Inara.
2021-09-10 16:44:11 +02:00
Alexey Gorb
88c9bb0254 Fix for engineered modules in SLEF imports from Inara. Restored the deleted code. 2021-09-06 23:46:55 +02:00
Alexey Gorb
45f1dd2da9 Fix for engineered modules in SLEF imports from Inara. 2021-08-16 00:04:14 +02:00
Alexey Gorb
46bcc2313f Moved the resistance modifiers value calculation to the setModValue of a Module class. 2021-08-15 14:37:45 +02:00
Alexey Gorb
50f9c0faa1 Fix for engineered modules in SLEF imports from Inara. Unused function removed. 2021-08-11 12:04:25 +02:00
Alexey Gorb
74829a09c0 Fix for engineered modules in SLEF imports from Inara. 2021-08-11 11:55:24 +02:00
Felix Linker
45508ba2d4 Merge pull request #673 from alexeygorb/feature/fix-inara-slef-import
Fix for engineered modules in SLEF imports from Inara.
2021-08-10 12:57:42 +02:00
Alexey Gorb
624adf2b64 Fix for engineered modules in SLEF imports from Inara. 2021-08-10 11:35:44 +02:00
5 changed files with 344 additions and 342 deletions

View File

@@ -44,7 +44,7 @@ export default class Modification extends TranslatedComponent {
if (reCast.endsWith(value) || reCast.startsWith(value)) { if (reCast.endsWith(value) || reCast.startsWith(value)) {
let { m, name, ship } = this.props; let { m, name, ship } = this.props;
value = Math.max(Math.min(value, 50000), -50000); value = Math.max(Math.min(value, 50000), -50000);
ship.setModification(m, name, value, true, true); ship.setModification(m, name, value, true);
} }
} }

View File

@@ -70,7 +70,7 @@ export default class Module {
/** /**
* Set a value for a given modification ID * Set a value for a given modification ID
* @param {Number} name The name of the modification * @param {String} name The name of the modification
* @param {object} value The value of the modification. If it is a numeric value then it should be an integer scaled so that -2.34% == -234 * @param {object} value The value of the modification. If it is a numeric value then it should be an integer scaled so that -2.34% == -234
* @param {Boolean} valueiswithspecial true if the value includes the special effect (when coming from a UI component) * @param {Boolean} valueiswithspecial true if the value includes the special effect (when coming from a UI component)
*/ */
@@ -81,7 +81,13 @@ export default class Module {
if (!this.origVals) { if (!this.origVals) {
this.origVals = {}; this.origVals = {};
} }
if (valueiswithspecial && this.blueprint && this.blueprint.special) { if (!valueiswithspecial) {
// Resistance modifiers scale with the base value.
if (name === 'kinres' || name === 'thermres' || name === 'causres' || name === 'explres') {
let baseValue = this.get(name, false);
value = (1 - baseValue) * value;
}
} else if (valueiswithspecial && this.blueprint && this.blueprint.special) {
// This module has a special effect, see if we need to alter the stored value // This module has a special effect, see if we need to alter the stored value
const modifierActions = Modifications.modifierActions[this.blueprint.special.edname]; const modifierActions = Modifications.modifierActions[this.blueprint.special.edname];
if (modifierActions && modifierActions[name]) { if (modifierActions && modifierActions[name]) {
@@ -113,7 +119,7 @@ export default class Module {
/** /**
* Helper to obtain a module's value. * Helper to obtain a module's value.
* @param {String} name The name of the modifier to obtain * @param {String} name The name of the modifier to obtain
* @param {Number} modified Whether to return the raw or modified value * @param {Boolean} modified Whether to return the raw or modified value
* @return {Number} The value queried * @return {Number} The value queried
*/ */
get(name, modified = true) { get(name, modified = true) {

View File

@@ -492,25 +492,18 @@ export default class Ship {
* @param {Object} m The module to change * @param {Object} m The module to change
* @param {Object} name The name of the modification to change * @param {Object} name The name of the modification to change
* @param {Number} value The new value of the modification. The value of the modification is scaled to provide two decimal places of precision in an integer. For example 1.23% is stored as 123 * @param {Number} value The new value of the modification. The value of the modification is scaled to provide two decimal places of precision in an integer. For example 1.23% is stored as 123
* @param {bool} sentfromui True if this update was sent from the UI * @param {boolean} isAbsolute True if value is an absolute value and not a modification value
* @param {bool} isAbsolute True if value is an absolute value and not a
* modification value
*/ */
setModification(m, name, value, sentfromui, isAbsolute) { setModification(m, name, value, isAbsolute = false) {
if (isNaN(value)) { if (isNaN(value)) {
// Value passed is invalid; reset it to 0 // Value passed is invalid; reset it to 0
value = 0; value = 0;
} }
if (isAbsolute) { if (isAbsolute) {
m.setPretty(name, value, sentfromui); m.setPretty(name, value, isAbsolute);
} else { } else {
// Resistance modifiers scale with the base value m.setModValue(name, value, false);
if (name == 'kinres' || name == 'thermres' || name == 'causres' || name == 'explres') {
let baseValue = m.get(name, false);
value = (1 - baseValue) * value;
}
m.setModValue(name, value, sentfromui);
} }
// Handle special cases // Handle special cases
@@ -543,7 +536,7 @@ export default class Ship {
this.recalculateArmour(); this.recalculateArmour();
} else if (name === 'shieldreinforcement') { } else if (name === 'shieldreinforcement') {
this.recalculateShieldCells(); this.recalculateShieldCells();
} else if (name === 'burst' || name == 'burstrof' || name === 'clip' || name === 'damage' || name === 'distdraw' || name === 'jitter' || name === 'piercing' || name === 'range' || name === 'reload' || name === 'rof' || name === 'thermload') { } else if (name === 'burst' || name === 'burstrof' || name === 'clip' || name === 'damage' || name === 'distdraw' || name === 'jitter' || name === 'piercing' || name === 'range' || name === 'reload' || name === 'rof' || name === 'thermload') {
this.recalculateDps(); this.recalculateDps();
this.recalculateHps(); this.recalculateHps();
this.recalculateEps(); this.recalculateEps();

View File

@@ -327,26 +327,43 @@ export function setPercent(ship, m, percent) {
ship.clearModifications(m); ship.clearModifications(m);
// Pick given value as multiplier // Pick given value as multiplier
const mult = percent / 100; 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) { for (const featureName in features) {
let value; let value;
if (Modifications.modifications[featureName].higherbetter) { if (Modifications.modifications[featureName].higherbetter) {
// Higher is better, but is this making it better or worse? // Higher is better, but is this making it better or worse?
if (features[featureName][0] < 0 || (features[featureName][0] === 0 && features[featureName][1] < 0)) { 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 { } else {
value = features[featureName][0] + ((features[featureName][1] - features[featureName][0]) * mult); value = features[featureName][0] + ((features[featureName][1] - features[featureName][0]) * quality);
} }
} else { } else {
// Higher is worse, but is this making it better or worse? // Higher is worse, but is this making it better or worse?
if (features[featureName][0] < 0 || (features[featureName][0] === 0 && features[featureName][1] < 0)) { 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 { } 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);
} }
} }
@@ -360,23 +377,6 @@ export function setRandom(ship, m) {
setPercent(ship, m, Math.random() * 100); setPercent(ship, m, Math.random() * 100);
} }
/**
* Set a modification feature value
* @param {Object} ship The ship for which to perform the modifications
* @param {Object} m The module for which to perform the modifications
* @param {string} featureName The feature being set
* @param {number} value The value being set for the feature
*/
function _setValue(ship, m, featureName, value) {
if (Modifications.modifications[featureName].type == 'percentage') {
ship.setModification(m, featureName, value * 10000);
} else if (Modifications.modifications[featureName].type == 'numeric') {
ship.setModification(m, featureName, value * 100);
} else {
ship.setModification(m, featureName, value);
}
}
/** /**
* Provide 'percent' primary query * Provide 'percent' primary query
* @param {Object} m The module for which to perform the query * @param {Object} m The module for which to perform the query

View File

@@ -1,303 +1,306 @@
import Ship from '../shipyard/Ship'; import Ship from '../shipyard/Ship';
import { HARDPOINT_NUM_TO_CLASS, shipModelFromJson } from './CompanionApiUtils'; import { HARDPOINT_NUM_TO_CLASS, shipModelFromJson } from './CompanionApiUtils';
import { Ships } from 'coriolis-data/dist'; import { Ships } from 'coriolis-data/dist';
import Module from '../shipyard/Module'; import Module from '../shipyard/Module';
import { Modules } from 'coriolis-data/dist'; import { Modules } from 'coriolis-data/dist';
import { Modifications } 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 * Obtain a module given its FD Name
* @param {string} fdname the FD Name of the module * @param {string} fdname the FD Name of the module
* @return {Module} the module * @return {Module} the module
*/ */
function _moduleFromFdName(fdname) { function _moduleFromFdName(fdname) {
if (!fdname) return null; if (!fdname) return null;
fdname = fdname.toLowerCase(); fdname = fdname.toLowerCase();
// Check standard modules // Check standard modules
for (const grp in Modules.standard) { for (const grp in Modules.standard) {
if (Modules.standard.hasOwnProperty(grp)) { if (Modules.standard.hasOwnProperty(grp)) {
for (const i in Modules.standard[grp]) { for (const i in Modules.standard[grp]) {
if (Modules.standard[grp][i].symbol && Modules.standard[grp][i].symbol.toLowerCase() === fdname) { if (Modules.standard[grp][i].symbol && Modules.standard[grp][i].symbol.toLowerCase() === fdname) {
// Found it // Found it
return new Module({ template: Modules.standard[grp][i] }); return new Module({ template: Modules.standard[grp][i] });
} }
} }
} }
} }
// Check hardpoint modules // Check hardpoint modules
for (const grp in Modules.hardpoints) { for (const grp in Modules.hardpoints) {
if (Modules.hardpoints.hasOwnProperty(grp)) { if (Modules.hardpoints.hasOwnProperty(grp)) {
for (const i in Modules.hardpoints[grp]) { for (const i in Modules.hardpoints[grp]) {
if (Modules.hardpoints[grp][i].symbol && Modules.hardpoints[grp][i].symbol.toLowerCase() === fdname) { if (Modules.hardpoints[grp][i].symbol && Modules.hardpoints[grp][i].symbol.toLowerCase() === fdname) {
// Found it // Found it
return new Module({ template: Modules.hardpoints[grp][i] }); return new Module({ template: Modules.hardpoints[grp][i] });
} }
} }
} }
} }
// Check internal modules // Check internal modules
for (const grp in Modules.internal) { for (const grp in Modules.internal) {
if (Modules.internal.hasOwnProperty(grp)) { if (Modules.internal.hasOwnProperty(grp)) {
for (const i in Modules.internal[grp]) { for (const i in Modules.internal[grp]) {
if (Modules.internal[grp][i].symbol && Modules.internal[grp][i].symbol.toLowerCase() === fdname) { if (Modules.internal[grp][i].symbol && Modules.internal[grp][i].symbol.toLowerCase() === fdname) {
// Found it // Found it
return new Module({ template: Modules.internal[grp][i] }); return new Module({ template: Modules.internal[grp][i] });
} }
} }
} }
} }
// Not found // Not found
return null; return null;
} }
/** /**
* Build a ship from the journal Loadout event JSON * Build a ship from the journal Loadout event JSON
* @param {object} json the Loadout event JSON * @param {object} json the Loadout event JSON
* @return {Ship} the built ship * @return {Ship} the built ship
*/ */
export function shipFromLoadoutJSON(json) { export function shipFromLoadoutJSON(json) {
// Start off building a basic ship // Start off building a basic ship
const shipModel = shipModelFromJson(json); const shipModel = shipModelFromJson(json);
if (!shipModel) { if (!shipModel) {
throw 'No such ship found: "' + json.Ship + '"'; throw 'No such ship found: "' + json.Ship + '"';
} }
const shipTemplate = Ships[shipModel]; const shipTemplate = Ships[shipModel];
let ship = new Ship(shipModel, shipTemplate.properties, shipTemplate.slots); let ship = new Ship(shipModel, shipTemplate.properties, shipTemplate.slots);
ship.buildWith(null); ship.buildWith(null);
// Initial Ship building, don't do engineering yet. // Initial Ship building, don't do engineering yet.
let modsToAdd = []; let modsToAdd = [];
for (const module of json.Modules) { for (const module of json.Modules) {
switch (module.Slot.toLowerCase()) { switch (module.Slot.toLowerCase()) {
// Cargo Hatch. // Cargo Hatch.
case 'cargohatch': case 'cargohatch':
ship.cargoHatch.enabled = module.On; ship.cargoHatch.enabled = module.On;
ship.cargoHatch.priority = module.Priority; ship.cargoHatch.priority = module.Priority;
break; break;
// Add the bulkheads // Add the bulkheads
case 'armour': case 'armour':
if (module.Item.toLowerCase().endsWith('_armour_grade1')) { if (module.Item.toLowerCase().endsWith('_armour_grade1')) {
ship.useBulkhead(0, true); ship.useBulkhead(0, true);
} else if (module.Item.toLowerCase().endsWith('_armour_grade2')) { } else if (module.Item.toLowerCase().endsWith('_armour_grade2')) {
ship.useBulkhead(1, true); ship.useBulkhead(1, true);
} else if (module.Item.toLowerCase().endsWith('_armour_grade3')) { } else if (module.Item.toLowerCase().endsWith('_armour_grade3')) {
ship.useBulkhead(2, true); ship.useBulkhead(2, true);
} else if (module.Item.toLowerCase().endsWith('_armour_mirrored')) { } else if (module.Item.toLowerCase().endsWith('_armour_mirrored')) {
ship.useBulkhead(3, true); ship.useBulkhead(3, true);
} else if (module.Item.toLowerCase().endsWith('_armour_reactive')) { } else if (module.Item.toLowerCase().endsWith('_armour_reactive')) {
ship.useBulkhead(4, true); ship.useBulkhead(4, true);
} else { } else {
throw 'Unknown bulkheads "' + module.Item + '"'; throw 'Unknown bulkheads "' + module.Item + '"';
} }
ship.bulkheads.enabled = true; ship.bulkheads.enabled = true;
if (module.Engineering) _addModifications(ship.bulkheads.m, module.Engineering.Modifiers, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect); if (module.Engineering) _addModifications(ship.bulkheads.m, module.Engineering.Modifiers, module.Engineering.Quality, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect);
break; break;
case 'powerplant': case 'powerplant':
const powerplant = _moduleFromFdName(module.Item); const powerplant = _moduleFromFdName(module.Item);
ship.use(ship.standard[0], powerplant, true); ship.use(ship.standard[0], powerplant, true);
ship.standard[0].enabled = module.On; ship.standard[0].enabled = module.On;
ship.standard[0].priority = module.Priority; ship.standard[0].priority = module.Priority;
if (module.Engineering) _addModifications(powerplant, module.Engineering.Modifiers, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect); if (module.Engineering) _addModifications(powerplant, module.Engineering.Modifiers, module.Engineering.Quality, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect);
break; break;
case 'mainengines': case 'mainengines':
const thrusters = _moduleFromFdName(module.Item); const thrusters = _moduleFromFdName(module.Item);
ship.use(ship.standard[1], thrusters, true); ship.use(ship.standard[1], thrusters, true);
ship.standard[1].enabled = module.On; ship.standard[1].enabled = module.On;
ship.standard[1].priority = module.Priority; ship.standard[1].priority = module.Priority;
if (module.Engineering) _addModifications(thrusters, module.Engineering.Modifiers, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect); if (module.Engineering) _addModifications(thrusters, module.Engineering.Modifiers, module.Engineering.Quality, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect);
break; break;
case 'frameshiftdrive': case 'frameshiftdrive':
const frameshiftdrive = _moduleFromFdName(module.Item); const frameshiftdrive = _moduleFromFdName(module.Item);
ship.use(ship.standard[2], frameshiftdrive, true); ship.use(ship.standard[2], frameshiftdrive, true);
ship.standard[2].enabled = module.On; ship.standard[2].enabled = module.On;
ship.standard[2].priority = module.Priority; ship.standard[2].priority = module.Priority;
if (module.Engineering) _addModifications(frameshiftdrive, module.Engineering.Modifiers, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect); if (module.Engineering) _addModifications(frameshiftdrive, module.Engineering.Modifiers, module.Engineering.Quality, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect);
break; break;
case 'lifesupport': case 'lifesupport':
const lifesupport = _moduleFromFdName(module.Item); const lifesupport = _moduleFromFdName(module.Item);
ship.use(ship.standard[3], lifesupport, true); ship.use(ship.standard[3], lifesupport, true);
ship.standard[3].enabled = module.On === true; ship.standard[3].enabled = module.On === true;
ship.standard[3].priority = module.Priority; ship.standard[3].priority = module.Priority;
if (module.Engineering) _addModifications(lifesupport, module.Engineering.Modifiers, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect); if (module.Engineering) _addModifications(lifesupport, module.Engineering.Modifiers, module.Engineering.Quality, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect);
break; break;
case 'powerdistributor': case 'powerdistributor':
const powerdistributor = _moduleFromFdName(module.Item); const powerdistributor = _moduleFromFdName(module.Item);
ship.use(ship.standard[4], powerdistributor, true); ship.use(ship.standard[4], powerdistributor, true);
ship.standard[4].enabled = module.On; ship.standard[4].enabled = module.On;
ship.standard[4].priority = module.Priority; ship.standard[4].priority = module.Priority;
if (module.Engineering) _addModifications(powerdistributor, module.Engineering.Modifiers, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect); if (module.Engineering) _addModifications(powerdistributor, module.Engineering.Modifiers, module.Engineering.Quality, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect);
break; break;
case 'radar': case 'radar':
const sensors = _moduleFromFdName(module.Item); const sensors = _moduleFromFdName(module.Item);
ship.use(ship.standard[5], sensors, true); ship.use(ship.standard[5], sensors, true);
ship.standard[5].enabled = module.On; ship.standard[5].enabled = module.On;
ship.standard[5].priority = module.Priority; ship.standard[5].priority = module.Priority;
if (module.Engineering) _addModifications(sensors, module.Engineering.Modifiers, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect); if (module.Engineering) _addModifications(sensors, module.Engineering.Modifiers, module.Engineering.Quality, module.Engineering.BlueprintName, module.Engineering.Level, module.Engineering.ExperimentalEffect);
break; break;
case 'fueltank': case 'fueltank':
const fueltank = _moduleFromFdName(module.Item); const fueltank = _moduleFromFdName(module.Item);
ship.use(ship.standard[6], fueltank, true); ship.use(ship.standard[6], fueltank, true);
ship.standard[6].enabled = true; ship.standard[6].enabled = true;
ship.standard[6].priority = 0; ship.standard[6].priority = 0;
break; break;
default: default:
} }
if (module.Slot.toLowerCase().search(/hardpoint/) !== -1) { if (module.Slot.toLowerCase().search(/hardpoint/) !== -1) {
// Add hardpoints // Add hardpoints
let hardpoint; let hardpoint;
let hardpointClassNum = -1; let hardpointClassNum = -1;
let hardpointSlotNum = -1; let hardpointSlotNum = -1;
let hardpointArrayNum = 0; let hardpointArrayNum = 0;
for (let i in shipTemplate.slots.hardpoints) { for (let i in shipTemplate.slots.hardpoints) {
if (shipTemplate.slots.hardpoints[i] === hardpointClassNum) { if (shipTemplate.slots.hardpoints[i] === hardpointClassNum) {
// Another slot of the same class // Another slot of the same class
hardpointSlotNum++; hardpointSlotNum++;
} else { } else {
// The first slot of a new class // The first slot of a new class
hardpointClassNum = shipTemplate.slots.hardpoints[i]; hardpointClassNum = shipTemplate.slots.hardpoints[i];
hardpointSlotNum = 1; hardpointSlotNum = 1;
} }
// Now that we know what we're looking for, find it // Now that we know what we're looking for, find it
const hardpointName = HARDPOINT_NUM_TO_CLASS[hardpointClassNum] + 'Hardpoint' + hardpointSlotNum; const hardpointName = HARDPOINT_NUM_TO_CLASS[hardpointClassNum] + 'Hardpoint' + hardpointSlotNum;
const hardpointSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === hardpointName.toLowerCase()); const hardpointSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === hardpointName.toLowerCase());
if (!hardpointSlot) { if (!hardpointSlot) {
// This can happen with old imports that don't contain new hardpoints // This can happen with old imports that don't contain new hardpoints
} else if (!hardpointSlot) { } else {
// No module hardpoint = _moduleFromFdName(hardpointSlot.Item);
} else { ship.use(ship.hardpoints[hardpointArrayNum], hardpoint, true);
hardpoint = _moduleFromFdName(hardpointSlot.Item); ship.hardpoints[hardpointArrayNum].enabled = hardpointSlot.On;
ship.use(ship.hardpoints[hardpointArrayNum], hardpoint, true); ship.hardpoints[hardpointArrayNum].priority = hardpointSlot.Priority;
ship.hardpoints[hardpointArrayNum].enabled = hardpointSlot.On; modsToAdd.push({ coriolisMod: hardpoint, json: hardpointSlot });
ship.hardpoints[hardpointArrayNum].priority = hardpointSlot.Priority; }
modsToAdd.push({ coriolisMod: hardpoint, json: hardpointSlot }); hardpointArrayNum++;
} }
hardpointArrayNum++; }
} }
}
} let internalSlotNum = 0;
let militarySlotNum = 1;
let internalSlotNum = 0; for (let i in shipTemplate.slots.internal) {
let militarySlotNum = 1; if (!shipTemplate.slots.internal.hasOwnProperty(i)) {
for (let i in shipTemplate.slots.internal) { continue;
if (!shipTemplate.slots.internal.hasOwnProperty(i)) { }
continue; const isMilitary = isNaN(shipTemplate.slots.internal[i]) ? shipTemplate.slots.internal[i].name == 'Military' : false;
}
const isMilitary = isNaN(shipTemplate.slots.internal[i]) ? shipTemplate.slots.internal[i].name == 'Military' : false; // The internal slot might be a standard or a military slot. Military slots have a different naming system
let internalSlot = null;
// The internal slot might be a standard or a military slot. Military slots have a different naming system if (isMilitary) {
let internalSlot = null; const internalName = 'Military0' + militarySlotNum;
if (isMilitary) { internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase());
const internalName = 'Military0' + militarySlotNum; militarySlotNum++;
internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase()); } else {
militarySlotNum++; // Slot numbers are not contiguous so handle skips.
} else { for (; internalSlot === null && internalSlotNum < 99; internalSlotNum++) {
// Slot numbers are not contiguous so handle skips. // Slot sizes have no relationship to the actual size, either, so check all possibilities
for (; internalSlot === null && internalSlotNum < 99; internalSlotNum++) { for (let slotsize = 0; slotsize < 9; slotsize++) {
// Slot sizes have no relationship to the actual size, either, so check all possibilities const internalName = 'Slot' + (internalSlotNum <= 9 ? '0' : '') + internalSlotNum + '_Size' + slotsize;
for (let slotsize = 0; slotsize < 9; slotsize++) { if (json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase())) {
const internalName = 'Slot' + (internalSlotNum <= 9 ? '0' : '') + internalSlotNum + '_Size' + slotsize; internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase());
if (json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase())) { break;
internalSlot = json.Modules.find(elem => elem.Slot.toLowerCase() === internalName.toLowerCase()); }
break; }
} }
} }
}
} if (!internalSlot) {
// This can happen with old imports that don't contain new slots
if (!internalSlot) { } else {
// This can happen with old imports that don't contain new slots const internalJson = internalSlot;
} else { const internal = _moduleFromFdName(internalJson.Item);
const internalJson = internalSlot; ship.use(ship.internal[i], internal, true);
const internal = _moduleFromFdName(internalJson.Item); ship.internal[i].enabled = internalJson.On === true;
ship.use(ship.internal[i], internal, true); ship.internal[i].priority = internalJson.Priority;
ship.internal[i].enabled = internalJson.On === true; modsToAdd.push({ coriolisMod: internal, json: internalSlot });
ship.internal[i].priority = internalJson.Priority; }
modsToAdd.push({ coriolisMod: internal, json: internalSlot }); }
}
} for (const i of modsToAdd) {
if (i.json.Engineering) {
for (const i of modsToAdd) { _addModifications(i.coriolisMod, i.json.Engineering.Modifiers, i.json.Engineering.Quality, i.json.Engineering.BlueprintName, i.json.Engineering.Level, i.json.Engineering.ExperimentalEffect);
if (i.json.Engineering) { }
_addModifications(i.coriolisMod, i.json.Engineering.Modifiers, i.json.Engineering.BlueprintName, i.json.Engineering.Level, i.json.Engineering.ExperimentalEffect); }
} // We don't have any information on it so guess it's priority 5 and disabled
} if (!ship.cargoHatch) {
// We don't have any information on it so guess it's priority 5 and disabled ship.cargoHatch.enabled = false;
if (!ship.cargoHatch) { ship.cargoHatch.priority = 4;
ship.cargoHatch.enabled = false; }
ship.cargoHatch.priority = 4;
} // Now update the ship's codes before returning it
return ship.updatePowerPrioritesString().updatePowerEnabledString().updateModificationsString();
// Now update the ship's codes before returning it }
return ship.updatePowerPrioritesString().updatePowerEnabledString().updateModificationsString();
} /**
* Add the modifications for a module
/** * @param {Module} module the module
* Add the modifications for a module * @param {Object} modifiers the modifiers
* @param {Module} module the module * @param {float} quality quality of the modifiers 0 to 1
* @param {Object} modifiers the modifiers * @param {Object} blueprint the blueprint of the modification
* @param {Object} blueprint the blueprint of the modification * @param {Object} grade the grade of the modification
* @param {Object} grade the grade of the modification * @param {Object} specialModifications special modification
* @param {Object} specialModifications special modification */
*/ function _addModifications(module, modifiers, quality, blueprint, grade, specialModifications) {
function _addModifications(module, modifiers, blueprint, grade, specialModifications) { if (!modifiers && !quality) return;
if (!modifiers) return; let special;
let special; if (specialModifications) {
if (specialModifications) { if (specialModifications == 'special_plasma_slug') {
if (specialModifications == 'special_plasma_slug') { if (module.symbol.match(/PlasmaAccelerator/i)) {
if (module.symbol.match(/PlasmaAccelerator/i)) { specialModifications = 'special_plasma_slug_pa';
specialModifications = 'special_plasma_slug_pa'; } else {
} else { specialModifications = 'special_plasma_slug_cooled';
specialModifications = 'special_plasma_slug_cooled'; }
} }
} special = Modifications.specials[specialModifications];
special = Modifications.specials[specialModifications]; }
} // Add the blueprint definition, grade and special
// Add the blueprint definition, grade and special if (blueprint) {
if (blueprint) { module.blueprint = getBlueprint(blueprint, module);
module.blueprint = getBlueprint(blueprint, module); if (grade) {
if (grade) { module.blueprint.grade = Number(grade);
module.blueprint.grade = Number(grade); }
} if (special) {
if (special) { module.blueprint.special = special;
module.blueprint.special = special; }
} }
} if (modifiers) {
for (const i in modifiers) { for (const i in modifiers) {
// Some special modifications // Some special modifications
// Look up the modifiers to find what we need to do // Look up the modifiers to find what we need to do
const findMod = val => Object.keys(Modifications.modifierActions).find(elem => elem.toString().toLowerCase().replace(/(outfittingfieldtype_|persecond)/igm, '') === val.toString().toLowerCase().replace(/(outfittingfieldtype_|persecond)/igm, '')); const findMod = val => Object.keys(Modifications.modifierActions).find(elem => elem.toString().toLowerCase().replace(/(outfittingfieldtype_|persecond)/igm, '') === val.toString().toLowerCase().replace(/(outfittingfieldtype_|persecond)/igm, ''));
const modifierActions = Modifications.modifierActions[findMod(modifiers[i].Label)]; const modifierActions = Modifications.modifierActions[findMod(modifiers[i].Label)];
// TODO: Figure out how to scale this value. // TODO: Figure out how to scale this value.
if (!!modifiers[i].LessIsGood) { if (!!modifiers[i].LessIsGood) {
} }
let value = (modifiers[i].Value / modifiers[i].OriginalValue * 100 - 100) * 100; let value = (modifiers[i].Value / modifiers[i].OriginalValue * 100 - 100) * 100;
if (value === Infinity) { if (value === Infinity) {
value = modifiers[i].Value * 100; value = modifiers[i].Value * 100;
} }
if (modifiers[i].Label.search('DamageFalloffRange') >= 0) { if (modifiers[i].Label.search('DamageFalloffRange') >= 0) {
value = (modifiers[i].Value / module.range - 1) * 100; value = (modifiers[i].Value / module.range - 1) * 100;
} }
if (modifiers[i].Label.search('Resistance') >= 0) { if (modifiers[i].Label.search('Resistance') >= 0) {
value = (modifiers[i].Value * 100) - (modifiers[i].OriginalValue * 100); value = (modifiers[i].Value * 100) - (modifiers[i].OriginalValue * 100);
} }
if (modifiers[i].Label.search('ShieldMultiplier') >= 0 || modifiers[i].Label.search('DefenceModifierHealthMultiplier') >= 0) { if (modifiers[i].Label.search('ShieldMultiplier') >= 0 || modifiers[i].Label.search('DefenceModifierHealthMultiplier') >= 0) {
value = ((100 + modifiers[i].Value) / (100 + modifiers[i].OriginalValue) * 100 - 100) * 100; value = ((100 + modifiers[i].Value) / (100 + modifiers[i].OriginalValue) * 100 - 100) * 100;
} }
// Carry out the required changes // Carry out the required changes
for (const action in modifierActions) { for (const action in modifierActions) {
if (isNaN(modifierActions[action])) { if (isNaN(modifierActions[action])) {
module.setModValue(action, modifierActions[action]); module.setModValue(action, modifierActions[action]);
} else { } else {
module.setModValue(action, value, true); module.setModValue(action, value, true);
} }
} }
} }
} } else if (quality) {
setQualityCB(module.blueprint, quality, (featureName, value) => module.setModValue(featureName, value, false));
}
}