X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=data%2Frbot%2Fplugins%2Fgames%2Funo.rb;h=4ae05f6e5e5fa85425e2438b6774d067bfa23ea5;hb=11fe3ea3c6848fc1838a4d284ddcfaeb30ac17bc;hp=12b77f6e9bfc6ff42add969fd4980f5a60cc8372;hpb=b2af728968fcb8c1e109164332a1094cc17c9102;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/games/uno.rb b/data/rbot/plugins/games/uno.rb index 12b77f6e..4ae05f6e 100644 --- a/data/rbot/plugins/games/uno.rb +++ b/data/rbot/plugins/games/uno.rb @@ -108,7 +108,7 @@ class UnoGame @color = 'Wild' raise if value and not value == '+4' if value - @value = value.dup + @value = value.dup @shortform = 'w'+value else @value = nil @@ -329,21 +329,35 @@ class UnoGame def next_turn(opts={}) @players << @players.shift @player_has_picked = false - show_turn + show_turn unless opts[:silent] end def can_play(card) # if play is forced, check against the only allowed cards return false if @must_play and not @must_play.include?(card) - # When a +something is online, you can only play a +something of same or - # higher something, or a Reverse of the correct color, or a Reverse on - # a Reverse - # TODO make optional if @picker > 0 - return true if card.picker >= @last_picker - return true if card.value == 'Reverse' and (card.color == @color or @discard.value == card.value) - return false + # During a picker run (i.e. after a +something was played and before a + # player is forced to pick) you can only play pickers (+2, +4) and + # Reverse. Reverse can be played if the previous card matches by color or + # value (as usual), a +4 can always be played, a +2 can be played on a +2 + # of any color or on a Reverse of the correct color unless a +4 was + # played on it + # TODO make optional + case card.value + when 'Reverse' + # Reverse can be played if it matches color or value + return (card.color == @color) || (@discard.value == card.value) + when '+2' + return false if @last_picker > 2 + return true if @discard.value == card.value + return true if @discard.value == 'Reverse' and @color == card.color + return false + when '+4' + return true + else + return false + end else # You can always play a Wild return true if Wild === card @@ -397,7 +411,7 @@ class UnoGame # only be possible if the first W+4 was illegal, so it wouldn't # apply for a W+4 played on a +2 anyway. # - if @picker == 0 and Wild === cards.first and cards.first.value + if @picker == 0 and Wild === cards.first and cards.first.value # save the previous discard in case of challenge @last_discard = @discard.dup # save the color too, in case it was a Wild @@ -592,6 +606,7 @@ class UnoGame def show_user_cards(player) p = Player === player ? player : get_player(player) + return unless p notify p, _('Your cards: %{cards}') % { :cards => p.cards.join(' ') } @@ -649,9 +664,9 @@ class UnoGame end cards = 7 if @start_time - cards = @players.inject(0) do |s, pl| + cards = (@players.inject(0) do |s, pl| s +=pl.cards.length - end/@players.length + end*1.0/@players.length).ceil end p = Player.new(user) @players << p @@ -684,11 +699,18 @@ class UnoGame } case @players.length when 2 + if @join_timer + @bot.timer.remove(@join_timer) + announce _("game start countdown stopped") + @join_timer = nil + end if p == @players.first - next_turn + next_turn :silent => @start_time.nil? + end + if @start_time + end_game + return end - end_game - return when 1 end_game(true) return @@ -728,6 +750,11 @@ class UnoGame def end_game(halted = false) runtime = @start_time ? Time.now - @start_time : 0 + if @join_timer + @bot.timer.remove(@join_timer) + announce _("game start countdown stopped") + @join_timer = nil + end if halted if @start_time announce _("%{uno} game halted after %{time}") % { @@ -746,7 +773,11 @@ class UnoGame } end if @picker > 0 and not halted - p = @players[1] + if @discard.value == 'Reverse' + p = @players.last + else + p = @players[1] + end announce _("%{p} has to pick %{b}%{n}%{b} cards!") % { :p => p, :n => @picker, :b => Bold } @@ -826,8 +857,14 @@ class UnoPlugin < Plugin _("The points won with a game of %{uno} are totalled from the cards remaining in the hands of the other players."), _("Each normal (not special) card is worth its face value (from 0 to 9 points)."), _("Each colored special card (+2, Reverse, Skip) is worth 20 points."), - _("Each Wild and Wild +4 is worth 50 points.") + _("Each Wild and Wild +4 is worth 50 points."), + help(plugin, 'top'), + help(plugin, 'topwin'), ].join(" ") % { :uno => UnoGame::UNO } + when 'top' + _("You can see the scoring table with 'uno top N' where N is the number of top scores to show.") + when 'topwin' + _("You can see the winners table with 'uno topwin N' where N is the number of top winners to show.") when /cards?/ [ _("There are 108 cards in a standard %{uno} deck."), @@ -844,7 +881,7 @@ class UnoPlugin < Plugin _("'uno end' to end the game before its natural completion") ].join("; ") else - _("%{uno} game. !uno to start a game. see 'help uno rules' for the rules, 'help uno admin' for admin commands. In-game commands: %{cmds}.") % { + _("%{uno} game. !uno to start a game. see 'help uno rules' for the rules, 'help uno admin' for admin commands, 'help uno score' for scoring rules. In-game commands: %{cmds}.") % { :uno => UnoGame::UNO, :cmds => help(plugin, 'commands') } @@ -853,7 +890,9 @@ class UnoPlugin < Plugin def message(m) return unless @games.key?(m.channel) + return unless m.plugin # skip messages such as: botname, g = @games[m.channel] + replied = true case m.plugin.intern when :jo # join game return if m.params @@ -915,11 +954,14 @@ class UnoPlugin < Plugin when :tu # show whose turn is it return if m.params if g.has_turn?(m.source) - m.nickreply _("it's your turn, sleepyhead") + m.reply _("it's your turn, sleepyhead"), :nick => true else g.show_turn(:cards => false) end + else + replied=false end + m.replied=true if replied end def create_game(m, p) @@ -1131,6 +1173,14 @@ class UnoPlugin < Plugin scores << [v.won.inject(0) { |s, w| s+=w.score }, k] end + if wins.empty? + m.reply(_("no %{uno} games were completed here") % { + :uno => UnoGame::UNO + }) + return + end + + if n = p[:scorenum] msg = _("%{uno} %{num} highest scores: ") % { :uno => UnoGame::UNO, :num => p[:scorenum]