class BCDice::GameSystem::MagicaLogia::SkillExpandTable
Constants
- CATEGORIES
Public Class Methods
from_i18n(key, locale, skill_table)
click to toggle source
# File lib/bcdice/game_system/MagicaLogia.rb, line 98 def self.from_i18n(key, locale, skill_table) table = I18n.t(key, locale: locale, raise: false) new(table[:name], table[:type], table[:items], skill_table) end
new(name, type, items, skill_table)
click to toggle source
# File lib/bcdice/game_system/MagicaLogia.rb, line 103 def initialize(name, type, items, skill_table) @name = name @items = items.freeze @skill_table = skill_table m = /(\d+)D(\d+)/i.match(type) unless m raise ArgumentError, "Unexpected table type: #{type}" end @times = m[1].to_i @sides = m[2].to_i end
Public Instance Methods
roll(randomizer)
click to toggle source
# File lib/bcdice/game_system/MagicaLogia.rb, line 117 def roll(randomizer) value = randomizer.roll_sum(@times, @sides) text = expand(@items[value - @times], randomizer) return DiceTable::RollResult.new(@name, value, text) end
Private Instance Methods
expand(chosen, randomizer)
click to toggle source
# File lib/bcdice/game_system/MagicaLogia.rb, line 126 def expand(chosen, randomizer) chosen.gsub(/%{([a-z]+)}/) do m = Regexp.last_match type = m[1].to_sym roll_skill(type, randomizer) end end
roll_skill(type, randomizer)
click to toggle source
# File lib/bcdice/game_system/MagicaLogia.rb, line 137 def roll_skill(type, randomizer) if type == :skill return @skill_table.roll_skill(randomizer) end if type == :element return @skill_table.roll_category(randomizer) end index = CATEGORIES.index(type) raise ArgumentError unless index @skill_table.categories[index].roll(randomizer).name end