dice.rb
rbmud-0.2/lib/dice.rb · 1.5 KB
From the archive RbMUD-0.2.tar.bz2
Download the archive « Back to the archive contents
#!/usr/bin/env ruby
# $Revision: 1.2 $
# $Date: 2003/12/04 22:18:34 $
# $Author: jefus $
# some globally accessible dice rolling methods are always good.
class Dice
def Dice.roll(dice, sides)
result = 0
dice.times { result = result + rand(sides) + 1 }
return result
end
# skill checks are performed by rolling the control die (1d20) and
# adding in the results of the situation die, which varies depending on
# the difficulty of the task.
def Dice.control
return Dice.roll(1, 20)
end
# modifier ranges from -5 (no sweat) to +7 (nearly impossible)
# the value returned by this method is added to the result of the control
# die for the final skill check result.
def Dice.situation(modifier = 0)
case modifier
when -5 # no sweat
return Dice.roll(1, 20) * -1
when -4 # cakewalk
return Dice.roll(1, 12) * -1
when -3 # extremely easy
return Dice.roll(1, 8) * -1
when -2 # very easy
return Dice.roll(1, 6) * -1
when -1 # easy
return Dice.roll(1, 4) * -1
when 0 # average
return 0
when 1 # tough
return Dice.roll(1, 4)
when 2 # hard
return Dice.roll(1, 6)
when 3 # challenging
return Dice.roll(1, 8)
when 4 # formidable
return Dice.roll(1, 12)
when 5 # grueling
return Dice.roll(1, 20)
when 6 # gargantuan
return Dice.roll(2, 20)
when 7 # nearly impossible
return Dice.roll(3, 20)
else
Logger.log("Dice.situation: modifier out of range (#{modifier})")
return 0
end
end
end
Logger.log("Dice code initialized.")