Esempio n. 1
0
    def limit_callback(self, message, pile, limit, callee):
        message = message.strip().split()
        if message[0].startswith("!"):
            message = message[1:]
        discard = []
        no_find = []
        for s in message:
            if s.isdigit() and int(s) <= len(pile):
                discard.append(pile.cards[int(s)-1])
            elif s in pile:
                discard.append(pile.find_card(s))
            else:
                no_find.append(s)
        if len(pile) - len(discard) < limit:
            self.output("You cannot discard that many cards.")
            callee()

        if len(no_find) > 0:
            no_find = "Could not find card%s: %s" % ("" if len(no_find) == 1 else "s",
                                                     pretty_print_list(no_find))
        else:
            no_find = ""

        self.output("You discarded: %s.%s" % \
                    (pretty_print_list(discard),
                     no_find))
        self.game.discard(discard)
        if len(pile) > limit:
            callee()
            return False
        
        self.output("Okay, you are all set with the limit.")
        return True
Esempio n. 2
0
    def limit_callback(self, message, pile, limit, callee):
        message = message.strip().split()
        if message[0].startswith("!"):
            message = message[1:]
        discard = []
        no_find = []
        for s in message:
            if s.isdigit() and int(s) <= len(pile):
                discard.append(pile.cards[int(s)-1])
            elif s in pile:
                discard.append(pile.find_card(s))
            else:
                no_find.append(s)
        if len(pile) - len(discard) < limit:
            self.output("You cannot discard that many cards.")
            callee()

        if len(no_find) > 0:
            no_find = "Could not find card%s: %s" % ("" if len(no_find) == 1 else "s",
                                                     pretty_print_list(no_find))
        else:
            no_find = ""

        self.output("You discarded: %s.%s" % \
                    (pretty_print_list(discard),
                     no_find))
        self.game.discard(discard)
        if len(pile) > limit:
            callee()
            return False
        
        self.output("Okay, you are all set with the limit.")
        return True
Esempio n. 3
0
 def enforce_hand_limit(self):
     
     def callback(message):
         r = self.game.rule_pile
         t = self.limit_callback(message, self.hand, r.hand_limit, self.enforce_hand_limit)
         self.enforce_keeper_limit()
         return t
     
     h = len(self.hand)
     r = self.game.rule_pile
     if r.hand_limit == 0 and h > 0:
         self.output("Your hand is over the limit of 0. " +
                     "Now discarding all of your cards.")
         self.game.discard(self.hand)
         
     if r.hand_limit > 0 and h > r.hand_limit:
         self.plugin.pubout("%s's hand is over the limit and must discard manually." % self.name)
         self.output("Your hand is over the limit.")
         hand = ["(%d) %s" % (i+1, c) for i, c in enumerate(self.hand)]
         self.output("You have: " + pretty_print_list(hand))
         i = h - r.hand_limit
         self.request_input("Please discard %d card%s." % (i, "" if i == 1 else "s"),
                            (callback, discard_regex % "RKGA"))
         return
     
     self.enforce_keeper_limit()
Esempio n. 4
0
 def enforce_hand_limit(self):
     
     def callback(message):
         r = self.game.rule_pile
         t = self.limit_callback(message, self.hand, r.hand_limit, self.enforce_hand_limit)
         self.enforce_keeper_limit()
         return t
     
     h = len(self.hand)
     r = self.game.rule_pile
     if r.hand_limit == 0 and h > 0:
         self.output("Your hand is over the limit of 0. " +
                     "Now discarding all of your cards.")
         self.game.discard(self.hand)
         
     if r.hand_limit > 0 and h > r.hand_limit:
         self.plugin.pubout("%s's hand is over the limit and must discard manually." % self.name)
         self.output("Your hand is over the limit.")
         hand = ["(%d) %s" % (i+1, c) for i, c in enumerate(self.hand)]
         self.output("You have: " + pretty_print_list(hand))
         i = h - r.hand_limit
         self.request_input("Please discard %d card%s." % (i, "" if i == 1 else "s"),
                            (callback, discard_regex % "RKGA"))
         return
     
     self.enforce_keeper_limit()
Esempio n. 5
0
    def list_keepers(self, channel, user, params):
        def printHelp():
            self.privout(
                channel, """
            Syntax:    %B!listkeepers [%Uuser%U]%B
            Please say or message !help listkeepers for more information.
            """)

        if len(params) == 1:
            keepUser, keepUserStr = params[0].lower(), "%s's" % params[0]
        elif len(params) == 0:
            keepUser, keepUserStr = user.lower(), "Your"
        else:
            return printHelp()
        keep_str = pretty_print_list(self.users[keepUser].keepers.cards)
        if keep_str == "":
            keep_str = " no keepers."
        else:
            keep_str = ": " + keep_str
        if keepUser not in self.users or self.users[keepUser] not in \
               self.users[user.lower()].game.players:
            return self.privout(
                channel, "There is no user in this channel " +
                "by the nickname '%s'" % keepUser)
        self.privout(channel,
                     '%s keeper pile contains%s' % (keepUserStr, keep_str))
Esempio n. 6
0
 def draw(self, channel, user, params):
     def printHelp():
         self.privout(channel, """
         Syntax:    %B!draw [%Unumcards%U]%B
         Please say or message !help draw for more information.
         """)
     if len(params) == 0:
         num_cards = 0
     elif len(params) == 1 and params[0].isdigit():
         num_cards = int(params[0])
     else:
         return printHelp()
     
     player = self.users[user.lower()]
     handlen = len(player.hand)
     if player.halt_game is not None:
         return self.privout(channel, ("You cannot draw a card while %s " + \
                                   "is in effect.") % player.halt_game)
     cards = player.draw(num_cards)
     if cards is None:
         return self.turn_postfix(player)
     player.draw_amount += len(cards)
     # Make sure to reply to user
     # Don't show the cards in public!
     self.privout(user, "You drew: " + pretty_print_list(cards_str))
     if player.draws_left > 0:
         self.privout(user, "You can draw %d more card%s." % \
                 (player.draws_left, "" if player.draws_left else "s"))
     self.turn_postfix(player)
     return cards
Esempio n. 7
0
 def list_hand(self, channel, user, params):
     hand_str = ["%d: %s" % (i+1, c) for i, c in \
                 enumerate(self.users[user.lower()].hand)]
     hand_str = pretty_print_list(hand_str)
     if hand_str == "":
         hand_str = " no cards."
     else:
         hand_str = ": " + hand_str
     self.privout(user, 'Your hand contains%s' % hand_str)
Esempio n. 8
0
 def list_hand(self, channel, user, params):
     hand_str = ["%d: %s" % (i+1, c) for i, c in \
                 enumerate(self.users[user.lower()].hand)]
     hand_str = pretty_print_list(hand_str)
     if hand_str == "":
         hand_str = " no cards."
     else:
         hand_str = ": " + hand_str
     self.privout(user, 'Your hand contains%s' % hand_str)
Esempio n. 9
0
 def status(self, msg_channel, user, params):
     if getattr(self, "game", None) is None:
         self.privout(msg_channel, "No game is in progress.")
     elif self.game.started:
         self.privout(msg_channel, "A game is in progress.")
     else:
         self.privout(msg_channel,
                      "A game is starting, the queue contains: " + \
                          pretty_print_list(self.game.players))
Esempio n. 10
0
 def status(self, msg_channel, user, params):
     if getattr(self, "game", None) is None:
         self.privout(msg_channel, "No game is in progress.")
     elif self.game.started:
         self.privout(msg_channel, "A game is in progress.")
     else:
         self.privout(msg_channel,
                      "A game is starting, the queue contains: " + \
                          pretty_print_list(self.game.players))
Esempio n. 11
0
 def enforce_keeper_limit(self):
     def callback(message):
         r = self.game.rule_pile
         t = self.limit_callback(message, self.keepers, r.keeper_limit, \
                                     self.enforce_keeper_limit)
         self.callback()
         return t
     
     k = len(self.keepers.non_creepers)
     r = self.game.rule_pile
     if r.keeper_limit > 0 and k > r.keeper_limit:
         self.plugin.pubout("%s's keeper pile is over the limit and must discard manually." % self.name)
         self.output("Your keeper pile is over the limit.")
         keepers = ["(%d) %s" % (i+1, c) for i, c in enumerate(self.keepers)]
         self.output("You have: " + pretty_print_list(keepers))
         i = k - r.keeper_limit
         self.request_input("Please discard %d keeper%s." % \
                            (i, "" if i == 1 else "s"),
                            (callback, discard_regex % "K"))
         return
     self.callback()
Esempio n. 12
0
 def enforce_keeper_limit(self):
     def callback(message):
         r = self.game.rule_pile
         t = self.limit_callback(message, self.keepers, r.keeper_limit, \
                                     self.enforce_keeper_limit)
         self.callback()
         return t
     
     k = len(self.keepers.non_creepers)
     r = self.game.rule_pile
     if r.keeper_limit > 0 and k > r.keeper_limit:
         self.plugin.pubout("%s's keeper pile is over the limit and must discard manually." % self.name)
         self.output("Your keeper pile is over the limit.")
         keepers = ["(%d) %s" % (i+1, c) for i, c in enumerate(self.keepers)]
         self.output("You have: " + pretty_print_list(keepers))
         i = k - r.keeper_limit
         self.request_input("Please discard %d keeper%s." % \
                            (i, "" if i == 1 else "s"),
                            (callback, discard_regex % "K"))
         return
     self.callback()
Esempio n. 13
0
 def list_keepers(self, channel, user, params):
     def printHelp():
         self.privout(channel, """
         Syntax:    %B!listkeepers [%Uuser%U]%B
         Please say or message !help listkeepers for more information.
         """)
     if len(params) == 1:
         keepUser, keepUserStr = params[0].lower(), "%s's" % params[0]
     elif len(params) == 0:
         keepUser, keepUserStr = user.lower(), "Your"
     else:
         return printHelp()
     keep_str = pretty_print_list(self.users[keepUser].keepers.cards)
     if keep_str == "":
         keep_str = " no keepers."
     else:
         keep_str = ": " + keep_str
     if keepUser not in self.users or self.users[keepUser] not in \
            self.users[user.lower()].game.players:
         return self.privout(channel, "There is no user in this channel " +
                         "by the nickname '%s'" % keepUser)
     self.privout(channel, '%s keeper pile contains%s' % (keepUserStr, keep_str))
Esempio n. 14
0
 def __str__(self):
     s = pretty_print_list((self.goal1, self.goal2))
     if s != "":
         s = ": " + s
     return "Double Agenda (R_DA)%s" % s
Esempio n. 15
0
 def description(self):
     num_keepers = len(self._k)
     return "The player who has %s on the table wins." % \
            pretty_print_list([self.find_keeper(i).title_uncapped \
                               for i in self._k], use_both=True)
Esempio n. 16
0
    def help(self, channel, user, params):
        help_text = {
            'commands': """
            My commands are: %CommandList
            Say %B!help %UCOMMAND%U%B for help with each command.
            """,
            
            'startgame': """
            Syntax:    %B!startgame
            Start a game in this channel.
            """,

            'endgame': """
            Syntax:    %B!endgame
            End the current game.
            """,
            
            'cardinfo': """
            Syntax:    %B!cardinfo %Ushortname%U%B
            Find the description of a card by its internal name.
            For instance, the Keeper love has an internal name
            of 'K_LO'. You can find a card's internal name when
            it is in play by using !listhand, !listkeepers,
            !listrules or !currentgoal, or use !search to find
            a card.
            """,
            
            'draw': """
            Syntax:    %B!draw%B
            Draw the maximum number of cards allowed from the draw pile.
            
            Syntax:    %B!draw %Unumcards%U%B
            Draw a number of cards from the draw pile.
            """,
            
            'play': """
            Syntax:    %B!play %Ucard%U%B
            Play card 'card'. Card can either be card number in
            your hand or an internal name like 'K_LO' for 'Love'.
            """,
            
            'currentgoal': """
            Syntax:    %B!currentgoal%B
            Say the current goal.
            """,
            
            'listrules': """
            Syntax:    %B!listrules%B
            List the current rules.
            """,
            
            'listhand': """
            Syntax:    %B!listhand%B
            List your current hand.
            """,
            
            'listkeepers': """
            Syntax:    %B!listkeepers%B
            List your current keeper pile.
            Syntax:    %B!listkeepers %Uusername%U%B
            List the keepers of 'username'.
            """,
            
            'join': """
            Syntax:    %B!join%B
            Join the game.
            """,
            
            'help': """
            Syntax:    %B!help%B
            ...
            """,
            
            'search': """
            Syntax:    %B!search %Uparameters%U%B
            Search for a specific card.
            """,

            'quit': """
            Syntax:    %B!quit
            Quit the current game.
            """,
        }

        if len(params) == 0:
            command = ''
        else:
            command = params[0].strip().lower()

        if len(command) > 0 and command[0] == "!":
            command = command[1:].strip()

        if channel == self.bot.nickname:
            channel = user

        command = command_aliases.get(command, command)

        if command in help_text:
            self.privout(channel, help_text[command].replace("%CommandList",
                                  pretty_print_list(command_handlers.keys())))
            aliases = reverse_aliases[command]
            self.privout(channel, "Aliases: " + pretty_print_list('!%s' % (a,) for a in aliases))
        else:
            self.privout(channel, "There is no command called !%s" % (command,))
Esempio n. 17
0
 def __str__(self):
     s = pretty_print_list((self.goal1, self.goal2))
     if s != "":
         s = ": " + s
     return "Double Agenda (R_DA)%s" % s
Esempio n. 18
0
 def description(self):
     num_keepers = len(self._k)
     return "The player who has %s on the table wins." % \
            pretty_print_list([self.find_keeper(i).title_uncapped \
                               for i in self._k], use_both=True)