From d15e49f315827623d227b8d7148d95a74839c7bb Mon Sep 17 00:00:00 2001 From: Cmdr McDonald Date: Wed, 22 Mar 2017 17:53:26 +0000 Subject: [PATCH] Ignore rpshot for eps and hps --- ChangeLog.md | 1 + src/app/components/ModificationsMenu.jsx | 24 +++++-------- src/app/shipyard/Module.js | 8 ++--- src/app/shipyard/Ship.js | 33 ++++++++++++++--- src/app/utils/BlueprintFunctions.js | 46 ++++++++++++++++++++++++ src/app/utils/CompanionApiUtils.js | 5 +-- 6 files changed, 92 insertions(+), 25 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index ec2992c6..0158383b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -11,6 +11,7 @@ * Ensure that hull reinforcement modifications take the inherent resistance in to account when calculating modification percentages * Add tooltip for blueprints providing details of the features they alter * Use opponent's saved pips if available + * Ignore rounds per shot for EPS and HPS calculations; it's already factored in to the numbers #2.2.19 * Power management panel now displays modules in descending order of power usage by default diff --git a/src/app/components/ModificationsMenu.jsx b/src/app/components/ModificationsMenu.jsx index 8faea959..ee950579 100644 --- a/src/app/components/ModificationsMenu.jsx +++ b/src/app/components/ModificationsMenu.jsx @@ -5,7 +5,7 @@ import { isEmpty, stopCtxPropagation } from '../utils/UtilityFunctions'; import cn from 'classnames'; import { Modifications } from 'coriolis-data/dist'; import Modification from './Modification'; -import { blueprintTooltip } from '../utils/BlueprintFunctions'; +import { getBlueprint, blueprintTooltip } from '../utils/BlueprintFunctions'; /** * Modifications menu @@ -51,10 +51,11 @@ export default class ModificationsMenu extends TranslatedComponent { let blueprints = []; for (const blueprintName in Modifications.modules[m.grp].blueprints) { for (const grade of Modifications.modules[m.grp].blueprints[blueprintName]) { - const close = this._blueprintSelected.bind(this, Modifications.blueprints[blueprintName].id, grade); + const close = this._blueprintSelected.bind(this, blueprintName, grade); const key = blueprintName + ':' + grade; - const tooltipContent = blueprintTooltip(translate, Modifications.blueprints[blueprintName].grades[grade].features); - blueprints.push(
{translate(Modifications.blueprints[blueprintName].name + ' grade ' + grade)}
); + const blueprint = getBlueprint(blueprintName, m); + const tooltipContent = blueprintTooltip(translate, blueprint.grades[grade].features); + blueprints.push(
{translate(blueprint.name + ' grade ' + grade)}
); } } @@ -105,12 +106,12 @@ export default class ModificationsMenu extends TranslatedComponent { /** * Activated when a blueprint is selected - * @param {int} blueprintId The ID of the selected blueprint - * @param {int} grade The grade of the selected blueprint + * @param {int} fdname The Frontier name of the blueprint + * @param {int} grade The grade of the selected blueprint */ - _blueprintSelected(blueprintId, grade) { + _blueprintSelected(fdname, grade) { const { m } = this.props; - const blueprint = Object.assign({}, _.find(Modifications.blueprints, function(o) { return o.id === blueprintId; })); + const blueprint = getBlueprint(fdname, m); blueprint.grade = grade; m.blueprint = blueprint; @@ -155,13 +156,6 @@ export default class ModificationsMenu extends TranslatedComponent { * @param {number} value The value of the roll */ _setRollResult(ship, m, featureName, value) { - if (Modifications.modifications[featureName].method !== 'overwrite') { - if (m.grp == 'sb' && featureName == 'shieldboost') { - // Shield boosters are a special case. Their boost is dependent on their base so we need to calculate the value here - value = ((1 + m.shieldboost) * (1 + value) - 1) / m.shieldboost - 1; - } - } - if (Modifications.modifications[featureName].type == 'percentage') { ship.setModification(m, featureName, value * 10000); } else if (Modifications.modifications[featureName].type == 'numeric') { diff --git a/src/app/shipyard/Module.js b/src/app/shipyard/Module.js index e013609b..2ea29321 100755 --- a/src/app/shipyard/Module.js +++ b/src/app/shipyard/Module.js @@ -554,10 +554,10 @@ export default class Module { getEps() { // EPS is a synthetic value let distdraw = this.getDistDraw(); - let rpshot = this.roundspershot || 1; + // We don't use rpshot here as dist draw is per combined shot let rof = this.getRoF() || 1; - return distdraw * rpshot * rof; + return distdraw * rof; } /** @@ -567,10 +567,10 @@ export default class Module { getHps() { // HPS is a synthetic value let heat = this.getThermalLoad(); - let rpshot = this.roundspershot || 1; + // We don't use rpshot here as dist draw is per combined shot let rof = this.getRoF() || 1; - return heat * rpshot * rof; + return heat * rof; } /** diff --git a/src/app/shipyard/Ship.js b/src/app/shipyard/Ship.js index ff564bbb..d207279e 100755 --- a/src/app/shipyard/Ship.js +++ b/src/app/shipyard/Ship.js @@ -1,6 +1,7 @@ import * as Calc from './Calculations'; import * as ModuleUtils from './ModuleUtils'; import * as Utils from '../utils/UtilityFunctions'; +import { getBlueprint } from '../utils/BlueprintFunctions'; import Module from './Module'; import LZString from 'lz-string'; import * as _ from 'lodash'; @@ -588,7 +589,13 @@ export default class Ship { this.bulkheads.m = null; this.useBulkhead(comps && comps.bulkheads ? comps.bulkheads : 0, true); this.bulkheads.m.mods = mods && mods[0] ? mods[0] : {}; - this.bulkheads.m.blueprint = blueprints && blueprints[0] ? blueprints[0] : {}; + if (blueprints && blueprints[0]) { + this.bulkheads.m.blueprint = getBlueprint(blueprints[0].fdname, this.bulkheads.m); + this.bulkheads.m.blueprint.grade = blueprints[0].grade; + this.bulkheads.m.blueprint.special = blueprints[0].special; + } else { + this.bulkheads.m.blueprint = {}; + } this.cargoHatch.priority = priorities ? priorities[0] * 1 : 0; this.cargoHatch.enabled = enabled ? enabled[0] * 1 : true; @@ -602,7 +609,13 @@ export default class Ship { let module = ModuleUtils.standard(i, comps.standard[i]); if (module != null) { module.mods = mods && mods[i + 1] ? mods[i + 1] : {}; - module.blueprint = blueprints && blueprints[i + 1] ? blueprints[i + 1] : {}; + if (blueprints && blueprints[i + 1]) { + module.blueprint = getBlueprint(blueprints[i + 1].fdname, module); + module.blueprint.grade = blueprints[i + 1].grade; + module.blueprint.special = blueprints[i + 1].special; + } else { + module.blueprint = {}; + } } this.use(standard[i], module, true); } @@ -624,7 +637,13 @@ export default class Ship { let module = ModuleUtils.hardpoints(comps.hardpoints[i]); if (module != null) { module.mods = mods && mods[cl + i] ? mods[cl + i] : {}; - module.blueprint = blueprints && blueprints[cl + i] ? blueprints[cl + i] : {}; + if (blueprints && blueprints[cl + i]) { + module.blueprint = getBlueprint(blueprints[cl + i].fdname, module); + module.blueprint.grade = blueprints[cl + i].grade; + module.blueprint.special = blueprints[cl + i].special; + } else { + module.blueprint = {}; + } } this.use(hps[i], module, true); } @@ -644,7 +663,13 @@ export default class Ship { let module = ModuleUtils.internal(comps.internal[i]); if (module != null) { module.mods = mods && mods[cl + i] ? mods[cl + i] : {}; - module.blueprint = blueprints && blueprints[cl + i] ? blueprints[cl + i] : {}; + if (blueprints && blueprints[cl + i]) { + module.blueprint = getBlueprint(blueprints[cl + i].fdname, module); + module.blueprint.grade = blueprints[cl + i].grade; + module.blueprint.special = blueprints[cl + i].special; + } else { + module.blueprint = {}; + } } this.use(internal[i], module, true); } diff --git a/src/app/utils/BlueprintFunctions.js b/src/app/utils/BlueprintFunctions.js index ece22eed..0389f2cf 100644 --- a/src/app/utils/BlueprintFunctions.js +++ b/src/app/utils/BlueprintFunctions.js @@ -70,3 +70,49 @@ export function isBeneficial(feature, values) { return fact; } } + +/** + * Get a blueprint with a given name and an optional module + * @param {string} name The name of the blueprint + * @param {Object} module The module for which to obtain this blueprint + * @returns {Object} The matching blueprint + */ +export function getBlueprint(name, module) { + // Start with a copy of the blueprint + const blueprint = JSON.parse(JSON.stringify(Modifications.blueprints[name])); + if (module) { + if (module.grp === 'bh') { + // Bulkheads need to have their resistances altered + for (const grade in blueprint.grades) { + for (const feature in blueprint.grades[grade].features) { + if (feature === 'explres') { + blueprint.grades[grade].features[feature][0] *= (1 - module.explres); + blueprint.grades[grade].features[feature][1] *= (1 - module.explres); + } + if (feature === 'kinres') { + blueprint.grades[grade].features[feature][0] *= (1 - module.kinres); + blueprint.grades[grade].features[feature][1] *= (1 - module.kinres); + } + if (feature === 'thermres') { + blueprint.grades[grade].features[feature][0] *= (1 - module.thermres); + blueprint.grades[grade].features[feature][1] *= (1 - module.thermres); + } + } + } + } + if (module.grp === 'sb') { + // Shield boosters are treated internally as straight modifiers, so rather than (for example) + // being a 4% boost they are a 104% multiplier. We need to fix the values here so that they look + // accurate as per the information in Elite + for (const grade in blueprint.grades) { + for (const feature in blueprint.grades[grade].features) { + if (feature === 'shieldboost') { + blueprint.grades[grade].features[feature][0] = ((1 + blueprint.grades[grade].features[feature][0]) * (1 + module.shieldboost) - 1)/ module.shieldboost - 1; + blueprint.grades[grade].features[feature][1] = ((1 + blueprint.grades[grade].features[feature][1]) * (1 + module.shieldboost) - 1)/ module.shieldboost - 1; + } + } + } + } + } + return blueprint; +} diff --git a/src/app/utils/CompanionApiUtils.js b/src/app/utils/CompanionApiUtils.js index 6c6a2272..47a1db01 100644 --- a/src/app/utils/CompanionApiUtils.js +++ b/src/app/utils/CompanionApiUtils.js @@ -2,6 +2,7 @@ import React from 'react'; import { Modifications, Modules, Ships } from 'coriolis-data/dist'; import Module from '../shipyard/Module'; import Ship from '../shipyard/Ship'; +import { getBlueprint } from '../utils/BlueprintFunctions'; // mapping from fd's ship model names to coriolis' const SHIP_FD_NAME_TO_CORIOLIS_NAME = { @@ -335,9 +336,9 @@ function _addModifications(module, modifiers, blueprint, grade) { } } - // Add the blueprint ID, grade and special + // Add the blueprint definition, grade and special if (blueprint) { - module.blueprint = Object.assign({}, Modifications.blueprints[blueprint]); + module.blueprint = getBlueprint(blueprint, module); if (grade) { module.blueprint.grade = Number(grade); }