From d4e24de8f47a57ab79b9eeebbf707e2b61530a0d Mon Sep 17 00:00:00 2001 From: dgw Date: Sun, 26 Jul 2015 22:39:00 -0700 Subject: [PATCH] Lay some groundwork for UNO! calling (#7) --- unobot.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/unobot.py b/unobot.py index 6c01252..b4767db 100644 --- a/unobot.py +++ b/unobot.py @@ -105,9 +105,11 @@ def __init__(self, trigger): self.deadPlayers = {} self.playerOrder = [self.owner] self.currentPlayer = 0 + self.previousPlayer = None self.topCard = None self.way = 1 self.drawn = NO + self.unoCalled = NO self.deck = [] self.startTime = None @@ -221,6 +223,16 @@ def play(self, bot, trigger): return WIN self.show_on_turn(bot) + def call_uno(self, bot, trigger): + caller = trigger.nick + with lock: + if len(self.players[caller]) != 1: + z = [self.get_card(), self.get_card()] + self.players[caller].extend(z) + bot.notice(STRINGS['DRAWN_CARD'] % self.render_cards(z, UnoBot.get_card_theme(bot, caller)), caller) + else: + self.unoCalled = caller + def draw(self, bot, trigger): if not self.deck: return @@ -401,6 +413,7 @@ def create_deck(): def inc_player(self): with lock: + self.previousPlayer = self.currentPlayer self.currentPlayer += self.way if self.currentPlayer == len(self.players): self.currentPlayer = 0 @@ -512,6 +525,11 @@ def play(self, bot, trigger): bot.say(STRINGS['WIN'] % (winner, game_duration)) self.game_ended(bot, trigger, winner) + def call_uno(self, bot, trigger): + if trigger.sender not in self.games: + return + self.games[trigger.sender].call_uno(bot, trigger) + def draw(self, bot, trigger): if trigger.sender not in self.games: return @@ -733,6 +751,13 @@ def unoplay(bot, trigger): unobot.play(bot, trigger) +@module.rule('^uno!?$') +@module.priority('high') +@module.require_chanmsg +def unocalled(bot, trigger): + unobot.call_uno(bot, trigger) + + @module.commands('draw') @module.priority('high') @module.require_chanmsg