Module: Natural20::FighterBuilder

Included in:
CharacterBuilder
Defined in:
lib/natural_20/cli/builder/fighter_builder.rb

Instance Method Summary collapse

Instance Method Details

#fighter_builder(build_values) ⇒ Object



2
3
4
5
6
7
8
9
10
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/natural_20/cli/builder/fighter_builder.rb', line 2

def fighter_builder(build_values)
  @class_values ||= {
    attributes: [],
    saving_throw_proficiencies: %w[strength constitution],
    equipped: [],
    inventory: []
  }

  fighter_features = %w[archery defense dueling great_weapon_fighting protection two_weapon_fighting]
  @class_values[:attributes] << prompt.select(t('builder.fighter.select_fighting_style')) do |q|
    fighter_features.each do |style|
      q.choice t("builder.fighter.#{style}"), style
    end
  end

  starting_equipment = []
  starting_equipment << prompt.select(t('builder.fighter.select_starting_weapon')) do |q|
    q.choice t('object.weapons.chain_mail'), :chain_mail
    q.choice t('object.weapons.longbow_and_arrows'), :longbow_and_arrows
  end

  starting_equipment << prompt.select(t('builder.fighter.select_starting_weapon_2')) do |q|
    q.choice t('object.martial_weapon_and_shield'), :martial_weapon_and_shield
    q.choice t('object.two_martial_weapons'), :two_martial_weapons
  end

  starting_equipment << prompt.select(t('builder.fighter.select_starting_weapon_3')) do |q|
    q.choice t('object.light_crossbow_and_20_bolts'), :light_crossbow_and_20_bolts
    q.choice t('object.two_handaxes'), :two_handaxes
  end

  # starting_equipment << prompt.select(t('builder.fighter.select_starting_weapon_4')) do |q|
  #   q.choice t('object.dungeoneers_pack'), :dungeoneers_pack
  #   q.choice t('object.explorers_pack'), :explorers_pack
  # end

  martial_weapons = session.load_weapons.map do |k, weapon|
    next unless weapon[:proficiency_type]&.include?('martial')
    next if weapon[:rarity] && weapon[:rarity] != 'common'

    k
  end.compact

  starting_equipment.each do |equipment|
    case equipment
    when :chain_mail
      @class_values[:equipped] << 'chain_mail'
    when :longbow_and_arrows
      @class_values[:inventory] << {
        type: 'longbow',
        qty: 1
      }
    when :martial_weapon_and_shield
      chosen_martial_weapon = prompt.select(t('builder.select_martial_weapon')) do |q|
        martial_weapons.each do |weapon|
          q.choice t("object.weapons.#{weapon}"), weapon
        end
      end
      @class_values[:inventory] << {
        type: chosen_martial_weapon,
        qty: 1
      }
      @class_values[:inventory] << {
        type: 'shield',
        qty: 1
      }
    when :two_martial_weapons
      chosen_martial_weapons = prompt.multi_select(t('builder.select_martial_weapon'), min: 2, max: 2) do |q|
        martial_weapons.each do |weapon|
          q.choice t("object.weapons.#{weapon}"), weapon
        end
      end
      chosen_martial_weapons.each do |w|
        @class_values[:inventory] << {
          type: w,
          qty: 1
        }
      end
    when :light_crossbow_and_20_bolts
      @class_values[:inventory] << {
        type: 'crossbow',
        qty: 1
      }
      @class_values[:inventory] << {
        type: 'bolts',
        qty: 20
      }
    when :two_handaxes
      @class_values[:inventory] << {
        type: 'handaxe',
        qty: 2
      }
      # when :dungeoneers_pack
      # when :explorers_pack
    end
  end

  result = Natural20::DieRoll.parse(@class_properties[:hit_die])
  @values[:max_hp] = result.die_count * result.die_type.to_i + modifier_table(@values.dig(:ability, :con))

  @class_values
end