Module: Rollable

Extended by:
ActiveSupport::Concern
Included in:
Moves::Basic, Moves::Rollable
Defined in:
app/models/concerns/rollable.rb

Overview

This rollable concern extends a move and add rolling functionality including using luck on rolls

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Instance Method Details

#lucky_roll(hunter, lose_experience) ⇒ Object


31
32
33
34
35
36
37
# File 'app/models/concerns/rollable.rb', line 31

def lucky_roll(hunter, lose_experience)
  roll = 12 + hunter.send(rating)
  outcome = outcome(roll, hunter)
  hunter.gain_experience(-1) if lose_experience
  hunter.update(luck: hunter.luck - 1)
  Result.new(roll, "Your total #{roll} resulted in #{outcome}")
end

#outcome(roll, _hunter) ⇒ Object


39
40
41
42
43
44
45
46
47
48
# File 'app/models/concerns/rollable.rb', line 39

def outcome(roll, _hunter)
  case roll
  when 0..6
    six_and_under
  when 7..9
    seven_to_nine
  when (10..)
    ten_plus
  end
end

#roll(hunter) ⇒ Object


20
21
22
# File 'app/models/concerns/rollable.rb', line 20

def roll(hunter)
  Random.new.rand(2..12) + hunter.send(rating)
end

#roll_results(hunter) ⇒ Object


24
25
26
27
28
29
# File 'app/models/concerns/rollable.rb', line 24

def roll_results(hunter)
  roll = roll(hunter)
  outcome = outcome(roll, hunter)
  hunter.gain_experience(1) if roll <= 6
  Result.new(roll, "Your total #{roll} resulted in #{outcome}")
end

#rollable?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'app/models/concerns/rollable.rb', line 16

def rollable?
  true
end