Created
July 7, 2017 02:05
-
-
Save wffurr/7ce611a425c56fb46e22682e9c569950 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var yaml = require('js-yaml'); | |
var sde = {}; | |
// This list is not complete. | |
sde.FACILITIES = { | |
'Assembly Array': 0.98, | |
'Raitaru': 0.99, | |
'Raitaru T1 Rig NS': 0.94842, | |
}; | |
sde.TYPES = yaml.safeLoad(fs.readFileSync('./sde/typeIDs.yaml', 'utf8')); | |
sde.GROUPS = yaml.safeLoad(fs.readFileSync('./sde/groupIDs.yaml', 'utf8')); | |
sde.BLUEPRINTS = yaml.safeLoad(fs.readFileSync('./sde/blueprints.yaml', 'utf8')); | |
sde.NAMES_TO_TYPE_IDS = {}; | |
for (typeid in sde.TYPES) { | |
if (sde.TYPES.hasOwnProperty(typeid)) { | |
sde.NAMES_TO_TYPE_IDS[sde.TYPES[typeid].name] = typeid; | |
} | |
} | |
sde.getItemTypeAndGroup = function(item_name) { | |
var typeid = sde.NAMES_TO_TYPE_IDS[item_name]; | |
var group = sde.GROUPS[sde.TYPES[typeid].groupID].name; | |
return { 'typeid': typeid, 'group': group }; | |
}; | |
sde.getBlueprintData = function(blueprint_name) { | |
var typeid = sde.NAMES_TO_TYPE_IDS[blueprint_name]; | |
var blueprint_data = sde.BLUEPRINTS[typeid]; | |
blueprint_data.blueprint_group = sde.GROUPS[sde.TYPES[typeid].groupID].name; | |
var addTypeNames = function(obj) { | |
for (var key in obj) { | |
if (obj.hasOwnProperty(key)) { | |
if (key === 'typeID') { | |
obj.name = sde.TYPES[obj[key]].name; | |
} else if (typeof obj[key] === 'object') { | |
addTypeNames(obj[key]); | |
} | |
} | |
} | |
}; | |
addTypeNames(blueprint_data); | |
return blueprint_data; | |
}; | |
/** Returns list of materials and amounts needed to build the blueprint */ | |
sde.getMaterials = function(name, me, facility, runs) { | |
const blueprint_data = sde.getBlueprintData(name); | |
const activity = blueprint_data.blueprint_group.indexOf('Relic') > -1 ? | |
'invention' : 'manufacturing'; | |
let material_efficiency = activity == 'invention' ? 1 : | |
sde.FACILITIES[facility] * me; | |
// No facility bonus in the Subsystem Assembly Array, also used for T3C hulls | |
if (facility == 'Assembly Array' && | |
blueprint_data.blueprint_group in { 'Subsystem Blueprints':1, | |
'Strategic Cruiser Blueprints':1 }) { | |
material_efficiency = me; | |
} | |
return blueprint_data.activities[activity].materials.map(material => { | |
const qty = | |
Math.ceil(Math.max(material.quantity * material_efficiency, 1) * runs); | |
return { 'item_name': material.name, 'quantity': qty }; | |
}); | |
}; | |
module.exports = sde; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment