UNPKG

@runox-game/game-engine

Version:
70 lines (69 loc) 3.49 kB
"use strict"; 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.YellUnoCommand = 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 after_yell_uno_event_1 = require("../events/after-yell-uno.event"); var log_levels_enum_1 = require("../log/log-levels.enum"); var constants_1 = require("../constants"); /** * Class that allows a player to yell Uno */ var YellUnoCommand = /** @class */ (function (_super) { __extends(YellUnoCommand, _super); /** * Class that allows a player to yell Uno * * @param yellerId - identifier of the player who wants to yell Uno */ function YellUnoCommand(yellerId) { var _this = _super.call(this) || this; _this.yellerId = yellerId; return _this; } YellUnoCommand.prototype.execute = function (state) { var yeller = this.yellerId ? state.playersGroup.getPlayerById(this.yellerId) : state.turn.player; // es posible que el jugador tenga 2 cartas al momento de gritar UNO! state.log("es posible que el jugador tenga 2 cartas al momento de gritar UNO!", log_levels_enum_1.LogLevel.ALL); if (yeller.hand.cards.length <= 2 && !state.unoYellers[yeller.id]) { state.log("si no grito antes entonces lo marca como que grito", log_levels_enum_1.LogLevel.ALL); // si no grito antes entonces lo marca como que grito state.unoYellers[yeller.id] = true; state.log(yeller.name + " grit\u00F3 UNO", log_levels_enum_1.LogLevel.USER); this.events.dispatchAfterYellUno(new after_yell_uno_event_1.AfterYellUnoEvent(yeller)); } else { state.log("si tiene mas de 2 cartas o ya habia gritado entonces debemos validar que no haya mentido", log_levels_enum_1.LogLevel.ALL); // si tiene mas de 2 cartas o ya habia gritado entonces debemos validar que no haya mentido if (yeller.hand.cards.length > 2) { var newCards = state.giveCards(constants_1.Constants.PENALITY_FOR_YELL_UNO, yeller); state.log(yeller.name + " toma dos cartas por cantar UNO cuando no deb\u00EDa", log_levels_enum_1.LogLevel.USER); this.events.dispatchAfterTakeCards(new after_take_cards_event_1.AfterTakeCardsEvent(newCards, yeller)); } } }; YellUnoCommand.prototype.validate = function (state) { if (!!state.winner) { return new command_result_1.CommandValidation(false, 'Runox ya terminó'); } return new command_result_1.CommandValidation(true); }; return YellUnoCommand; }(game_command_1.GameCommand)); exports.YellUnoCommand = YellUnoCommand;