diff --git a/composables/actions/buy.ts b/composables/actions/buy.ts new file mode 100644 index 0000000..ba5e37a --- /dev/null +++ b/composables/actions/buy.ts @@ -0,0 +1,17 @@ +import type { CardsCollectionItem } from '@nuxt/content' +import type { BoardCard } from '~/types/Board' +import type { Action } from '~/types/Action' + +export const buy: Action = (action: CardsCollectionItem['interactions'][0]['actions'][0], baseCard: BoardCard, interactingCard: BoardCard) => { + const boardStore = useBoardStore() + const cardStore = useCardStore() + + assert(action.card !== undefined, 'Action `buy` requires the `card` property to be set!') + + const card = cardStore.getCardByIdentifier(action.card) + assert(card !== undefined, 'Card not found!') + assert(typeof action.amount === 'number', 'Action `buy` requires the `amount` property to be set to an number!') + + const { x, y } = getDropCoordinates(baseCard.x, baseCard.z) + boardStore.addCard(card, x, y, true, action.amount * (interactingCard.amount ?? 1)) +} diff --git a/composables/actions/destroyInteracting.ts b/composables/actions/destroyInteracting.ts new file mode 100644 index 0000000..5d90d11 --- /dev/null +++ b/composables/actions/destroyInteracting.ts @@ -0,0 +1,14 @@ +import type { CardsCollectionItem } from '@nuxt/content' +import type { BoardCard } from '~/types/Board' +import type { Action } from '~/types/Action' + +export const destroyInteracting: Action = (_action: CardsCollectionItem['interactions'][0]['actions'][0], baseCard: BoardCard, interactingCard: BoardCard) => { + const boardStore = useBoardStore() + + if (baseCard.stackedCard) { + const { x, y } = getDropCoordinates(baseCard.x, baseCard.z) + boardStore.unstackCard(baseCard.stackedCard, { x, y }) + } + + boardStore.removeCard(interactingCard) +} diff --git a/composables/useAction.ts b/composables/useAction.ts index 5a44ce1..7ba2010 100644 --- a/composables/useAction.ts +++ b/composables/useAction.ts @@ -14,6 +14,8 @@ import { destroyAll } from './actions/destroyAll' import { destroyRandom } from './actions/destroyRandom' import { random } from './actions/random' import { win } from './actions/win' +import { buy } from './actions/buy' +import { destroyInteracting } from './actions/destroyInteracting' import type { BoardCard } from '~/types/Board' import type { Action } from '~/types/Action' import { reveal } from '~/composables/actions/reveal' @@ -35,6 +37,8 @@ const allActions: { [key: string]: Action } = { random, reveal, win, + buy, + destroyInteracting, } export const useAction = () => { diff --git a/content/cards/merchant.json b/content/cards/merchant.json index 71e478e..44eecdd 100644 --- a/content/cards/merchant.json +++ b/content/cards/merchant.json @@ -7,23 +7,27 @@ "interactions": [ { "card": "metal", - "consume": true, "actions": [ { - "type": "spawn", + "type": "buy", "card": "money", "amount": 6 + }, + { + "type": "destroyInteracting" } ] }, { "card": "fuel", - "consume": true, "actions": [ { - "type": "spawn", + "type": "buy", "card": "money", "amount": 25 + }, + { + "type": "destroyInteracting" } ] }