import { CorporationCard } from '../corporation/CorporationCard' ; import { Player } from '../../Player' ; import { Tags } from '../Tags' ; import { Card } from '../Card' ; import { CardName } from '../../CardName' ; import { CardType } from '../CardType' ; import { IProjectCard } from '../IProjectCard' ; import { SelectCard } from '../../inputs/SelectCard' ; import { Resources } from '../../Resources' ; import { SelectHowToPayDeferred } from '../../deferredActions/SelectHowToPayDeferred' ; import { DeferredAction } from '../../deferredActions/DeferredAction' ; import { CardRenderer } from '../render/CardRenderer' ; import { Size } from '../render/Size' ; import { MoonExpansion } from '../../moon/MoonExpansion' ; import { all } from '../Options' ; export class Playwrights extends Card implements CorporationCard { constructor ( ) { super ( { name : CardName . PLAYWRIGHTS , tags : [ Tags . ENERGY ] , startingMegaCredits : 38 , cardType : CardType . CORPORATION , metadata : { cardNumber : 'R40' , description : 'You start with 38 M€ and 1 Energy production.' , renderData : CardRenderer . builder ( ( b ) => { b . br . br ; b . megacredits ( 38 ) . production ( ( pb ) => pb . energy ( 1 ) ) ; b . corpBox ( 'action' , ( cb ) => { cb . action ( 'Replay a played event from any player by paying its cost ONLY in M€ (discounts and rebates apply), then REMOVE IT FROM PLAY.' , ( eb ) => { eb . megacredits ( 1000 ) . startAction ; eb . text ( 'replay' , Size . SMALL , true ) ; eb . nbsp . cards ( 1 , { all , secondaryTag : Tags . EVENT } ) ; } ) ; } ) ; } ) , } , } ) ; } private checkLoops : number = 0 ; public play ( player ) { player . addProduction ( Resources . ENERGY , 1 ) ; return undefined ; } public canAct ( player ) { const replayableEvents = this . getReplayableEvents ( player ) ; return replayableEvents . length > 0 ; } public action ( player ) { const players = player . game . getPlayers ( ) ; const replayableEvents = this . getReplayableEvents ( player ) ; return new SelectCard < IProjectCard > ( 'Select event card to replay at cost in M€ and remove from play' , 'Select' , replayableEvents , ( foundCards ) => { const selectedCard = foundCards [ 0 ] ; players . forEach ( ( p ) => { const cardIndex = p . playedCards . findIndex ( ( c ) => c . name === selectedCard . name ) ; if ( cardIndex !== - 1 ) { p . playedCards . splice ( cardIndex , 1 ) ; } } ) ; const cost = player . getCardCost ( selectedCard ) ; player . game . defer ( new SelectHowToPayDeferred ( player , cost , { title : 'Select how to pay to replay the event' , afterPay : ( ) => { player . playCard ( selectedCard , undefined , false ) ; player . removedFromPlayCards . push ( selectedCard ) ; if ( selectedCard . name === CardName . LAW_SUIT ) { player . game . defer ( new DeferredAction ( player , ( ) => { player . game . getPlayers ( ) . some ( ( p ) => { const card = p . playedCards [ p . playedCards . length - 1 ] ; if ( card ?. name === selectedCard . name ) { p . playedCards . pop ( ) ; return true ; } return false ; } ) ; return undefined ; } ) ) ; } } , } ) ) ; return undefined ; } ) ; } public getCheckLoops ( ) { return this . checkLoops ; } private getReplayableEvents ( player ) { const playedEvents = [ ] ; this . checkLoops ++ ; player . game . getPlayers ( ) . forEach ( ( p ) => { playedEvents . push ( ... p . playedCards . filter ( ( card ) => { return card . cardType === CardType . EVENT && player . canAfford ( player . getCardCost ( card ) , { reserveUnits : MoonExpansion . adjustedReserveCosts ( player , card ) , } ) && player . canPlayIgnoringCost ( card ) ; } ) ) ; } ) ; this . checkLoops -- ; return playedEvents ; } }