UNPKG

@screeps/engine

Version:

This is a module for Screeps standalone server. See [main repository](https://github.com/screeps/screeps) for more info.

72 lines (60 loc) 2.16 kB
'use strict'; var _ = require('lodash'), utils = require('../../../utils'), driver = utils.getDriver(), C = driver.constants; module.exports = function (object, intent, scope) { let roomObjects = scope.roomObjects, bulk = scope.bulk, roomController = scope.roomController, gameTime = scope.gameTime; if (!object || object.type != 'tower' || !object.store) { return; } var target = roomObjects[intent.id]; if (!target || target == object) { return; } if (target.type == 'creep' && target.spawning) { return; } if (!target.hits) { return; } if (object.store.energy < C.TOWER_ENERGY_COST) { return; } var rampart = _.find(roomObjects, { type: 'rampart', x: target.x, y: target.y }); if (rampart) { target = rampart; } var range = Math.max(Math.abs(target.x - object.x), Math.abs(target.y - object.y)); var amount = C.TOWER_POWER_ATTACK; if (range > C.TOWER_OPTIMAL_RANGE) { if (range > C.TOWER_FALLOFF_RANGE) { range = C.TOWER_FALLOFF_RANGE; } amount -= amount * C.TOWER_FALLOFF * (range - C.TOWER_OPTIMAL_RANGE) / (C.TOWER_FALLOFF_RANGE - C.TOWER_OPTIMAL_RANGE); } [C.PWR_OPERATE_TOWER, C.PWR_DISRUPT_TOWER].forEach(power => { var effect = _.find(object.effects, { power }); if (effect && effect.endTime > gameTime) { amount *= C.POWER_INFO[power].effect[effect.level - 1]; } }); amount = Math.floor(amount); if (!amount) { return; } require('../_damage')(object, target, amount, C.EVENT_ATTACK_TYPE_RANGED, scope); object.store.energy -= C.TOWER_ENERGY_COST; bulk.update(object, { store: { energy: object.store.energy } }); object.actionLog.attack = { x: target.x, y: target.y }; if (target.actionLog) { target.actionLog.attacked = { x: object.x, y: object.y }; } if (target.notifyWhenAttacked) { utils.sendAttackingNotification(target, roomController); } }; //# sourceMappingURL=../../../sourcemaps/processor/intents/towers/attack.js.map