mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-08 22:33:24 +00:00
Checkpoint - handle non-numeric modifiers
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user