Class: BCDice::Base

Inherits:
Object
  • Object
show all
Includes:
Deprecated::Checker, Translate
Defined in:
lib/bcdice/base.rb

Direct Known Subclasses

GameSystem::AFF2e, GameSystem::Agnostos, GameSystem::Ainecadette, GameSystem::Airgetlamh, GameSystem::AlchemiaStruggle, GameSystem::Alsetto, GameSystem::AlterRaise, GameSystem::Amadeus, GameSystem::AngelGear, GameSystem::AniMalus, GameSystem::AnimaAnimus, GameSystem::Aoharubaan, GameSystem::Arianrhod, GameSystem::ArknightsFan, GameSystem::ArsMagica, GameSystem::AssaultEngine, GameSystem::Avandner, GameSystem::Ayabito, GameSystem::BBN, GameSystem::BadLife, GameSystem::Bakenokawa, GameSystem::BarnaKronika, GameSystem::BattleTech, GameSystem::BeastBindTrinity, GameSystem::BeginningIdol, GameSystem::BeginningIdol2022, GameSystem::BlackJacket, GameSystem::BladeOfArcana, GameSystem::BlindMythos, GameSystem::BloodCrusade, GameSystem::BloodMoon, GameSystem::Bloodorium, GameSystem::CardRanker, GameSystem::CastleInGray, GameSystem::ChaosFlare, GameSystem::Chill, GameSystem::Chill3, GameSystem::CodeLayerd, GameSystem::ColossalHunter, GameSystem::Comes, GameSystem::ConvictorDrive, GameSystem::CrashWorld, GameSystem::Cthulhu, GameSystem::Cthulhu7th, GameSystem::Cthulhu7th_ChineseTraditional, GameSystem::Cthulhu7th_Korean, GameSystem::CthulhuTech, GameSystem::CyberpunkRed, GameSystem::DarkBlaze, GameSystem::DarkDaysDrive, GameSystem::DarkSouls, GameSystem::DeadlineHeroes, GameSystem::DemonParasite, GameSystem::DemonSpike, GameSystem::DesperateRun, GameSystem::DetatokoSaga, GameSystem::DiceBot, GameSystem::DiceOfTheDead, GameSystem::DivineCharger, GameSystem::DoubleCross, GameSystem::Dracurouge, GameSystem::DungeonsAndDragons, GameSystem::DungeonsAndDragons5, GameSystem::EarthDawn, GameSystem::EclipsePhase, GameSystem::Elric, GameSystem::Elysion, GameSystem::EmbryoMachine, GameSystem::Emoklore, GameSystem::EndBreaker, GameSystem::FateCoreSystem, GameSystem::Fiasco, GameSystem::FilledWith, GameSystem::FinalFantasyXIV, GameSystem::FullFace, GameSystem::FutariSousa, GameSystem::GURPS, GameSystem::Garako, GameSystem::GardenOrder, GameSystem::GehennaAn, GameSystem::GeishaGirlwithKatana, GameSystem::GhostLive, GameSystem::GoblinSlayer, GameSystem::GoldenSkyStories, GameSystem::Gorilla, GameSystem::GranCrest, GameSystem::GundamSentinel, GameSystem::Gundog, GameSystem::GundogRevised, GameSystem::GurpsFW, GameSystem::HarnMaster, GameSystem::HatsuneMiku, GameSystem::HeroScale, GameSystem::Hieizan, GameSystem::HouraiGakuen, GameSystem::HunterTheReckoning5th, GameSystem::HuntersMoon, GameSystem::IfIfIf, GameSystem::Illusio, GameSystem::InfiniteFantasia, GameSystem::Insane, GameSystem::InvisibleLiar, GameSystem::Irisbane, GameSystem::IthaWenUa, GameSystem::JamesBond, GameSystem::JuinKansen, GameSystem::Kamigakari, GameSystem::KamitsubakiCityUnderConstructionNarrative, GameSystem::KanColle, GameSystem::Karukami, GameSystem::KemonoNoMori, GameSystem::KillDeathBusiness, GameSystem::KizunaBullet, GameSystem::KurayamiCrying, GameSystem::Kutulu, GameSystem::KyokoShinshoku, GameSystem::Liminal, GameSystem::LiveraDoll, GameSystem::LogHorizon, GameSystem::LostRecord, GameSystem::LostRoyal, GameSystem::MagicaLogia, GameSystem::MamonoScramble, GameSystem::MeikyuDays, GameSystem::MeikyuKingdom, GameSystem::MetalHead, GameSystem::MetalHeadExtream, GameSystem::MonotoneMuseum, GameSystem::NRR, GameSystem::NSSQ, GameSystem::Nechronica, GameSystem::NeverCloud, GameSystem::NightWizard, GameSystem::NightmareHunterDeep, GameSystem::NinjaSlayer, GameSystem::NinjaSlayer2, GameSystem::NjslyrBattle, GameSystem::NobunagasBlackCastle, GameSystem::Nuekagami, GameSystem::OneWayHeroics, GameSystem::OracleEngine, GameSystem::OrgaRain, GameSystem::Oukahoushin3rd, GameSystem::Paradiso, GameSystem::Paranoia, GameSystem::ParanoiaRebooted, GameSystem::PastFutureParadox, GameSystem::Peekaboo, GameSystem::Pendragon, GameSystem::PersonaO, GameSystem::PhantasmAdventure, GameSystem::Postman, GameSystem::Raisondetre, GameSystem::RecordOfLodossWar, GameSystem::RecordOfSteam, GameSystem::Revulture, GameSystem::RokumonSekai2, GameSystem::RoleMaster, GameSystem::RuinBreakers, GameSystem::RuneQuest, GameSystem::RuneQuestRoleplayingInGlorantha, GameSystem::RyuTuber, GameSystem::Ryutama, GameSystem::SRS, GameSystem::SajinsenkiAGuS, GameSystem::SamsaraBallad, GameSystem::Satasupe, GameSystem::Sengensyou, GameSystem::ShadowRun, GameSystem::ShadowRun4, GameSystem::SharedFantasia, GameSystem::ShinMegamiTenseiKakuseihen, GameSystem::ShinkuuGakuen, GameSystem::ShinobiGami, GameSystem::Shiranui, GameSystem::ShoujoTenrankai, GameSystem::ShuumatsuBargainWars, GameSystem::ShuumatsuKikou, GameSystem::Siren, GameSystem::Skynauts, GameSystem::SkynautsBouken, GameSystem::StarryDolls, GameSystem::SteamPunkers, GameSystem::StellarKnights, GameSystem::StellarLife, GameSystem::StrangerOfSwordCity, GameSystem::StratoShout, GameSystem::Strave, GameSystem::SwordWorld, GameSystem::TalesFromTheLoop, GameSystem::TensaiGunshiNiNaro, GameSystem::TheOneRing2nd, GameSystem::TheUnofficialHollowKnightRPG, GameSystem::TherapieSein, GameSystem::TokumeiTenkousei, GameSystem::TokyoGhostResearch, GameSystem::TokyoNova, GameSystem::Torg, GameSystem::TorgEternity, GameSystem::ToshiakiHolyGrailWar, GameSystem::TrailOfCthulhu, GameSystem::TrinitySeven, GameSystem::TunnelsAndTrolls, GameSystem::TwilightGunsmoke, GameSystem::UnsungDuet, GameSystem::Utakaze, GameSystem::VampireTheMasquerade5th, GameSystem::Ventangle, GameSystem::Villaciel, GameSystem::VisionConnect, GameSystem::WARPS, GameSystem::WaresBlade, GameSystem::Warhammer, GameSystem::Warhammer4, GameSystem::WerewolfTheApocalypse5th, GameSystem::WitchQuest, GameSystem::WorldOfDarkness, GameSystem::YankeeYogSothoth, GameSystem::YearZeroEngine, GameSystem::Yggdrasill, GameSystem::Yotabana, GameSystem::ZettaiReido, GameSystem::ZombiLine

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Translate

#translate

Constructor Details

#initialize(command) ⇒ Base

Returns a new instance of Base.



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
# File 'lib/bcdice/base.rb', line 74

def initialize(command)
  @raw_input = command

  @sort_add_dice = false # 加算ダイスでダイス目をソートするかどうか
  @sort_barabara_dice = false # バラバラダイスでダイス目をソートするかどうか

  @d66_sort_type = D66SortType::NO_SORT # 入れ替えの種類 詳しくはBCDice::D66SortTypeを参照すること

  @enabled_d9 = false # D9ダイスを有効にするか(ガンドッグ)で使用

  @round_type = RoundType::FLOOR # 割り算をした時の端数の扱い (FLOOR: 切り捨て, CEIL: 切り上げ, ROUND: 四捨五入)

  @sides_implicit_d = 6 # 1D のようにダイスの面数が指定されていない場合に何面ダイスにするか

  @upper_dice_reroll_threshold = nil # UpperDiceで振り足しをする出目の閾値 nilの場合デフォルト設定なし
  @reroll_dice_reroll_threshold = nil # RerollDiceで振り足しをする出目の閾値 nilの場合デフォルト設定なし

  @default_cmp_op = nil # 目標値が空欄の場合の比較演算子をシンボルで指定する (:>, :>= :<, :<=, :==, :!=)
  @default_target_number = nil # 目標値が空欄の場合の目標値 こちらだけnilにするのは想定していないので注意

  @enabled_upcase_input = true # 入力を String#upcase するかどうか

  @locale = :ja_jp # i18n用の言語設定

  @randomizer = BCDice::Randomizer.new
  @debug = false
end

Class Attribute Details

.prefixesArray<String> (readonly)

接頭辞(反応するコマンド)の配列を返す

Returns:

  • (Array<String>)


18
19
20
# File 'lib/bcdice/base.rb', line 18

def prefixes
  @prefixes
end

Instance Attribute Details

#d66_sort_typeSymbol (readonly)

D66のダイス入れ替えの種類

Returns:

  • (Symbol)


107
108
109
# File 'lib/bcdice/base.rb', line 107

def d66_sort_type
  @d66_sort_type
end

#default_cmp_opSymbol? (readonly)

デフォルトの比較演算子

Returns:

  • (Symbol, nil)


132
133
134
# File 'lib/bcdice/base.rb', line 132

def default_cmp_op
  @default_cmp_op
end

#default_target_numberInteger? (readonly)

デフォルトの目標値

Returns:

  • (Integer, nil)


137
138
139
# File 'lib/bcdice/base.rb', line 137

def default_target_number
  @default_target_number
end

#randomizerObject

Returns the value of attribute randomizer.



102
103
104
# File 'lib/bcdice/base.rb', line 102

def randomizer
  @randomizer
end

#reroll_dice_reroll_thresholdInteger? (readonly)

RerollDiceで振り足しをする出目の閾値

Returns:

  • (Integer, nil)


127
128
129
# File 'lib/bcdice/base.rb', line 127

def reroll_dice_reroll_threshold
  @reroll_dice_reroll_threshold
end

#round_typeSymbol (readonly)

端数処理の種類

Returns:

  • (Symbol)


112
113
114
# File 'lib/bcdice/base.rb', line 112

def round_type
  @round_type
end

#sides_implicit_dInteger (readonly)

ダイスの面数が指定されていない場合に何面ダイスにするか

Returns:

  • (Integer)


117
118
119
# File 'lib/bcdice/base.rb', line 117

def sides_implicit_d
  @sides_implicit_d
end

#upper_dice_reroll_thresholdInteger? (readonly)

UpperDiceで振り足しをする出目の閾値

Returns:

  • (Integer, nil)


122
123
124
# File 'lib/bcdice/base.rb', line 122

def upper_dice_reroll_threshold
  @upper_dice_reroll_threshold
end

Class Method Details

.command_patternRegexp

応答するコマンド全てにマッチする正規表現を返す 正規表現を一度生成したら、以後コマンドの登録はできないようにする

Returns:

  • (Regexp)


53
54
55
56
57
58
59
60
61
62
# File 'lib/bcdice/base.rb', line 53

def command_pattern
  @command_pattern ||= nil
  return @command_pattern if @command_pattern

  @prefixes ||= []
  @prefixes.freeze
  pattarns = CommonCommand::COMMANDS.map { |c| c::PREFIX_PATTERN.source } + @prefixes

  @command_pattern = /^S?(#{pattarns.join('|')})/i.freeze
end

.eval(command) ⇒ Result

Parameters:

  • command (String)

Returns:



66
67
68
# File 'lib/bcdice/base.rb', line 66

def eval(command)
  new(command).eval
end

.prefixes_patternRegexp

ゲームシステム固有のコマンドにマッチする正規表現を返す 正規表現を一度生成したら、以後コマンドの登録はできないようにする

Returns:

  • (Regexp)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bcdice/base.rb', line 35

def prefixes_pattern
  @prefixes_pattern ||= nil
  return @prefixes_pattern if @prefixes_pattern

  @prefixes ||= []
  @prefixes.freeze
  @prefixes_pattern =
    if @prefixes.empty?
      /(?!)/ # 何にもマッチしない正規表現
    else
      /^(S)?(#{@prefixes.join('|')})/i
    end.freeze
end

.register_prefix(*prefixes) ⇒ Object

応答するコマンドのprefixを登録する

Parameters:

  • prefixes (Array<String>)


22
23
24
25
# File 'lib/bcdice/base.rb', line 22

def register_prefix(*prefixes)
  @prefixes ||= []
  @prefixes.concat(prefixes.flatten)
end

.register_prefix_from_super_classObject



27
28
29
# File 'lib/bcdice/base.rb', line 27

def register_prefix_from_super_class
  register_prefix(superclass.prefixes)
end

Instance Method Details

#change_text(string) ⇒ String

Deprecated.

これを使わずに eval_common_command 内でパースすることを推奨する

ゲームシステムごとの入力コマンドの前処理

Parameters:

  • string (String)

Returns:

  • (String)


183
184
185
# File 'lib/bcdice/base.rb', line 183

def change_text(string)
  string
end

#check_result(total, rand_results, cmp_op, target) ⇒ Result?

Parameters:

Returns:



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/bcdice/base.rb', line 192

def check_result(total, rand_results, cmp_op, target)
  ret = check_result_legacy(total, rand_results, cmp_op, target)
  return ret if ret

  sides_list = rand_results.map(&:sides)
  value_list = rand_results.map(&:value)
  dice_total = value_list.sum()

  ret =
    case sides_list
    when [100]
      result_1d100(total, dice_total, cmp_op, target)
    when [20]
      result_1d20(total, dice_total, cmp_op, target)
    when [6, 6]
      result_2d6(total, dice_total, value_list, cmp_op, target)
    end

  return nil if ret == Result.nothing
  return ret if ret

  ret =
    case sides_list.uniq
    when [10]
      result_nd10(total, dice_total, value_list, cmp_op, target)
    when [6]
      result_nd6(total, dice_total, value_list, cmp_op, target)
    end

  return nil if ret == Result.nothing
  return ret if ret

  return result_ndx(total, cmp_op, target)
end

#enable_debugObject

デバッグを有用にする



161
162
163
# File 'lib/bcdice/base.rb', line 161

def enable_debug
  @debug = true
end

#enabled_d9?Boolean

D9ダイスが有効か

Returns:

  • (Boolean)


156
157
158
# File 'lib/bcdice/base.rb', line 156

def enabled_d9?
  @enabled_d9
end

#evalResult?

コマンドを評価する

Returns:

  • (Result, nil)

    コマンド実行結果。コマンドが実行できなかった場合はnilを返す



167
168
169
170
171
172
173
174
175
176
177
# File 'lib/bcdice/base.rb', line 167

def eval
  command = BCDice::Preprocessor.process(@raw_input, self)

  result = dice_command(command) || eval_common_command(@raw_input)
  return nil unless result

  result.rands = @randomizer.rand_results
  result.detailed_rands = @randomizer.detailed_rand_results

  return result
end

#grich_text(count_one, dice_total_count, count_success) ⇒ String?

シャドウラン用グリッチ判定

Parameters:

  • count_one (Integer)

    出目1の数

  • dice_total_count (Integer)

    ダイスロールしたダイスの数

  • count_success (Integer)

    成功数

Returns:

  • (String, nil)


232
# File 'lib/bcdice/base.rb', line 232

def grich_text(count_one, dice_total_count, count_success); end

#sort_add_dice?Boolean

加算ダイスでダイス目をソートするかどうか

Returns:

  • (Boolean)


142
143
144
# File 'lib/bcdice/base.rb', line 142

def sort_add_dice?
  @sort_add_dice
end

#sort_barabara_dice?Boolean

バラバラダイスでダイス目をソートするかどうか

Returns:

  • (Boolean)


149
150
151
# File 'lib/bcdice/base.rb', line 149

def sort_barabara_dice?
  @sort_barabara_dice
end