warriorjs-engine
Version:
The bowels of WarriorJS
83 lines (61 loc) • 4.83 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', {
value: true
});
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _get = function get(_x2, _x3, _x4) { var _again = true; _function: while (_again) { var object = _x2, property = _x3, receiver = _x4; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x2 = parent; _x3 = property; _x4 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _constantsRelativeDirections = require('../constants/RelativeDirections');
var _constantsRelativeDirections2 = _interopRequireDefault(_constantsRelativeDirections);
var _Base2 = require('./Base');
var _Base3 = _interopRequireDefault(_Base2);
var TARGET_DAMAGE_AMOUNT = 8;
var SURROUNDING_DAMAGE_AMOUNT = 4;
var SURROUNDINGS = [[1, 1], [1, -1], [2, 0], [0, 0]];
var Detonate = (function (_Base) {
_inherits(Detonate, _Base);
function Detonate() {
_classCallCheck(this, Detonate);
_get(Object.getPrototypeOf(Detonate.prototype), 'constructor', this).apply(this, arguments);
this._description = 'Detonate a bomb in a given direction (forward by default) which damages that space and surrounding 4 spaces (including yourself).';
}
_createClass(Detonate, [{
key: 'perform',
value: function perform() {
var _this = this;
var direction = arguments.length <= 0 || arguments[0] === undefined ? _constantsRelativeDirections2['default'].forward : arguments[0];
this.verifyDirection(direction);
if (this._unit.getPosition()) {
this._unit.say('detonates a bomb ' + direction + ' launching a deadly explosion.');
this.bomb(direction, 1, 0, TARGET_DAMAGE_AMOUNT);
SURROUNDINGS.forEach(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2);
var x = _ref2[0];
var y = _ref2[1];
return _this.bomb(direction, x, y, SURROUNDING_DAMAGE_AMOUNT);
});
}
}
}, {
key: 'bomb',
value: function bomb(direction, x, y, damageAmount) {
if (this._unit.getPosition()) {
var receiver = this.getSpace(direction, x, y).getUnit();
if (receiver) {
if (receiver.getActions().explode) {
receiver.say('caught in bomb\'s flames which detonates ticking explosive');
receiver.getActions().explode.perform();
} else {
this.damage(receiver, damageAmount);
}
}
}
}
}]);
return Detonate;
})(_Base3['default']);
exports['default'] = Detonate;
module.exports = exports['default'];