Class: HDeck::CardCaster

Inherits:
Object
  • Object
show all
Defined in:
lib/hdeck/card_caster.rb

Overview

Manager class for Card Caster

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(alignment: 'CN') ⇒ CardCaster

Returns a new instance of CardCaster.



6
7
8
9
# File 'lib/hdeck/card_caster.rb', line 6

def initialize(alignment: 'CN')
  @alignment = alignment
  @deck = Deck.new
end

Instance Attribute Details

#alignmentObject

Returns the value of attribute alignment.



4
5
6
# File 'lib/hdeck/card_caster.rb', line 4

def alignment
  @alignment
end

#deckObject

Returns the value of attribute deck.



4
5
6
# File 'lib/hdeck/card_caster.rb', line 4

def deck
  @deck
end

Instance Method Details

#detect_alignment_match(card) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/hdeck/card_caster.rb', line 40

def detect_alignment_match(card)
  return :full if card.morality == @alignment

  @alignment.each_char do |sign|
    return :partial if card.morality.include?(sign)
  end

  :none
end

#draw_card(shuffle_before: true, replace: false, calculate_match: false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hdeck/card_caster.rb', line 11

def draw_card(shuffle_before: true, replace: false, calculate_match: false)
  if deck.length <= 0
    puts 'Deck is out of cards'
    return
  end

  deck.shuffle if shuffle_before

  drawn_card = deck.draw(replace: replace)

  if calculate_match
    # Bonuses applied via Role Dealer feat
    case detect_alignment_match(drawn_card)
    when :full
      puts "Full alignment match!\n"\
            "--------------------\n"\
            "crit range: 19-20\n"\
            "crit damage bonus: x3\n"\
            "+4 bonus to confirmation roll\n"
    when :partial
      puts "Partial alignment match!\n"\
            "--------------------\n"\
            "crit range: 19-20\n"
    end
  end

  puts("\n#{drawn_card.to_s}\n\n")
end