feat: cartes Événement (pioche partagée de 18 cartes, 6 effets, synergies, ciblage)
- Nouveau server/src/game/events.js : 6 événements (Récolte exceptionnelle, Épidémie, Levée des troupes, Accord royal, Complot découvert, Grande fête au château), deck PARTAGÉ de 18 cartes (3 exemplaires de chacun) mélangé au démarrage de la partie. - Room.js : buyEventDraw() (coût fixe 1 point dans chacune des 4 jauges, effet immédiat contrairement aux objets/bâtiments — pas de conflit de stock possible), playEventCard() (choix de jouer une carte de sa main, max 1 par tour, avec ciblage optionnel), _resolvePendingEventPlays() (résolution de TOUS les événements du tour AVANT le calcul des gains de cartes personnage, défausse systématique, protection "Complot découvert" pour soi-même uniquement). Les 6 effets incluent leurs synergies avec les objets/bâtiments existants (Charrue, Trousse+Église pour Épidémie, Trébuchet, Sceau Royal, Château Royal → pioche bonus). - IMPORTANT : le ciblage de joueur (Accord royal, variante Trousse d'Épidémie) transite par teamIndex (identifiant public) et non socketId (jamais exposé au client via getPlayersInfo/getStateFor) — le serveur résout teamIndex -> joueur réel au moment de la résolution. - Nouvel event socket 'buy-event-draw' (effet immédiat) et 'play-event' (résolution différée), eventResults inclus dans round-result. - Client : events.js (miroir), EventCardObject.js (carte épurée façon CardObject, badge rouge "!" pour les événements à effet négatif). BootScene génère les textures plein cadre (méthode _generateClippedTexture généralisée, réutilisée avec les personnages). - GameScene : bouton de pioche à droite du bouton de confirmation (état grisé selon jauges/main pleine/pioche déjà tentée), seconde main de cartes événement (max 2) au-dessus de ce bouton, sélection d'une carte pour la jouer avec séquence de ciblage interactive (surbrillance des slots adversaires cliquables) pour Accord royal et la variante Trousse d'Épidémie. - 61 nouveaux tests unitaires serveur (events.js + Room.js : pioche, choix de jouer, résolution des 6 effets avec/sans synergie, Complot découvert, ordre événements-avant-personnages, deck partagé). - Nouveaux helpers et tests d'intégration E2E Playwright (e2e/tests/events.spec.js) pour la pioche, la limite de main à 2, et les 6 effets — certains scénarios restent probabilistes (pioche aléatoire dans le deck partagé) et peuvent nécessiter une stabilisation supplémentaire du timing.
This commit is contained in:
1 parent
9139989fa7
commit
1726f8f96b
17 files changed
+1952
-16
No files matched your search
@@ -0,0 +1,375 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import {
|
||||
installPhaserDebugHook, createRoom, joinRoom, startGame,
|
||||
playFullTurn, getMyGauges, getMyEventHand,
|
||||
clickEventDrawButton, drawEventUntil, playEventCard
|
||||
} from './helpers.js'
|
||||
|
||||
/**
|
||||
* Tests d'intégration E2E : cartes Événement (pioche partagée de 18 cartes,
|
||||
* main limitée à 2, choix de jouer une carte, résolution avant les gains de
|
||||
* cartes personnage, synergies avec objets/bâtiments, ciblage de joueurs).
|
||||
*/
|
||||
test.describe('Cartes Événement', () => {
|
||||
test('le bouton de pioche est grisé/non cliquable tant que les jauges sont à 0', async ({ browser }) => {
|
||||
const ctx1 = await browser.newContext()
|
||||
const ctx2 = await browser.newContext()
|
||||
const p1 = await ctx1.newPage()
|
||||
const p2 = await ctx2.newPage()
|
||||
await installPhaserDebugHook(p1)
|
||||
await installPhaserDebugHook(p2)
|
||||
|
||||
const roomId = await createRoom(p1, 'Alice')
|
||||
await joinRoom(p2, 'Bob', roomId)
|
||||
await startGame(p1)
|
||||
await p1.waitForTimeout(2000)
|
||||
|
||||
const drew = await clickEventDrawButton(p1)
|
||||
expect(drew).toBe(false)
|
||||
|
||||
await ctx1.close()
|
||||
await ctx2.close()
|
||||
})
|
||||
|
||||
test('acheter une pioche débite 1 point de chacune des 4 jauges et ajoute une carte à la main', async ({ browser }) => {
|
||||
test.setTimeout(60_000)
|
||||
|
||||
const ctx1 = await browser.newContext()
|
||||
const ctx2 = await browser.newContext()
|
||||
const p1 = await ctx1.newPage()
|
||||
const p2 = await ctx2.newPage()
|
||||
await installPhaserDebugHook(p1)
|
||||
await installPhaserDebugHook(p2)
|
||||
|
||||
const roomId = await createRoom(p1, 'Alice')
|
||||
await joinRoom(p2, 'Bob', roomId)
|
||||
await startGame(p1)
|
||||
await p1.waitForTimeout(2000)
|
||||
|
||||
// Accumuler au moins 1 point sur les 4 jauges en jouant des cartes qui
|
||||
// maximisent la somme des 4 attributs.
|
||||
let gauges = await getMyGauges(p1)
|
||||
let attempts = 0
|
||||
while (!['food', 'war', 'health', 'diplo'].every(a => gauges[a] >= 1) && attempts < 6) {
|
||||
await playFullTurn([p1, p2], [['food', 'war', 'health', 'diplo'], ['food', 'war', 'health', 'diplo']])
|
||||
gauges = await getMyGauges(p1)
|
||||
attempts++
|
||||
}
|
||||
expect(['food', 'war', 'health', 'diplo'].every(a => gauges[a] >= 1)).toBe(true)
|
||||
|
||||
const before = { ...gauges }
|
||||
const drew = await clickEventDrawButton(p1)
|
||||
expect(drew).toBe(true)
|
||||
|
||||
const after = await getMyGauges(p1)
|
||||
expect(after.food).toBe(before.food - 1)
|
||||
expect(after.war).toBe(before.war - 1)
|
||||
expect(after.health).toBe(before.health - 1)
|
||||
expect(after.diplo).toBe(before.diplo - 1)
|
||||
|
||||
const hand = await getMyEventHand(p1)
|
||||
expect(hand.length).toBe(1)
|
||||
|
||||
await ctx1.close()
|
||||
await ctx2.close()
|
||||
})
|
||||
|
||||
test('la main d\'événements est limitée à 2 cartes (le bouton se désactive ensuite)', async ({ browser }) => {
|
||||
test.setTimeout(90_000)
|
||||
|
||||
const ctx1 = await browser.newContext()
|
||||
const ctx2 = await browser.newContext()
|
||||
const p1 = await ctx1.newPage()
|
||||
const p2 = await ctx2.newPage()
|
||||
await installPhaserDebugHook(p1)
|
||||
await installPhaserDebugHook(p2)
|
||||
|
||||
const roomId = await createRoom(p1, 'Alice')
|
||||
await joinRoom(p2, 'Bob', roomId)
|
||||
await startGame(p1)
|
||||
await p1.waitForTimeout(2000)
|
||||
|
||||
async function ensureGaugesAndDraw() {
|
||||
let gauges = await getMyGauges(p1)
|
||||
let attempts = 0
|
||||
while (!['food', 'war', 'health', 'diplo'].every(a => gauges[a] >= 1) && attempts < 6) {
|
||||
await playFullTurn([p1, p2], [['food', 'war', 'health', 'diplo'], ['food', 'war', 'health', 'diplo']])
|
||||
gauges = await getMyGauges(p1)
|
||||
attempts++
|
||||
}
|
||||
return clickEventDrawButton(p1)
|
||||
}
|
||||
|
||||
expect(await ensureGaugesAndDraw()).toBe(true)
|
||||
// La pioche est immédiate (pas de coût d'un tour), mais un joueur ne peut
|
||||
// tenter qu'UNE pioche par tour : il faut jouer le tour pour pouvoir
|
||||
// retenter la pioche suivante.
|
||||
await playFullTurn([p1, p2])
|
||||
expect(await ensureGaugesAndDraw()).toBe(true)
|
||||
|
||||
const hand = await getMyEventHand(p1)
|
||||
expect(hand.length).toBe(2)
|
||||
|
||||
// Une 3e tentative doit être refusée (main pleine)
|
||||
await playFullTurn([p1, p2])
|
||||
let gauges = await getMyGauges(p1)
|
||||
let attempts = 0
|
||||
while (!['food', 'war', 'health', 'diplo'].every(a => gauges[a] >= 1) && attempts < 6) {
|
||||
await playFullTurn([p1, p2], [['food', 'war', 'health', 'diplo'], ['food', 'war', 'health', 'diplo']])
|
||||
gauges = await getMyGauges(p1)
|
||||
attempts++
|
||||
}
|
||||
const thirdDraw = await clickEventDrawButton(p1)
|
||||
expect(thirdDraw).toBe(false)
|
||||
|
||||
await ctx1.close()
|
||||
await ctx2.close()
|
||||
})
|
||||
|
||||
test('jouer "Récolte exceptionnelle" donne +2 Nourriture, résolu avant les gains de carte personnage', async ({ browser }) => {
|
||||
test.setTimeout(90_000)
|
||||
|
||||
const ctx1 = await browser.newContext()
|
||||
const ctx2 = await browser.newContext()
|
||||
const p1 = await ctx1.newPage()
|
||||
const p2 = await ctx2.newPage()
|
||||
const errors = []
|
||||
p1.on('pageerror', e => errors.push(e.message))
|
||||
await installPhaserDebugHook(p1)
|
||||
await installPhaserDebugHook(p2)
|
||||
|
||||
const roomId = await createRoom(p1, 'Alice')
|
||||
await joinRoom(p2, 'Bob', roomId)
|
||||
await startGame(p1)
|
||||
await p1.waitForTimeout(2000)
|
||||
|
||||
const drawn = await drawEventUntil(p1, [p2], 'bountiful_harvest')
|
||||
test.skip(!drawn, 'Récolte exceptionnelle non piochée dans la limite de tentatives (probabiliste)')
|
||||
|
||||
const foodBefore = (await getMyGauges(p1)).food
|
||||
|
||||
await playEventCard(p1, 'bountiful_harvest')
|
||||
// Neutraliser le gain de carte personnage sur food en jouant la carte
|
||||
// MINIMISANT food pour les deux joueurs, afin d'isoler l'effet événement.
|
||||
await playFullTurn([p1, p2], [
|
||||
{ attr: 'food', mode: 'min' },
|
||||
{ attr: 'food', mode: 'min' }
|
||||
])
|
||||
|
||||
const foodAfter = (await getMyGauges(p1)).food
|
||||
expect(foodAfter).toBeGreaterThanOrEqual(foodBefore + 2)
|
||||
expect(errors).toEqual([])
|
||||
|
||||
await ctx1.close()
|
||||
await ctx2.close()
|
||||
})
|
||||
|
||||
test('jouer "Épidémie" fait perdre 1 Santé à tous les joueurs (effet de base, sans objet/bâtiment)', async ({ browser }) => {
|
||||
test.setTimeout(90_000)
|
||||
|
||||
const ctx1 = await browser.newContext()
|
||||
const ctx2 = await browser.newContext()
|
||||
const p1 = await ctx1.newPage()
|
||||
const p2 = await ctx2.newPage()
|
||||
await installPhaserDebugHook(p1)
|
||||
await installPhaserDebugHook(p2)
|
||||
|
||||
const roomId = await createRoom(p1, 'Alice')
|
||||
await joinRoom(p2, 'Bob', roomId)
|
||||
await startGame(p1)
|
||||
await p1.waitForTimeout(2000)
|
||||
|
||||
// Accumuler un peu de Santé pour les deux joueurs afin que la perte soit visible sans clamp à 0.
|
||||
for (let t = 0; t < 3; t++) {
|
||||
await playFullTurn([p1, p2], [
|
||||
['health'],
|
||||
{ attr: 'health', mode: 'min' }
|
||||
])
|
||||
}
|
||||
|
||||
const drawn = await drawEventUntil(p1, [p2], 'epidemic')
|
||||
test.skip(!drawn, 'Épidémie non piochée dans la limite de tentatives (probabiliste)')
|
||||
|
||||
const p1HealthBefore = (await getMyGauges(p1)).health
|
||||
|
||||
await playEventCard(p1, 'epidemic')
|
||||
await playFullTurn([p1, p2], [
|
||||
{ attr: 'health', mode: 'min' },
|
||||
{ attr: 'health', mode: 'min' }
|
||||
])
|
||||
|
||||
const p1HealthAfter = (await getMyGauges(p1)).health
|
||||
// Le lanceur lui-même perd aussi 1 Santé avec l'effet de base (tout le
|
||||
// monde affecté), avant tout gain de carte personnage neutralisé.
|
||||
expect(p1HealthAfter).toBeLessThanOrEqual(p1HealthBefore)
|
||||
|
||||
await ctx1.close()
|
||||
await ctx2.close()
|
||||
})
|
||||
|
||||
test('jouer "Accord royal" avec ciblage : le joueur choisi en gain reçoit +1 Diplomatie', async ({ browser }) => {
|
||||
test.setTimeout(90_000)
|
||||
|
||||
const ctx1 = await browser.newContext()
|
||||
const ctx2 = await browser.newContext()
|
||||
const ctx3 = await browser.newContext()
|
||||
const p1 = await ctx1.newPage()
|
||||
const p2 = await ctx2.newPage()
|
||||
const p3 = await ctx3.newPage()
|
||||
await installPhaserDebugHook(p1)
|
||||
await installPhaserDebugHook(p2)
|
||||
await installPhaserDebugHook(p3)
|
||||
|
||||
const roomId = await createRoom(p1, 'Alice')
|
||||
await joinRoom(p2, 'Bob', roomId)
|
||||
await joinRoom(p3, 'Carl', roomId)
|
||||
await startGame(p1)
|
||||
await p1.waitForTimeout(2000)
|
||||
|
||||
const drawn = await drawEventUntil(p1, [p2, p3], 'royal_accord')
|
||||
test.skip(!drawn, 'Accord royal non piochée dans la limite de tentatives (probabiliste)')
|
||||
|
||||
const bobDiploBefore = (await p2.evaluate(() => {
|
||||
const game = window.__ALL_GAMES__[window.__ALL_GAMES__.length - 1]
|
||||
const scene = game.scene.getScene('GameScene')
|
||||
const me = scene.store.players.find(p => p.teamIndex === scene.store.myTeamIndex)
|
||||
return me.gauges.diplo
|
||||
}))
|
||||
|
||||
// Cible teamIndex 1 (Bob) pour le gain, pas de cible pour la perte (laissée non cliquée)
|
||||
await playEventCard(p1, 'royal_accord', [1])
|
||||
await playFullTurn([p1, p2, p3])
|
||||
|
||||
const bobDiploAfter = (await p2.evaluate(() => {
|
||||
const game = window.__ALL_GAMES__[window.__ALL_GAMES__.length - 1]
|
||||
const scene = game.scene.getScene('GameScene')
|
||||
const me = scene.store.players.find(p => p.teamIndex === scene.store.myTeamIndex)
|
||||
return me.gauges.diplo
|
||||
}))
|
||||
|
||||
expect(bobDiploAfter).toBeGreaterThanOrEqual(bobDiploBefore + 1)
|
||||
|
||||
await ctx1.close()
|
||||
await ctx2.close()
|
||||
await ctx3.close()
|
||||
})
|
||||
|
||||
test('jouer "Complot découvert" ne modifie aucune jauge par lui-même', async ({ browser }) => {
|
||||
test.setTimeout(90_000)
|
||||
|
||||
const ctx1 = await browser.newContext()
|
||||
const ctx2 = await browser.newContext()
|
||||
const p1 = await ctx1.newPage()
|
||||
const p2 = await ctx2.newPage()
|
||||
const errors = []
|
||||
p1.on('pageerror', e => errors.push(e.message))
|
||||
await installPhaserDebugHook(p1)
|
||||
await installPhaserDebugHook(p2)
|
||||
|
||||
const roomId = await createRoom(p1, 'Alice')
|
||||
await joinRoom(p2, 'Bob', roomId)
|
||||
await startGame(p1)
|
||||
await p1.waitForTimeout(2000)
|
||||
|
||||
const drawn = await drawEventUntil(p1, [p2], 'plot_uncovered')
|
||||
test.skip(!drawn, 'Complot découvert non piochée dans la limite de tentatives (probabiliste)')
|
||||
|
||||
await playEventCard(p1, 'plot_uncovered')
|
||||
await playFullTurn([p1, p2], [
|
||||
{ attr: 'food', mode: 'min' },
|
||||
{ attr: 'food', mode: 'min' }
|
||||
])
|
||||
|
||||
expect(errors).toEqual([])
|
||||
|
||||
await ctx1.close()
|
||||
await ctx2.close()
|
||||
})
|
||||
|
||||
test('jouer "Grande fête au château" donne +1 Nourriture et +1 Diplomatie', async ({ browser }) => {
|
||||
test.setTimeout(90_000)
|
||||
|
||||
const ctx1 = await browser.newContext()
|
||||
const ctx2 = await browser.newContext()
|
||||
const p1 = await ctx1.newPage()
|
||||
const p2 = await ctx2.newPage()
|
||||
await installPhaserDebugHook(p1)
|
||||
await installPhaserDebugHook(p2)
|
||||
|
||||
const roomId = await createRoom(p1, 'Alice')
|
||||
await joinRoom(p2, 'Bob', roomId)
|
||||
await startGame(p1)
|
||||
await p1.waitForTimeout(2000)
|
||||
|
||||
const drawn = await drawEventUntil(p1, [p2], 'castle_feast')
|
||||
test.skip(!drawn, 'Grande fête non piochée dans la limite de tentatives (probabiliste)')
|
||||
|
||||
const before = await getMyGauges(p1)
|
||||
|
||||
await playEventCard(p1, 'castle_feast')
|
||||
await playFullTurn([p1, p2], [
|
||||
{ attr: ['food', 'diplo'], mode: 'min' },
|
||||
{ attr: ['food', 'diplo'], mode: 'min' }
|
||||
])
|
||||
|
||||
const after = await getMyGauges(p1)
|
||||
expect(after.food).toBeGreaterThanOrEqual(before.food + 1)
|
||||
expect(after.diplo).toBeGreaterThanOrEqual(before.diplo + 1)
|
||||
|
||||
await ctx1.close()
|
||||
await ctx2.close()
|
||||
})
|
||||
|
||||
test('les résultats des cartes Événement jouées apparaissent dans le résumé du tour', async ({ browser }) => {
|
||||
test.setTimeout(90_000)
|
||||
|
||||
const ctx1 = await browser.newContext()
|
||||
const ctx2 = await browser.newContext()
|
||||
const p1 = await ctx1.newPage()
|
||||
const p2 = await ctx2.newPage()
|
||||
await installPhaserDebugHook(p1)
|
||||
await installPhaserDebugHook(p2)
|
||||
|
||||
const roomId = await createRoom(p1, 'Alice')
|
||||
await joinRoom(p2, 'Bob', roomId)
|
||||
await startGame(p1)
|
||||
await p1.waitForTimeout(2000)
|
||||
|
||||
const drawn = await drawEventUntil(p1, [p2], 'bountiful_harvest')
|
||||
test.skip(!drawn, 'Récolte exceptionnelle non piochée dans la limite de tentatives (probabiliste)')
|
||||
|
||||
await playEventCard(p1, 'bountiful_harvest')
|
||||
|
||||
// Jouer manuellement pour observer le texte affiché juste après résolution,
|
||||
// sans attendre le waitForTimeout complet de playFullTurn.
|
||||
const canvas1 = p1.locator('#phaser-container canvas')
|
||||
const box1 = await canvas1.boundingBox()
|
||||
const cardPos = await p1.evaluate(() => {
|
||||
const game = window.__ALL_GAMES__[window.__ALL_GAMES__.length - 1]
|
||||
const scene = game.scene.getScene('GameScene')
|
||||
const b = scene.handCards[0].getBounds()
|
||||
return { x: b.centerX, y: b.centerY }
|
||||
})
|
||||
await p1.mouse.click(box1.x + cardPos.x, box1.y + cardPos.y)
|
||||
await p1.waitForTimeout(200)
|
||||
const btnPos = await p1.evaluate(() => {
|
||||
const game = window.__ALL_GAMES__[window.__ALL_GAMES__.length - 1]
|
||||
const scene = game.scene.getScene('GameScene')
|
||||
const b = scene.playBtn.getBounds()
|
||||
return { x: b.centerX, y: b.centerY }
|
||||
})
|
||||
await p1.mouse.click(box1.x + btnPos.x, box1.y + btnPos.y)
|
||||
|
||||
await playFullTurn([p2])
|
||||
await p1.waitForTimeout(500)
|
||||
|
||||
const readyText = await p1.evaluate(() => {
|
||||
const game = window.__ALL_GAMES__[window.__ALL_GAMES__.length - 1]
|
||||
return game.scene.getScene('GameScene').readyText.text
|
||||
})
|
||||
expect(readyText).toContain('Récolte exceptionnelle')
|
||||
|
||||
await ctx1.close()
|
||||
await ctx2.close()
|
||||
})
|
||||
})
|
||||
@@ -271,3 +271,109 @@ export async function getShopBuildingIds(page) {
|
||||
return scene.buildingTokens.map(t => t.itemData.id)
|
||||
})
|
||||
}
|
||||
|
||||
// ── Cartes Événement ─────────────────────────────────────────────────────────
|
||||
|
||||
/** Lit ma main d'événements actuelle (ids, max 2) depuis le store Pinia exposé par la scène. */
|
||||
export async function getMyEventHand(page) {
|
||||
return page.evaluate(() => {
|
||||
const game = window.__ALL_GAMES__[window.__ALL_GAMES__.length - 1]
|
||||
const scene = game.scene.getScene('GameScene')
|
||||
return scene.store.myEventHand ?? []
|
||||
})
|
||||
}
|
||||
|
||||
/** Clique sur le bouton de pioche d'événement (si actuellement cliquable). */
|
||||
export async function clickEventDrawButton(page) {
|
||||
const canvas = page.locator('#phaser-container canvas')
|
||||
const box = await canvas.boundingBox()
|
||||
const btnInfo = await page.evaluate(() => {
|
||||
const game = window.__ALL_GAMES__[window.__ALL_GAMES__.length - 1]
|
||||
const scene = game.scene.getScene('GameScene')
|
||||
const btn = scene.eventDrawBtn
|
||||
if (!btn || !btn.input || !btn.input.enabled) return null
|
||||
const b = btn.getBounds()
|
||||
return { x: b.centerX, y: b.centerY }
|
||||
})
|
||||
if (!btnInfo) return false
|
||||
await page.mouse.click(box.x + btnInfo.x, box.y + btnInfo.y)
|
||||
await page.waitForTimeout(400)
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Pioche des cartes événement jusqu'à obtenir l'id demandé (ou jusqu'à
|
||||
* atteindre maxDraws tentatives). Le deck partagé est mélangé aléatoirement
|
||||
* (18 cartes, 3 exemplaires de chacun des 6 événements) donc aucune pioche
|
||||
* spécifique n'est garantie à coup sûr — mais avec un nombre de tentatives
|
||||
* suffisant sur un deck de cette taille, la probabilité de ne jamais tomber
|
||||
* sur l'événement recherché reste négligeable en pratique de test.
|
||||
*
|
||||
* IMPORTANT : cette fonction gère l'espacement en tours nécessaire pour
|
||||
* reconstituer les jauges entre deux pioches (coût de 1 point dans chacune
|
||||
* des 4 jauges) — l'appelant doit fournir `otherPages` pour que playFullTurn
|
||||
* puisse faire progresser les tours pendant l'accumulation.
|
||||
*/
|
||||
export async function drawEventUntil(page, otherPages, eventId, maxDraws = 12) {
|
||||
for (let attempt = 0; attempt < maxDraws; attempt++) {
|
||||
const hand = await getMyEventHand(page)
|
||||
if (hand.includes(eventId)) return true
|
||||
if (hand.length >= 2) return false // main pleine sans l'event recherché : abandon
|
||||
|
||||
const gauges = await getMyGauges(page)
|
||||
const affordable = ['food', 'war', 'health', 'diplo'].every(a => (gauges[a] ?? 0) >= 1)
|
||||
|
||||
if (affordable) {
|
||||
const drew = await clickEventDrawButton(page)
|
||||
if (drew) continue // retente immédiatement la vérification de main sans jouer de tour
|
||||
}
|
||||
|
||||
// Jauges insuffisantes : jouer un tour complet (toutes les cartes au
|
||||
// hasard, peu importe l'attribut) pour accumuler au moins 1 point sur
|
||||
// chaque jauge avant de retenter.
|
||||
await playFullTurn([page, ...otherPages])
|
||||
}
|
||||
return (await getMyEventHand(page)).includes(eventId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sélectionne (clique) une carte de ma main d'événements pour la jouer ce
|
||||
* tour. Si l'événement nécessite un ciblage, fournir `targetTeamIndexes`
|
||||
* (tableau, dans l'ordre attendu par GameScene._startTargeting : pour
|
||||
* royal_accord [gainTargetTeamIndex, loseTargetTeamIndex], pour epidemic
|
||||
* [targetTeamIndex]) — les clics correspondants sur les slots adversaires
|
||||
* sont effectués automatiquement.
|
||||
*/
|
||||
export async function playEventCard(page, eventId, targetTeamIndexes = []) {
|
||||
const canvas = page.locator('#phaser-container canvas')
|
||||
const box = await canvas.boundingBox()
|
||||
|
||||
const cardPos = await page.evaluate((eventId) => {
|
||||
const game = window.__ALL_GAMES__[window.__ALL_GAMES__.length - 1]
|
||||
const scene = game.scene.getScene('GameScene')
|
||||
const card = scene.eventCards.find(c => c.eventData.id === eventId)
|
||||
if (!card) return null
|
||||
const b = card.getBounds()
|
||||
return { x: b.centerX, y: b.centerY }
|
||||
}, eventId)
|
||||
if (!cardPos) return false
|
||||
|
||||
await page.mouse.click(box.x + cardPos.x, box.y + cardPos.y)
|
||||
await page.waitForTimeout(250)
|
||||
|
||||
for (const teamIndex of targetTeamIndexes) {
|
||||
const slotPos = await page.evaluate((teamIndex) => {
|
||||
const game = window.__ALL_GAMES__[window.__ALL_GAMES__.length - 1]
|
||||
const scene = game.scene.getScene('GameScene')
|
||||
const idx = scene.store.players.findIndex(p => p.teamIndex === teamIndex)
|
||||
if (idx === -1) return null
|
||||
const slot = scene.playSlots[idx]
|
||||
return slot ? { x: slot.x, y: slot.y } : null
|
||||
}, teamIndex)
|
||||
if (!slotPos) continue
|
||||
await page.mouse.click(box.x + slotPos.x, box.y + slotPos.y)
|
||||
await page.waitForTimeout(250)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in new issue
Block a user