Use single calculation for shield metrics

This commit is contained in:
Cmdr McDonald
2017-04-04 08:51:02 +01:00
parent 1237833c7a
commit 42c43d3f2d
4 changed files with 11 additions and 48 deletions

View File

@@ -310,7 +310,7 @@
"unladenRange": 18.74,
"yaw": 10,
"fullTankRange": 18.36,
"hardness": 170,
"hardness": 65,
"ladenRange": 16.59,
"unladenFastestRange": 74.2,
"ladenFastestRange": 66.96,

View File

@@ -54,6 +54,9 @@ export default class Modification extends TranslatedComponent {
this.setState({ value });
}
/**
* Triggered when an update to slider value is finished i.e. when losing focus
*/
_updateFinished() {
this.props.onChange();
}

View File

@@ -1204,53 +1204,13 @@ export default class Ship {
* @return {this} The ship instance (for chaining operations)
*/
recalculateShield() {
let shield = 0;
let shieldBoost = 1;
let shieldExplRes = null;
let shieldKinRes = null;
let shieldThermRes = null;
let shieldExplDRStart = null;
let shieldExplDREnd = null;
let shieldKinDRStart = null;
let shieldKinDREnd = null;
let shieldThermDRStart = null;
let shieldThermDREnd = null;
const sgSlot = this.findInternalByGroup('sg');
if (sgSlot && sgSlot.enabled) {
// Shield from generator
shield = Calc.shieldStrength(this.hullMass, this.baseShieldStrength, sgSlot.m, 1);
shieldExplRes = 1 - sgSlot.m.getExplosiveResistance();
shieldExplDRStart = shieldExplRes * 0.7;
shieldExplDREnd = 0;
shieldKinRes = 1 - sgSlot.m.getKineticResistance();
shieldKinDRStart = shieldKinRes * 0.7;
shieldKinDREnd = 0;
shieldThermRes = 1 - sgSlot.m.getThermalResistance();
shieldThermDRStart = shieldThermRes * 0.7;
shieldThermDREnd = 0;
// Shield from boosters
for (let slot of this.hardpoints) {
if (slot.enabled && slot.m && slot.m.grp == 'sb') {
shieldBoost += slot.m.getShieldBoost();
shieldExplRes *= (1 - slot.m.getExplosiveResistance());
shieldKinRes *= (1 - slot.m.getKineticResistance());
shieldThermRes *= (1 - slot.m.getThermalResistance());
}
}
}
// We apply diminishing returns to the boosted value
shieldBoost = Math.min(shieldBoost, (1 - Math.pow(Math.E, -0.7 * shieldBoost)) * 2.5);
shield = shield * shieldBoost;
this.shield = shield;
this.shieldExplRes = shieldExplRes ? 1 - this.diminishingReturns(shieldExplRes, shieldExplDREnd, shieldExplDRStart) : null;
this.shieldKinRes = shieldKinRes ? 1 - this.diminishingReturns(shieldKinRes, shieldKinDREnd, shieldKinDRStart) : null;
this.shieldThermRes = shieldThermRes ? 1 - this.diminishingReturns(shieldThermRes, shieldThermDREnd, shieldThermDRStart) : null;
// Obtain shield metrics with 0 pips to sys (parts affected by SYS aren't used here)
const metrics = Calc.shieldMetrics(this, 0);
this.shield = metrics.generator + metrics.boosters;
this.shieldExplRes = this.shield > 0 ? 1 - metrics.explosive.total : null;
this.shieldKinRes = this.shield > 0 ? 1 - metrics.kinetic.total : null;
this.shieldThermRes = this.shield > 0 ? 1 - metrics.thermal.total : null;
return this;
}