Showing posts with label OGC. Show all posts
Showing posts with label OGC. Show all posts

Sunday, November 26, 2006

BAB ruby class for OGL system

Jamis Buck's Dice class inspired me (a lot). A few weeks ago, I decided to start thinking about a role-playing session manager. I'm still thinking about it, but in the interim, I started work on a few classes, just to "feel better". Included below is a BAB class. It is released as OGC as described by the OGL. This class also has associated tests, if you are truly curious.

$ 5.bab.good
=> 5

$ 4.bab.poor # Suck it wizard
=> 2

$ 3.bab.medium + 5.bab.poor + 3.bab.poor # 3 Rogue / 5 Wizard / 3 Arcane Trickster
=> 5






class Bab
class InvalidCount < Exception # :nodoc:
end
TYPES = [:good, :medium, :poor]
attr_reader :count, :epic_count

def initialize( count )
raise InvalidCount unless count.is_a?(Integer) && count > 0
@count = count > 20 ? 20 : count
@epic_count = count > 20 ? count - 20 : 0
end

def good
self.count + epic_value
end

def medium
((self.count * 3) / 4) + epic_value
end

def poor
(self.count / 2) + epic_value
end

private
def epic_value
(self.epic_count + 1) / 2
end

end

class Integer
def bab
Bab.new(self)
end
end