Class: Fudge::Roll

Inherits:
DiceBag::Roll show all
Defined in:
lib/dicebag/systems/fudge.rb

Overview

This models a standard Fudge RPG dice pool.

Instance Attribute Summary

Attributes inherited from DiceBag::Roll

#dstr, #tree

Instance Method Summary collapse

Methods inherited from DiceBag::Roll

#average, #maximum, #minimum, #notes, #notes_to_s, #result

Methods included from RollString

#inspect

Constructor Details

#initialize(number = 4) ⇒ Roll

Returns a new instance of Roll.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dicebag/systems/fudge.rb', line 11

def initialize(number = 4)
  @number = number
  @total  = nil
  @tally  = nil

  # This is a very silly way to do this, since there is no need to
  # actually add the dice together here. But we need all of the d6's
  # together in the same roll.
  dstr = (['1d6'] * number).join(' + ')

  super(dstr)
end

Instance Method Details

#rollObject



24
25
26
27
28
29
30
31
32
# File 'lib/dicebag/systems/fudge.rb', line 24

def roll
  super

  generate_tally

  @total = @tally.count('+') - @tally.count('-')

  [@total, tally_to_s]
end

#tallyObject



40
41
42
43
44
# File 'lib/dicebag/systems/fudge.rb', line 40

def tally
  roll unless @tally

  @tally
end

#to_sObject



46
47
48
49
50
# File 'lib/dicebag/systems/fudge.rb', line 46

def to_s
  base = "#{@number}dF"

  @total ? "#{base} #{tally_to_s} => #{@total}" : base
end

#totalObject



34
35
36
37
38
# File 'lib/dicebag/systems/fudge.rb', line 34

def total
  roll unless @total

  @total
end