Created
May 30, 2020 00:55
-
-
Save jhmartin/bacfe8e357fb12169f2f60b59851cf3e 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
JSON.stringify(Game.market.getAllOrders(order => order.resourceType == RESOURCE_GHODIUM && order.type == ORDER_SELL && Game.market.calcTransactionCost(200, 'W12N64', order.roomName) < 500)); |
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 roleExtractor = { | |
/** @param {Creep} creep **/ | |
run: function(creep) { | |
if (creep.memory.extracting && creep.carryCapacity == _.sum(creep.carry)) { | |
creep.memory.extracting = false; | |
} | |
if (!creep.memory.extracting && 0 == _.sum(creep.carry)) { | |
creep.memory.extracting = true; | |
if (creep.ticksToLive < 200) { | |
creep.suicide(); | |
} | |
} | |
if (creep.memory.extracting) { | |
var target; | |
if (creep.memory.depositId) { | |
target = Game.getObjectById(creep.memory.depositId); | |
} else { | |
var targets = creep.room.find(FIND_MINERALS); | |
target = targets[0]; | |
creep.memory.depositId = target.id; | |
creep.memory.mineralType = target.mineralType; | |
} | |
if (creep.harvest(target) == ERR_NOT_IN_RANGE) { | |
creep.moveTo(target); | |
} | |
} else { | |
if (creep.room.terminal) { | |
if (creep.transfer(creep.room.terminal, creep.memory.mineralType) == ERR_NOT_IN_RANGE) { | |
creep.moveTo(creep.room.terminal); | |
} | |
} else if (creep.room.storage) { | |
if (creep.transfer(creep.room.storage, creep.memory.mineralType) == ERR_NOT_IN_RANGE) { | |
creep.moveTo(creep.room.storage); | |
} | |
} | |
} | |
} | |
}; | |
module.exports = roleExtractor; |
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
// Terminal trade execution | |
if (spawn.room.terminal && (Game.time % 10 == 0)) { | |
if (spawn.room.terminal.store[RESOURCE_ENERGY] >= 2000 && spawn.room.terminal.store[RESOURCE_HYDROGEN] >= 2000) { | |
var orders = Game.market.getAllOrders(order => order.resourceType == RESOURCE_HYDROGEN && | |
order.type == ORDER_BUY && | |
Game.market.calcTransactionCost(200, spawn.room.name, order.roomName) < 400); | |
console.log('Hydrogen buy orders found: ' orders.length); | |
orders.sort(function(a,b){return b.price - a.price;}); | |
console.log('Best price: ' orders[0].price); | |
if (orders[0].price > 0.7) { | |
var result = Game.market.deal(orders[0].id, 200, spawn.room.name); | |
if (result == 0) { | |
console.log('Order completed successfully'); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment