initial (re)implementation of engineer mods

still some kinds to work out.
This commit is contained in:
willyb321
2017-12-17 11:15:51 +11:00
parent b0e2cfd7db
commit 31dc789f6e

View File

@@ -123,6 +123,7 @@ export function shipModelFromJson(json) {
*/ */
export function shipFromJson(json) { export function shipFromJson(json) {
// Start off building a basic ship // Start off building a basic ship
console.log(json);
const shipModel = shipModelFromJson(json); const shipModel = shipModelFromJson(json);
if (!shipModel) { if (!shipModel) {
throw 'No such ship found: "' + json.name + '"'; throw 'No such ship found: "' + json.name + '"';
@@ -158,13 +159,13 @@ export function shipFromJson(json) {
throw 'Unknown bulkheads "' + armourJson.name + '"'; throw 'Unknown bulkheads "' + armourJson.name + '"';
} }
ship.bulkheads.enabled = true; ship.bulkheads.enabled = true;
if (armourJson.modifiers) _addModifications(ship.bulkheads.m, armourJson.modifiers, armourJson.recipeName, armourJson.recipeLevel); if (json.modules.Armour.WorkInProgress_modifications) _addModifications(ship.bulkheads.m, json.modules.Armour.WorkInProgress_modifications, json.modules.Armour.engineer.recipeName, json.modules.Armour.engineer.recipeLevel);
// Add the standard modules // Add the standard modules
// Power plant // Power plant
const powerplantJson = json.modules.PowerPlant.module; const powerplantJson = json.modules.PowerPlant.module;
const powerplant = _moduleFromEdId(powerplantJson.id); const powerplant = _moduleFromEdId(powerplantJson.id);
if (powerplantJson.modifiers) _addModifications(powerplant, powerplantJson.modifiers, powerplantJson.recipeName, powerplantJson.recipeLevel); if (json.modules.PowerPlant.WorkInProgress_modifications) _addModifications(powerplant, json.modules.PowerPlant.WorkInProgress_modifications, json.modules.PowerPlant.engineer.recipeName, json.modules.PowerPlant.engineer.recipeLevel);
ship.use(ship.standard[0], powerplant, true); ship.use(ship.standard[0], powerplant, true);
ship.standard[0].enabled = powerplantJson.on === true; ship.standard[0].enabled = powerplantJson.on === true;
ship.standard[0].priority = powerplantJson.priority; ship.standard[0].priority = powerplantJson.priority;
@@ -172,7 +173,7 @@ export function shipFromJson(json) {
// Thrusters // Thrusters
const thrustersJson = json.modules.MainEngines.module; const thrustersJson = json.modules.MainEngines.module;
const thrusters = _moduleFromEdId(thrustersJson.id); const thrusters = _moduleFromEdId(thrustersJson.id);
if (thrustersJson.modifiers) _addModifications(thrusters, thrustersJson.modifiers, thrustersJson.recipeName, thrustersJson.recipeLevel); if (json.modules.MainEngines.WorkInProgress_modifications) _addModifications(thrusters, json.modules.MainEngines.WorkInProgress_modifications, json.modules.MainEngines.engineer.recipeName, json.modules.MainEngines.engineer.recipeLevel);
ship.use(ship.standard[1], thrusters, true); ship.use(ship.standard[1], thrusters, true);
ship.standard[1].enabled = thrustersJson.on === true; ship.standard[1].enabled = thrustersJson.on === true;
ship.standard[1].priority = thrustersJson.priority; ship.standard[1].priority = thrustersJson.priority;
@@ -180,7 +181,7 @@ export function shipFromJson(json) {
// FSD // FSD
const frameshiftdriveJson = json.modules.FrameShiftDrive.module; const frameshiftdriveJson = json.modules.FrameShiftDrive.module;
const frameshiftdrive = _moduleFromEdId(frameshiftdriveJson.id); const frameshiftdrive = _moduleFromEdId(frameshiftdriveJson.id);
if (frameshiftdriveJson.modifiers) _addModifications(frameshiftdrive, frameshiftdriveJson.modifiers, frameshiftdriveJson.recipeName, frameshiftdriveJson.recipeLevel); if (json.modules.FrameShiftDrive.WorkInProgress_modifications) _addModifications(frameshiftdrive, json.modules.FrameShiftDrive.WorkInProgress_modifications, json.modules.FrameShiftDrive.engineer.recipeName, json.modules.FrameShiftDrive.engineer.recipeLevel);
ship.use(ship.standard[2], frameshiftdrive, true); ship.use(ship.standard[2], frameshiftdrive, true);
ship.standard[2].enabled = frameshiftdriveJson.on === true; ship.standard[2].enabled = frameshiftdriveJson.on === true;
ship.standard[2].priority = frameshiftdriveJson.priority; ship.standard[2].priority = frameshiftdriveJson.priority;
@@ -188,7 +189,7 @@ export function shipFromJson(json) {
// Life support // Life support
const lifesupportJson = json.modules.LifeSupport.module; const lifesupportJson = json.modules.LifeSupport.module;
const lifesupport = _moduleFromEdId(lifesupportJson.id); const lifesupport = _moduleFromEdId(lifesupportJson.id);
if (lifesupportJson.modifiers)_addModifications(lifesupport, lifesupportJson.modifiers, lifesupportJson.recipeName, lifesupportJson.recipeLevel); if (json.modules.LifeSupport.WorkInProgress_modifications) _addModifications(lifesupport, json.modules.LifeSupport.WorkInProgress_modifications, json.modules.LifeSupport.engineer.recipeName, json.modules.LifeSupport.engineer.recipeLevel);
ship.use(ship.standard[3], lifesupport, true); ship.use(ship.standard[3], lifesupport, true);
ship.standard[3].enabled = lifesupportJson.on === true; ship.standard[3].enabled = lifesupportJson.on === true;
ship.standard[3].priority = lifesupportJson.priority; ship.standard[3].priority = lifesupportJson.priority;
@@ -196,7 +197,7 @@ export function shipFromJson(json) {
// Power distributor // Power distributor
const powerdistributorJson = json.modules.PowerDistributor.module; const powerdistributorJson = json.modules.PowerDistributor.module;
const powerdistributor = _moduleFromEdId(powerdistributorJson.id); const powerdistributor = _moduleFromEdId(powerdistributorJson.id);
if (powerdistributorJson.modifiers) _addModifications(powerdistributor, powerdistributorJson.modifiers, powerdistributorJson.recipeName, powerdistributorJson.recipeLevel); if (json.modules.PowerDistributor.WorkInProgress_modifications) _addModifications(powerdistributor, json.modules.PowerDistributor.WorkInProgress_modifications, json.modules.PowerDistributor.engineer.recipeName, json.modules.PowerDistributor.engineer.recipeLevel);
ship.use(ship.standard[4], powerdistributor, true); ship.use(ship.standard[4], powerdistributor, true);
ship.standard[4].enabled = powerdistributorJson.on === true; ship.standard[4].enabled = powerdistributorJson.on === true;
ship.standard[4].priority = powerdistributorJson.priority; ship.standard[4].priority = powerdistributorJson.priority;
@@ -204,7 +205,8 @@ export function shipFromJson(json) {
// Sensors // Sensors
const sensorsJson = json.modules.Radar.module; const sensorsJson = json.modules.Radar.module;
const sensors = _moduleFromEdId(sensorsJson.id); const sensors = _moduleFromEdId(sensorsJson.id);
if (sensorsJson.modifiers) _addModifications(sensors, sensorsJson.modifiers, sensorsJson.recipeName, sensorsJson.recipeLevel); if (json.modules.Radar.WorkInProgress_modifications) _addModifications(sensors, json.modules.Radar.WorkInProgress_modifications, json.modules.Radar.engineer.recipeName, json.modules.Radar.engineer.recipeLevel);
ship.use(ship.standard[5], sensors, true); ship.use(ship.standard[5], sensors, true);
ship.standard[5].enabled = sensorsJson.on === true; ship.standard[5].enabled = sensorsJson.on === true;
ship.standard[5].priority = sensorsJson.priority; ship.standard[5].priority = sensorsJson.priority;
@@ -240,7 +242,7 @@ export function shipFromJson(json) {
} else { } else {
const hardpointJson = hardpointSlot.module; const hardpointJson = hardpointSlot.module;
const hardpoint = _moduleFromEdId(hardpointJson.id); const hardpoint = _moduleFromEdId(hardpointJson.id);
if (hardpointJson.modifiers) _addModifications(hardpoint, hardpointJson.modifiers, hardpointJson.recipeName, hardpointJson.recipeLevel); if (hardpointSlot.WorkInProgress_modifications) _addModifications(hardpoint, hardpointSlot.WorkInProgress_modifications, hardpointSlot.engineer.recipeName, hardpointSlot.engineer.recipeLevel, hardpointSlot.specialModifications);
ship.use(ship.hardpoints[hardpointArrayNum], hardpoint, true); ship.use(ship.hardpoints[hardpointArrayNum], hardpoint, true);
ship.hardpoints[hardpointArrayNum].enabled = hardpointJson.on === true; ship.hardpoints[hardpointArrayNum].enabled = hardpointJson.on === true;
ship.hardpoints[hardpointArrayNum].priority = hardpointJson.priority; ship.hardpoints[hardpointArrayNum].priority = hardpointJson.priority;
@@ -282,7 +284,7 @@ export function shipFromJson(json) {
} else { } else {
const internalJson = internalSlot.module; const internalJson = internalSlot.module;
const internal = _moduleFromEdId(internalJson.id); const internal = _moduleFromEdId(internalJson.id);
if (internalJson.modifiers) _addModifications(internal, internalJson.modifiers, internalJson.recipeName, internalJson.recipeLevel); if (internalSlot.WorkInProgress_modifications) _addModifications(internal, internalSlot.WorkInProgress_modifications, internalSlot.engineer.recipeName, internalSlot.engineer.recipeLevel);
ship.use(ship.internal[i], internal, true); ship.use(ship.internal[i], internal, true);
ship.internal[i].enabled = internalJson.on === true; ship.internal[i].enabled = internalJson.on === true;
ship.internal[i].priority = internalJson.priority; ship.internal[i].priority = internalJson.priority;
@@ -299,37 +301,48 @@ export function shipFromJson(json) {
* @param {Object} modifiers the modifiers * @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
*/ */
function _addModifications(module, modifiers, blueprint, grade) { function _addModifications(module, modifiers, blueprint, grade, specialModifications) {
if (!modifiers || !modifiers.modifiers) return; console.log(module);
console.log(modifiers);
if (!modifiers) return;
let special; let special;
for (const i in modifiers.modifiers) { if (specialModifications) {
special = Modifications.specials[Object.keys(specialModifications)[0]]
}
for (const i in modifiers) {
// Some special modifications // Some special modifications
if (modifiers.modifiers[i].name === 'mod_weapon_clip_size_override') { if (modifiers[i].name === 'mod_weapon_clip_size_override') {
// This is a numeric addition to the clip size, but we need to work it out in terms of being a percentage so // This is a numeric addition to the clip size, but we need to work it out in terms of being a percentage so
// that it works the same as other modifications // that it works the same as other modifications
const origClip = module.clip || 1; const origClip = module.clip || 1;
module.setModValue('clip', ((modifiers.modifiers[i].value - origClip) / origClip) * 10000); module.setModValue('clip', ((modifiers[i].value - origClip) / origClip) * 10000);
} else if (modifiers.modifiers[i].name === 'mod_weapon_burst_size') { } else if (modifiers[i].name === 'mod_weapon_burst_size') {
// This is an absolute number that acts as an override // This is an absolute number that acts as an override
module.setModValue('burst', modifiers.modifiers[i].value * 100); module.setModValue('burst', modifiers[i].value * 100);
} else if (modifiers.modifiers[i].name === 'mod_weapon_burst_rof') { } else if (modifiers[i].name === 'mod_weapon_burst_rof') {
// This is an absolute number that acts as an override // This is an absolute number that acts as an override
module.setModValue('burstrof', modifiers.modifiers[i].value * 100); module.setModValue('burstrof', modifiers[i].value * 100);
} else if (modifiers.modifiers[i].name === 'mod_weapon_falloffrange_from_range') { } else if (modifiers[i].name === 'mod_weapon_falloffrange_from_range') {
// Obtain the falloff value directly from the range // Obtain the falloff value directly from the range
module.setModValue('fallofffromrange', 1); module.setModValue('fallofffromrange', 1);
} else if (modifiers.modifiers[i].name && modifiers.modifiers[i].name.startsWith('special_')) { } else if (modifiers[i].name && modifiers[i].name.startsWith('special_')) {
// We don't add special effects directly, but keep a note of them so they can be added when fetching values // We don't add special effects directly, but keep a note of them so they can be added when fetching values
special = Modifications.specials[modifiers.modifiers[i].name]; special = Modifications.specials[modifiers[i].name];
} else { } else {
// Look up the modifiers to find what we need to do // Look up the modifiers to find what we need to do
const modifierActions = Modifications.modifierActions[modifiers.modifiers[i].name]; const modifierActions = Modifications.modifierActions[i];
const value = modifiers.modifiers[i].value; let value;
if (i === 'shieldbst') {
value = modifiers[i].value - 1;
} else {
value = modifiers[i].value - 1;
}
// Carry out the required changes // Carry out the required changes
for (const action in modifierActions) { for (const action in modifierActions) {
console.log(action);
if (isNaN(modifierActions[action])) { if (isNaN(modifierActions[action])) {
module.setModValue(action, modifierActions[action]); module.setModValue(action, modifierActions[action]);
} else { } else {
@@ -339,6 +352,7 @@ function _addModifications(module, modifiers, blueprint, grade) {
mod = 0; mod = 0;
} }
module.setModValue(action, ((1 + mod) * (1 + actionValue) - 1) * 10000); module.setModValue(action, ((1 + mod) * (1 + actionValue) - 1) * 10000);
// Bulkhead boost is based off the inherent boost of the module
} }
} }
} }
@@ -380,17 +394,17 @@ function _addModifications(module, modifiers, blueprint, grade) {
// Shield generator resistance is actually a damage modifier, so needs to be inverted. // Shield generator resistance is actually a damage modifier, so needs to be inverted.
// In addition, the modification is based off the inherent resistance of the module // In addition, the modification is based off the inherent resistance of the module
if (ModuleUtils.isShieldGenerator(module.grp)) { // if (ModuleUtils.isShieldGenerator(module.grp)) {
if (module.getModValue('explres')) { // if (module.getModValue('explres')) {
module.setModValue('explres', ((1 - (1 - module.explres) * (1 + module.getModValue('explres') / 10000)) - module.explres) * 10000); // module.setModValue('explres', ((1 - (1 - module.explres) * (1 + module.getModValue('explres') / 10000)) - module.explres) * 10000);
} // }
if (module.getModValue('kinres')) { // if (module.getModValue('kinres')) {
module.setModValue('kinres', ((1 - (1 - module.kinres) * (1 + module.getModValue('kinres') / 10000)) - module.kinres) * 10000); // module.setModValue('kinres', ((1 - (1 - module.kinres) * (1 + module.getModValue('kinres') / 10000)) - module.kinres) * 10000);
} // }
if (module.getModValue('thermres')) { // if (module.getModValue('thermres')) {
module.setModValue('thermres', ((1 - (1 - module.thermres) * (1 + module.getModValue('thermres') / 10000)) - module.thermres) * 10000); // module.setModValue('thermres', ((1 - (1 - module.thermres) * (1 + module.getModValue('thermres') / 10000)) - module.thermres) * 10000);
} // }
} // }
// Hull reinforcement package resistance is actually a damage modifier, so needs to be inverted. // Hull reinforcement package resistance is actually a damage modifier, so needs to be inverted.
// In addition, the modification is based off the inherent resistance of the module // In addition, the modification is based off the inherent resistance of the module
@@ -423,7 +437,7 @@ function _addModifications(module, modifiers, blueprint, grade) {
// Bulkhead boost is based off the inherent boost of the module // Bulkhead boost is based off the inherent boost of the module
if (module.grp == 'bh') { if (module.grp == 'bh') {
const alteredBoost = (1 + module.hullboost) * (1 + module.getModValue('hullboost') / 10000) - 1; const alteredBoost = (1 + module.hullboost) * (1 + module.getModValue('hullboost') / 10000) - 1;
module.setModValue('hullboost', (alteredBoost / module.hullboost - 1) * 10000); module.setModValue('hullboost', (alteredBoost / module.hullboost - 1) * 1000);
} }
// Jitter is an absolute number, so we need to divide it by 100 // Jitter is an absolute number, so we need to divide it by 100