Class: BCDice::GameSystem::Ryutama

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

Constant Summary collapse

ID =

ゲームシステムの識別子

'Ryutama'
NAME =

ゲームシステム名

'りゅうたま'
SORT_KEY =

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

'りゆうたま'
HELP_MESSAGE =

ダイスボットの使い方

<<~INFO_MESSAGE_TEXT
  ・判定
   Rx,y>=t(x,y:使用する能力値、t:目標値)
   1ゾロ、クリティカルも含めて判定結果を表示します
   能力値1つでの判定は Rx>=t で行えます
  例)R8,6>=13
INFO_MESSAGE_TEXT

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

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) ⇒ Ryutama

Returns a new instance of Ryutama.



26
27
28
29
# File 'lib/bcdice/game_system/Ryutama.rb', line 26

def initialize(command)
  super(command)
  @validDiceTypes = [20, 12, 10, 8, 6, 4, 2]
end

Instance Method Details

#eval_game_system_specific_command(command) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bcdice/game_system/Ryutama.rb', line 31

def eval_game_system_specific_command(command)
  debug('eval_game_system_specific_command begin')

  unless command =~ /^R(\d+)(,(\d+))?([+\-\d]+)?(>=(\d+))?/
    debug('unmatched!')
    return ''
  end
  debug('matched')

  dice1 = Regexp.last_match(1).to_i
  dice2 = Regexp.last_match(3).to_i
  modifyString = Regexp.last_match(4)
  difficulty = Regexp.last_match(6)

  dice1, dice2 = getDiceType(dice1, dice2)
  if dice1 == 0
    return ''
  end

  modifyString ||= ''
  modify = ArithmeticEvaluator.eval(modifyString)
  difficulty = getDiffculty(difficulty)

  value1 = getRollValue(dice1)
  value2 = getRollValue(dice2)
  total = value1 + value2 + modify

  result = getResultText(value1, value2, dice1, dice2, difficulty, total)
  unless result.empty?
    result = "#{result}"
  end

  value1Text = "#{value1}(#{dice1})"
  value2Text = (value2 == 0 ? "" : "+#{value2}(#{dice2})")
  modifyText = getModifyString(modify)

  baseText = getBaseText(dice1, dice2, modify, difficulty)
  output = "(#{baseText}) > #{value1Text}#{value2Text}#{modifyText}#{total}#{result}"
  return output
end

#getBaseText(dice1, dice2, modify, difficulty) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/bcdice/game_system/Ryutama.rb', line 172

def getBaseText(dice1, dice2, modify, difficulty)
  baseText = "R#{dice1}"

  if dice2 != 0
    baseText += ",#{dice2}"
  end

  baseText += getModifyString(modify)

  unless difficulty.nil?
    baseText += ">=#{difficulty}"
  end

  return baseText
end

#getDiceType(dice1, dice2) ⇒ Object



72
73
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
101
102
103
104
105
106
107
108
# File 'lib/bcdice/game_system/Ryutama.rb', line 72

def getDiceType(dice1, dice2)
  debug('getDiceType begin')

  if dice2 != 0
    if isValidDiceOne(dice1)
      return dice1, dice2
    else
      return 0, 0
    end
  end

  if isValidDice(dice1, dice2)
    return dice1, dice2
  end

  diceBase = dice1

  dice1 = diceBase / 10
  dice2 = diceBase % 10

  if isValidDice(dice1, dice2)
    return dice1, dice2
  end

  dice1 = diceBase / 100
  dice2 = diceBase % 100

  if isValidDice(dice1, dice2)
    return dice1, dice2
  end

  if isValidDiceOne(diceBase)
    return diceBase, 0
  end

  return 0, 0
end

#getDiffculty(difficulty) ⇒ Object



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

def getDiffculty(difficulty)
  unless difficulty.nil?
    difficulty = difficulty.to_i
  end

  return difficulty
end

#getModifyString(modify) ⇒ Object



188
189
190
191
192
193
194
195
196
# File 'lib/bcdice/game_system/Ryutama.rb', line 188

def getModifyString(modify)
  if modify > 0
    return "+" + modify.to_s
  elsif modify < 0
    return modify.to_s
  end

  return ''
end

#getResultText(value1, value2, dice1, dice2, difficulty, total) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/bcdice/game_system/Ryutama.rb', line 134

def getResultText(value1, value2, dice1, dice2, difficulty, total)
  if isFamble(value1, value2)
    return "1ゾロ【1ゾロポイント+1】"
  end

  if isCritical(value1, value2, dice1, dice2)
    return "クリティカル成功"
  end

  if difficulty.nil?
    return ''
  end

  if total >= difficulty
    return "成功"
  end

  return "失敗"
end

#getRollValue(dice) ⇒ Object



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

def getRollValue(dice)
  return 0 if dice == 0

  value = @randomizer.roll_once(dice)
  return value
end

#isCritical(value1, value2, dice1, dice2) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/bcdice/game_system/Ryutama.rb', line 158

def isCritical(value1, value2, dice1, dice2)
  return false if value2 == 0

  if (value1 == 6) && (value2 == 6)
    return true
  end

  if (value1 == dice1) && (value2 == dice2)
    return true
  end

  return false
end

#isFamble(value1, value2) ⇒ Object



154
155
156
# File 'lib/bcdice/game_system/Ryutama.rb', line 154

def isFamble(value1, value2)
  return (value1 == 1) && (value2 == 1)
end

#isValidDice(dice1, dice2) ⇒ Object



110
111
112
113
# File 'lib/bcdice/game_system/Ryutama.rb', line 110

def isValidDice(dice1, dice2)
  return isValidDiceOne(dice1) &&
         isValidDiceOne(dice2)
end

#isValidDiceOne(dice) ⇒ Object



115
116
117
# File 'lib/bcdice/game_system/Ryutama.rb', line 115

def isValidDiceOne(dice)
  @validDiceTypes.include?(dice)
end