import { SlotMachine } from '.'; export class SpecialActions { /** * Spins the slot machine for a specified number of spins * @param slotMachine actual slot machine * @param times how many times the slot machine should spin * @param spinAPICall called when the slot machine is spinning, should return an array of symbols that will be shown on the reels * @param onSpinEnd called between spins * @returns an object with 1. a promise that resolves when all the spins are done, 2. an object that contains variables like turbo and forceStop */ public static doConsecutiveSpins(slotMachine: SlotMachine, times: number, spinAPICall: () => Promise, onSpinEnd?: () => void): { promise: Promise, controller: {turbo: Boolean, forceStop: Boolean} } { const controller = { turbo: false, forceStop: false }; const promise = new Promise(async (resolve, reject) => { try { for (let i = 0; i < times; i++) { slotMachine.startSpin(controller.turbo); const finalSymbols = await spinAPICall(); await slotMachine.stopSpin(finalSymbols, controller.forceStop); if (onSpinEnd) { onSpinEnd(); } } resolve(slotMachine); } catch (error) { reject(error); } }); return {promise, controller}; } }