]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/games/uno.rb
time: support POSIX time
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / games / uno.rb
index ecf322d5f48f62e0f399ac2b109cfb781f0cb991..870526fc38e8a9636d14252d97dcdca535d06147 100644 (file)
@@ -244,6 +244,7 @@ class UnoGame
   end
 
   def start_game
+    @join_timer = nil
     debug "Starting game"
     @players.shuffle!
     show_order
@@ -397,10 +398,24 @@ 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)
@@ -529,6 +544,10 @@ class UnoGame
       }
       deal(p, @picker)
       @picker = 0
+      # make sure that if this is the "pick and pass" after a W+4,
+      # then the following player cannot do a challenge:
+      @last_discard = nil
+      @last_color = nil
     else
       if @player_has_picked
         announce _("%{p} passes turn") % { :p => p }
@@ -733,11 +752,17 @@ class UnoGame
   def replace_player(old, new)
     # The new user
     user = channel.get_user(new)
+    if not user
+      announce _("there is no '%{nick}' here") % {
+        :nick => new
+      }
+      return false
+    end
     if p = get_player(user)
       announce _("%{p} is already playing %{uno} here") % {
         :p => p, :uno => UNO
       }
-      return
+      return false
     end
     # We scan the player list of the player with the old nick, instead
     # of using get_player, in case of IRC drops etc
@@ -747,12 +772,13 @@ class UnoGame
         announce _("%{p} takes %{b}%{old}%{b}'s place at %{uno}") % {
           :p => p, :b => Bold, :old => old, :uno => UNO
         }
-        return
+        return true
       end
     end
     announce _("%{b}%{old}%{b} isn't playing %{uno} here") % {
       :uno => UNO, :b => Bold, :old => old
     }
+    return false
   end
 
   def end_game(halted = false)