X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Froulette.rb;h=9fce8d8ae890e5d7a22d40611810bdd70a30b263;hb=7b7f1309e8c3dbc3bb4408d56489ae5fba77d57a;hp=f979274046974c57cdca7c93af18e58b5c8dc74c;hpb=127d9152199cac9b431586bb7b17f6f297b6864f;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/roulette.rb b/data/rbot/plugins/roulette.rb index f9792740..9fce8d8a 100644 --- a/data/rbot/plugins/roulette.rb +++ b/data/rbot/plugins/roulette.rb @@ -1,14 +1,23 @@ -RouletteHistory = Struct.new("RouletteHistory", :games, :shots, :deaths, :misses, :wins) unless defined?(Struct::RouletteHistory) +RouletteHistory = Struct.new("RouletteHistory", :games, :shots, :deaths, :misses, :wins) class RoulettePlugin < Plugin + BotConfig.register BotConfigBooleanValue.new('roulette.autospin', + :default => true, + :desc => "Automatically spins the roulette at the butlast shot") + BotConfig.register BotConfigBooleanValue.new('roulette.kick', + :default => false, + :desc => "Kicks shot players from the channel") + def initialize super reset_chambers @players = Array.new end + def help(plugin, topic="") - "roulette => play russian roulette - starts a new game if one isn't already running. One round in a six chambered gun. Take turns to say roulette to the bot, until somebody dies. roulette reload => force the gun to reload, roulette stats => show stats from all games, roulette stats => show stats for , roulette clearstats => clear stats (config level auth required)" + "roulette => play russian roulette - starts a new game if one isn't already running. One round in a six chambered gun. Take turns to say roulette to the bot, until somebody dies. roulette reload => force the gun to reload, roulette stats => show stats from all games, roulette stats => show stats for , roulette clearstats => clear stats (config level auth required), roulette spin => spins the cylinder" end + def clearstats(m, params) @registry.clear m.okay @@ -55,6 +64,7 @@ class RoulettePlugin < Plugin @registry["player " + plyr] = pdata } @players = Array.new + @bot.kick(m.replyto, m.sourcenick, "*BANG*") if @bot.config['roulette.kick'] else m.reply "#{m.sourcenick}: chamber #{6 - @chambers.length} of 6 => +click+" playerdata.misses += 1 @@ -66,10 +76,18 @@ class RoulettePlugin < Plugin if shot || @chambers.empty? reload(m) + elsif @chambers.length == 1 and @bot.config['roulette.autospin'] + spin(m) end end + def reload(m, params = {}) - @bot.action m.replyto, "reloads" + if m.private? + m.reply "you gotta play roulette in channel dude" + return + end + + m.act "reloads" reset_chambers # all players win on a reload # (allows you to play 3-shot matches etc) @@ -93,10 +111,23 @@ class RoulettePlugin < Plugin @players = Array.new end + + def spin(m, params={}) + # Spinning is just like resetting, except that nobody wins + if m.private? + m.reply "you gotta play roulette in channel dude" + return + end + + m.act "spins the cylinder" + reset_chambers + end + def reset_chambers @chambers = [false, false, false, false, false, false] @chambers[rand(@chambers.length)] = true end + def playerstats(m, params) player = params[:player] pstats = @registry["player " + player] @@ -106,6 +137,7 @@ class RoulettePlugin < Plugin m.reply "#{player} has played #{pstats.games} games, won #{pstats.wins} and lost #{pstats.deaths}. #{player} pulled the trigger #{pstats.shots} times and found the chamber empty on #{pstats.misses} occasions." end end + def stats(m, params) if @registry.has_key?("totals") totals = @registry["totals"] @@ -173,9 +205,15 @@ class RoulettePlugin < Plugin end end end + plugin = RoulettePlugin.new + +plugin.default_auth('clearstats', false) + plugin.map 'roulette reload', :action => 'reload' +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', :auth => 'config' +plugin.map 'roulette clearstats', :action => 'clearstats' plugin.map 'roulette' +