Class: BCDice::GameSystem::DetatokoSaga

Inherits:
Base
  • Object
show all
Defined in:
lib/bcdice/game_system/DetatokoSaga.rb

Direct Known Subclasses

DetatokoSaga_Korean

Constant Summary collapse

ID =

ゲームシステムの識別子

'DetatokoSaga'
NAME =

ゲームシステム名

'でたとこサーガ'
SORT_KEY =

ゲームシステム名の読みがな

'てたとこさあか'
HELP_MESSAGE =

ダイスボットの使い方

<<~INFO_MESSAGE_TEXT
  ・通常判定 xDS or xDSy or xDS>=t or xDSy>=t or xDS+z>=t or xDSy+z>=t
   (x=スキルランク、y=現在フラグ値(省略時0)、z=修正値(省略時0)、t=目標値(省略時8))
   例)3DS 2DS5 0DS 3DS>=10 3DS7>=12 2DS3+1 3DS2+1>=10
  ・判定値 xJD or xJDy or xJDy+z or xJDy-z or xJDy/z
   (x=スキルランク、y=現在フラグ値(省略時0)、z=修正値(省略時0))
   例)3JD 2JD5 3JD7+1 4JD/3
  ・体力烙印表 SST (StrengthStigmaTable)
  ・気力烙印表 WST (WillStigmaTable)
  ・体力バッドエンド表 SBET (StrengthBadEndTable)
  ・気力バッドエンド表 WBET (WillBadEndTable)
INFO_MESSAGE_TEXT
ALIAS =
{
  "StrengthStigmaTable" => "SST",
  "WillStigmaTable" => "WST",
  "StrengthBadEndTable" => "SBET",
  "WillBadEndTable" => "WBET",
}.transform_keys(&:upcase).freeze
TABLES =
translate_tables(:ja_jp).freeze

Instance Attribute Summary

Attributes inherited from Base

#d66_sort_type, #default_cmp_op, #default_target_number, #randomizer, #reroll_dice_reroll_threshold, #round_type, #sides_implicit_d, #upper_dice_reroll_threshold

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#change_text, #check_result, command_pattern, #enable_debug, #enabled_d9?, eval, #eval, #grich_text, prefixes_pattern, register_prefix, register_prefix_from_super_class, #sort_add_dice?, #sort_barabara_dice?

Methods included from Translate

#translate

Constructor Details

#initialize(command) ⇒ DetatokoSaga

Returns a new instance of DetatokoSaga.



31
32
33
34
35
36
# File 'lib/bcdice/game_system/DetatokoSaga.rb', line 31

def initialize(command)
  super(command)

  @sort_add_dice = true
  @d66_sort_type = D66SortType::ASC
end

Class Method Details

.translate_tables(locale) ⇒ Object



213
214
215
216
217
218
219
220
# File 'lib/bcdice/game_system/DetatokoSaga.rb', line 213

def self.translate_tables(locale)
  {
    "SST" => DiceTable::Table.from_i18n("DetatokoSaga.table.SST", locale),
    "WST" => DiceTable::Table.from_i18n("DetatokoSaga.table.WST", locale),
    "SBET" => DiceTable::Table.from_i18n("DetatokoSaga.table.SBET", locale),
    "WBET" => DiceTable::Table.from_i18n("DetatokoSaga.table.WBET", locale),
  }
end

Instance Method Details

#checkJudgeValue(string) ⇒ Object

スキル判定値 xJD or xJDy or xJDy+z or xJDy-z or xJDy/z



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/bcdice/game_system/DetatokoSaga.rb', line 137

def checkJudgeValue(string)
  debug("checkJudgeValue begin string", string)

  m = %r{^(\d+)JD(\d+)?(([+-/])(\d+))?$}i.match(string)
  unless m
    return nil
  end

  skill = m[1].to_i
  flag = m[2].to_i
  operator = m[4]
  value = m[5].to_i

  result = translate("DetatokoSaga.JD.input_options", skill: skill, flag: flag)

  modifyText = getModifyText(operator, value)
  result += translate("DetatokoSaga.JD.modifier", modifier: modifyText) unless modifyText.empty?

  total, rollText = getRollResult(skill)
  result += "#{total}[#{rollText}]#{modifyText}"

  totalResult = getTotalResultValue(total, value, operator)
  result += "#{totalResult}"

  result += getCheckFlagResult(total, flag)

  return result
end

#checkRoll(string) ⇒ Object

通常判定 xDS or xDSy or xDS>=z or xDSy>=z



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/bcdice/game_system/DetatokoSaga.rb', line 52

def checkRoll(string)
  debug("checkRoll begin string", string)

  m = %r{^(\d+)DS(\d+)?(([+-/])(\d+))?(?:>=(\d+))?$}i.match(string)
  unless m
    return nil
  end

  skill = m[1].to_i
  flag = m[2].to_i
  operator = m[4]
  value = m[5].to_i
  target = m[6]&.to_i || 8

  result = translate("DetatokoSaga.DS.input_options", skill: skill, flag: flag, target: target)

  modifyText = getModifyText(operator, value)
  result += translate("DetatokoSaga.DS.modifier", modifier: modifyText) unless modifyText.empty?

  total, rollText = getRollResult(skill)

  result += "#{total}[#{rollText}]#{modifyText}"

  totalResult = getTotalResultValue(total, value, operator)
  result += "#{totalResult}"

  unless modifyText.empty?
    case operator
    when "+"
      total += value
    when "-"
      total -= value
    end
  end

  success = getSuccess(total, target)
  result += "#{success}"

  result += getCheckFlagResult(total, flag)

  return result
end

#eval_game_system_specific_command(command) ⇒ Object



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

def eval_game_system_specific_command(command)
  debug("eval_game_system_specific_command begin string", command)

  result = checkRoll(command)
  return result if result

  result = checkJudgeValue(command)
  return result if result

  debug("各種表として処理")
  return roll_tables(ALIAS[command] || command, self.class::TABLES)
end

#getCheckFlagResult(total, flag) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/bcdice/game_system/DetatokoSaga.rb', line 118

def getCheckFlagResult(total, flag)
  if total > flag
    return ""
  end

  will = getDownWill(flag)
  return translate("DetatokoSaga.less_than_flag", will: will)
end

#getDownWill(flag) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/bcdice/game_system/DetatokoSaga.rb', line 127

def getDownWill(flag)
  if flag >= 10
    return "6"
  end

  dice = @randomizer.roll_once(6)
  return "1D6->#{dice}"
end

#getModifyText(operator, value) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/bcdice/game_system/DetatokoSaga.rb', line 166

def getModifyText(operator, value)
  return '' if value == 0

  operatorText =
    case operator
    when "+"
      ""
    when "-"
      ""
    when "/"
      "÷"
    else
      return ""
    end

  return "#{operatorText}#{value}"
end

#getRollResult(skill) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/bcdice/game_system/DetatokoSaga.rb', line 95

def getRollResult(skill)
  diceCount = skill + 1
  diceCount = 3 if  skill == 0

  dice = @randomizer.roll_barabara(diceCount, 6)
  diceText = dice.join(',')

  dice = dice.sort
  dice = dice.reverse if skill != 0

  total = dice[0] + dice[1]

  return total, diceText
end

#getSuccess(check, target) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/bcdice/game_system/DetatokoSaga.rb', line 110

def getSuccess(check, target)
  if check >= target
    translate("DetatokoSaga.DS.success")
  else
    translate("DetatokoSaga.DS.failure")
  end
end

#getTotalResultValue(total, value, operator) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/bcdice/game_system/DetatokoSaga.rb', line 184

def getTotalResultValue(total, value, operator)
  case operator
  when "+"
    return "#{total}+#{value}" + translate("DetatokoSaga.total_value", total: total + value)
  when "-"
    return "#{total}-#{value}" + translate("DetatokoSaga.total_value", total: total - value)
  when "/"
    return getTotalResultValueWhenSlash(total, value)
  else
    return translate("DetatokoSaga.total_value", total: total)
  end
end

#getTotalResultValueWhenSlash(total, value) ⇒ Object



197
198
199
200
201
202
203
204
# File 'lib/bcdice/game_system/DetatokoSaga.rb', line 197

def getTotalResultValueWhenSlash(total, value)
  return translate("DetatokoSaga.division_by_zero_error") if value == 0

  quotient = ((1.0 * total) / value).ceil

  result = "#{total}÷#{value}" + translate("DetatokoSaga.total_value", total: quotient)
  return result
end