3 # Description: Rbot plugin. Rolls rpg style dice
4 # Author: David Dorward (http://david.us-lot.org/ - you might find a more up to date version of this plugin there)
8 # You can get rbot from: http://www.linuxbrit.co.uk/rbot/
11 # 0.1 - Initial release
12 # 0.1.1 - bug fix, only 1 digit for number of dice sides on first roll
13 # 0.3.0 - Spelling correction on changelog 0.1.1
14 # - Return results of each roll
15 # 0.3.1 - Minor documentation update
16 # 0.3.2 - Bug fix, could not subtract numbers (String can't be coerced into Fixnum)
18 # TODO: Test! Test! Test!
20 # Fumble/Critical counter (1's and x's where x is sides on dice)
21 ####################################################
24 attr_reader :total, :view
25 def initialize(view, total)
31 class DicePlugin < Plugin
32 def help(plugin, topic="")
33 "dice <string> (where <string> is something like: d6 or 2d6 or 2d6+4 or 2d6+1d20 or 2d6+1d5+4d7-3d4-6) => Rolls that set of virtual dice"
39 unless dice[0] =~ /^[0-9]+/
42 for i in 0...dice[0].to_i
43 r = r + rand(dice[1].to_i) + 1
58 viewer = DiceDisplay.new("[" + porm.to_s + d.to_s + "=" + r.to_s + "] ", r)
63 unless(m.params && m.params =~ /^[0-9]*d[0-9]+([+-]([0-9]+|[0-9]*d[0-9])+)*$/)
64 m.reply "incorrect usage: " + help(m.plugin)
67 a = m.params.scan(/^[0-9]*d[0-9]+|[+-][0-9]*d[0-9]+|[+-][0-9]+/)
69 t = "[" + a[0].to_s + "=" + r.to_s + "] "
72 r = r + tmp.total.to_i
75 m.reply r.to_s + " | " + t
78 plugin = DicePlugin.new
79 plugin.register("dice")
80 ##############################################