Class: BCDice::DiceTable::SaiFicSkillTable

Inherits:
Object
  • Object
show all
Defined in:
lib/bcdice/dice_table/sai_fic_skill_table.rb,
lib/bcdice/dice_table/sai_fic_skill_table/skill.rb,
lib/bcdice/dice_table/sai_fic_skill_table/category.rb

Direct Known Subclasses

GameSystem::BeginningIdol::SkillTable

Defined Under Namespace

Classes: Category, Skill

Constant Summary collapse

DEFAULT_RTT =
"ランダム特技表(%<category_dice>d,%<row_dice>d) > %<text>s"
DEFAULT_RCT =
"ランダム分野表(%<category_dice>d) > %<category_name>s"
DEFAULT_RTTN =
"%<category_name>s分野ランダム特技表(%<row_dice>d) > %<text>s"
DEFAULT_S =
"《%<skill_name>s/%<category_name>s%<row_dice>d》"
RTTN =
["RTT1", "RTT2", "RTT3", "RTT4", "RTT5", "RTT6"].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items, rtt: nil, rct: nil, rttn: nil, rtt_format: DEFAULT_RTT, rct_format: DEFAULT_RCT, rttn_format: DEFAULT_RTTN, s_format: DEFAULT_S) ⇒ SaiFicSkillTable

サイコロ・フィクション用ダイステーブルを初期化する。既存の実装の互換性維持とルールブックの記載に準拠するために、コマンドと書式文字列を指定できる。

Parameters:

  • items (Array)

    特技リスト

  • rtt (String) (defaults to: nil)

    RTTに相当するコマンド

  • rct (String) (defaults to: nil)

    RCTに相当するコマンド

  • rttn (Array) (defaults to: nil)

    RTT1~6に相当するコマンドの配列

  • rtt_format (String) (defaults to: DEFAULT_RTT)

    RTTコマンドの出力用の書式文字列

  • rct_format (String) (defaults to: DEFAULT_RCT)

    RCTコマンドの出力用の書式文字列

  • rttn_format (String) (defaults to: DEFAULT_RTTN)

    RTTNコマンドの出力用の書式文字列

  • s_format (String) (defaults to: DEFAULT_S)

    Skill#to_s出力用の書式文字列



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bcdice/dice_table/sai_fic_skill_table.rb', line 38

def initialize(items, rtt: nil, rct: nil, rttn: nil, rtt_format: DEFAULT_RTT, rct_format: DEFAULT_RCT, rttn_format: DEFAULT_RTTN, s_format: DEFAULT_S)
  @categories = items.map.with_index(1) do |(name, skills), index|
    SaiFicSkillTable::Category.new(name, skills, index, s_format)
  end
  @rtt = rtt
  @rct = rct
  @rttn = rttn.to_a
  @rtt_format = rtt_format
  @rct_format = rct_format
  @rttn_format = rttn_format
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



51
52
53
# File 'lib/bcdice/dice_table/sai_fic_skill_table.rb', line 51

def categories
  @categories
end

Class Method Details

.from_i18n(key, locale, rtt: nil, rct: nil, rttn: nil) ⇒ SaiFicSkillTable

Parameters:

  • key (String)
  • locale (Symbol)
  • rtt (String) (defaults to: nil)

    RTTに相当するコマンド

  • rct (String) (defaults to: nil)

    RCTに相当するコマンド

  • rttn (Array) (defaults to: nil)

    RTT1~6に相当するコマンドの配列

Returns:



15
16
17
18
19
20
21
# File 'lib/bcdice/dice_table/sai_fic_skill_table.rb', line 15

def self.from_i18n(key, locale, rtt: nil, rct: nil, rttn: nil)
  global = I18n.t("RTT", locale: locale, raise: false, default: {})
  table = global.merge(I18n.t(key, locale: locale, raise: true))
  items = table[:items]
  table = table.select { |k, _| [:rtt_format, :rttn_format, :rct_format, :s_format].include?(k) }
  new(items, **table, rtt: rtt, rct: rct, rttn: rttn)
end

Instance Method Details

#prefixesObject



79
80
81
# File 'lib/bcdice/dice_table/sai_fic_skill_table.rb', line 79

def prefixes
  (["RTT[1-6]?", "RCT", @rtt, @rct] + @rttn).compact
end

#roll_category(randomizer) ⇒ SaiFicSkillTable::Category

1D6を振り、ランダムで分野を決定する



69
70
71
# File 'lib/bcdice/dice_table/sai_fic_skill_table.rb', line 69

def roll_category(randomizer)
  @categories[randomizer.roll_once(6) - 1]
end

#roll_command(randomizer, command) ⇒ Object

コマンドを解釈し、結果を取得するreturn [String]



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/bcdice/dice_table/sai_fic_skill_table.rb', line 55

def roll_command(randomizer, command)
  c = command
  if ["RTT", @rtt].include?(c)
    format_skill(@rtt_format, roll_skill(randomizer))
  elsif ["RCT", @rct].include?(c)
    cat = roll_category(randomizer)
    format(@rct_format, category_dice: cat.dice, category_name: cat.name)
  elsif (index = RTTN.index(c)) || (index = @rttn.index(c))
    format_skill(@rttn_format, @categories[index].roll(randomizer))
  end
end

#roll_skill(randomizer) ⇒ SaiFicSkillTable::Skill

1D6と2D6を振り、ランダムで特技を決定する



75
76
77
# File 'lib/bcdice/dice_table/sai_fic_skill_table.rb', line 75

def roll_skill(randomizer)
  roll_category(randomizer).roll(randomizer)
end