Skip to content
Permalink
Browse files

feat: added cooldown support for method StructureLab.unboostCreep

  • Loading branch information...
o4kapuk committed Sep 14, 2018
1 parent c2d73df commit 29e67146bd73adfc603da31982a4a0e0cfd9f252
Showing with 22 additions and 4 deletions.
  1. +3 −0 src/game/structures.js
  2. +13 −4 src/processor/intents/labs/unboost-creep.js
  3. +6 −0 src/utils.js
@@ -504,6 +504,9 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
if(!this.my || !target.my) {
return C.ERR_NOT_OWNER;
}
if(this.cooldown > 0) {
return C.ERR_TIRED;
}
if(!_.some(target.body, p => !!p.boost)) {
return C.ERR_NOT_FOUND;
}
@@ -4,6 +4,9 @@ const _ = require('lodash'),
C = driver.constants;

module.exports = function(object, intent, scope) {
if(object.cooldown > 0) {
return;
}
const {roomObjects, bulk} = scope;
const target = roomObjects[intent.id];
if(!target || target.type != 'creep' || target.user != object.user) {
@@ -21,11 +24,11 @@ module.exports = function(object, intent, scope) {
require('../creeps/_recalc-body')(target);
bulk.update(target, {body: target.body, energyCapacity: target.energyCapacity});

C.RESOURCES_ALL.forEach(function(r){
const cooldown = _.reduce(C.RESOURCES_ALL, function(a, r){
if(!boostedParts[r]) {
return;
return a;
}

const energyReturn = boostedParts[r]*C.LAB_UNBOOST_ENERGY;
if(energyReturn>0) {
require('../creeps/_create-energy')(target.x, target.y, target.room, energyReturn, C.RESOURCE_ENERGY, scope);
@@ -35,5 +38,11 @@ module.exports = function(object, intent, scope) {
if(mineralReturn > 0) {
require('../creeps/_create-energy')(target.x, target.y, target.room, mineralReturn, r, scope);
}
});

return a + boostedParts[r]*utils.calcTotalReactionsTime(r)*C.LAB_UNBOOST_MINERAL/C.LAB_REACTION_AMOUNT;
}, 0);

if(cooldown > 0) {
bulk.update(object, { cooldown });
}
};
@@ -1063,4 +1063,10 @@ exports.calcTerminalEnergyCost = function(amount, range) {

exports.calcNeededGcl = function(gclLevel) {
return C.GCL_MULTIPLY * Math.pow(gclLevel-1, C.GCL_POW);
};

exports.calcTotalReactionsTime = function(mineral) {
const reagents = _.reduce(C.REACTIONS, (a,n,j) => { _.forEach(n, (k,v) => a[k] = [v,j]); return a; }, {});
const calcStep = m => !!C.REACTION_TIME[m] ? C.REACTION_TIME[m] + calcStep(reagents[m][0]) + calcStep(reagents[m][1]) : 0;
return calcStep(mineral);
};

0 comments on commit 29e6714

Please sign in to comment.
You can’t perform that action at this time.