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)
  @valid_dice_types = [20, 12, 10, 8, 6, 4, 2]
end

Instance Method Details

#critical?(value1, value2, dice1, dice2) ⇒ Boolean

Returns:

  • (Boolean)


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

def critical?(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

#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
  modify_string = Regexp.last_match(4)
  difficulty = Regexp.last_match(6)

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

  modify_string ||= ''
  modify = ArithmeticEvaluator.eval(modify_string)
  difficulty = get_difficulty(difficulty)

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

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

  value1_text = "#{value1}(#{dice1})"
  value2_text = (value2 == 0 ? "" : "+#{value2}(#{dice2})")
  modify_text = get_modify_string(modify)

  base_text = get_base_text(dice1, dice2, modify, difficulty)
  output = "(#{base_text}) > #{value1_text}#{value2_text}#{modify_text}#{total}#{result}"
  return output
end

#famble?(value1, value2) ⇒ Boolean

Returns:

  • (Boolean)


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

def famble?(value1, value2)
  return (value1 == 1) && (value2 == 1)
end

#get_base_text(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 get_base_text(dice1, dice2, modify, difficulty)
  base_text = "R#{dice1}"

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

  base_text += get_modify_string(modify)

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

  return base_text
end

#get_dice_type(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 get_dice_type(dice1, dice2)
  debug('get_dice_type begin')

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

  if valid_dice?(dice1, dice2)
    return dice1, dice2
  end

  dice_base = dice1

  dice1 = dice_base / 10
  dice2 = dice_base % 10

  if valid_dice?(dice1, dice2)
    return dice1, dice2
  end

  dice1 = dice_base / 100
  dice2 = dice_base % 100

  if valid_dice?(dice1, dice2)
    return dice1, dice2
  end

  if valid_dice_one?(dice_base)
    return dice_base, 0
  end

  return 0, 0
end

#get_difficulty(difficulty) ⇒ Object



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

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

  return difficulty
end

#get_modify_string(modify) ⇒ Object



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

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

  return ''
end

#get_result_text(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 get_result_text(value1, value2, dice1, dice2, difficulty, total)
  if famble?(value1, value2)
    return "1ゾロ【1ゾロポイント+1】"
  end

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

  if difficulty.nil?
    return ''
  end

  if total >= difficulty
    return "成功"
  end

  return "失敗"
end

#get_roll_value(dice) ⇒ Object



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

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

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

#valid_dice?(dice1, dice2) ⇒ Boolean

Returns:

  • (Boolean)


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

def valid_dice?(dice1, dice2)
  return valid_dice_one?(dice1) &&
         valid_dice_one?(dice2)
end

#valid_dice_one?(dice) ⇒ Boolean

Returns:

  • (Boolean)


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

def valid_dice_one?(dice)
  @valid_dice_types.include?(dice)
end