Exemple #1
0
 def perform(self):
     """ Perform the command """
     card = self.cardFinder.card
     zone = self.cardFinder.zone
     context = PlayerContext(self.owner.game, card)
     
     self.owner.spendPower(card.calculateCost())
     coroutine = self.owner.gainCard(card, zone, toZone=context.loadZone(DISCARD_PILE))
     response = yield coroutine.next()
     while True:
         response = yield coroutine.send(response)
Exemple #2
0
    def perform(self):
        """ Perform the command """
        card = self.cardFinder.card
        zone = self.cardFinder.zone
        context = PlayerContext(self.owner.game, card)

        self.owner.spendPower(card.calculateCost())
        coroutine = self.owner.gainCard(card,
                                        zone,
                                        toZone=context.loadZone(DISCARD_PILE))
        response = yield coroutine.next()
        while True:
            response = yield coroutine.send(response)
Exemple #3
0
 def play(self, game, effectTypesToIgnore=[]):
     """ Play the card and perform any effects """
     context = PlayerContext(game, self)
     coroutine = PerformEffects(self.playEffects,
                                context,
                                effectTypesToIgnore=effectTypesToIgnore)
     response = yield coroutine.next()
     while True:
         response = yield coroutine.send(response)
Exemple #4
0
    def cleanup(self):
        """ Cleanup the turn """
        context = PlayerContext(self.game, None)
        for effect in self.cleanupEffects:
            effect.perform(context)

        self.player.deck.discardAll(self.playedCards)
        self.player.deck.discardAll(self.player.hand)
        self.player.drawHand()
Exemple #5
0
 def gainCard(self, card, fromZone, toZone=None, game=None):
     """ Gain the provided card """
     fromZone.remove(card)
     toZone.add(card)
     event = CardsEvent([card], toZone,
                        PlayerContext(game, card, player=self))
     coroutine = PerformEffects(card.onGainEffects, event.context)
     response = yield coroutine.next()
     while True:
         response = yield coroutine.send(response)
Exemple #6
0
    def playCard(self, card, effectTypesToIgnore=[]):
        """ Play card """
        coroutine = card.play(self.game,
                              effectTypesToIgnore=effectTypesToIgnore)
        try:
            response = yield coroutine.next()
            while True:
                response = yield coroutine.send(response)
        except StopIteration:
            pass

        coroutine = self.ongoingEffects.send(
            PlayedCardEvent(card, PlayerContext(self.game, card)))
        try:
            response = yield coroutine.next()
            while True:
                response = yield coroutine.send(response)
        except StopIteration:
            pass
        self.playedCards.append(card)
Exemple #7
0
    def toJSON(self, game):
        """ Return the Player as a JSON Dictionary """
        context = PlayerContext(game, None, player=self.player)

        cards = {}
        cardsByType = {
            str(cardType): list(cardsForType)
            for cardType, cardsForType in groupby(
                sorted(self.player.deck, key=lambda card: card.cardType),
                key=lambda card: card.cardType)
        }

        cardTypes = []
        for cardType in sorted(cardsByType.keys()):
            cardTypes.append(cardType)
            cardsForType = cardsByType[cardType]

            cardsSortedByCost = sorted(
                cardsForType, key=lambda card: card.calculatePoints(context))
            cards[cardType] = {
                str(points): GetCardListJSON(cardsForPoints, game)
                for points, cardsForPoints in groupby(
                    cardsSortedByCost,
                    key=lambda card: card.calculatePoints(context))
            }
            cards[cardType]['total'] = sum([
                int(points) * len(cardsForPoints)
                for points, cardsForPoints in cards[cardType].items()
            ])
            cards[cardType]['pointValues'] = sorted([
                points for points in cards[cardType].keys()
                if points != 'total'
            ])

        cards['cardTypes'] = cardTypes
        return {
            'points': self.playerResults.points,
            'name': self.player.name,
            'isYou': self.isYou,
            'cards': cards
        }
Exemple #8
0
    def gainCard(self, card, fromZone, toZone=None):
        """ Gain the provided card """
        coroutine = self.player.gainCard(card,
                                         fromZone,
                                         toZone=toZone,
                                         game=self.game)
        try:
            response = yield coroutine.next()
            while True:
                response = yield coroutine.send(response)
        except StopIteration:
            pass

        coroutine = self.ongoingEffects.send(
            GainedCardEvent(card, PlayerContext(self.game, card)))
        try:
            response = yield coroutine.next()
            while True:
                response = yield coroutine.send(response)
        except StopIteration:
            pass

        self.gainedCards.append(card)
Exemple #9
0
 def canActivate(self, game):
     """ Return if the Activatable can activate """
     context = PlayerContext(game, None)
     return self.condition is None or self.condition.evaluate(context)
 def __init__(self, game):
     """ Initialize the Start of Turn Event """
     self.context = PlayerContext(game, None, event=self)
Exemple #11
0
 def calculatePoints(self, game):
     """ Calculate the Player's Victory Points """
     context = PlayerContext(game, None, player=self)
     return sum([card.calculatePoints(context) for card in self.deck])
Exemple #12
0
 def isOver(self):
     """ Return if the game is over """
     return self.condition.evaluate(PlayerContext(self.game, None))
Exemple #13
0
def BuildPlayerContext(mainDeck=[], **kwargs):
    """ Build a Card for testing purposes """
    return PlayerContext(BuildGame(mainDeck=mainDeck), None, **kwargs)