diff --git a/src/game/structures.js b/src/game/structures.js index 18993594..003acec1 100644 --- a/src/game/structures.js +++ b/src/game/structures.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}); /** diff --git a/src/processor/intents/labs/intents.js b/src/processor/intents/labs/intents.js index eeb81ca3..1410bf95 100644 --- a/src/processor/intents/labs/intents.js +++ b/src/processor/intents/labs/intents.js @@ -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); }; \ No newline at end of file diff --git a/src/processor/intents/labs/unboost-creep.js b/src/processor/intents/labs/unboost-creep.js new file mode 100644 index 00000000..c5cecdda --- /dev/null +++ b/src/processor/intents/labs/unboost-creep.js @@ -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); + } + }); +}; \ No newline at end of file diff --git a/src/utils.js b/src/utils.js index 498b626c..b61319fb 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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,