diff --git a/src/app/components/ModificationsMenu.jsx b/src/app/components/ModificationsMenu.jsx index 024cf290..c844f253 100644 --- a/src/app/components/ModificationsMenu.jsx +++ b/src/app/components/ModificationsMenu.jsx @@ -42,11 +42,10 @@ export default class ModificationsMenu extends TranslatedComponent { let { m } = props; let list = []; - for (let modId of Modifications.validity[m.grp]) { - let modifiers = Modifications.modifiers[modId] - list.push(
-
{translate(modifiers.name)}{' (%)'}
- + for (let modName of Modifications.validity[m.grp]) { + list.push(
+
{translate(modName)}{' (%)'}
+
); } @@ -64,16 +63,16 @@ export default class ModificationsMenu extends TranslatedComponent { /** * Update modification given a value. - * @param {Number} modId The ID of the modification + * @param {Number} name The name of the modification * @param {Number} value The value to set, in the range [0,1] */ - _updateValue(modId, value) { + _updateValue(name, value) { let scaledValue = Math.floor(value * 100) / 10000; let m = this.props.m; let ship = this.props.ship; - ship.setModification(m, modId, scaledValue); + ship.setModification(m, name, scaledValue); this.props.onChange(); } diff --git a/src/app/components/StandardSlot.jsx b/src/app/components/StandardSlot.jsx index 1d15d6f4..534c1c38 100644 --- a/src/app/components/StandardSlot.jsx +++ b/src/app/components/StandardSlot.jsx @@ -69,22 +69,22 @@ export default class StandardSlot extends TranslatedComponent {
{ m.grp == 'bh' && m.name ?
{translate(m.name)}
: null } - { m.optmass ?
{translate('optimal mass')}: {m.optmass}{units.T}
: null } - { m.maxmass ?
{translate('max mass')}: {m.maxmass}{units.T}
: null } - { m.range ?
{translate('range')}: {m.range}{units.km}
: null } + { m.getOptimalMass() ?
{translate('optimal mass')}: {m.getOptimalMass()}{units.T}
: null } + { m.getMaxMass() ?
{translate('max mass')}: {m.getMaxMass()}{units.T}
: null } + { m.getRange() ?
{translate('range')}: {m.getRange()}{units.km}
: null } { m.time ?
{translate('time')}: {formats.time(m.time)}
: null } - { m.eff ?
{translate('efficiency')}: {m.eff}
: null } + { m.getThermalEfficiency() ?
{translate('efficiency')}: {m.getThermalEfficiency()}
: null } { m.getPowerGeneration() > 0 ?
{translate('power')}: {formats.round(m.getPowerGeneration())}{units.MW}
: null } - { m.maxfuel ?
{translate('max')} {translate('fuel')}: {m.maxfuel}{units.T}
: null } - { m.weaponcapacity ?
{translate('WEP')}: {m.weaponcapacity}{units.MJ} / {m.weaponrecharge}{units.MW}
: null } - { m.systemcapacity ?
{translate('SYS')}: {m.systemcapacity}{units.MJ} / {m.systemrecharge}{units.MW}
: null } - { m.enginecapacity ?
{translate('ENG')}: {m.enginecapacity}{units.MJ} / {m.enginerecharge}{units.MW}
: null } + { m.getMaxFuelPerJump() ?
{translate('max')} {translate('fuel')}: {m.getMaxFuelPerJump()}{units.T}
: null } + { m.getWeaponsCapacity() ?
{translate('WEP')}: {m.getWeaponsCapacity()}{units.MJ} / {m.getWeaponsRechargeRate()}{units.MW}
: null } + { m.getSystemsCapacity() ?
{translate('SYS')}: {m.getSystemsCapacity()}{units.MJ} / {m.getSystemsRechargeRate()}{units.MW}
: null } + { m.getEnginesCapacity() ?
{translate('ENG')}: {m.getEnginesCapacity()}{units.MJ} / {m.getEnginesRechargeRate()}{units.MW}
: null }
{menu} ); - //{ validMods.length > 0 ?
: null } + // { validMods.length > 0 ?
: null } } } diff --git a/src/app/components/StandardSlotSection.jsx b/src/app/components/StandardSlotSection.jsx index 0971cf15..6e60046b 100644 --- a/src/app/components/StandardSlotSection.jsx +++ b/src/app/components/StandardSlotSection.jsx @@ -163,7 +163,7 @@ export default class StandardSlotSection extends SlotSection { selected={currentMenu == st[4]} onChange={this.props.onChange} ship={ship} - warning= {m => m.enginecapacity < ship.boostEnergy} + warning= {m => m.getEnginesCapacity() < ship.boostEnergy} />; slots[6] = m.enginecapacity < ship.boostEnergy} />; slots[7] = 0 ? Math.pow(fuelRemaining / fsd.fuelmul, 1 / fsd.fuelpower) * fsd.optmass / mass : 0; + let fastestRange = fuelRemaining > 0 ? Math.pow(fuelRemaining / fsd.fuelmul, 1 / fsd.fuelpower) * fsd.getOptimalMass() / mass : 0; // For each max fuel jump, calculate the max jump range based on fuel mass left in the tank for (let j = 0; j < jumps; j++) { mass += fsd.maxfuel; - fastestRange += Math.pow(fsd.maxfuel / fsd.fuelmul, 1 / fsd.fuelpower) * fsd.optmass / mass; + fastestRange += Math.pow(fsd.getMaxFuelPerJump() / fsd.fuelmul, 1 / fsd.fuelpower) * fsd.getOptimalMass() / mass; } return fastestRange; }; diff --git a/src/app/shipyard/Module.js b/src/app/shipyard/Module.js index 3af7768a..9010e61c 100755 --- a/src/app/shipyard/Module.js +++ b/src/app/shipyard/Module.js @@ -27,42 +27,50 @@ export default class Module { } /** - * Get a value for a given modification ID - * @param {Number} modId The ID of the modification - * @return {Number} The value of the modification, as a decimal value from -1 to 1 + * Get a value for a given modification + * @param {Number} name The name of the modification + * @return {Number} The value of the modification, as a decimal value from -1 to 1 */ - getModValue(modId) { - return this.mods ? this.mods[modId] / 10000 : null; + getModValue(name) { + return this.mods ? this.mods[name] / 10000 : null; } /** * Set a value for a given modification ID - * @param {Number} modId The ID of the modification - * @param {Number} value The value of the modification, as a decimal value from -1 to 1 + * @param {Number} name The name of the modification + * @param {Number} value The value of the modification, as a decimal value from -1 to 1 */ - setModValue(modId, value) { + setModValue(name, value) { if (value == null || value == 0) { - delete this.mods[modId]; + delete this.mods[name]; } else { // Store value with 2dp - this.mods[modId] = Math.round(value * 10000); + this.mods[name] = Math.round(value * 10000); } } + /** + * Helper to obtain a modified value using standard multipliers + * @param {String} name the name of the modifier to obtain + * @return {Number} the mass of this module + */ + _getModifiedValue(name) { + let result = 0; + if (this[name]) { + result = this[name]; + if (result) { + let mult = this.getModValue(name); + if (mult) { result = result * (1 + mult); } + } + } + return result; + } /** * Get the power generation of this module, taking in to account modifications * @return {Number} the power generation of this module */ getPowerGeneration() { - let result = 0; - if (this.pGen) { - result = this.pGen; - if (result) { - let mult = this.getModValue(1); - if (mult) { result = result * (1 + mult); } - } - } - return result; + return this._getModifiedValue('pGen'); } /** @@ -70,15 +78,7 @@ export default class Module { * @return {Number} the power usage of this module */ getPowerUsage() { - let result = 0; - if (this.power) { - result = this.power; - if (result) { - let mult = this.getModValue(2); - if (mult) { result = result * (1 + mult); } - } - } - return result; + return this._getModifiedValue('power'); } /** @@ -86,15 +86,7 @@ export default class Module { * @return {Number} the integrity of this module */ getIntegrity() { - let result = 0; - if (this.health) { - result = this.health; - if (result) { - let mult = this.getModValue(3); - if (mult) { result = result * (1 + mult); } - } - } - return result; + return this._getModifiedValue('integrity'); } /** @@ -102,14 +94,206 @@ export default class Module { * @return {Number} the mass of this module */ getMass() { - let result = 0; - if (this.mass) { - result = this.mass; - if (result) { - let mult = this.getModValue(4); - if (mult) { result = result * (1 + mult); } - } - } - return result; + return this._getModifiedValue('mass'); + } + + /** + * Get the thermal efficiency of this module, taking in to account modifications + * @return {Number} the thermal efficiency of this module + */ + getThermalEfficiency() { + return this._getModifiedValue('eff'); + } + + /** + * Get the maximum mass of this module, taking in to account modifications + * @return {Number} the maximum mass of this module + */ + getMaxMass() { + return this._getModifiedValue('maxmass'); + } + + /** + * Get the optimal mass of this module, taking in to account modifications + * @return {Number} the optimal mass of this module + */ + getOptimalMass() { + return this._getModifiedValue('optmass'); + } + + /** + * Get the optimal multiplier of this module, taking in to account modifications + * @return {Number} the optimal multiplier of this module + */ + getOptimalMultiplier() { + return this._getModifiedValue('optmult'); + } + + /** + * Get the damage per second for this module, taking in to account modifications + * @return {Number} the damage per second of this module + */ + getDamagePerSecond() { + return this._getModifiedValue('dps'); + } + + /** + * Get the energy per second for this module, taking in to account modifications + * @return {Number} the energy per second of this module + */ + getEnergyPerSecond() { + return this._getModifiedValue('eps'); + } + + /** + * Get the heat per second for this module, taking in to account modifications + * @return {Number} the heat per second of this module + */ + getHeatPerSecond() { + return this._getModifiedValue('hps'); + } + + /** + * Get the maximum fuel per jump for this module, taking in to account modifications + * @return {Number} the maximum fuel per jump of this module + */ + getMaxFuelPerJump() { + return this._getModifiedValue('maxfuel'); + } + + /** + * Get the systems capacity for this module, taking in to account modifications + * @return {Number} the systems capacity of this module + */ + getSystemsCapacity() { + return this._getModifiedValue('syscap'); + } + + /** + * Get the engines capacity for this module, taking in to account modifications + * @return {Number} the engines capacity of this module + */ + getEnginesCapacity() { + return this._getModifiedValue('engcap'); + } + + /** + * Get the weapons capacity for this module, taking in to account modifications + * @return {Number} the weapons capacity of this module + */ + getWeaponsCapacity() { + return this._getModifiedValue('wepcap'); + } + + /** + * Get the systems recharge rate for this module, taking in to account modifications + * @return {Number} the systems recharge rate of this module + */ + getSystemsRechargeRate() { + return this._getModifiedValue('sysrate'); + } + + /** + * Get the engines recharge rate for this module, taking in to account modifications + * @return {Number} the engines recharge rate of this module + */ + getEnginesRechargeRate() { + return this._getModifiedValue('engrate'); + } + + /** + * Get the weapons recharge rate for this module, taking in to account modifications + * @return {Number} the weapons recharge rate of this module + */ + getWeaponsRechargeRate() { + return this._getModifiedValue('weprate'); + } + + /** + * Get the kinetic resistance for this module, taking in to account modifications + * @return {Number} the kinetic resistance of this module + */ + getKineticResistance() { + return this._getModifiedValue('kinres'); + } + + /** + * Get the thermal resistance for this module, taking in to account modifications + * @return {Number} the thermal resistance of this module + */ + getThermalResistance() { + return this._getModifiedValue('thermres'); + } + + /** + * Get the explosive resistance for this module, taking in to account modifications + * @return {Number} the explosive resistance of this module + */ + getExplosiveResistance() { + return this._getModifiedValue('explres'); + } + + /** + * Get the regeneration rate for this module, taking in to account modifications + * @return {Number} the regeneration rate of this module + */ + getRegenerationRate() { + return this._getModifiedValue('regen'); + } + + /** + * Get the broken regeneration rate for this module, taking in to account modifications + * @return {Number} the broken regeneration rate of this module + */ + getBrokenRegenerationRate() { + return this._getModifiedValue('brokenregen'); + } + + /** + * Get the range rate for this module, taking in to account modifications + * @return {Number} the range rate of this module + */ + getRange() { + return this._getModifiedValue('range'); + } + + /** + * Get the capture arc for this module, taking in to account modifications + * @return {Number} the capture arc of this module + */ + getCaptureArc() { + return this._getModifiedValue('arc'); + } + + /** + * Get the armour for this module, taking in to account modifications + * @return {Number} the armour of this module + */ + getArmour() { + return this._getModifiedValue('armour'); + } + + /** + * Get the delay for this module, taking in to account modifications + * @return {Number} the delay of this module + */ + getDelay() { + return this._getModifiedValue('delay'); + } + + /** + * Get the duration for this module, taking in to account modifications + * @return {Number} the duration of this module + */ + getDuration() { + return this._getModifiedValue('duration'); + } + + /** + * Get the shield reinforcement for this module, taking in to account modifications + * @return {Number} the shield reinforcement of this module + */ + getShieldReinforcement() { + return this._getModifiedValue('shieldreinforcement'); } } diff --git a/src/app/shipyard/ModuleSet.js b/src/app/shipyard/ModuleSet.js index a9148a57..b3ddf314 100755 --- a/src/app/shipyard/ModuleSet.js +++ b/src/app/shipyard/ModuleSet.js @@ -126,7 +126,7 @@ export default class ModuleSet { let pd = this.standard[4][0]; for (let p of this.standard[4]) { - if (p.mass < pd.mass && p.enginecapacity >= boostEnergy) { + if (p.mass < pd.mass && p.getEnginesCapacity() >= boostEnergy) { pd = p; } } diff --git a/src/app/shipyard/Serializer.js b/src/app/shipyard/Serializer.js index 99c47323..7b8284be 100644 --- a/src/app/shipyard/Serializer.js +++ b/src/app/shipyard/Serializer.js @@ -76,7 +76,7 @@ export function toDetailedBuild(buildName, ship) { ship: ship.name, references: [{ name: 'Coriolis.io', - url: `https://coriolis.io/outfit/${ship.id}/${code}?bn=${encodeURIComponent(buildName)}`, + url: `https://coriolis.edcd.io/outfit/${ship.id}/${code}?bn=${encodeURIComponent(buildName)}`, code, shipId: ship.id }], diff --git a/src/app/shipyard/Ship.js b/src/app/shipyard/Ship.js index 7c35e54e..9074f96f 100755 --- a/src/app/shipyard/Ship.js +++ b/src/app/shipyard/Ship.js @@ -35,7 +35,7 @@ function decodeModsToArray(code, arr) { let mods = moduleMods[i].split(';'); for (let j = 0; j < mods.length; j++) { let modElements = mods[j].split(':'); - arr[i][Number(modElements[0])] = Number(modElements[1]); + arr[i][modElements[0]] = Number(modElements[1]); } } } @@ -135,7 +135,7 @@ export default class Ship { */ canThrust() { return this.getSlotStatus(this.standard[1]) == 3 && // Thrusters are powered - this.ladenMass < this.standard[1].m.maxmass; // Max mass not exceeded + this.ladenMass < this.standard[1].m.getMaxMass(); // Max mass not exceeded } /** @@ -143,9 +143,9 @@ export default class Ship { * @return {[type]} True if boost capable */ canBoost() { - return this.canThrust() && // Thrusters operational - this.getSlotStatus(this.standard[4]) == 3 && // Power distributor operational - this.boostEnergy <= this.standard[4].m.enginecapacity; // PD capacitor is sufficient for boost + return this.canThrust() && // Thrusters operational + this.getSlotStatus(this.standard[4]) == 3 && // Power distributor operational + this.boostEnergy <= this.standard[4].m.getEnginesCapacity(); // PD capacitor is sufficient for boost } /** @@ -179,7 +179,7 @@ export default class Ship { */ calcUnladenRange(massDelta, fuel, fsd) { fsd = fsd || this.standard[2].m; - return Calc.jumpRange(this.unladenMass + (massDelta || 0) + Math.min(fsd.maxfuel, fuel || this.fuelCapacity), fsd || this.standard[2].m, fuel); + return Calc.jumpRange(this.unladenMass + (massDelta || 0) + Math.min(fsd.getMaxFuelPerJump(), fuel || this.fuelCapacity), fsd || this.standard[2].m, fuel); } /** @@ -405,31 +405,37 @@ export default class Ship { /** * Set a modification value * @param {Object} m The module to change - * @param {Object} mId The ID of the modification to change + * @param {Object} name The name of the modification to change * @param {Number} value The new value of the modification */ - setModification(m, mId, value) { + setModification(m, name, value) { // Handle special cases - if (mId == 1) { + if (name == 'pGen') { // Power generation - m.setModValue(mId, value); + m.setModValue(name, value); this.updatePower(); - } else if (mId == 2) { + } else if (name == 'power') { // Power usage - m.setModValue(mId, value); + m.setModValue(name, value); this.updatePower(); - } else if (mId == 4) { + } else if (name == 'mass') { // Mass let oldMass = m.getMass(); - m.setModValue(mId, value); + m.setModValue(name, value); let newMass = m.getMass(); this.unladenMass = this.unladenMass - oldMass + newMass; this.ladenMass = this.ladenMass - oldMass + newMass; this.updateTopSpeed(); this.updateJumpStats(); + } else if (name == 'maxfuel') { + m.setModValue(name, value); + this.updateJumpStats(); + } else if (name == 'optmass') { + m.setModValue(name, value); + this.updateJumpStats(); } else { // Generic - m.setModValue(mId, value); + m.setModValue(name, value); } } @@ -566,7 +572,7 @@ export default class Ship { } if (parts[3]) { - //decodeModsToArray(LZString.decompressFromBase64(parts[3].replace(/-/g, '/')), mods); + // decodeModsToArray(LZString.decompressFromBase64(parts[3].replace(/-/g, '/')), mods); decodeModsToArray(parts[3], mods); } @@ -960,7 +966,7 @@ export default class Ship { } allMods.push(slotMods.join(';')); } - //this.serialized.modifications = LZString.compressToBase64(allMods.join(',').replace(/,+$/, '')).replace(/\//g, '-'); + // this.serialized.modifications = LZString.compressToBase64(allMods.join(',').replace(/,+$/, '')).replace(/\//g, '-'); this.serialized.modifications = allMods.join(',').replace(/,+$/, ''); return this; } @@ -1132,5 +1138,4 @@ export default class Ship { } return this; } - } diff --git a/src/app/utils/SlotFunctions.js b/src/app/utils/SlotFunctions.js index 944ba617..3ea9681c 100644 --- a/src/app/utils/SlotFunctions.js +++ b/src/app/utils/SlotFunctions.js @@ -123,12 +123,12 @@ const PROP_BLACKLIST = { mass: 1, cost: 1, recover: 1, - weaponcapacity: 1, - weaponrecharge: 1, - enginecapacity: 1, - enginerecharge: 1, - systemcapacity: 1, - systemrecharge: 1, + wepcap: 1, + weprate: 1, + engcap: 1, + engrate: 1, + syscap: 1, + sysrate: 1, breachdps: 1, breachmin: 1, breachmax: 1, @@ -251,21 +251,21 @@ export function diffDetails(language, m, mm) { if (m.grp == 'pd') { propDiffs.push(
{`${translate('WEP')}: `} - {m.weaponcapacity}{units.MJ} + {m.getWeaponsCapacity()}{units.MJ} {' / '} - {m.weaponrecharge}{units.MW} + {m.getWeaponsRechargeRate()}{units.MW}
); propDiffs.push(
{`${translate('SYS')}: `} - {m.systemcapacity}{units.MJ} + {m.getSystemsCapacity()}{units.MJ} {' / '} - {m.systemrecharge}{units.MW} + {m.getSystemsRechargeRate()}{units.MW}
); propDiffs.push(
{`${translate('ENG')}: `} - {m.enginecapacity}{units.MJ} + {m.getEnginesCapacity()}{units.MJ} {' / '} - {m.enginerecharge}{units.MW} + {m.getEnginesRechargeRate()}{units.MW}
); }