Class: BCDice::Base
- Inherits:
-
Object
- Object
- BCDice::Base
- 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
-
.prefixes ⇒ Array<String>
readonly
接頭辞(反応するコマンド)の配列を返す.
Instance Attribute Summary collapse
-
#d66_sort_type ⇒ Symbol
readonly
D66のダイス入れ替えの種類.
-
#default_cmp_op ⇒ Symbol?
readonly
デフォルトの比較演算子.
-
#default_target_number ⇒ Integer?
readonly
デフォルトの目標値.
-
#randomizer ⇒ Object
Returns the value of attribute randomizer.
-
#reroll_dice_reroll_threshold ⇒ Integer?
readonly
RerollDiceで振り足しをする出目の閾値.
-
#round_type ⇒ Symbol
readonly
端数処理の種類.
-
#sides_implicit_d ⇒ Integer
readonly
ダイスの面数が指定されていない場合に何面ダイスにするか.
-
#upper_dice_reroll_threshold ⇒ Integer?
readonly
UpperDiceで振り足しをする出目の閾値.
Class Method Summary collapse
-
.command_pattern ⇒ Regexp
応答するコマンド全てにマッチする正規表現を返す 正規表現を一度生成したら、以後コマンドの登録はできないようにする.
- .eval(command) ⇒ Result
-
.prefixes_pattern ⇒ Regexp
ゲームシステム固有のコマンドにマッチする正規表現を返す 正規表現を一度生成したら、以後コマンドの登録はできないようにする.
-
.register_prefix(*prefixes) ⇒ Object
応答するコマンドのprefixを登録する.
- .register_prefix_from_super_class ⇒ Object
Instance Method Summary collapse
-
#change_text(string) ⇒ String
deprecated
Deprecated.
これを使わずに
eval_common_command
内でパースすることを推奨する - #check_result(total, rand_results, cmp_op, target) ⇒ Result?
-
#enable_debug ⇒ Object
デバッグを有用にする.
-
#enabled_d9? ⇒ Boolean
D9ダイスが有効か.
-
#eval ⇒ Result?
コマンドを評価する.
-
#grich_text(count_one, dice_total_count, count_success) ⇒ String?
シャドウラン用グリッチ判定.
-
#initialize(command) ⇒ Base
constructor
A new instance of Base.
-
#sort_add_dice? ⇒ Boolean
加算ダイスでダイス目をソートするかどうか.
-
#sort_barabara_dice? ⇒ Boolean
バラバラダイスでダイス目をソートするかどうか.
Methods included from 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
.prefixes ⇒ Array<String> (readonly)
接頭辞(反応するコマンド)の配列を返す
18 19 20 |
# File 'lib/bcdice/base.rb', line 18 def prefixes @prefixes end |
Instance Attribute Details
#d66_sort_type ⇒ Symbol (readonly)
D66のダイス入れ替えの種類
107 108 109 |
# File 'lib/bcdice/base.rb', line 107 def d66_sort_type @d66_sort_type end |
#default_cmp_op ⇒ Symbol? (readonly)
デフォルトの比較演算子
132 133 134 |
# File 'lib/bcdice/base.rb', line 132 def default_cmp_op @default_cmp_op end |
#default_target_number ⇒ Integer? (readonly)
デフォルトの目標値
137 138 139 |
# File 'lib/bcdice/base.rb', line 137 def default_target_number @default_target_number end |
#randomizer ⇒ Object
Returns the value of attribute randomizer.
102 103 104 |
# File 'lib/bcdice/base.rb', line 102 def randomizer @randomizer end |
#reroll_dice_reroll_threshold ⇒ Integer? (readonly)
RerollDiceで振り足しをする出目の閾値
127 128 129 |
# File 'lib/bcdice/base.rb', line 127 def reroll_dice_reroll_threshold @reroll_dice_reroll_threshold end |
#round_type ⇒ Symbol (readonly)
端数処理の種類
112 113 114 |
# File 'lib/bcdice/base.rb', line 112 def round_type @round_type end |
#sides_implicit_d ⇒ Integer (readonly)
ダイスの面数が指定されていない場合に何面ダイスにするか
117 118 119 |
# File 'lib/bcdice/base.rb', line 117 def sides_implicit_d @sides_implicit_d end |
#upper_dice_reroll_threshold ⇒ Integer? (readonly)
UpperDiceで振り足しをする出目の閾値
122 123 124 |
# File 'lib/bcdice/base.rb', line 122 def upper_dice_reroll_threshold @upper_dice_reroll_threshold end |
Class Method Details
.command_pattern ⇒ 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
66 67 68 |
# File 'lib/bcdice/base.rb', line 66 def eval(command) new(command).eval end |
.prefixes_pattern ⇒ 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を登録する
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_class ⇒ Object
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
これを使わずに eval_common_command
内でパースすることを推奨する
ゲームシステムごとの入力コマンドの前処理
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?
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_debug ⇒ Object
デバッグを有用にする
161 162 163 |
# File 'lib/bcdice/base.rb', line 161 def enable_debug @debug = true end |
#enabled_d9? ⇒ Boolean
D9ダイスが有効か
156 157 158 |
# File 'lib/bcdice/base.rb', line 156 def enabled_d9? @enabled_d9 end |
#eval ⇒ Result?
コマンドを評価する
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?
シャドウラン用グリッチ判定
232 |
# File 'lib/bcdice/base.rb', line 232 def grich_text(count_one, dice_total_count, count_success); end |
#sort_add_dice? ⇒ Boolean
加算ダイスでダイス目をソートするかどうか
142 143 144 |
# File 'lib/bcdice/base.rb', line 142 def sort_add_dice? @sort_add_dice end |
#sort_barabara_dice? ⇒ Boolean
バラバラダイスでダイス目をソートするかどうか
149 150 151 |
# File 'lib/bcdice/base.rb', line 149 def @sort_barabara_dice end |