From ad06e23afa9e9182a93633e6a97d18b6a5b58936 Mon Sep 17 00:00:00 2001 From: Cmdr McDonald Date: Sat, 14 Jan 2017 16:20:48 +0000 Subject: [PATCH] Add total DPS and effectiveness information to 'Damage Dealt' section --- ChangeLog.md | 3 +- src/app/components/DamageDealt.jsx | 53 ++++++++++++++++++++---------- src/app/i18n/en.js | 1 + 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 40746e83..9bf715ac 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,8 +2,9 @@ * Use SSL-enabled server for shortlinks * Add falloff for weapons * Use falloff when calculating weapon effectiveness in damage dealt - * Add engagement range slider to allow user to see change in weapon effectiveness with range + * Add engagement range slider to 'Damage Dealt' section to allow user to see change in weapon effectiveness with range * Use better DPE calculation methodology + * Add total DPS and effectiveness information to 'Damage Dealt' section #2.2.8 * Fix issue where filling all internals with cargo racks would include restricted slots diff --git a/src/app/components/DamageDealt.jsx b/src/app/components/DamageDealt.jsx index 72961f77..eb27dc20 100644 --- a/src/app/components/DamageDealt.jsx +++ b/src/app/components/DamageDealt.jsx @@ -77,8 +77,8 @@ export default class DamageDealt extends TranslatedComponent { * Set the initial weapons state */ componentWillMount() { - const weapons = this._calcWeapons(this.props.ship, this.state.against, this.state.range * this.state.maxRange); - this.setState({ weapons }); + const data = this._calcWeapons(this.props.ship, this.state.against, this.state.range * this.state.maxRange); + this.setState({ weapons: data.weapons, totals: data.totals }); } /** @@ -89,8 +89,8 @@ export default class DamageDealt extends TranslatedComponent { */ componentWillReceiveProps(nextProps, nextContext) { if (nextProps.code != this.props.code) { - const weapons = this._calcWeapons(this.props.ship, this.state.against, this.state.range * this.state.maxRange); - this.setState({ weapons }); + const data = this._calcWeapons(this.props.ship, this.state.against, this.state.range * this.state.maxRange); + this.setState({ weapons: data.weapons, totals: data.totals }); } return true; } @@ -106,6 +106,13 @@ export default class DamageDealt extends TranslatedComponent { // Tidy up the range so that it's to 4 decimal places range = Math.round(10000 * range) / 10000; + // Track totals + let totals = {}; + totals.effectiveness = 0; + totals.effectiveDps = 0; + totals.effectiveSDps = 0; + let totalDps = 0; + let weapons = []; for (let i = 0; i < ship.hardpoints.length; i++) { if (ship.hardpoints[i].m) { @@ -130,6 +137,9 @@ export default class DamageDealt extends TranslatedComponent { const effectiveness = (m.getPiercing() >= against.properties.hardness ? 1 : m.getPiercing() / against.properties.hardness) * dropoff; const effectiveDps = m.getDps() * effectiveness * dropoff; const effectiveSDps = (m.getClip() ? (m.getClip() * m.getDps() / m.getRoF()) / ((m.getClip() / m.getRoF()) + m.getReload()) * effectiveness : effectiveDps) * dropoff; + totals.effectiveDps += effectiveDps; + totals.effectiveSDps += effectiveSDps; + totalDps += m.getDps(); weapons.push({ id: i, mount: m.mount, @@ -141,8 +151,9 @@ export default class DamageDealt extends TranslatedComponent { } } } - - return weapons; + totals.effectiveness = totals.effectiveDps / totalDps; + + return {weapons: weapons, totals: totals}; } /** @@ -158,8 +169,8 @@ export default class DamageDealt extends TranslatedComponent { */ _onShipChange(s) { const against = Ships[s]; - const weapons = this._calcWeapons(this.props.ship, against); - this.setState({ against, weapons }); + const data = this._calcWeapons(this.props.ship, against); + this.setState({ against, weapons: data.weapons, totals: data.totals }); } /** @@ -236,8 +247,8 @@ export default class DamageDealt extends TranslatedComponent { * @param {number} range Range 0-1 */ _rangeChange(range) { - const weapons = this._calcWeapons(this.props.ship, this.state.against, this.state.range * this.state.maxRange); - this.setState({ range, weapons }); + const data = this._calcWeapons(this.props.ship, this.state.against, this.state.range * this.state.maxRange); + this.setState({ range, weapons: data.weapons, totals: data.totals }); } /** @@ -247,7 +258,7 @@ export default class DamageDealt extends TranslatedComponent { render() { const { language, onWindowResize, sizeRatio, tooltip, termtip } = this.context; const { formats, translate, units } = language; - const { expanded, maxRange, range } = this.state; + const { expanded, maxRange, range, totals } = this.state; const sortOrder = this._sortOrder; const onCollapseExpand = this._onCollapseExpand; @@ -259,16 +270,24 @@ export default class DamageDealt extends TranslatedComponent { - - - - - - + + + + + + {this._renderRows(translate, formats)} + + + + + + + +
{translate('weapon')}{translate('effective dps')}{translate('effective sdps')}{translate('effectiveness')}
{translate('weapon')}{translate('effective dps')}{translate('effective sdps')}{translate('effectiveness')}
{translate('total')}{formats.round1(totals.effectiveDps)}{formats.round1(totals.effectiveSDps)}{formats.pct(totals.effectiveness)}
diff --git a/src/app/i18n/en.js b/src/app/i18n/en.js index 11ec1786..091cb560 100644 --- a/src/app/i18n/en.js +++ b/src/app/i18n/en.js @@ -125,6 +125,7 @@ export const terms = { 'internal protection': 'Internal protection', 'external protection': 'External protection', 'engagement range': 'Engagement range', + 'total': 'Total', // Modifications ammo: 'Ammunition maximum',