@runox-game/game-engine
Version:
RunoX game engine
61 lines (60 loc) • 2.7 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.TakeDeckCardCommand = void 0;
var game_command_1 = require("./game.command");
var command_result_1 = require("./command-result");
var after_take_cards_event_1 = require("../events/after-take-cards.event");
var log_levels_enum_1 = require("../log/log-levels.enum");
var random_1 = require("../utils/random");
/**
* Class that allows the current player to take a card from the deck
*/
var TakeDeckCardCommand = /** @class */ (function (_super) {
__extends(TakeDeckCardCommand, _super);
/**
* Class that allows the current player to take a card from the deck
*/
function TakeDeckCardCommand() {
return _super.call(this) || this;
}
TakeDeckCardCommand.prototype.execute = function (state) {
var currentPlayer = state.turn.player;
var newCards;
if (state.gameModes.randomTakeDeckCard) {
newCards = state.giveCards(random_1.randomizeInteger(1, 5), currentPlayer);
}
else {
newCards = state.giveCards(1, currentPlayer);
}
state.log(currentPlayer.name + " toma las cartas " + newCards
.map(function (x) { return x.sprite; })
.join(', '), log_levels_enum_1.LogLevel.USER);
this.events.dispatchAfterTakeCards(new after_take_cards_event_1.AfterTakeCardsEvent(newCards, currentPlayer));
state.unoYellers[currentPlayer.id] = false;
this.checkForPlayersWhoShouldHaveYelledUno(state);
};
TakeDeckCardCommand.prototype.validate = function (state) {
if (!!state.winner) {
return new command_result_1.CommandValidation(false, 'Runox ya terminó');
}
if (!state.turn.player) {
return new command_result_1.CommandValidation(false, 'No se le asigno turno a un jugador');
}
return new command_result_1.CommandValidation(true);
};
return TakeDeckCardCommand;
}(game_command_1.GameCommand));
exports.TakeDeckCardCommand = TakeDeckCardCommand;