From 8fe20f6f65ece16c3481b015a7178bb8cbbf8c7c Mon Sep 17 00:00:00 2001 From: Cmdr McDonald Date: Thu, 24 Nov 2016 12:50:33 +0000 Subject: [PATCH] Checkpoint - handle non-numeric modifiers --- src/app/shipyard/Module.js | 14 +++++++++----- src/app/shipyard/Ship.js | 7 ++++++- src/app/utils/CompanionApiUtils.js | 14 +++++++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/app/shipyard/Module.js b/src/app/shipyard/Module.js index a6378157..6e8533da 100755 --- a/src/app/shipyard/Module.js +++ b/src/app/shipyard/Module.js @@ -28,7 +28,7 @@ export default class Module { /** * Get a value for a given modification * @param {Number} name The name of the modification - * @return {Number} The value of the modification, as an integer value scaled so that 1.23% == 123 + * @return {object} The value of the modification. If it is a numeric value then it is returned as an integer value scaled so that 1.23% == 123 */ getModValue(name) { return this.mods && this.mods[name] ? this.mods[name] : null; @@ -37,7 +37,7 @@ export default class Module { /** * Set a value for a given modification ID * @param {Number} name The name of the modification - * @param {Number} value The value of the modification, as an integer scaled so that -2.34% == -234 + * @param {object} value The value of the modification. If it is a numeric value then it should be an integer scaled so that -2.34% == -234 */ setModValue(name, value) { if (!this.mods) { @@ -47,8 +47,12 @@ export default class Module { if (value == null || value == 0) { delete this.mods[name]; } else { - // Round just to be sure - this.mods[name] = Math.round(value); + if (isNaN(value)) { + this.mods[name] = value; + } else { + // Round just to be sure + this.mods[name] = Math.round(value); + } } } @@ -546,6 +550,6 @@ export default class Module { * @return {string} the damage types for this module; any combination of E T and K */ getDamageType() { - return this.type; + return this.getModValue('type') || this.type; } } diff --git a/src/app/shipyard/Ship.js b/src/app/shipyard/Ship.js index c1f5082c..bbbb974b 100755 --- a/src/app/shipyard/Ship.js +++ b/src/app/shipyard/Ship.js @@ -1413,7 +1413,12 @@ export default class Ship { } for (let slotMod of slot) { buffer.writeInt8(slotMod.id, curpos++); - buffer.writeInt32LE(slotMod.value, curpos); + if (isNaN(slotMod.value)) { + // We need to write the value out as a four-byte string + buffer.writeInt32LE(slotMod.value, curpos); + } else { + buffer.writeInt32LE(slotMod.value, curpos); + } // console.log('ENCODE Slot ' + i + ': ' + Modifications.modifications[slotMod.id] + ' = ' + slotMod.value); curpos += 4; } diff --git a/src/app/utils/CompanionApiUtils.js b/src/app/utils/CompanionApiUtils.js index c5293149..227acb07 100644 --- a/src/app/utils/CompanionApiUtils.js +++ b/src/app/utils/CompanionApiUtils.js @@ -284,12 +284,16 @@ function _addModifications(module, modifiers, blueprint, grade) { // Carry out the required changes for (const action in modifierActions) { - const actionValue = modifierActions[action] * value; - let mod = module.getModValue(action) / 10000; - if (!mod) { - mod = 0; + if (isNaN(modifierActions[action])) { + module.setModValue(action, modifierActions[action]); + } else { + const actionValue = modifierActions[action] * value; + let mod = module.getModValue(action) / 10000; + if (!mod) { + mod = 0; + } + module.setModValue(action, ((1 + mod) * (1 + actionValue) - 1) * 10000); } - module.setModValue(action, ((1 + mod) * (1 + actionValue) - 1) * 10000); } }