module Natural20::WizardClass

typed: false

Constants

WIZARD_SPELL_SLOT_TABLE

Attributes

arcane_recovery[RW]
wizard_level[RW]
wizard_spell_slots[RW]

Public Instance Methods

initialize_wizard() click to toggle source
# File lib/natural_20/concerns/wizard_class.rb, line 30
def initialize_wizard
  @spell_slots[:wizard] = reset_spell_slots
  @arcane_recovery = 1
end
max_slots_for_wizard(level) click to toggle source
# File lib/natural_20/concerns/wizard_class.rb, line 75
def max_slots_for_wizard(level)
  WIZARD_SPELL_SLOT_TABLE[wizard_level - 1][level] || 0
end
short_rest_for_wizard(battle) click to toggle source

@param battle [Natural20::Battle]

# File lib/natural_20/concerns/wizard_class.rb, line 44
def short_rest_for_wizard(battle)
  if @arcane_recovery.positive?
    controller = battle.controller_for(self)
    if controller && controller.respond_to?(:arcane_recovery_ui)
      max_sum = (wizard_level / 2).ceil
      loop do
        current_sum = 0
        avail_levels = WIZARD_SPELL_SLOT_TABLE[wizard_level - 1].each_with_index.map do |slots, index|
          next if index.zero?
          next if index >= 6 # none of the spell sltos can be 6 or higher

          next if @spell_slots[:wizard][index] >= slots
          next if current_sum > max_sum

          current_sum += index
          index
        end.compact

        break if avail_levels.empty?

        level = controller.arcane_recovery_ui(self, avail_levels)
        break if level.nil?

        @spell_slots[:wizard][level] += 1
        @arcane_recovery = 0
        max_sum -= level
      end
    end
  end
end
special_actions_for_wizard(_session, _battle) click to toggle source
# File lib/natural_20/concerns/wizard_class.rb, line 39
def special_actions_for_wizard(_session, _battle)
  []
end
spell_attack_modifier() click to toggle source
# File lib/natural_20/concerns/wizard_class.rb, line 35
def spell_attack_modifier
  proficiency_bonus + int_mod
end

Protected Instance Methods

reset_spell_slots() click to toggle source
# File lib/natural_20/concerns/wizard_class.rb, line 81
def reset_spell_slots
  WIZARD_SPELL_SLOT_TABLE[wizard_level - 1].each_with_index.map do |slots, index|
    [index, slots]
  end.to_h
end