Skip to content
Permalink
Browse files

feat: new method StructureLab.unboostCreep

  • Loading branch information...
o4kapuk committed Sep 12, 2018
1 parent efc703f commit 49469d43a7303ccad3466ee5550375ac6625b5ab
Showing with 65 additions and 0 deletions.
  1. +19 −0 src/game/structures.js
  2. +3 −0 src/processor/intents/labs/intents.js
  3. +38 −0 src/processor/intents/labs/unboost-creep.js
  4. +5 −0 src/utils.js
@@ -496,6 +496,25 @@ exports.make = function(_runtimeData, _intents, _register, _globals) {
return C.OK;
});

StructureLab.prototype.unboostCreep = register.wrapFn(function(target) {
if(!target || !target.id || !register.creeps[target.id] || !(target instanceof globals.Creep)) {
register.assertTargetObject(target);
return C.ERR_INVALID_TARGET;
}
if(!this.my || !target.my) {
return C.ERR_NOT_OWNER;
}
if(!_.some(target.body, p => !!p.boost)) {
return C.ERR_NOT_FOUND;
}
if(!this.pos.isNearTo(target)) {
return C.ERR_NOT_IN_RANGE;
}

intents.set(this.id, 'unboostCreep', {id: target.id});
return C.OK;
});

Object.defineProperty(globals, 'StructureLab', {enumerable: true, value: StructureLab});

/**
@@ -10,4 +10,7 @@ module.exports = function(object, objectIntents, scope) {

if(objectIntents.boostCreep)
require('./boost-creep')(object, objectIntents.boostCreep, scope);

if(objectIntents.unboostCreep)
require('./unboost-creep')(object, objectIntents.unboostCreep, roomObjects, roomTerrain, bulk, bulkUsers, roomController, stats);
};
@@ -0,0 +1,38 @@
const _ = require('lodash'),
utils = require('../../../utils'),
driver = utils.getDriver(),
C = driver.constants;

module.exports = function(object, intent, roomObjects, roomTerrain, bulk) {
const target = roomObjects[intent.id];
if(!target || target.type != 'creep' || target.user != object.user) {
return;
}
if(Math.abs(target.x - object.x) > 1 || Math.abs(target.y - object.y) > 1) {
return;
}
const boostedParts = _.mapValues(_.groupBy(_.filter(target.body,p=>!!p.boost), 'boost'), v=>v.length);
if(!_.some(boostedParts)) {
return;
}

target.body.forEach(function(p) {p.boost = null;});
require('../creeps/_recalc-body')(target);
bulk.update(target, {body: target.body, energyCapacity: target.energyCapacity});

C.RESOURCES_ALL.forEach(function(r){
if(!boostedParts[r]) {
return;
}

const energyReturn = boostedParts[r]*C.LAB_UNBOOST_ENERGY;
if(energyReturn>0) {
require('../creeps/_create-energy')(target.x, target.y, target.room, energyReturn, roomObjects, bulk, C.RESOURCE_ENERGY);
}

const mineralReturn = boostedParts[r]*C.LAB_UNBOOST_MINERAL;
if(mineralReturn > 0) {
require('../creeps/_create-energy')(target.x, target.y, target.room, mineralReturn, roomObjects, bulk, r);
}
});
};
@@ -783,6 +783,11 @@ exports.storeIntents = function(userId, userIntents, userRuntimeData) {
bodyPartsCount: parseInt(objectIntentsResult.boostCreep.bodyPartsCount)
};
}
if(objectIntentsResult.unboostCreep) {
objectIntents.unboostCreep = {
id: ""+objectIntentsResult.unboostCreep.id
}
}
if(objectIntentsResult.send) {
objectIntents.send = {
targetRoomName: ""+objectIntentsResult.send.targetRoomName,

0 comments on commit 49469d4

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