UNPKG

slotify.js

Version:

A video slot game session framework for JavaScript

92 lines (91 loc) 3.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GameSessionSimulation = void 0; var GameSessionSimulationModel_1 = require("./GameSessionSimulationModel"); var GameSessionSimulation = /** @class */ (function () { function GameSessionSimulation(session, config, simulationModel) { if (simulationModel === void 0) { simulationModel = new GameSessionSimulationModel_1.GameSessionSimulationModel(session); } this._currentGameNumber = 0; this._session = session; this._config = config; this._simulationModel = simulationModel; this._numberOfRounds = this._config.numberOfRounds ? this._config.numberOfRounds : 0; this._changeBetStrategy = config.changeBetStrategy; if (!this._numberOfRounds) { this._numberOfRounds = 1000; } } GameSessionSimulation.prototype.run = function () { var i; for (i = 0; i < this._numberOfRounds; i++) { this.doBeforePlay(); if (this.canPlayNextGame()) { this.doPlay(); } else { this.setBetOnCantPlayNextBet(); if (this.canPlayNextGame()) { this.doPlay(); } else { break; } } } this.onFinished(); }; GameSessionSimulation.prototype.getRtp = function () { return this._simulationModel.getRtp(); }; GameSessionSimulation.prototype.getTotalBetAmount = function () { return this._simulationModel.getTotalBetAmount(); }; GameSessionSimulation.prototype.getTotalReturn = function () { return this._simulationModel.getTotalReturnAmount(); }; GameSessionSimulation.prototype.getCurrentGameNumber = function () { return this._currentGameNumber; }; GameSessionSimulation.prototype.getTotalGameToPlayNumber = function () { return this._numberOfRounds; }; GameSessionSimulation.prototype.setBetOnCantPlayNextBet = function () { var bets; bets = this._session.getAvailableBets(); bets.sort(); this._session.setBet(bets[0]); }; GameSessionSimulation.prototype.onFinished = function () { if (this.onFinishedCallback) { this.onFinishedCallback(); } }; GameSessionSimulation.prototype.canPlayNextGame = function () { return this._session.canPlayNextGame(); }; GameSessionSimulation.prototype.setBetBeforePlay = function () { if (this._changeBetStrategy) { this._changeBetStrategy.setBetForPlay(this._session); } }; GameSessionSimulation.prototype.doPlay = function () { this._currentGameNumber++; this.setBetBeforePlay(); this._simulationModel.updateTotalBetBeforePlay(); this._session.play(); this._simulationModel.updateTotalReturnAfterPlay(); this.doAfterPlay(); }; GameSessionSimulation.prototype.doBeforePlay = function () { if (this.beforePlayCallback) { this.beforePlayCallback(); } }; GameSessionSimulation.prototype.doAfterPlay = function () { if (this.afterPlayCallback) { this.afterPlayCallback(); } }; return GameSessionSimulation; }()); exports.GameSessionSimulation = GameSessionSimulation;