@runox-game/game-engine
Version:
RunoX game engine
48 lines (47 loc) • 2.22 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.FinalizeTurnCommand = void 0;
var game_command_1 = require("./game.command");
var command_result_1 = require("./command-result");
var before_turn_event_1 = require("../events/before-turn.event");
var log_levels_enum_1 = require("../log/log-levels.enum");
/**
* Class that allows the end of the current player's turn and select the next one
*/
var FinalizeTurnCommand = /** @class */ (function (_super) {
__extends(FinalizeTurnCommand, _super);
/**
* Class that allows the end of the current player's turn and select the next one
*/
function FinalizeTurnCommand() {
return _super.call(this) || this;
}
FinalizeTurnCommand.prototype.execute = function (state) {
var nextPlayer = state.nextPlayerToPlay;
state.log(state.nextPlayerToPlay.name + " finaliza y contin\u00FAa " + nextPlayer.name, log_levels_enum_1.LogLevel.USER);
state.turn.setPlayerTurn(nextPlayer);
this.events.dispatchBeforeTurn(new before_turn_event_1.BeforeTurnEvent(nextPlayer));
state.events.dispatchStateChanged(state);
};
FinalizeTurnCommand.prototype.validate = function (state) {
if (!state.playersGroup.players.length) {
return new command_result_1.CommandValidation(false, 'No se puede finalizar el turno si no hay jugadores');
}
return new command_result_1.CommandValidation(true);
};
return FinalizeTurnCommand;
}(game_command_1.GameCommand));
exports.FinalizeTurnCommand = FinalizeTurnCommand;