Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Year zero engine dicebotの修正と機能強化 #233

Merged
merged 5 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 99 additions & 32 deletions src/diceBot/YearZeroEngine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,132 @@ class YearZeroEngine < DiceBot
ID = 'YearZeroEngine'

# ゲームシステム名
NAME = 'イヤーゼロエンジン'
NAME = 'YearZeroEngine'

# ゲームシステム名の読みがな
SORT_KEY = 'いやあせろえんしん'

# ダイスボットの使い方
HELP_MESSAGE = <<INFO_MESSAGE_TEXT
・判定コマンド(YZEx+x+x)
YZE(能力ダイス数)+(技能ダイス数)+(修正ダイス数) # YearZeroEngine(TALES FROM THE LOOP等)の判定(6を数える)
※ 技能と修正ダイス数は省略可能
・判定コマンド(nYZEx+x+x)
(難易度)YZE(能力ダイス数)+(技能ダイス数)+(アイテムダイス数) # (6のみを数える)

・判定コマンド(nMYZx+x+x)
(難易度)MYZ(能力ダイス数)+(技能ダイス数)+(アイテムダイス数) # (1と6を数え、プッシュ可能数を表示)

※ 難易度と技能、アイテムダイス数は省略可能
INFO_MESSAGE_TEXT

ABILITY_INDEX = 2 # 能力値ダイスのインデックス
SKILL_INDEX = 4 # 技能値ダイスのインデックス
MODIFIED_INDEX = 6 # 修正ダイスのインデックス
DIFFICULTY_INDEX = 1 # 難易度のインデックス
COMMAND_TYPE_INDEX = 2 # コマンドタイプのインデックス
ABILITY_INDEX = 3 # 能力値ダイスのインデックス
SKILL_INDEX = 5 # 技能値ダイスのインデックス
MODIFIED_INDEX = 7 # 修正ダイスのインデックス

setPrefixes(['YZE.*'])
setPrefixes(['(\d+)?(YZE|MYZ).*'])

def rollDiceCommand(command)
m = /\A(YZE)(\d+)(\+(\d+))?(\+(\d+))?/.match(command)
m = /\A(\d+)?(YZE|MYZ)(\d+)(\+(\d+))?(\+(\d+))?/.match(command)
unless m
return ''
end

successDice = 0
matchText = m[ABILITY_INDEX]
abilityDiceText, successDice = makeDiceRoll(matchText, successDice)
dice_result_info = {:total_success_dice => 0, :total_botch_dice => 0, :base_botch_dice => 0, :skill_botch_dice => 0, :gear_botch_dice => 0, :push_dice => 0, :difficulty => 0}
ysakasin marked this conversation as resolved.
Show resolved Hide resolved

dice_result_info[:difficulty] = m[DIFFICULTY_INDEX].to_i

command_type = m[COMMAND_TYPE_INDEX]

total_success_dice = 0

dice_pool = m[ABILITY_INDEX].to_i
ability_dice_text, success_dice, botch_dice = make_dice_roll(dice_pool)

dice_result_info[:total_success_dice] += success_dice
dice_result_info[:total_botch_dice] += botch_dice
dice_result_info[:base_botch_dice] += botch_dice # 能力ダメージ
dice_result_info[:push_dice] += (dice_pool - (success_dice + botch_dice))

dice_count_text = "(#{dice_pool}D6)"
dice_text = ability_dice_text

if m[SKILL_INDEX]
dice_pool = m[SKILL_INDEX].to_i
skill_dice_text, success_dice, botch_dice = make_dice_roll(dice_pool)

dice_result_info[:total_success_dice] += success_dice
dice_result_info[:total_botch_dice] += botch_dice
dice_result_info[:skill_botch_dice] += botch_dice # 技能ダイスの1はpushで振り直し可能
dice_result_info[:push_dice] += (dice_pool - success_dice) # 技能ダイスのみ1を含む

dice_count_text += "+(#{dice_pool}D6)"
dice_text += "+#{skill_dice_text}"
end

if m[MODIFIED_INDEX]
dice_pool = m[MODIFIED_INDEX].to_i
modified_dice_text, success_dice, botch_dice = make_dice_roll(dice_pool)

diceCountText = "(#{matchText}D6)"
diceText = abilityDiceText
dice_result_info[:total_success_dice] += success_dice
dice_result_info[:total_botch_dice] += botch_dice
dice_result_info[:gear_botch_dice] += botch_dice # ギアダメージ
dice_result_info[:push_dice] += (dice_pool - (success_dice + botch_dice))

matchText = m[SKILL_INDEX]
if matchText
skillDiceText, successDice = makeDiceRoll(matchText, successDice)
dice_count_text += "+(#{dice_pool}D6)"
dice_text += "+#{modified_dice_text}"
end
return make_result_text(command_type, dice_count_text, dice_text, dice_result_info)
end

diceCountText += "+(#{matchText}D6)"
diceText += "+#{skillDiceText}"
def make_result_text(command_type, dice_count_text, dice_text, dice_result_info)
if command_type == 'YZE'
return make_result_with_yze(dice_count_text, dice_text, dice_result_info)
elsif command_type == 'MYZ'
return make_result_with_myz(dice_count_text, dice_text, dice_result_info)
end

matchText = m[MODIFIED_INDEX]
if matchText
modifiedDiceText, successDice = makeDiceRoll(matchText, successDice)
return 'Error' # 到達しないはず
end

def make_result_with_yze(dice_count_text, dice_text, dice_result_info)
total_success_dice = dice_result_info[:total_success_dice]
difficulty = dice_result_info[:difficulty]

diceCountText += "+(#{matchText}D6)"
diceText += "+#{modifiedDiceText}"
result_text = "#{dice_count_text} > #{dice_text} 成功数:#{total_success_dice}"
if difficulty > 0
if total_success_dice >= difficulty
result_text = "#{result_text} 難易度=#{difficulty}:判定成功!"
else
result_text = "#{result_text} 難易度=#{difficulty}:判定失敗!"
end
end
return result_text
end

def make_result_with_myz(dice_count_text, dice_text, dice_result_info)
base_botch_dice = dice_result_info[:base_botch_dice]
skill_botch_dice = dice_result_info[:skill_botch_dice]
gear_botch_dice = dice_result_info[:gear_botch_dice]
push_dice = dice_result_info[:push_dice]

return "#{diceCountText} > #{diceText} 成功数:#{successDice}"
result_text = make_result_with_yze(dice_count_text, dice_text, dice_result_info)

return "#{result_text}\n出目1:[能力:#{base_botch_dice},技能:#{skill_botch_dice},アイテム:#{gear_botch_dice}) プッシュ可能=#{push_dice}ダイス"
end

def makeDiceRoll(matchText, successDice)
dice = matchText.to_i
_, diceText, = roll(dice, 6)
def make_dice_roll(dice_pool)
botch_dice = 0
success_dice = 0

_, dice_text, = roll(dice_pool, 6)

diceText.split(',').each do |takeDice|
if takeDice == "6"
successDice += 1
dice_text.split(',').each do |take_dice|
if take_dice == "6"
success_dice += 1
elsif take_dice == "1"
botch_dice += 1
end
end
return "[#{diceText}]", successDice
return "[#{dice_text}]", success_dice, botch_dice
end
end
Loading