Checkpoint - handle non-numeric modifiers

This commit is contained in:
Cmdr McDonald
2016-11-24 12:50:33 +00:00
parent 11af7f567a
commit 8fe20f6f65
3 changed files with 24 additions and 11 deletions

View File

@@ -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) {
@@ -46,11 +46,15 @@ export default class Module {
if (value == null || value == 0) {
delete this.mods[name];
} else {
if (isNaN(value)) {
this.mods[name] = value;
} else {
// Round just to be sure
this.mods[name] = Math.round(value);
}
}
}
/**
* Helper to obtain a modified value using standard multipliers
@@ -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;
}
}

View File

@@ -1413,7 +1413,12 @@ export default class Ship {
}
for (let slotMod of slot) {
buffer.writeInt8(slotMod.id, 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;
}

View File

@@ -284,6 +284,9 @@ function _addModifications(module, modifiers, blueprint, grade) {
// Carry out the required changes
for (const action in modifierActions) {
if (isNaN(modifierActions[action])) {
module.setModValue(action, modifierActions[action]);
} else {
const actionValue = modifierActions[action] * value;
let mod = module.getModValue(action) / 10000;
if (!mod) {
@@ -292,6 +295,7 @@ function _addModifications(module, modifiers, blueprint, grade) {
module.setModValue(action, ((1 + mod) * (1 + actionValue) - 1) * 10000);
}
}
}
// Add the blueprint ID and grade
if (blueprint) {