]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/games/uno.rb
uno plugin: fix check for card presence
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / games / uno.rb
index 1d49642ceae554c748798986c5b983e120bb1207..fdedc1447f7153cbb28762e983ec968a0b3b5a1d 100644 (file)
@@ -126,14 +126,14 @@ class UnoGame
       @cards = []
     end
     def has_card?(short)
-      cards = []
+      has = []
       @cards.each { |c|
-        cards << c if c.shortform == short
+        has << c if c.shortform == short
       }
-      if cards.empty?
+      if has.empty?
         return false
       else
-        return cards
+        return has
       end
     end
     def to_s
@@ -263,6 +263,7 @@ class UnoGame
     end
     if card.picker > 0
       @picker += card.picker
+      @last_picker = @discard.picker
     end
     if card.special?
       @special = true
@@ -279,13 +280,11 @@ class UnoGame
 
   def can_play(card)
     # When a +something is online, you can only play
-    # a +something of same or higher something, or a Reverse
+    # a +something of same or higher something, or a Reverse of
+    # the correct color
     # TODO make optional
     if @picker > 0
-      if card.color and card.color != @color
-        return false
-      end
-      if card.value == 'Reverse' or card.picker >= @discard.picker
+      if (card.value == 'Reverse' and card.color == @color) or card.picker >= @last_picker
         return true
       else
         return false
@@ -353,8 +352,10 @@ class UnoGame
           announce _("%{p}, choose a color with: co r|b|g|y") % { :p => p }
         end
       else
-        announce _("you don't have that card")
+        announce _("you don't have two cards of that kind")
       end
+    else
+      announce _("you don't have that card")
     end
   end
 
@@ -391,7 +392,9 @@ class UnoGame
       announce _('what color is that?')
       return
     end
-    announce _('color is now %{c}') % { :c => @color.downcase }
+    announce _('color is now %{c}') % {
+      :c => UnoGame.irc_color_bg(@color)+" #{@color} "
+    }
     next_turn
   end
 
@@ -475,6 +478,7 @@ class UnoGame
         end
       end
     end
+    picked.sort!
     notify player, _("You picked %{picked}") % { :picked => picked.join(' ') }
     player.cards += picked
     player.cards.sort!
@@ -500,11 +504,11 @@ class UnoGame
       :uno => UNO, :p => @players.first
     }
     if @picker > 0
-      p = @player[1]
+      p = @players[1]
       announce _("%{p} has to pick %{b}%{n}%{b} cards!") % {
         :p => p, :n => @picker, :b => Bold
       }
-      deal(@player[1], @picker)
+      deal(p, @picker)
       @picker = 0
     end
     score = @players.inject(0) do |sum, p|
@@ -555,8 +559,10 @@ class UnoPlugin < Plugin
     g = @games[m.channel]
     case m.plugin.intern
     when :jo # join game
+      return if m.params
       g.add_player(m.source)
     when :pe # pick card
+      return if m.params
       if g.has_turn?(m.source)
         if g.player_has_picked
           m.reply _("you already picked a card")
@@ -569,6 +575,7 @@ class UnoPlugin < Plugin
         m.reply _("It's not your turn")
       end
     when :pa # pass turn
+      return if m.params
       if g.has_turn?(m.source)
         g.pass(m.source)
       else
@@ -587,17 +594,22 @@ class UnoPlugin < Plugin
         m.reply _("It's not your turn")
       end
     when :ca # show current cards
+      return if m.params
       g.show_all_cards(m.source)
     when :cd # show current discard
+      return if m.params
       g.show_discard
     # TODO
     # when :ch
     #   g.challenge
     when :od # show playing order
+      return if m.params
       g.show_order
     when :ti # show play time
+      return if m.params
       g.show_time
     when :tu # show whose turn is it
+      return if m.params
       if g.has_turn?(m.source)
         m.nickreply _("it's your turn, sleepyhead")
       else