Commits

Alexander Schremmer  committed 5192c25

Many small changes:
* Fix (un)pickling.
* Implement Princess.
* Fix Tournament (handle Duchy correctly, fix info msg).
* Fix typo in Develop desc.
* Add info msg to SpiceMerchant.
* Fix Quarry.
* Fix Venture.
* Handle empty hands in Forge.
* Introduce player_option_defaults.
* Fix cancling the "Which money cards do you want to play?" question.
* Fix potion playing.

  • Participants
  • Parent commits a0ee5d6

Comments (0)

Files changed (7)

File domination/cards/__init__.py

     def on_setup_card(cls, game):
         if [c for c in game.selected_cards if c.wants_money_selection]:
             game.player_options["automatic_money_selection"] = _("Play all available treasure cards")
+        game.player_option_defaults["automatic_money_selection"] = True
 
 
 class ActionCard(Card):

File domination/cards/cornucopia.py

 from domination.gameengine import InfoRequest, SelectCard, SelectHandCards, \
      MultipleChoice, Question, YesNoQuestion, Defended, SelectActionCard
 from domination.tools import _
-from domination.macros.__macros__ import handle_defense, generator_forward
+from domination.macros.__macros__ import handle_defense, generator_forward, fetch_card_from_supply
 
 
 class BagOfGold(PrizeCard, ActionCard):
 class Princess(PrizeCard, ActionCard):
     name = _("Princess")
     edition = Cornucopia
-    implemented = False #FIXME not implemented completely
     cost = 0
     desc = _("+1 Buy | While this is in play, Cards cost 2 Money less, but not less than 0 Money.")
 
     def activate_action(self, game, player):
         player.remaining_deals += 1
+        decreased_for_cards = []
+        for card in game.card_classes.itervalues():
+            if card.cost >= 2:
+                card.cost -= 2
+                decreased_for_cards.append(card)
+        def restore_cards(player):
+            for card in decreased_for_cards:
+                card.cost += 2
+        player.register_turn_cleanup(restore_cards)
 
 class Remake(ActionCard):
     name = _("Remake")
                         card.discard(player)
                         card_cls = (yield SelectCard(game, player, _("Which prize card do you want to gain?"),
                             [type(c) for c in game.tournament_cards] + [Duchy]))
-                        card = [c for c in game.tournament_cards if isinstance(c, card_cls)][0]
+                        if card_cls is Duchy:
+                            with fetch_card_from_supply(game, card_cls) as new_card:
+                                card = new_card
+                        else:
+                            card = [c for c in game.tournament_cards if isinstance(c, card_cls)][0]
+                            game.tournament_cards.remove(card)
                         player.deck.append(card)
-                        game.tournament_cards.remove(card)
                     else:
                         others_revealed = True
                     for info_player in game.following_participants(other_player):
-                        yield InfoRequest(game, info_player, _("%s gains a card:", (other_player.name, )), [card])
+                        yield InfoRequest(game, info_player, _("%s reveals a card:", (other_player.name, )), [card])
         if not others_revealed:
             player.virtual_money += 1
             player.draw_cards(1)

File domination/cards/hinterlands.py

     name = _("Develop")
     edition = Hinterlands
     cost = 3
-    desc = _("Trash a Crad from your hand. "
+    desc = _("Trash a card from your hand. "
             "Gain a card costing exactly 1 Money more than it "
             "and a card costing exactly 1 Money less than it, "
             "in either order, putting them on top of your deck.")
 class NobleBrigand(AttackCard):
     name = _("Noble Brigand")
     edition = Hinterlands
+    implemented = False # XXX doesnt work at all
     cost = 4
     desc = _("+1 Money. When you buy this or play it, each other player reveals the top 2 cards of his deck,"
             "trashes a revealed Silver or Gold you choose, and discards the rest. "
         if cards:
             card = cards[0]
             card.trash(game, player)
+            for info_player in game.following_participants(player):
+                yield InfoRequest(game, info_player,
+                        _("%s trashes:", (player.name, )), [card])
             actions = [("cards_action",   _("+2 Cards +1 Action")),
                        ("moneys_buy", _("+2 Money +1 Buy"))]
 

File domination/cards/prosperity.py

                             _("%s trashes:", (player.name, )), [card])
         for other_player in game.following_players(player):
             cards = yield SelectHandCards(game, other_player, count_lower=0, count_upper=1,
-                    msg=_("%s played Bishop. You may trash a card:?", (player.name, )))
+                    msg=_("%s played Bishop. You may trash a card:", (player.name, )))
             if cards:
                 for card in cards:
                     card.trash(game, other_player)
     def activate_action(self, game, player):
         decreased_for_cards = []
         action_card_classes  = [cls for cls in game.card_classes.itervalues()
-                    if isinstance(cls, ActionCard)]
+                    if issubclass(cls, ActionCard)]
         for card in action_card_classes:
             if card.cost >= 1:
                 card.cost -= 1
     desc = _("When you play this, you reveal cards from your deck until you reveal a Treasure. Discard the other cards. Play that Treasure.")
 
     def activate_action(self, game, player):
-        found_treasure = []
+        found_treasure = None
         to_be_discarded = []
         while True:
             ret = player.draw_cards(1)
             for info_player in game.participants:
                 yield InfoRequest(game, info_player, _("%s reveals:", (player.name, )), [card])
             if isinstance(card, TreasureCard):
-                found_treasure.append(card)
+                found_treasure = card
                 break
             else:
                 to_be_discarded.append(card)
         player.discard_pile.extend(to_be_discarded)
-        found_treasure.activate_action(game, player)
+        if found_treasure is not None:
+            player.aux_cards.append(found_treasure)
+            gen = game.play_action_card(player, found_treasure)
+            generator_forward(gen)
+            player.activated_treasure_cards.append(found_treasure)
 
 class Rabble(AttackCard):
     name = _("Rabble")
         if player.hand:
             cards = yield SelectHandCards(game, player,
                     msg=_("Which cards do you want to trash?"))
+        else:
+            return
         # trash cards
         if cards:
             for card in cards:

File domination/gameengine.py

         self._hooks = {}
         self.prepare_hooks(selected_cards)
         self.player_options = {}
+        self.player_option_defaults = {}
 
     def __hash__(self):
         return hash(self.name)
 
     @property
     def hooks(self):
-        if not self._hooks:
+        if not hasattr(self, "_hooks"):
+            self._hooks = {}
             self.prepare_hooks(self.selected_cards)
         return self._hooks
 
                     if not player.options["automatic_money_selection"]:
                         cards = (yield SelectHandCards(self, player, _("Which money cards do you want to play?"), TreasureCard,
                             preselect_all=True))
+                        if cards is None:
+                            cards = []
                     else:
                         cards = [c for c in player.hand if isinstance(c, TreasureCard)]
                     player.aux_cards.extend(cards)
                     for card in cards:
                         player.hand.remove(card)
+                    player.activated_treasure_cards = cards
                     for card in cards:
                         gen = self.play_action_card(player, card)
                         generator_forward(gen)
-                    player.activated_treasure_cards = cards
 
                     # deal
                     break_selection = False
 
 class Player(object):
     is_ai = False
-    def __init__(self, name):
+    def __init__(self, name, game):
         self.name = name
         self.discard_pile = []
         self.deck = []
         self.turn_cleanups = []
         self.duration_cards = [] # duration_cards from seaside
         self.options = defaultdict(make_false)
+        for optionkey, optionvalue in game.player_option_defaults.items():
+            self.options[optionkey] = optionvalue
         self.activated_treasure_cards = None
 
         self.request_queue = []
 
     @property
     def remaining_potion(self):
-        return sum(card.potion for card in self.hand)\
+        return sum(card.potion for card in self.aux_cards)\
                 - self.used_potion
 
     @property

File domination/main.py

         for game, player in games.items():
             # XXX race condition possible
             if player.current:
-                game.kick(Player("Logout Button"), player)
+                game.kick(Player("Logout Button", game), player)
             else:
                 game.players.remove(player)
     return redirect(url_for("index"))
             return render_error(_("Please enter a name!"))
         game = DominationGame(name,
                 CardTypeRegistry.keys2classes(request.form.getlist('card_key')))
-        player = Player(session["username"])
+        player = Player(session["username"], game)
         game.players.append(player)
         app.games[name] = GameRunner(game, player)
         get_store()["games"][game] = player
             except ValueError:
                 n = 1
             for i in range(n):
-                player = AIPlayer(names[i] + " [AI]")
+                player = AIPlayer(names[i] + " [AI]", game)
                 game.players.append(player)
         return redirect(url_for('game', name=name))
     def transform_sets(sets):
     assert not game_runner in get_store()["games"]
     if not game_runner.joinable:
         return render_error(_("Game has begun or ended already."))
-    get_store()["games"][game_runner.game] = player = Player(session["username"])
+    get_store()["games"][game_runner.game] = player = Player(session["username"], game_runner.game)
     game = game_runner.game
     assert player not in game.players
     game.players.append(player)

File domination/tools.py

 class Translatable(unicode):
     def __new__(cls, string, parameters=()):
         inst = super(Translatable, cls).__new__(cls, string)
+        inst.pristine_str = string
         inst.parameters = parameters
         return inst
 
         return t.ugettext(self[:]) % self.parameters
 
     def __newargs__(self):
-        return (unicode.__unicode__(self), self.parameters)
+        return (self.pristine_str, self.parameters)
 
 
 def _(string, parameters=()):