/* -------------------------------------------- */ const NB_POKER_CARD = 54; const IDX2CARDFAMILY = ['c', 'd', 'h', 's']; /* -------------------------------------------- */ export class SoSCardDeck extends Application { /* -------------------------------------------- */ static async create(data, options) { data.deck = []; data.discard = []; data.cardState = []; return super.create(data, options); } /* -------------------------------------------- */ shuffleDeck() { this.cleanCardList(); // Randomize deck while (data.deck.length != NB_POKER_CARD) { let idx = new Roll("1d54").roll().total; if (!this.data.cardState[idx - 1]) { if (idx == 53) { // Red Joker data.deck.push = { cardName: 'jr' } } else if (idx == 54) { // Black Joker data.deck.push = { cardName: 'jb' } } else { let familyIdx = idx % 4; let cardName = IDX2CARDFAMILY[familyIdx] + String((idx % 13) + 1); data.deck.push = { cardName: cardName } } this.data.cardState[idx - 1] = true; } } } /* -------------------------------------------- */ cleanCardList() { data.discard = []; // Reinit discard pile data.deck = []; for (let i = 0; i < NB_POKER_CARD; i++) { data.cardState[i] = false; } } }