]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/games/uno.rb
markov plugin: don't echo a line a line that is just a substring of the input line
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / games / uno.rb
index f77d1c4261786fce20e14b2bd4d785f0b0bd2814..47fac28d52205109bf4a70abab358e53c99776e1 100644 (file)
@@ -160,6 +160,9 @@ class UnoGame
   # number of cards to be picked if the player can't play an appropriate card
   attr_reader :picker
 
+  # game start time
+  attr :start_time
+
   # the IRC user that created the game
   attr_accessor :manager
 
@@ -569,7 +572,7 @@ class UnoGame
   end
 
   def has_turn?(source)
-    @players.first.user == source
+    @start_time && (@players.first.user == source)
   end
 
   def show_picker
@@ -589,6 +592,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(' ')
     }
@@ -646,9 +650,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
@@ -850,6 +854,7 @@ class UnoPlugin < Plugin
 
   def message(m)
     return unless @games.key?(m.channel)
+    return unless m.plugin # skip messages such as: <someuser> botname,
     g = @games[m.channel]
     case m.plugin.intern
     when :jo # join game
@@ -869,7 +874,7 @@ class UnoPlugin < Plugin
         m.reply _("It's not your turn")
       end
     when :pa # pass turn
-      return if m.params
+      return if m.params or not g.start_time
       if g.has_turn?(m.source)
         g.pass(m.source)
       else
@@ -891,7 +896,7 @@ class UnoPlugin < Plugin
       return if m.params
       g.show_all_cards(m.source)
     when :cd # show current discard
-      return if m.params
+      return if m.params or not g.start_time
       g.show_discard
     when :ch
       if g.has_turn?(m.source)