X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fgames%2Froulette.rb;h=2d7e7429d1e6070db55488534af4b80a82bf1dfd;hb=6eed70298a021fc6b789936c8fa7e591ac6427be;hp=9fce8d8ae890e5d7a22d40611810bdd70a30b263;hpb=2e6f388addc0bb9ddc0cb991af50220c1e5e64c3;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/games/roulette.rb b/data/rbot/plugins/games/roulette.rb index 9fce8d8a..2d7e7429 100644 --- a/data/rbot/plugins/games/roulette.rb +++ b/data/rbot/plugins/games/roulette.rb @@ -1,17 +1,21 @@ -RouletteHistory = Struct.new("RouletteHistory", :games, :shots, :deaths, :misses, :wins) +define_structure :RouletteHistory, :games, :shots, :deaths, :misses, :wins, :points class RoulettePlugin < Plugin - BotConfig.register BotConfigBooleanValue.new('roulette.autospin', - :default => true, + Config.register Config::BooleanValue.new('roulette.autospin', + :default => true, :desc => "Automatically spins the roulette at the butlast shot") - BotConfig.register BotConfigBooleanValue.new('roulette.kick', - :default => false, + Config.register Config::BooleanValue.new('roulette.kick', + :default => false, :desc => "Kicks shot players from the channel") + Config.register Config::BooleanValue.new('roulette.twice_in_a_row', + :default => false, + :desc => "Allow players to go twice in a row") def initialize super reset_chambers @players = Array.new + @last = '' end def help(plugin, topic="") @@ -33,26 +37,33 @@ class RoulettePlugin < Plugin if @registry.has_key?("player " + m.sourcenick) playerdata = @registry["player " + m.sourcenick] else - playerdata = RouletteHistory.new(0,0,0,0,0) + playerdata = RouletteHistory.new(0,0,0,0,0,0) end totals = nil if @registry.has_key?("totals") totals = @registry["totals"] else - totals = RouletteHistory.new(0,0,0,0,0) + totals = RouletteHistory.new(0,0,0,0,0,0) end + if @last == m.sourcenick and not @bot.config['roulette.twice_in_a_row'] + m.reply "you can't go twice in a row!" + return + end + + @last = m.sourcenick unless @players.include?(m.sourcenick) @players << m.sourcenick playerdata.games += 1 end playerdata.shots += 1 totals.shots += 1 - + shot = @chambers.pop + chamberNo = 6 - @chambers.length if shot - m.reply "#{m.sourcenick}: chamber #{6 - @chambers.length} of 6 => *BANG*" + m.reply "#{m.sourcenick}: chamber #{chamberNo} of 6 => *BANG*" playerdata.deaths += 1 totals.deaths += 1 @players.each {|plyr| @@ -63,17 +74,19 @@ class RoulettePlugin < Plugin totals.wins += 1 @registry["player " + plyr] = pdata } - @players = Array.new + @players.clear + @last = '' @bot.kick(m.replyto, m.sourcenick, "*BANG*") if @bot.config['roulette.kick'] else - m.reply "#{m.sourcenick}: chamber #{6 - @chambers.length} of 6 => +click+" + m.reply "#{m.sourcenick}: chamber #{chamberNo} of 6 => +click+" playerdata.misses += 1 + playerdata.points += 2**chamberNo totals.misses += 1 end @registry["player " + m.sourcenick] = playerdata @registry["totals"] = totals - + if shot || @chambers.empty? reload(m) elsif @chambers.length == 1 and @bot.config['roulette.autospin'] @@ -95,7 +108,7 @@ class RoulettePlugin < Plugin if @registry.has_key?("totals") totals = @registry["totals"] else - totals = RouletteHistory.new(0,0,0,0,0) + totals = RouletteHistory.new(0,0,0,0,0,0) end @players.each {|plyr| @@ -109,7 +122,8 @@ class RoulettePlugin < Plugin totals.games += 1 @registry["totals"] = totals - @players = Array.new + @players.clear + @last = '' end def spin(m, params={}) @@ -162,7 +176,7 @@ class RoulettePlugin < Plugin k = match[1] total_players += 1 - + win_rate = v.wins.to_f / v.games * 100 if h_win_percent[0].nil? || win_rate > h_win_percent[1] && v.games > 2 h_win_percent = [[k], win_rate] @@ -204,6 +218,33 @@ class RoulettePlugin < Plugin m.reply "roulette stats: #{total_games} games completed, #{total_shots} shots fired at #{total_players} players. Luckiest: #{h_luck_percent[0].join(',')} (#{sprintf '%.1f', h_luck_percent[1]}% clicks). Unluckiest: #{l_luck_percent[0].join(',')} (#{sprintf '%.1f', l_luck_percent[1]}% clicks). Highest survival rate: #{h_win_percent[0].join(',')} (#{sprintf '%.1f', h_win_percent[1]}%). Lowest survival rate: #{l_win_percent[0].join(',')} (#{sprintf '%.1f', l_win_percent[1]}%). Most wins: #{won_most[0].join(',')} (#{won_most[1]}). Most deaths: #{died_most[0].join(',')} (#{died_most[1]})." end end + + # Figure out who the winnar is! + def hof(m, params) + fool = m.sourcenick + tmpKey = params[:key].to_s + targetKey = tmpKey.to_sym + m.reply("Checking out the #{tmpKey} HoF...") + tmp = @registry.to_hash + tmp.delete("totals") + sorted = tmp.sort { |a,b| b[1][targetKey] <=> a[1][targetKey] } + + winnersLeft = 5 + + winners = [] + sorted.each do |player| + playerName = player[0].split(" ")[1] + if player[0] == "totals" or playerName == "" + next + end + winners << "#{playerName} has #{player[1][targetKey]}" + winnersLeft -= 1 + if winnersLeft == 0 + break + end + end + m.reply(winners.join(" | ")) + end end plugin = RoulettePlugin.new @@ -215,5 +256,6 @@ plugin.map 'roulette spin', :action => 'spin' plugin.map 'roulette stats :player', :action => 'playerstats' plugin.map 'roulette stats', :action => 'stats' plugin.map 'roulette clearstats', :action => 'clearstats' +plugin.map 'roulette hof :key', :action => 'hof', :defaults => {:key => "points"}, :requirements => {:key => /^(?:games|shots|deaths|misses|wins|points)$/} plugin.map 'roulette'