]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/games/uno.rb
UNO! plugin: clean join_timer when game starts
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / games / uno.rb
index a86c33dba8d03216fa37cc9814baa885a470a318..e619027ceb2a7ee14abd4240a50868ad1a0b2cb2 100644 (file)
@@ -211,6 +211,13 @@ class UnoGame
     @bot.notice player.user, msg, opts
   end
 
+  def notify_error(player, msg, opts={})
+    announce _("you can't do that, %{p}") % {
+      :p => player.user
+    }
+    notify player, msg, opts
+  end
+
   def make_base_stock
     @base_stock = COLORS.inject([]) do |list, clr|
       VALUES.each do |n|
@@ -237,6 +244,7 @@ class UnoGame
   end
 
   def start_game
+    @join_timer = nil
     debug "Starting game"
     @players.shuffle!
     show_order
@@ -329,7 +337,7 @@ 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)
@@ -390,14 +398,28 @@ class UnoGame
       toplay = (full == short) ? 1 : 2
     end
     debug [full, short, jolly, jcolor, toplay].inspect
-    # r7r7 -> r7r7, r7, nil, nil
-    # r7 -> r7, r7, nil, nil
-    # w -> w, nil, w, nil
-    # wg -> wg, nil, w, g
+    # r7r7 -> r7r7, r7, nil, nil, 2
+    # r7 -> r7, r7, nil, nil, 1
+    # w -> w, nil, w, nil, 1
+    # wg -> wg, nil, w, g, 1
+
+    # if @color is nil, the player just played a wild without specifying
+    # a color. (s)he should now use "co <colorname>", but we allow him to
+    # replay the wild _and_ specify the color, without actually replaying
+    # the card (which would otherwise happen if the player has another wild)
+    if @color.nil?
+      if jcolor
+        choose_color(p.user, jcolor)
+      else
+        announce _("you already played your card, ") + _("%{p}, choose a color with: co r|b|g|y") % { :p => p }
+      end
+      return
+    end
+
     if cards = p.has_card?(short)
       debug cards
       unless can_play(cards.first)
-        announce _("you can't play that card")
+        notify_error p, _("you can't play that card")
         return
       end
       if cards.length >= toplay
@@ -451,10 +473,10 @@ class UnoGame
           announce _("%{p}, choose a color with: co r|b|g|y") % { :p => p }
         end
       else
-        announce _("you don't have two cards of that kind")
+        notify_error p, _("you don't have two cards of that kind")
       end
     else
-      announce _("you don't have that card")
+      notify_error p, _("you don't have that card")
     end
   end
 
@@ -699,11 +721,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
@@ -743,6 +772,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}") % {