# number of cards to be picked if the player can't play an appropriate card
attr_reader :picker
- def initialize(plugin, channel)
+ # game start time
+ attr :start_time
+
+ # the IRC user that created the game
+ attr_accessor :manager
+
+ def initialize(plugin, channel, manager)
@channel = channel
@plugin = plugin
@bot = plugin.bot
@picker = 0
@last_picker = 0
@must_play = nil
+ @manager = manager
end
def get_player(user)
end
def choose_color(user, color)
+ # you can only pick a color if the current color is unset
+ if @color
+ announce _("you can't pick a color now, %{p}") % {
+ :p => get_player(user)
+ }
+ return
+ end
case color
when 'r'
@color = 'Red'
end
def has_turn?(source)
- @players.first.user == source
+ @start_time && (@players.first.user == source)
end
def show_picker
def show_user_cards(player)
p = Player === player ? player : get_player(player)
+ return unless p
notify p, _('Your cards: %{cards}') % {
:cards => p.cards.join(' ')
}
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
_("'od' to show the playing order"),
_("'ti' to show play time"),
_("'tu' to show whose turn it is")
- ].join(" ; ")
+ ].join("; ")
when 'challenge'
_("A Wild +4 can only be played legally if you don't have normal (not special) cards of the current color. ") +
_("The next player can challenge a W+4 by using the 'ch' command. ") +
_("Wild +4 also forces the next player to take 4 cards, but it can only be played if you can't play a color card. ") +
_("you can play another +2 or +4 card on a +2 card, and a +4 on a +4, forcing the first player who can't play one to pick the cumulative sum of all cards. ") +
_("you can also play a Reverse on a +2 or +4, bouncing the effect back to the previous player (that now comes next). ")
+ when /scor(?:e|ing)/, /points?/
+ [
+ _("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.")
+ ].join(" ") % { :uno => UnoGame::UNO }
+ when /cards?/
+ [
+ _("There are 108 cards in a standard %{uno} deck."),
+ _("For each color (Blue, Green, Red, Yellow) there are 19 numbered cards (from 0 to 9), with two of each number except for 0."),
+ _("There are also 6 special cards for each color, two each of +2, Reverse, Skip."),
+ _("Finally, there are 4 Wild and 4 Wild +4 cards.")
+ ].join(" ") % { :uno => UnoGame::UNO }
+ when 'admin'
+ _("The game manager (the user that started the game) can execute the following commands to manage it: ") +
+ [
+ _("'uno drop <user>' to drop a user from the game (any user can drop itself using 'uno drop')"),
+ _("'uno replace <old> [with] <new>' to replace a player with someone else (useful in case of disconnects)"),
+ _("'uno transfer [to] <nick>' to transfer game ownership to someone else"),
+ _("'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. commands: %{cmds}") % {
+ _("%{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 => UnoGame::UNO,
:cmds => help(plugin, 'commands')
- })
+ }
end
end
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
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
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)
def create_game(m, p)
if @games.key?(m.channel)
- m.reply _("There is already an %{uno} game running here, say 'jo' to join in") % { :uno => UnoGame::UNO }
+ m.reply _("There is already an %{uno} game running here, managed by %{who}. say 'jo' to join in") % {
+ :who => @games[m.channel].manager,
+ :uno => UnoGame::UNO
+ }
return
end
- @games[m.channel] = UnoGame.new(self, m.channel)
+ @games[m.channel] = UnoGame.new(self, m.channel, m.source)
+ @bot.auth.irc_to_botuser(m.source).set_temp_permission('uno::manage', true, m.channel)
m.reply _("Ok, created %{uno} game on %{channel}, say 'jo' to join in") % {
:uno => UnoGame::UNO,
:channel => m.channel
}
end
+ def transfer_ownership(m, p)
+ unless @games.key?(m.channel)
+ m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
+ return
+ end
+ g = @games[m.channel]
+ old = g.manager
+ new = m.channel.get_user(p[:nick])
+ if new
+ g.manager = new
+ @bot.auth.irc_to_botuser(old).reset_temp_permission('uno::manage', m.channel)
+ @bot.auth.irc_to_botuser(new).set_temp_permission('uno::manage', true, m.channel)
+ m.reply _("%{uno} game ownership transferred from %{old} to %{nick}") % {
+ :uno => UnoGame::UNO, :old => old, :nick => p[:nick]
+ }
+ else
+ m.reply _("who is this %{nick} you want me to transfer game ownership to?") % p
+ end
+ end
+
def end_game(m, p)
unless @games.key?(m.channel)
m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
@games[m.channel].end_game(true)
end
+ def cleanup
+ @games.each { |k, g| g.end_game(true) }
+ super
+ end
+
def chan_reg(channel)
@registry.sub_registry(channel.downcase)
end
pstats[k] = pls
end
+ @bot.auth.irc_to_botuser(@games[channel].manager).reset_temp_permission('uno::manage', channel)
@games.delete(channel)
end
}
scores.sort! { |a1, a2| -(a1.first <=> a2.first) }
scores = scores[0, n.to_i].compact
+ i = 0
if scores.length <= 5
- i = 0
list = "\n" + scores.map { |a|
i+=1
_("%{i}. %{b}%{nick}%{b} with %{b}%{score}%{b} points") % {
}
wins.sort! { |a1, a2| -(a1.first <=> a2.first) }
wins = wins[0, n.to_i].compact
+ i = 0
if wins.length <= 5
- i = 0
list = "\n" + wins.map { |a|
i+=1
_("%{i}. %{b}%{nick}%{b} with %{b}%{score}%{b} wins") % {
pg = UnoPlugin.new
pg.map 'uno', :private => false, :action => :create_game
-pg.map 'uno end', :private => false, :action => :end_game
-pg.map 'uno drop', :private => false, :action => :drop_player
-pg.map 'uno giveup', :private => false, :action => :drop_player
-pg.map 'uno drop :nick', :private => false, :action => :drop_player, :auth_path => ':other'
-pg.map 'uno replace :old [with] :new', :private => false, :action => :replace_player
+pg.map 'uno end', :private => false, :action => :end_game, :auth_path => 'manage'
+pg.map 'uno drop', :private => false, :action => :drop_player, :auth_path => 'manage::drop::self!'
+pg.map 'uno giveup', :private => false, :action => :drop_player, :auth_path => 'manage::drop::self!'
+pg.map 'uno drop :nick', :private => false, :action => :drop_player, :auth_path => 'manage::drop::other!'
+pg.map 'uno replace :old [with] :new', :private => false, :action => :replace_player, :auth_path => 'manage'
+pg.map 'uno transfer [game [ownership]] [to] :nick', :private => false, :action => :transfer_ownership, :auth_path => 'manage'
pg.map 'uno stock', :private => false, :action => :print_stock
pg.map 'uno chanstats', :private => false, :action => :do_chanstats
pg.map 'uno stats [:nick]', :private => false, :action => :do_pstats
pg.map 'uno topwin :winnum', :private => false, :action => :do_top, :defaults => { :winnum => 5 }
pg.default_auth('stock', false)
-pg.default_auth('end', false)
-pg.default_auth('drop::other', false)
-pg.default_auth('replace', false)
+pg.default_auth('manage', false)
+pg.default_auth('manage::drop::self', true)