Decks: leave tokens and other non-deck pieces out of the card count
All checks were successful
ci/woodpecker/push/check Pipeline was successful
All checks were successful
ci/woodpecker/push/check Pipeline was successful
Tokens, emblems, dungeons, planes/phenomena, schemes, vanguards, conspiracies, Theros heroes, stickers, attractions, contraptions, the TMNT bosses/events, and helper "Card"s no longer count toward a deck's size, composition stats, or legality checks. They still count toward cost and can stay in the deck. Closes #33
This commit is contained in:
@@ -10,6 +10,42 @@ export const shortBy = (e: DeckEntry) => Math.max(0, e.quantity - e.quantity_own
|
|||||||
* decks claim them. */
|
* decks claim them. */
|
||||||
export const claimedElsewhere = (e: DeckEntry) => Math.max(0, Math.min(e.quantity, e.quantity_owned) - e.quantity_spare);
|
export const claimedElsewhere = (e: DeckEntry) => Math.max(0, Math.min(e.quantity, e.quantity_owned) - e.quantity_spare);
|
||||||
|
|
||||||
|
/** Card types of game pieces that live outside the main deck: tokens and
|
||||||
|
* emblems, dungeons, Planechase planes, Archenemy schemes, Vanguard,
|
||||||
|
* Conspiracy draft cards, Theros hero cards, Unfinity sticker sheets, the TMNT
|
||||||
|
* co-op bosses and events, and the theme/minigame/helper "Card"s. */
|
||||||
|
const NON_DECK_TYPES = new Set([
|
||||||
|
"Token",
|
||||||
|
"Emblem",
|
||||||
|
"Dungeon",
|
||||||
|
"Plane",
|
||||||
|
"Phenomenon",
|
||||||
|
"Scheme",
|
||||||
|
"Vanguard",
|
||||||
|
"Conspiracy",
|
||||||
|
"Hero",
|
||||||
|
"Stickers",
|
||||||
|
"Boss",
|
||||||
|
"Event",
|
||||||
|
"Card",
|
||||||
|
]);
|
||||||
|
|
||||||
|
/** Subtypes of cards that go in their own side deck rather than the main one. */
|
||||||
|
const NON_DECK_SUBTYPES = new Set(["Attraction", "Contraption"]);
|
||||||
|
|
||||||
|
/** Whether a card is part of the deck proper — false for tokens, emblems, and
|
||||||
|
* the other non-deck pieces above, which a deck can hold (to keep them with
|
||||||
|
* it) but which don't count toward its size or deck-building rules. */
|
||||||
|
export function isDeckCard(e: DeckEntry): boolean {
|
||||||
|
return !e.type_line.split(" // ").some((face) => {
|
||||||
|
const [types, subtypes = ""] = face.split("—");
|
||||||
|
return (
|
||||||
|
types.split(/\s+/).some((t) => NON_DECK_TYPES.has(t)) ||
|
||||||
|
subtypes.split(/\s+/).some((t) => NON_DECK_SUBTYPES.has(t))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export interface DeckStats {
|
export interface DeckStats {
|
||||||
totalCards: number;
|
totalCards: number;
|
||||||
uniqueCards: number;
|
uniqueCards: number;
|
||||||
@@ -38,12 +74,12 @@ export interface DeckStats {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Deck composition stats, excluding the commander (shown separately in its
|
* Deck composition stats, excluding the commander (shown separately in its
|
||||||
* own hero display) and the maybeboard (cards under consideration, not
|
* own hero display), the maybeboard (cards under consideration, not
|
||||||
* actually part of the deck) — matches the usual "99 + commander" framing
|
* actually part of the deck), and tokens and other non-deck pieces — matches the usual "99 + commander" framing
|
||||||
* even for non-Commander decks, where it's just "everything but those".
|
* even for non-Commander decks, where it's just "everything but those".
|
||||||
*/
|
*/
|
||||||
export function computeDeckStats(contents: DeckEntry[]): DeckStats {
|
export function computeDeckStats(contents: DeckEntry[]): DeckStats {
|
||||||
const cards = contents.filter((e) => !e.is_commander && !e.is_maybeboard);
|
const cards = contents.filter((e) => !e.is_commander && !e.is_maybeboard && isDeckCard(e));
|
||||||
const totalCards = cards.reduce((sum, e) => sum + e.quantity, 0);
|
const totalCards = cards.reduce((sum, e) => sum + e.quantity, 0);
|
||||||
const lands = cards.filter((e) => e.type_line.includes("Land"));
|
const lands = cards.filter((e) => e.type_line.includes("Land"));
|
||||||
const nonlands = cards.filter((e) => !e.type_line.includes("Land"));
|
const nonlands = cards.filter((e) => !e.type_line.includes("Land"));
|
||||||
@@ -284,7 +320,7 @@ export function computeDeckLegality(deck: Deck | null | undefined, contents: Dec
|
|||||||
}
|
}
|
||||||
|
|
||||||
const issues: LegalityIssue[] = [];
|
const issues: LegalityIssue[] = [];
|
||||||
const cards = contents.filter((e) => !e.is_maybeboard);
|
const cards = contents.filter((e) => !e.is_maybeboard && isDeckCard(e));
|
||||||
|
|
||||||
if (COMMANDER_FORMATS.includes(deck.format)) {
|
if (COMMANDER_FORMATS.includes(deck.format)) {
|
||||||
// Brawl (Scryfall's `brawl` legality key = paper/Historic Brawl) is
|
// Brawl (Scryfall's `brawl` legality key = paper/Historic Brawl) is
|
||||||
@@ -414,7 +450,8 @@ export interface DeckSummary {
|
|||||||
commanders: DeckEntry[];
|
commanders: DeckEntry[];
|
||||||
/** WUBRG mask: the commanders' identity, else the whole mainboard's. */
|
/** WUBRG mask: the commanders' identity, else the whole mainboard's. */
|
||||||
colors: number;
|
colors: number;
|
||||||
/** Mainboard copies, commander included. */
|
/** Mainboard copies, commander included, tokens and other non-deck
|
||||||
|
* pieces not. */
|
||||||
size: number;
|
size: number;
|
||||||
/** The size the format calls for (a minimum for 60-card formats), or null
|
/** The size the format calls for (a minimum for 60-card formats), or null
|
||||||
* when there's no format to measure against. */
|
* when there's no format to measure against. */
|
||||||
@@ -452,9 +489,10 @@ export function summarizeDeck(deck: Deck, contents: DeckEntry[]): DeckSummary {
|
|||||||
const main = contents.filter((e) => !e.is_maybeboard);
|
const main = contents.filter((e) => !e.is_maybeboard);
|
||||||
const isPrimary = (e: DeckEntry) => Number(e.oracle_id === deck.commander_oracle_id);
|
const isPrimary = (e: DeckEntry) => Number(e.oracle_id === deck.commander_oracle_id);
|
||||||
const commanders = main.filter((e) => e.is_commander).sort((a, b) => isPrimary(b) - isPrimary(a));
|
const commanders = main.filter((e) => e.is_commander).sort((a, b) => isPrimary(b) - isPrimary(a));
|
||||||
const colorSource = commanders.length ? commanders : main;
|
const deckCards = main.filter(isDeckCard);
|
||||||
const size = main.reduce((n, e) => n + e.quantity, 0);
|
const colorSource = commanders.length ? commanders : deckCards;
|
||||||
const ownedCopies = main.reduce((n, e) => n + Math.min(e.quantity, e.quantity_owned), 0);
|
const size = deckCards.reduce((n, e) => n + e.quantity, 0);
|
||||||
|
const ownedCopies = deckCards.reduce((n, e) => n + Math.min(e.quantity, e.quantity_owned), 0);
|
||||||
const target = COMMANDER_FORMATS.includes(deck.format)
|
const target = COMMANDER_FORMATS.includes(deck.format)
|
||||||
? COMMANDER_DECK_SIZE
|
? COMMANDER_DECK_SIZE
|
||||||
: deck.format && deck.format !== "Other"
|
: deck.format && deck.format !== "Other"
|
||||||
|
|||||||
Reference in New Issue
Block a user