Something went wrong. Try again.
Your trusty automation assistant in TLE Community misadventures!
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103import _ from 'lodash'
import { lacuna, call, findPlanets, eachPlanet, findBuilding, archGetInventory, log, util,} from '@tlecommunity/super-core'
const RECIPES = [ 'goethite halite gypsum trona'.split(' '), 'gold anthracite uraninite bauxite'.split(' '), 'kerogen methane sulfur zircon'.split(' '), 'monazite fluorite beryl magnetite'.split(' '), 'rutile chromite chalcopyrite galena'.split(' '),]
class MakeHalls { constructor(options) { this.options = options
this.numMade = 0 }
calculateQuantity(inventory, recipe) { return _.min(_.map(recipe, (glyph) => inventory[glyph] || 0)) }
validateOptions() { return new Promise((resolve, reject) => { if (!this.options.planet) { reject('please specify a planet') } else { resolve(true) } }) }
makeRecipe(colony, archaeology, inventory, recipe) { let quantity = this.calculateQuantity(inventory, recipe) let prettyList = _.map(recipe, _.capitalize).join(', ') let plural = util.handlePlurality(quantity, 'Hall')
if (quantity === 0) { return }
log.info(`Making ${quantity} ${plural} with ${prettyList}`)
return call(() => lacuna.archaeology.assembleGlyphs({ building_id: archaeology.id, glyphs: recipe, quantity }) ).then((result) => { this.numMade += quantity }) }
async makeHalls(colony, archaeology, inventory) { for (const recipe of RECIPES) { await this.makeRecipe(colony, archaeology, inventory, recipe) } }
handleColony(colony, buildings) { return findBuilding(buildings, 'Archaeology Ministry').then((archaeology) => { if (!archaeology) { return new Promise((resolve, reject) => { reject(`No Archaeology Ministry on ${colony.name}`) }) }
return archGetInventory(archaeology.id).then((inventory) => { return this.makeHalls(colony, archaeology, inventory) }) }) }
run() { return new Promise((resolve, reject) => { findPlanets(this.options.planet) .then((colonies) => { return eachPlanet(colonies, _.bind(this.handleColony, this), { force: true, }) }) .then(() => { if (this.numMade > 0) { let plural = util.handlePlurality(this.numMade, 'Hall') resolve(`Made ${this.numMade} ${plural}`) } else { resolve(`Didn't make any Halls`) } }) .catch(reject) }) }}
export default MakeHalls