Commits

Dominic Kexel committed 1f6a7d1

see #15 added Masquerade

Comments (0)

Files changed (2)

cards/intrigue/masquerade.py

+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from cards.card import Card
+from cards.cardtypes import ACTION
+from game.gamestates import SP_ASKPLAYER, SP_WAIT, SP_PICKCARDSFROMHAND
+from game.askplayerinfo import AskPlayerInfo
+from cards.cornucopia.bagofgold import BagOfGold
+from cards.cornucopia.diadem import Diadem
+from cards.cornucopia.followers import Followers
+from cards.cornucopia.princess import Princess
+from cards.cornucopia.trustysteed import TrustySteed
+from game.subphaseinfo import SubPhaseInfo
+from framework.latecall import LateCall
+
+
+class Masquerade(Card):
+
+    type = ACTION
+    cost = (3, 0)
+    name = "Masquerade"
+
+    def __init__(self):
+        Card.__init__(self)
+        self.pending = 0
+        self.choosed = {}
+        
+    def action_step(self, game, player):
+        self.pending = 0
+        self.choosed = {}
+        
+        for _ in xrange(2):
+            game.draw_card(player)
+        
+        p = game.all_player_action(self, 
+                               self.handler,
+                               SP_PICKCARDSFROMHAND,
+                               "Choose a card to pass to the left")
+        
+        self.pending = len(p)
+                            
+    def handler(self, game, player, result):
+        if len(player.hand) > 0 and len(result) != 1:
+            game.whisper(player, "You have to choose one card")
+            return False
+        
+        if len(player.hand) > 0:
+            self.choosed[player.id] = result[0] if result else None
+                
+        self.pending -= 1
+
+        if player is game.active_player:
+            if self.pending:
+                return LateCall(lambda p=player, g=game: self.masq_handler(g, p))
+            else:
+                self.masq_handler(game, player)
+        
+        return True
+                
+    def masq_handler(self, game, player):
+        if len(self.choosed) > 1:
+            for pid in self.choosed:
+                player = game.get_player_by_id(pid)
+                next_player = game.next_player(player)
+                card = player.hand.get_card(self.choosed[pid])
+                player.hand.remove(card)
+                player.deck.remove(card)
+                next_player.hand.add(card)
+                next_player.deck.add(card)
+        
+        game.update_player()
+        
+        game.enter_subphase(SubPhaseInfo(SP_PICKCARDSFROMHAND, card=self,
+                            callback=self.trash_handler, info=
+                            "Pick up to one card to trash"))
+        
+    def trash_handler(self, game, player, result):
+        if len(result) > 1:
+            game.whisper(player, "You have to choose one or zero cards")
+            return False
+        
+        trash = [card for card in player.hand if card.id in result]
+        [game.trash_card(player, card) for card in trash]
+        game.resolved(self)
+        return True
+            
+                
+   
+                
+                
 
         return list(chain(self.commonpiles, self.kingdompiles))
 
-    def update_player(self, player):
+    def update_player(self, player=None):
         """Sending player info around"""
 
-        if player == self.active_player:
-            (self.server_call)[BOARD](player)
-        (self.server_call)[HAND](player)
-        (self.server_call)[PLAYERINFO](self._get_playerinfos())
+        def up(p):
+            if p == self.active_player:
+                (self.server_call)[BOARD](p)
+            (self.server_call)[HAND](p)
+            (self.server_call)[PLAYERINFO](self._get_playerinfos())
+
+        if player:
+            up(player)
+        else:
+            for p in self.players:
+                up(p)
 
     def __prepare_piles(self, list):
         """set up the piles, e.g. 10 each Action-Card, 12 or 8 of each Treasure etc."""
         previous_player = (self.players)[self.players.index(self._active_player) - 1]
         return previous_player if not previous_player is self.active_player else None
 
-    def next_player(self):
+    def next_player(self, current=None):
         """Return the next player after the actual one"""
 
+        if not current:
+            current = self._active_player
+
         try:
-            next_player = (self.players)[self.players.index(self._active_player) + 1]
+            next_player = (self.players)[self.players.index(current) + 1]
         except IndexError:
             next_player = (self.players)[0]
-        return next_player if not next_player is self.active_player else None
+        return next_player if not next_player is current else None
     
     def endphase(self, player):
         """End the current phase"""