Skip to content

Commit

Permalink
fix(core): flower pot not working incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinfreund committed Mar 28, 2024
1 parent 951eabc commit 569e19e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/lib/balatro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import case028 from './test-files/028.js'
import case029 from './test-files/029.js'
import case030 from './test-files/030.js'
import case031 from './test-files/031.js'
import case032 from './test-files/032.js'

export type TestCase = {
message: string
Expand Down Expand Up @@ -76,6 +77,7 @@ describe('calculateScore', () => {
case029('Lucky Flush, Bloodstone, 4x Oops! All 6s'),
case030('Pair, Sly Joker, Observatory'),
case031('One wild + Flower Pot'),
case032('Four wild + Flower Pot'),
])('$message', ({ initialState, expected }) => {
const score = calculateScore(getState(initialState))

Expand Down
23 changes: 19 additions & 4 deletions src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { flush, nOfAKind, straight } from '#lib/getHand.js'
import { isFaceCard } from '#utilities/isFaceCard.js'
import { isRank } from '#utilities/isRank.js'
import { isSuit } from '#utilities/isSuit.js'
import type { BlindName, DeckName, Edition, Enhancement, HandName, JokerDefinition, JokerEdition, JokerName, Luck, PlanetName, Rank, Score, Seal, Suit } from '#lib/types.js'
import type { BlindName, Card, DeckName, Edition, Enhancement, HandName, JokerDefinition, JokerEdition, JokerName, Luck, PlanetName, Rank, Score, Seal, Suit } from '#lib/types.js'

export const BLINDS: BlindName[] = ['Small Blind', 'Big Blind', 'The Hook', 'The Ox', 'The House', 'The Wall', 'The Wheel', 'The Arm', 'The Club', 'The Fish', 'The Psychic', 'The Goad', 'The Water', 'The Window', 'The Manacle', 'The Eye', 'The Mouth', 'The Plant', 'The Serpent', 'The Pillar', 'The Needle', 'The Head', 'The Tooth', 'The Flint', 'The Mark', 'Amber Acorn', 'Verdant Leaf', 'Violet Vessel', 'Crimson Heart', 'Cerulean Bell']

Expand Down Expand Up @@ -766,9 +766,24 @@ export const JOKER_DEFINITIONS: Record<JokerName, JokerDefinition> = {
'Flower Pot': {
rarity: 'uncommon',
effect ({ score, state }) {
const hasAllSuits = (['Spades', 'Hearts', 'Clubs', 'Diamonds'] as const).every((suit) => {
return state.scoringCards.some((card) => isSuit(card, suit))
})
let hasAllSuits = false
const suits = ['Spades', 'Hearts', 'Clubs', 'Diamonds'] as Suit[]
const cards = new Set<Card>()
for (const suit of suits) {
for (const card of state.scoringCards) {
if (cards.has(card)) {
continue
}

if (isSuit(card, suit)) {
cards.add(card)

if (cards.size === 4) {
hasAllSuits = true
}
}
}
}

score.multiplier *= (hasAllSuits ? 3 : 1)
},
Expand Down
6 changes: 3 additions & 3 deletions src/lib/test-files/031.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export default (message: string): TestCase => {
{ rank: '7', suit: 'Spades', enhancement: 'wild' },
],
scores: [
{ score: 36, formattedScore: '36', luck: 'none' },
{ score: 36, formattedScore: '36', luck: 'average' },
{ score: 36, formattedScore: '36', luck: 'all' },
{ score: 12, formattedScore: '12', luck: 'none' },
{ score: 12, formattedScore: '12', luck: 'average' },
{ score: 12, formattedScore: '12', luck: 'all' },
],
},
}
Expand Down
32 changes: 32 additions & 0 deletions src/lib/test-files/032.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { TestCase } from '#lib/balatro.test.js'

export default (message: string): TestCase => {
return {
message,
initialState: {
playedCards: [
{ rank: '7', suit: 'Spades', enhancement: 'wild' },
{ rank: '7', suit: 'Spades', enhancement: 'wild' },
{ rank: '7', suit: 'Spades', enhancement: 'wild' },
{ rank: '7', suit: 'Spades', enhancement: 'wild' },
],
jokers: [
{ name: 'Flower Pot' },
],
},
expected: {
hand: 'Four of a Kind',
scoringCards: [
{ rank: '7', suit: 'Spades', enhancement: 'wild' },
{ rank: '7', suit: 'Spades', enhancement: 'wild' },
{ rank: '7', suit: 'Spades', enhancement: 'wild' },
{ rank: '7', suit: 'Spades', enhancement: 'wild' },
],
scores: [
{ score: 1848, formattedScore: '1,848', luck: 'none' },
{ score: 1848, formattedScore: '1,848', luck: 'average' },
{ score: 1848, formattedScore: '1,848', luck: 'all' },
],
},
}
}

0 comments on commit 569e19e

Please sign in to comment.