diff options
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 41 |
1 files changed, 25 insertions, 16 deletions
@@ -1857,22 +1857,27 @@ states.swap_card_tableau_hand = { gen_spend_hero_points(); view.prompt = 'Swap a card in your tableau with a card in your hand.'; const faction = get_active_faction(); + const selected_cards = game.selected_cards[faction]; + const hand = game.hands[faction]; + const tableau = game.tableaus[faction]; gen_action('skip'); - if (game.tableaus[faction].length === 0) { + if (tableau.length === 0) { view.prompt = 'No card in your tableau to swap.'; return; } - if (game.hands[faction].length === 0) { + if (hand.length === 1) { view.prompt = 'No card in your hand to swap.'; return; } - if (!game.selected_cards[faction].some((card_id) => game.hands[faction].includes(card_id))) { - for (const c of game.hands[faction]) { - gen_action_card(c); + if (selected_cards.length === 1) { + for (const c of hand) { + if (selected_cards[0] !== c) { + gen_action_card(c); + } } } - if (!game.selected_cards[faction].some((card_id) => game.tableaus[faction].includes(card_id))) { - for (const c of game.tableaus[faction]) { + if (selected_cards.length === 2) { + for (const c of tableau) { gen_action_card(c); } } @@ -1884,22 +1889,20 @@ states.swap_card_tableau_hand = { const faction = get_active_faction(); const selected_cards = game.selected_cards[faction]; selected_cards.push(c); - if (selected_cards.length === 2) { - const hand_card_index = selected_cards.findIndex((card_id) => game.hands[faction].includes(card_id)); - const tableau_card_index = hand_card_index === 0 ? 1 : 0; + if (selected_cards.length === 3) { const hand = game.hands[faction]; const tableau = game.tableaus[faction]; - array_remove(hand, hand.indexOf(selected_cards[hand_card_index])); - array_remove(tableau, tableau.indexOf(selected_cards[tableau_card_index])); - hand.push(selected_cards[tableau_card_index]); - tableau.push(selected_cards[hand_card_index]); - game.selected_cards[faction] = []; + array_remove_item(hand, selected_cards[1]); + array_remove_item(tableau, selected_cards[2]); + hand.push(selected_cards[2]); + tableau.push(selected_cards[1]); + game.selected_cards[faction].length = 1; resolve_active_and_proceed(); } }, skip() { const faction = get_active_faction(); - game.selected_cards[faction] = []; + game.selected_cards[faction].length = 1; resolve_active_and_proceed(); }, }; @@ -3026,6 +3029,12 @@ function object_copy(original) { return copy; } } +function array_remove_item(array, item) { + let n = array.length; + for (let i = 0; i < n; ++i) + if (array[i] === item) + return array_remove(array, i); +} function array_remove(array, index) { let n = array.length; for (let i = index + 1; i < n; ++i) |