diff --git a/src/BoosterFactory.ts b/src/BoosterFactory.ts index f3708cf59..c8b662907 100644 --- a/src/BoosterFactory.ts +++ b/src/BoosterFactory.ts @@ -48,10 +48,10 @@ class ColorBalancedSlotCache { constructor(cardPool: CardPool, options: Options = {}) { const localGetCard = options.getCard ?? getCard; - for (const cid of cardPool.keys()) { + for (const [cid, count] of cardPool) { if (!(localGetCard(cid).colors.join() in this.byColor)) this.byColor[localGetCard(cid).colors.join()] = new CardPool(); - this.byColor[localGetCard(cid).colors.join()].set(cid, cardPool.get(cid) as number); + this.byColor[localGetCard(cid).colors.join()].set(cid, count); } this.monocolored = new CardPool(); @@ -242,9 +242,9 @@ function filterCardPool(slotedCardPool: SlotedCardPool, predicate: (cid: CardID) for (const slot in slotedCardPool) { specialCards[slot] = new CardPool(); filteredCardPool[slot] = new CardPool(); - for (const cid of slotedCardPool[slot].keys()) { - if (predicate(cid)) specialCards[slot].set(cid, slotedCardPool[slot].get(cid) as number); - else filteredCardPool[slot].set(cid, slotedCardPool[slot].get(cid) as number); + for (const [cid, count] of slotedCardPool[slot]) { + if (predicate(cid)) specialCards[slot].set(cid, count); + else filteredCardPool[slot].set(cid, count); } } return [specialCards, filteredCardPool]; @@ -532,13 +532,13 @@ class STXBoosterFactory extends BoosterFactory { // Filter STA cards according to session collections if (options.session && !options.session.unrestrictedCardPool()) { const STACards: CardPool = options.session.restrictedCollection(["sta"]); - for (const cid of STACards.keys()) { + for (const [cid, count] of STACards) { const card = getCard(cid); // Remove Japanese versions if (parseInt(card.collector_number) <= 63) this.mysticalArchiveByRarity[card.rarity].set( cid, - Math.min(options.maxDuplicates?.[card.rarity] ?? 99, STACards.get(cid) as number) + Math.min(options.maxDuplicates?.[card.rarity] ?? 99, count) ); } } else { @@ -1012,10 +1012,10 @@ class YDMUBoosterFactory extends BoosterFactory { if (options.session && !options.session.unrestrictedCardPool()) { const YDMUCards: CardPool = options.session.restrictedCollection(["ydmu"]); this.alchemyCards = { uncommon: new CardPool(), rare: new CardPool(), mythic: new CardPool() }; - for (const cid of YDMUCards.keys()) + for (const [cid, count] of YDMUCards) this.alchemyCards[getCard(cid).rarity].set( cid, - Math.min(options.maxDuplicates?.[getCard(cid).rarity] ?? 99, YDMUCards.get(cid) as number) + Math.min(options.maxDuplicates?.[getCard(cid).rarity] ?? 99, count) ); } else { this.alchemyCards = { uncommon: new CardPool(), rare: new CardPool(), mythic: new CardPool() }; @@ -1150,12 +1150,12 @@ class BROBoosterFactory extends BoosterFactory { if (options.session && !options.session.unrestrictedCardPool()) { const BRRCards: CardPool = options.session.restrictedCollection(["brr"]); - for (const cid of BRRCards.keys()) { + for (const [cid, count] of BRRCards) { const card = getCard(cid); if (parseInt(card.collector_number) <= 63) this.retroArtifacts[card.rarity].set( cid, - Math.min(options.maxDuplicates?.[card.rarity] ?? 99, BRRCards.get(cid) as number) + Math.min(options.maxDuplicates?.[card.rarity] ?? 99, count) ); } } else { @@ -1391,12 +1391,12 @@ class MOMBoosterFactory extends BoosterFactory { if (options.session && !options.session.unrestrictedCardPool()) { const MULCards: CardPool = options.session.restrictedCollection(["mul"]); - for (const cid of MULCards.keys()) { + for (const [cid, count] of MULCards) { const card = getCard(cid); if (parseInt(card.collector_number) <= 65) this.multiverseLegend[card.rarity].set( cid, - Math.min(options.maxDuplicates?.[card.rarity] ?? 99, MULCards.get(cid) as number) + Math.min(options.maxDuplicates?.[card.rarity] ?? 99, count) ); } } else { @@ -1626,13 +1626,10 @@ class WOEBoosterFactory extends BoosterFactory { super(cardPool, landSlot, options); if (options.session && !options.session.unrestrictedCardPool()) { const WOTCards: CardPool = options.session.restrictedCollection(["wot"]); - for (const cid of WOTCards.keys()) { + for (const [cid, count] of WOTCards) { const card = getCard(cid); if (parseInt(card.collector_number) <= WOEBoosterFactory.MaxWOTCollectorNumber) - this.wotPool[card.rarity].set( - cid, - Math.min(options.maxDuplicates?.[card.rarity] ?? 99, WOTCards.get(cid) as number) - ); + this.wotPool[card.rarity].set(cid, Math.min(options.maxDuplicates?.[card.rarity] ?? 99, count)); } } else { for (const cid of CardsBySet["wot"]) { diff --git a/src/Session.ts b/src/Session.ts index 814827d20..f7d2357cf 100644 --- a/src/Session.ts +++ b/src/Session.ts @@ -532,7 +532,7 @@ export class Session implements IIndexable { for (const s of sets) if (s in CardsBySet) for (const cid of CardsBySet[s].filter((cid) => cardPool.has(cid))) - restricted.set(cid, cardPool.get(cid) as number); + restricted.set(cid, cardPool.get(cid)!); else console.error(`Session.restrictedCollection Error: '${s}' not in CardsBySet.`); return restricted; } else return cardPool; @@ -561,13 +561,10 @@ export class Session implements IIndexable { // Compute the minimum count of each remaining card for (const c of intersection) { - collection.set(c, useCollection[0] ? (Connections[user_list[0]].collection.get(c) as number) : 4); + collection.set(c, useCollection[0] ? Connections[user_list[0]].collection.get(c)! : 4); for (let i = 1; i < user_list.length; ++i) if (useCollection[i]) - collection.set( - c, - Math.min(collection.get(c) as number, Connections[user_list[i]].collection.get(c) as number) - ); + collection.set(c, Math.min(collection.get(c)!, Connections[user_list[i]].collection.get(c)!)); } return collection; } @@ -920,10 +917,10 @@ export class Session implements IIndexable { // Add a new card to skipped pile. (Make sure there's enough cards for the player to draw if this is the last pile) if (s.cardPool.length > 1 || (s.currentPile < 2 && s.cardPool.length > 0)) - s.piles[s.currentPile].push(s.cardPool.pop() as UniqueCard); + s.piles[s.currentPile].push(s.cardPool.pop()!); // Give a random card from the card pool if this was the last pile if (s.currentPile === 2) { - const card = s.cardPool.pop() as UniqueCard; + const card = s.cardPool.pop()!; Connections[s.currentPlayer()].pickedCards.main.push(card); Connections[s.currentPlayer()].socket.emit("winstonDraftRandomCard", card); this.draftLog?.users[s.currentPlayer()].picks.push({ @@ -948,7 +945,7 @@ export class Session implements IIndexable { piles: [...s.piles.map((p, idx) => p.slice(0, idx < s.currentPile ? -1 : undefined).map((c) => c.id))], }); Connections[s.currentPlayer()].pickedCards.main.push(...s.piles[s.currentPile]); - if (s.cardPool.length > 0) s.piles[s.currentPile] = [s.cardPool.pop() as UniqueCard]; + if (s.cardPool.length > 0) s.piles[s.currentPile] = [s.cardPool.pop()!]; else s.piles[s.currentPile] = []; this.winstonNextRound(); return true; @@ -1250,8 +1247,8 @@ export class Session implements IIndexable { // Column Row const idx = choice < 3 ? 3 * i + choice : 3 * (choice - 3) + i; if (s.boosters[0][idx] !== null) { - Connections[s.currentPlayer()].pickedCards.main.push(s.boosters[0][idx] as UniqueCard); - pickedCards.push(s.boosters[0][idx] as UniqueCard); + Connections[s.currentPlayer()].pickedCards.main.push(s.boosters[0][idx]!); + pickedCards.push(s.boosters[0][idx]!); log.pick.push(idx); s.boosters[0][idx] = null; } diff --git a/src/cardUtils.ts b/src/cardUtils.ts index c46ad86de..2f289b0c2 100644 --- a/src/cardUtils.ts +++ b/src/cardUtils.ts @@ -58,7 +58,7 @@ export function pickCard( ); if (candidates.length > 0) { const tmpPool = new CardPool(); - for (const cid of candidates) tmpPool.set(cid, cardPool.get(cid) as number); + for (const cid of candidates) tmpPool.set(cid, cardPool.get(cid)!); cid = randomFunc(tmpPool); } }