UNPKG

@warriorjs/core

Version:
92 lines (78 loc) 2.39 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _Unit = require('./Unit'); var _Unit2 = _interopRequireDefault(_Unit); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } /** Class representing a warrior. */ class Warrior extends _Unit2.default { /** * Creates a warrior. * * @param {string} name The name of the warrior. * @param {string} character The character of the warrior. * @param {string} color The color of the warrior. * @param {number} maxHealth The max health in HP. */ constructor(name, character, color, maxHealth) { super(name, character, color, maxHealth, null, false); } performTurn() { super.performTurn(); if (!this.turn.action || this.isBound()) { this.log('does nothing'); } } earnPoints(points) { super.earnPoints(points); this.log(`earns ${points} points`); } losePoints(points) { super.losePoints(points); this.log(`loses ${points} points`); } /** * Returns a grouped collection of abilities. * * @returns {Object} The collection of abilities. */ getAbilities() { const abilities = [...this.abilities].map(([name, { action, description }]) => ({ name, action, description })); const sortedAbilities = abilities.sort((a, b) => a.name > b.name); const actions = sortedAbilities.filter(ability => ability.action).map((_ref) => { let { action } = _ref, rest = _objectWithoutProperties(_ref, ['action']); return rest; }); const senses = sortedAbilities.filter(ability => !ability.action).map((_ref2) => { let { action } = _ref2, rest = _objectWithoutProperties(_ref2, ['action']); return rest; }); return { actions, senses }; } /** * Returns the status of the warrior. * * The status includes the current health and score values. * * @returns {Object} The status of the warrior. */ getStatus() { return { health: this.health, score: this.score }; } } exports.default = Warrior; module.exports = exports.default;