Commits

Alexander Schremmer committed 646ab50 Merge

Merge Timos heads.

  • Participants
  • Parent commits 310e83a, 1f05ac0

Comments (0)

Files changed (5)

File domination/cards/alchemy.py

         player.remaining_deals += 1
         player.virtual_money += 1
         def handle_discard_action(p):
-            treasure_cards = [c for c in player.hand if isinstance(c, TreasureCard)]
-            treasure_card_classes = [type(c) for c in treasure_cards]
-            if treasure_card_classes:
-                card_cls = (yield SelectCard(game, player,
-                    _("Which treasure do you want to put on top of your deck?"),
-                    card_classes=treasure_card_classes))
-                card = [c for c in treasure_cards if isinstance(c, card_cls)][0]
+            cards = yield SelectHandCards(game, player, cls=TreasureCard,
+                    count_lower=0, count_upper=1,
+                    msg=_("Which treasure do you want to put on top of your deck?"))
+            if cards:
+                card = cards[0]
                 player.deck.append(card)
                 player.hand.remove(card)
         player.register_turn_cleanup(handle_discard_action)

File domination/cards/cornucopia.py

      AttackCard, ReactionCard, PrizeCard, CardSet, Cornucopia
 from domination.cards.base import Curse
 from domination.gameengine import InfoRequest, SelectCard, SelectHandCards, \
-     Question, YesNoQuestion, Defended, SelectActionCard
+     MultipleChoice, Question, YesNoQuestion, Defended, SelectActionCard
 from domination.tools import _
 from domination.macros.__macros__ import handle_defense, generator_forward
 
 
     def activate_action(self, game, player):
         to_be_discarded = []
-        found = None
+        found = []
         player.draw_cards(1)
         player.remaining_actions += 1
         if player.hand:
                 if type(card) in card_classes:
                     to_be_discarded.append(card)
                 else:
-                    found = card
+                    found.append(card)
                     break
-            for info_player in game.participants:
-                yield InfoRequest(game, info_player, _("%s reveals:", (player.name, )), to_be_discarded + [found])
+            if to_be_discarded + found:
+                for info_player in game.participants:
+                    yield InfoRequest(game, info_player, _("%s reveals:", (player.name, )), to_be_discarded + found)
             player.discard_pile.extend(to_be_discarded)
-            player.hand.append(found)
+        player.hand.extend(found)
 
 
 class Jester(AttackCard):
                 for info_player in game.following_participants(player):
                     yield InfoRequest(game, info_player,
                             _("%(player)s chooses '%(action)s'", {"player": player.name, "action": _(dict(actions)[answer])}), [])
-                new_card = game.supply[card.__name__].pop()
-                if answer == "give":
-                    other_player.discard_pile.append(new_card)
-                    yield InfoRequest(game, info_player,
-                            _("%s gains:", (other_player.name, )), [new_card])
-                if answer == "take":
-                    player.discard_pile.append(new_card)
-                    yield InfoRequest(game, info_player,
-                            _("%s gains:", (player.name, )), [new_card])
-                for val in game.check_empty_pile(card.__name__):
-                    yield val
+                if game.supply[card.__name__]:
+                    new_card = game.supply[card.__name__].pop()
+                    if answer == "give":
+                        other_player.discard_pile.append(new_card)
+                        yield InfoRequest(game, info_player,
+                                _("%s gains:", (other_player.name, )), [new_card])
+                    if answer == "take":
+                        player.discard_pile.append(new_card)
+                        yield InfoRequest(game, info_player,
+                                _("%s gains:", (player.name, )), [new_card])
+                    for val in game.check_empty_pile(card.__name__):
+                        yield val
 
 class Menagerie(ActionCard):
     name = _("Menagerie")

File domination/cards/intrigue.py

         for info_player in game.following_participants(player):
             yield InfoRequest(game, info_player,
                     _("%s trashes these cards:", (player.name, )), cards)
-        new_card = game.supply["Silver"].pop()
-        player.hand.append(new_card)
-        for info_player in game.following_participants(player):
-            yield InfoRequest(game, info_player,
-                    _("%s gains:", (player.name, )), [new_card])
-        for val in game.check_empty_pile("Silver"):
-            yield val
+        if game.supply["Silver"]:
+            new_card = game.supply["Silver"].pop()
+            player.hand.append(new_card)
+            for info_player in game.following_participants(player):
+                yield InfoRequest(game, info_player,
+                        _("%s gains:", (player.name, )), [new_card])
+            for val in game.check_empty_pile("Silver"):
+                yield val
 
 class Tribute(ActionCard):
     name = _("Tribute")

File domination/cards/prosperity.py

             for info_player in game.participants:
                 yield InfoRequest(game, info_player, _("%s discards:",
                         (other_player.name, )), to_be_discarded)
-            player.discard_pile.extend(to_be_discarded)
+            other_player.discard_pile.extend(to_be_discarded)
 
 class Vault(ActionCard):
     name = _("Vault")
             for info_player in game.participants:
                 yield InfoRequest(game, info_player, _("%s reveals:",
                         (player.name, )), [card])
-            new_card = game.supply[card.__name__].pop()
-            player.discard_pile.append(new_card)
-            for info_player in game.following_participants(player):
-                yield InfoRequest(game, info_player,
-                        _("%s gains:", (player.name, )), [new_card])
-            for val in game.check_empty_pile(card_cls.__name__):
-                yield val
+            if game.supply[card.__name__]:
+                new_card = game.supply[card.__name__].pop()
+                player.discard_pile.append(new_card)
+                for info_player in game.following_participants(player):
+                    yield InfoRequest(game, info_player,
+                            _("%s gains:", (player.name, )), [new_card])
+                for val in game.check_empty_pile(card.__name__):
+                    yield val
 
 class Mountebank(AttackCard):
     name = _("Mountebank")
         player.remaining_deals += 1
         player.draw_cards(1)
 
-class Goons(ActionCard):
+class Goons(AttackCard):
     name = _("Goons")
     edition = Prosperity
     cost = 6
     desc = _("Trash any number of cards from your hand. Gain a card with cost exactly equal to the the total cost in coins of the trashed cards.")
 
     def activate_action(self, game, player):
+        new_cards = []
         Forge_money = 0
         if player.hand:
             cards = yield SelectHandCards(game, player,
             and c.potioncost == 0],
             msg=_("Select a card that you want to have."), show_supply_count=True)
         if card_cls is not None:
-            new_card = game.supply[card_cls.__name__].pop()
-            player.discard_pile.append(new_card)
-            new_cards = [new_card]
-        else:
-            new_cards = []
+            if game.supply[card_cls.__name__]:
+                new_card = game.supply[card_cls.__name__].pop()
+                player.discard_pile.append(new_card)
+                new_cards = [new_card]
 
         for info_player in game.following_participants(player):
             yield InfoRequest(game, info_player,

File domination/cards/seaside.py

         player.virtual_money += 2
         player.draw_cards(5)
         drawn, player.hand = player.hand[-5:], player.hand[:-5]
-        yield InfoRequest(game, info_player, _("You draw:",), drawn)
-        yield InfoRequest(game, player, _("You draw:",), cards)
+        for info_player in game.following_participants(player):
+            yield InfoRequest(game, info_player, _("%s draws:", (player.name, )), drawn)
+        yield InfoRequest(game, player, _("You draw:",), drawn)
         actions = [("discard",    _("discard all 5 cards")),
                    ("backondeck", _("put the cards back in your specified order"))]
 
             player.seaside_haven_set_aside_cards = []
         player.remaining_actions += 1
         player.draw_cards(1)
-        cards = yield SelectHandCards(game, player, count_lower=1, count_upper=1,
-                msg=_("Which card do you want to set aside?"))
-        if cards:
-            card = cards[0]
-            player.hand.remove(card)
-            player.seaside_haven_set_aside_cards.append(card)
+        if player.hand:
+            cards = yield SelectHandCards(game, player, count_lower=1, count_upper=1,
+                    msg=_("Which card do you want to set aside?"))
+            if cards:
+                card = cards[0]
+                player.hand.remove(card)
+                player.seaside_haven_set_aside_cards.append(card)
 
     @classmethod
     def on_start_of_turn(cls, game, player):
     @classmethod
     def on_end_of_game(cls, game):
         for player in game.players:
-            player.hand.extend(getattr(player, "seaside_haven_set_aside_cards", []))
-            player.seaside_haven_set_aside_cards = []
+            if getattr(player, "seaside_haven_set_aside_cards", None):
+                player.hand.extend(player.seaside_haven_set_aside_cards)
+                player.seaside_haven_set_aside_cards = []
 
 
 class Explorer(ActionCard):
     def activate_action(self, game, player):
         province_cards = [c for c in player.hand if isinstance(c, Province)]
         if province_cards:
-            new_card = game.supply["Gold"].pop()
-            player.hand.append(new_card)
-            for info_player in game.following_participants(player):
-                yield InfoRequest(game, info_player,
-                        _("%s gains:", (player.name, )), [new_card])
-            for val in game.check_empty_pile("Gold"):
-                yield val
+            if game.supply["Gold"]:
+                new_card = game.supply["Gold"].pop()
+                player.hand.append(new_card)
+                for info_player in game.following_participants(player):
+                    yield InfoRequest(game, info_player,
+                            _("%s gains:", (player.name, )), [new_card])
+                for val in game.check_empty_pile("Gold"):
+                    yield val
         else:
-            new_card = game.supply["Silver"].pop()
-            player.hand.append(new_card)
-            for info_player in game.following_participants(player):
-                yield InfoRequest(game, info_player,
-                        _("%s gains:", (player.name, )), [new_card])
-            for val in game.check_empty_pile("Silver"):
-                yield val
+            if game.supply["Silver"]:
+                new_card = game.supply["Silver"].pop()
+                player.hand.append(new_card)
+                for info_player in game.following_participants(player):
+                    yield InfoRequest(game, info_player,
+                            _("%s gains:", (player.name, )), [new_card])
+                for val in game.check_empty_pile("Silver"):
+                    yield val
 
 
 class FishingVillage(ActionCard, DurationCard):
 class Island(ActionCard, VictoryCard):
     name = _("Island")
     edition = Seaside
-    implemented = False #FIXME not implemented completely
     cost = 4
     points = 2
     desc = _("Set aside this and another card from your hand. Return them to"
              " your deck at the end of the game.")
 
     def activate_action(self, game, player):
-        island_cards = [c for c in player.hand if isinstance(c, Island)]
+        if not hasattr(player, "seaside_island_set_aside_cards"):
+            player.seaside_island_set_aside_cards = []
+        island_cards = [c for c in player.aux_cards if isinstance(c, Island)]
         player.seaside_island_set_aside_cards.append(island_cards[0])
+        player.aux_cards.remove(island_cards[0])
         if player.hand:
             cards = yield SelectHandCards(game, player, count_lower=1, count_upper=1,
-                    msg=_("Which card do you want to put on the island?"))
-            if cards is not None:
+                    msg=_("Which card do you want to set aside?"))
+            if cards:
                 card = cards[0]
                 player.hand.remove(card)
                 player.seaside_island_set_aside_cards.append(card)
 
+    @classmethod
+    def on_end_of_game(cls, game):
+        for player in game.players:
+            if getattr(player, "seaside_nativevillage_set_aside_cards", None):
+                player.hand.extend(getattr(player, "seaside_island_set_aside_cards", []))
+                player.seaside_island_set_aside_cards = []
+
 
 class Ambassador(AttackCard):
     name = _("Ambassador")
 class NativeVillage(ActionCard):
     name = _("Native Village")
     edition = Seaside
-    implemented = False #FIXME not implemented completely
     cost = 2
     desc = _("+2 Actions. Choose one: Set aside the top card of your deck face down on your Native Village mat; or put all cards from your mat into your hand. You may look at the cards on your mat at any time; return them to your deck at the end of the game.")
 
     def activate_action(self, game, player):
+        if not hasattr(player, "seaside_nativevillage_set_aside_cards"):
+            player.seaside_nativevillage_set_aside_cards = []
         player.remaining_actions += 2
         actions = [("setaside", _("Set aside a card on the Native Village")),
                    ("return", _("Put all cards from the Native Village into your hand."))]
                     _("%(player)s chooses '%(action)s'", {"player": player.name, "action": _(dict(actions)[answer])}), [])
 
         if answer == "setaside":
-            if player.hand:
-                cards = yield SelectHandCards(game, player, count_lower=1, count_upper=1,
-                        msg=_("Which card do you want to put on the Native Village?"))
-                if cards is not None:
-                    card = cards[0]
-                    player.hand.remove(card)
-                    player.seaside_nativevillage_set_aside_cards.append(card)
+            player.draw_cards(1)
+            drawn, player.hand = player.hand[-1:], player.hand[:-1]
+            player.seaside_nativevillage_set_aside_cards.extend(drawn)
         elif answer == "return":
-            player.hand.extend(player.seaside_nativevillage_set_aside_cards)
-            player.seaside_nativevillage_set_aside_cards = []
+            if getattr(player, "seaside_nativevillage_set_aside_cards", None):
+                player.hand.extend(player.seaside_nativevillage_set_aside_cards)
+                player.seaside_nativevillage_set_aside_cards = []
+
+    @classmethod
+    def on_end_of_game(cls, game):
+        for player in game.players:
+            if getattr(player, "seaside_nativevillage_set_aside_cards", None):
+                player.hand.extend(player.seaside_nativevillage_set_aside_cards)
+                player.seaside_nativevillage_set_aside_cards = []
+
 
 class Wharf(ActionCard, DurationCard):
     name = _("Wharf")
                             _("%s trashes:", (player.name, )), [card])
             new_cards = []
             for i in range(0, 4):
-                new_cards.append(game.supply["Gold"].pop())
-                for val in game.check_empty_pile("Gold"):
-                    yield val
+                if game.supply["Gold"]:
+                    new_cards.append(game.supply["Gold"].pop())
+                    for val in game.check_empty_pile("Gold"):
+                        yield val
             player.deck.extend(new_cards)
             for info_player in game.participants:
                 yield InfoRequest(game, info_player,