-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwork.autotrader.js
47 lines (44 loc) · 1.56 KB
/
work.autotrader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Autotrader
*/
module.exports.run = function (debug = false) {
// So we need to run this per room we control
for (var name in Game.rooms) {
var _room = Game.rooms[name];
var terminal = _room.terminal;
var energyInTerminal = terminal.store[RESOURCE_ENERGY];
for (var mineral in this.getCurrentMinerals(debug)) {
var orders = this.fetchAllValidOrders(ORDER_BUY, mineral, energyInTerminal, debug);
console.log(JSON.stringify(orders));
}
}
}
module.exports.fetchAllValidOrders = function (roomName = null, type = ORDER_BUY, mineral = null, energy = 0, debug = false) {
if (!mineral) {
console.log('no mineral set');
return [];
}
var orders = Game.market.getAllOrders(
order => order.type == type && order.resourceType == mineral &&
Game.market.calcTransactionCost(100, order.roomName, roomName) < energy
);
return orders;
}
module.exports.getCurrentMinerals = function (debug = false) {
var array = [];
// First loop through the rooms
for (var name in Game.rooms) {
var _room = Game.rooms[name];
// Just return this
if (!_room.memory.mineral) {
// We need to check for this rooms minerals
var minerals = _room.find(FIND_MINERALS);
var mineral = Game.getObjectById(minerals[0].id);
_room.memory.mineral = mineral.mineralType;
}
// Put the room's minerals into the array
array.push(_room.memory.mineral);
}
// Send back the list
return array;
}