1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/**
* Modifier (AMD) deck view helpers (Phase 4 §6(d)): the pure read-only
* derivations the deck widget and its menu compute from the wire deck —
* the reference `ModifierDeck` accessors the header/view-model used.
*/
import type { ModifierCard, ModifierDeck } from '$lib/protocol/types';
/** The draw pile, top-first (the reference reverses `drawPileContents`). */
export function drawPileTopFirst(deck: ModifierDeck): ModifierCard[] {
return [...deck.drawPile].reverse();
}
/** The discard pile, bottom-first (draw order). */
export function discardPile(deck: ModifierDeck): ModifierCard[] {
return deck.discardPile;
}
/** Whether [gfx] is in the draw or discard pile (the reference `hasCard`). */
export function deckHasCard(deck: ModifierDeck, gfx: string): boolean {
return (
deck.drawPile.some((c) => c.gfx === gfx) ||
deck.discardPile.some((c) => c.gfx === gfx)
);
}
/** A `-1` card is available (in the draw or discard pile). */
export function deckHasMinus1(deck: ModifierDeck): boolean {
return deckHasCard(deck, 'minus1');
}
/**
* The `-2` is "not removed" (the reference `hasMinus2` is true when the
* removed pile has no `minus2` — i.e. the card can still be removed).
*/
export function deckMinus2Present(deck: ModifierDeck): boolean {
return !deck.removedPile.some((c) => c.gfx === 'minus2');
}
/** A `+0` card is in the deck. */
export function deckHasPlus0(deck: ModifierDeck): boolean {
return deckHasCard(deck, 'plus0');
}
/** The removable-counter total for [gfx] (0 when unset). */
export function removableTotal(deck: ModifierDeck, gfx: string): number {
return deck.removables[gfx] ?? 0;
}
/** The top `count` draw-pile cards (top-first) are revealed. */
export function revealedCards(
deck: ModifierDeck,
count: number
): ModifierCard[] {
const reversed = drawPileTopFirst(deck);
return reversed.slice(0, Math.max(0, Math.min(count, reversed.length)));
}
/**
* The Gloomhaven 2nd Edition faction cards (the reference
* `GameMethods.getFactionCards`): four addable cards per faction, or empty
* for an unknown faction.
*/
export function factionCards(faction: string): string[] {
if (faction === 'Demons') {
return [
'Demons-perks/plus1any',
'Demons-perks/plus1retaliate1flip',
'Demons-perks/plus0wardallyflip',
'Demons-perks/unique/fuck3'
];
}
if (faction === 'Merchant-Guild') {
return [
'Merchant-Guild-perks/plus1curse',
'Merchant-Guild-perks/plus1wound',
'Merchant-Guild-perks/plus0heal2flip',
'Merchant-Guild-perks/unique/fuck2'
];
}
if (faction === 'Military') {
return [
'Military-perks/plus1strengthenally',
'Military-perks/plus1shield1flip',
'Military-perks/plus1push2flip',
'Military-perks/unique/fuck1'
];
}
return [];
}
/**
* Whether [gfx] is in any character's personal deck (the reference
* `GameMethods.isCardInAnyCharacterDeck`) — the faction menu grays out
* cards another character already has.
*/
export function factionCardInAnyCharacterDeck(
deckNames: { name: string; deck: ModifierDeck }[],
gfx: string
): boolean {
return deckNames.some(({ deck }) =>
deck.drawPile.some((c) => c.gfx === gfx) ||
deck.discardPile.some((c) => c.gfx === gfx)
);
}
/** The sanctuary/party-card flag on a deck (gfx prefix, the reference `hasCSSanctuary`/`hasPartyCard`). */
export function deckHasSanctuaryCard(deck: ModifierDeck): boolean {
return deckPileHasPrefix(deck, 'sanctuary');
}
export function deckHasPartyCard(deck: ModifierDeck): boolean {
return deckPileHasPrefix(deck, 'party');
}
function deckPileHasPrefix(deck: ModifierDeck, prefix: string): boolean {
return (
deck.drawPile.some((c) => c.gfx.startsWith(prefix)) ||
deck.discardPile.some((c) => c.gfx.startsWith(prefix))
);
}
|